This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

A0A1……C2C3是干嘛用的?



        下面这段代码来自TMDSHVMTRPFCKIT的HVACI_Sensored。每次看到这段代码我就略过,突然想问一下,这段代码是干嘛用的啊?

         我看到C1控制了控制卡上面3个LED的状态,我猜测这段代码实现了一个类似操作系统的功能,对不对?这段代码还涉及到串口通讯,是不是电机控制的上位机(GUI)对应的DSP程序也在这里面?

void A0(void)
{
// loop rate synchronizer for A-tasks
if(CpuTimer0Regs.TCR.bit.TIF == 1)
{
CpuTimer0Regs.TCR.bit.TIF = 1; // clear flag

//-----------------------------------------------------------
(*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)
{
// loop rate synchronizer for B-tasks
if(CpuTimer1Regs.TCR.bit.TIF == 1)
{
CpuTimer1Regs.TCR.bit.TIF = 1; // clear flag

//-----------------------------------------------------------
(*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)
{
// loop rate synchronizer for C-tasks
if(CpuTimer2Regs.TCR.bit.TIF == 1)
{
CpuTimer2Regs.TCR.bit.TIF = 1; // clear flag

//-----------------------------------------------------------
(*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)
//--------------------------------------------------------
{

//-------------------
//the next time CpuTimer0 'counter' reaches Period value go to A2
A_Task_Ptr = &A2;
//-------------------
}

……

//-----------------------------------------
void C3(void) // SPARE
//-----------------------------------------
{

//-----------------
//the next time CpuTimer2 'counter' reaches Period value go to C1
C_Task_Ptr = &C1;
//-----------------
}