解釋,源碼,
解釋
因為UC/OS-II 是多任務,而且為每個任務開闢一個堆疊,所以單執行緒的DOS環境應該保存,在退出µC/OS-II 程式時返回到DOS。調用PC_DOSSaveReturn()可以保存當前DOS環境.
源碼
ucos 中 DOSSaveReturn 源碼:
void PC_DOSSaveReturn (void)
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
PC_ExitFlag = FALSE; /* Indicate that we are not exiting yet! */
OSTickDOSCtr = 1; /* Initialize the DOS tick counter */
PC_TickISR = PC_VectGet(VECT_TICK); /* Get MS-DOS's tick vector */
PC_VectSet(VECT_DOS_CHAIN, PC_TickISR); /* Store MS-DOS's tick to chain */
setjmp(PC_JumpBuf); /* Capture where we are in DOS */
if (PC_ExitFlag == TRUE) { /* See if we are exiting back to DOS */
OS_ENTER_CRITICAL();
PC_SetTickRate(18); /* Restore tick rate to 18.2 Hz */
OS_EXIT_CRITICAL();
PC_VectSet(VECT_TICK, PC_TickISR); /* Restore DOS's tick vector */
PC_DispClrScr(DISP_FGND_WHITE + DISP_BGND_BLACK); /* Clear the display */
exit(0); /* Return to DOS */
}
}