【正文】
typedef signed char INT16S。 /*有符號16位整數(shù)*/typedef unsigned char INT32U。 /*無符號32位整數(shù)*/typedef signed char INT32S。 /*有符號32位整數(shù)*/typedef float FP32。 /*單精度浮點數(shù)(32位長度)*/typedef double FP64。 /*雙精度浮點數(shù)(64位長度)*/typedef unsigned int OS_STK。 /*堆棧入口寬度為16位*/ 與處理器相關(guān)的代碼define OS_ENTER_CRITCAL() /*禁止中斷*/define OS_EXIT_CRITICAL() /*允許中斷*/define OS_STK_GROWTH 1 /*定義堆棧的增長方向:1=向下,0=向上*/define OS_TASK_SWOSStartHighRdy()的原型如程序清單 :void OSStartHighRdy (void){Call a userdefined OSTaskSwHook ()。Stack Pointer recovery tasks:Stack pointer = OSTCBHighRdyOSTCBStkPtr。OSRunning = TRUE。New task39。s stack to restore all processor registers。Return from interrupt instruction execution。} OSCtxSw()的原型程序清單:void OSCtxSw(void){Save processor registers。The current task39。s stack pointer is saved to the current task OS_TCB in:OSTCBCurOSTCBStkPtr = Stack pointer。Call a userdefined OSTaskSwHook ()。OSTCBCur = OSTCBHighRdy。OSPrioCur = OSPrioHighRdy。Get tasks need to restore the stack pointer:Stack pointer = OSTCBHighRdy OSTCBStkPtr。All processor registers from the new task39。s stack to restore it。Execution of an interrupt return instruction。}OSIntCtxSw()的原型程序清單:void OSIntCtxSw(void){Adjust the stack pointer to remove the call:OSIntExit (),OSIntCtxSw () onto the stack during the extra content。The current task stack pointer saved to the current task OS_TCB in:OSTCBCurOSTCBStkPtr = stack pointer。Call a userdefined OSTaskSwHook ()。OSTCBCur = OSTCBHighRdy。OSPrioCur = OSPrioHighRdy。Get tasks need to restore the stack pointer:Stack Pointer = OSTCBHighRdy OSTCBStkPtr。All processor registers from the new task39。s stack to restore it。Execution of an interrupt return instruction。}OSTickISR()程序清單 L void main(void){ OSInit ()。 / * initialize μC / OSII * // * Application initialization code ... * // * Call OSTaskCreate () to establish at least one task * /Allows the clock tick interrupt。 / * Do not allow here!!! * /OSStart ()。 / * begin multitask scheduling * /}程序清單 L void OSTickISR(void){Save processor registers。Call OSIntEnter () or directly to the OSIntNesting plus 1。Call OSTimeTick ()。Call OSIntExit ()。Restore processor registers。Execution of an interrupt return instruction。}移植測試程序:void OSTaskIdleHook (void){static i = 0 。if (i %300000 = = 0) /* Each light a LED light 30,000 times */{sysUtilsLightLed (LED_ ALL,FALSE) 。 /* Turn off all LED lights */sysUtilsLightLed (i %3+1,TRUE) 。 /* An LED light cycle */}i + + 。ret urn 。}