并没有真正触发CPU中断,只是利用定时器的计数匹配标志位来判断是否已经计数到设定时间,来定时调度一个任务,举个例子
void A0(void)
[
if(CpuTimer0Regs.TCR.bit.TIF == 1)
[
CpuTimer0Regs.TCR.bit.TIF = 1;
//-----------------------------------------------------------
(*A_Task_Ptr)(); // jump to an A Task (A1,A2,A3,...)
//-----------------------------------------------------------
VTimer0[0]++; // virtual timer 0, instance 0 (spare)
SerialCommsTimer++;
]
Alpha_State_Ptr = &B0; // Comment out to allow only A tasks
]
void B0(void)
[
if(CpuTimer1Regs.TCR.bit.TIF == 1)
[
CpuTimer1Regs.TCR.bit.TIF = 1;
//-----------------------------------------------------------
(*B_Task_Ptr)(); // jump to a B Task (B1,B2,B3,...)
//-----------------------------------------------------------
VTimer1[0]++; // virtual timer 1, instance 0 (spare)
]
Alpha_State_Ptr = &C0; // Allow C state tasks
]
void C0(void)
[
if(CpuTimer2Regs.TCR.bit.TIF == 1)
[
CpuTimer2Regs.TCR.bit.TIF = 1;
//-----------------------------------------------------------
(*C_Task_Ptr)(); // jump to a C Task (C1,C2,C3,...)
//-----------------------------------------------------------
VTimer2[0]++; //virtual timer 2, instance 0 (spare)
]
Alpha_State_Ptr = &A0; // Back to State A0
]
//=================================================================================
// A - TASKS (executed in every 1 msec)
//=================================================================================
//--------------------------------------------------------
void A1(void) // SPARE (not used)
[
if (Disable==1)
[
EALLOW;
EPwm1Regs.TZFRC.bit.OST=1;
EPwm2Regs.TZFRC.bit.OST=1;
EPwm3Regs.TZFRC.bit.OST=1;
EPwm4Regs.TZFRC.bit.OST=1;
EDIS;
]
A_Task_Ptr = &A2;
]
void A2(void) // SPARE (not used)
[ //the next time CpuTimer0 'counter' reaches Period value go to A3
A_Task_Ptr = &A3;
]
void A3(void) // SPARE (not used)
[ //the next time CpuTimer0 'counter' reaches Period value go to A1
A_Task_Ptr = &A1;
]
//=================================================================================
// B - TASKS (executed in every 5 msec)
//=================================================================================
void B1(void) // Toggle GPIO-00
[ //the next time CpuTimer1 'counter' reaches Period value go to B2
B_Task_Ptr = &B2;
]
void B2(void) // SPARE
[//the next time CpuTimer1 'counter' reaches Period value go to B3
B_Task_Ptr = &B3;
]
void B3(void) // SPARE
[ //the next time CpuTimer1 'counter' reaches Period value go to B1
B_Task_Ptr = &B1;
//-----------------
]
//=================================================================================
// C - TASKS (executed in every 50 msec)
//=================================================================================
void C1(void) // Toggle GPIO-34
[
GpioDataRegs.GPBTOGGLE.bit.GPIO34 = 1; // Blink LED
//-----------------
//the next time CpuTimer2 'counter' reaches Period value go to C2
C_Task_Ptr = &C2;
]
void C2(void) // SPARE
[ //the next time CpuTimer2 'counter' reaches Period value go to C3
C_Task_Ptr = &C3;
]
void C3(void) // SPARE
[ //the next time CpuTimer2 'counter' reaches Period value go to C1
C_Task_Ptr = &C1;
]
红色框部分是CPUtimer0计时到你设定时间,就会CpuTimer1Regs.TCR.bit.TIF 标志位等于1,所以任务A0就会判断通过,来运行,然后运行完,会把指针给到任务B,这样CPUtimer1定时到时间,如黄色部分,就会运行B0任务,然后再把指针扔个C任务,这样来回的调度。可以理解为一个小操作系统
A0任务下会有子任务A1,A2,A3。B C也同样。