Hello to all,
I'm currently programming a real time scheduler (RTOS) and for each task that allocates a static memory. I need to configure the stack pointer and the program counter to go back to where my program stopped and continue from that point. But I don't know how to do this with the TMS320F28379D, and I don't know the Assembler language. I have an example that works perfectly on the AVR microcontroller that I will attach here. I am really new in embedded and real time systems. The TCB (Task Control Block) contains a pointer to the stack and a variable for the status register. To make me understand better , here are my questions:
- A context switch for the task requires the entire execution context to saved, how can i implement this?
- How built a atomic operation section in c with code composer studio? The Atomic section is used to create an uninterrupted section of the code.
I tried to look at how FreeRtos did this but I think the code is a bit too complicated for me to understand. That's why I'm asking you if anyone has already done it or knows how to make it work more easily according to the attached template. Any help will be welcome.
Thank for support
typedef struct TCBlock {
uint8_t task_id;
State state;
Priority priority;
uint8_t sreg;
uint8_t * sp;
uint8_t stack[STACK_SIZE];
} TCBlock;
#define stack_push(r) asm volatile("push r"#r)
#define stack_pop(r) asm volatile("pop r"#r)
ISR(TIMER0_OVF_vect) __attribute__ ((naked, hot));
ISR(TIMER0_OVF_vect) {
stack_push(31);
stack_push(30);
stack_push(29);
stack_push(28);
stack_push(27);
stack_push(26);
stack_push(25);
stack_push(24);
stack_push(23);
stack_push(22);
stack_push(21);
stack_push(20);
stack_push(19);
stack_push(18);
stack_push(17);
stack_push(16);
stack_push(15);
stack_push(14);
stack_push(13);
stack_push(12);
stack_push(11);
stack_push(10);
stack_push( 9);
stack_push( 8);
stack_push( 7);
stack_push( 6);
stack_push( 5);
stack_push( 4);
stack_push( 3);
stack_push( 2);
stack_push( 1);
stack_push( 0);
taskset[task_id].sreg = SREG;
taskset[task_id].sp = (unsigned char*) SP;
//code for Dispatscher
SREG = taskset[task_id].sreg;
SP = (uint16_t)taskset[task_id].sp;
stack_pop( 0);
stack_pop( 1);
stack_pop( 2);
stack_pop( 3);
stack_pop( 4);
stack_pop( 5);
stack_pop( 6);
stack_pop( 7);
stack_pop( 8);
stack_pop( 9);
stack_pop(10);
stack_pop(11);
stack_pop(12);
stack_pop(13);
stack_pop(14);
stack_pop(15);
stack_pop(16);
stack_pop(17);
stack_pop(18);
stack_pop(19);
stack_pop(20);
stack_pop(21);
stack_pop(22);
stack_pop(23);
stack_pop(24);
stack_pop(25);
stack_pop(26);
stack_pop(27);
stack_pop(28);
stack_pop(29);
stack_pop(30);
stack_pop(31);
}
best regard
cabrel