I'm very new to embedded systems programming and learning about scheduling.
I am getting a Trigger A occurred in the command window of the debugger when I
hit RUN. When I step through the code it seems to reset? at asm cli at the end
of the code.
Please let me know if you all have any ideas.
/*
Started with Valvano Fixed Priority Scheduler. System
should light two LEDs alternately every 500 ms.
Program exits with "Trigger A occured" in command window
of debugger.
-----------------*/
#include /* common defines and macros */
#include /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12c128"
void Task1(void){
DDRT = 0xFF;
PUCR = 0x02;
for(;;)
{
PTT_PTT6= 1;
PTT_PTT7= 0;
}
} //end task1
void Task2(void){ //non real time
DDRT = 0xFF;
PUCR = 0x02;
for(;;)
{
PTT_PTT6= 0;
PTT_PTT7= 1;
}
} //end task2
struct TCB{
unsigned char *StackPt; //Stack Pointer
unsigned char MoreStack[91];//100 bytes if stack
unsigned char InitialReg[7];//initial CCR,B,A,X,Y
void (*InitialPC)(void);
};
typedef struct TCB TCBType;
TCBType *RunPt;
#define TheTask1 &sys[0] //real time
#define TheTask2 &sys[1] //non real time?
TCBType sys[2]={
{ TheTask1.InitialReg[0],{ 0},{0x40,0,0,0,0,0,0},Task1},
{ TheTask2.InitialReg[0],{ 0},{0x40,0,0,0,0,0,0},Task2}
};
struct Node{
struct Node *Next;
TCBType *ThreadPt;
unsigned short TimeSlice;
};
typedef struct Node NodeType;
NodeType *NodePt;
NodeType Schedule[2]={
{ &Schedule[1], TheTask1, 500},
{ &Schedule[0], TheTask2, 500}
};
void OS_Sleep(void){ //all this does is run non real time task
asm swi
}
#pragma CODE_SEG __SHORT_SEG NON_BANKED
interrupt 4 void swiISR(void){
asm ldx RunPt //cooperative multitasking
asm sts 0,X //thread goes to sleep when it's done
RunPt = TheTask2; //none real time thread
asm ldx RunPt
asm lds 0,x
}
#pragma CODE_SEG DEFAULT
#pragma CODE_SEG __SHORT_SEG NON_BANKED
interrupt 11 void threadSwitchISR(void){
asm ldx RunPt
asm sts 0,x
NodePt = NodePt->Next;
RunPt = NodePt->ThreadPt;
TC3 = TC3+NodePt->TimeSlice;
TFLG1 = 0x08;
asm ldx RunPt
asm lds 0,x
}
#pragma CODE_SEG DEFAULT
void main(void) {
NodePt = &Schedule[0];
RunPt = NodePt->ThreadPt;
TIOS |= 0x08;
TSCR1 = 0x80;
TSCR2 = 0x02;
TIE |= 0x08;
TC3 = TCNT+NodePt->TimeSlice;
TFLG1 = 0x08;
asm ldx RunPt
asm lds 0,x
asm rti
}