¹ØÓÚucosiiÈÎÎñÕ»µÄ³õʼ»¯
ÈÎÎñÕ»µÄ³õʼ»¯Æäʵ¾ÍÊÇΪCPU¼Ä´æÆ÷»¹Óи¡µãµ¥Ôª£¨Èç¹ûÓõ½µÄ»°£©¡°Ô¤ÁôλÖá±£¬¶øÇÒËûÃǵÄλÖÃÖ®¼äµÄÏȺó˳Ðò
Òª·ûºÏPendSV_HandlerÖжÔCPU¼Ä´æÆ÷ºÍ¸¡µãµ¥Ôª¼Ä´æÆ÷±£´æµÄ˳Ðò£¬ÒÔ¼°ÖжÏÏìӦʱӲ¼þ×Ô¶¯±£´æµÄCPU¼Ä´æÆ÷µÄ˳ÐòÒª
Çó¡£ÏêϸÄÚÈݿɲο¼ÁíһƪÎÄÕÂucosiiÈÎÎñÇл»¡£ÏÂÃæÏÈÉÏÈÎÎñÕ»³õʼ»¯µÄÔ´Âë¡£
OS_STK *OSTaskStkInit (void (*task)(void *p_arg), void *p_arg, OS_STK *ptos, INT16U opt) { OS_STK *stk; (void)opt; /* 'opt' is not used, prevent warning */ stk = ptos; /* Load stack pointer */ #if (__FPU_PRESENT==1)&&(__FPU_USED==1) *(--stk) = (INT32U)0x00000000L; //No Name Register *(--stk) = (INT32U)0x00001000L; //FPSCR *(--stk) = (INT32U)0x00000015L; //s15 *(--stk) = (INT32U)0x00000014L; //s14 *(--stk) = (INT32U)0x00000013L; //s13 *(--stk) = (INT32U)0x00000012L; //s12 *(--stk) = (INT32U)0x00000011L; //s11 *(--stk) = (INT32U)0x00000010L; //s10 *(--stk) = (INT32U)0x00000009L; //s9 *(--stk) = (INT32U)0x00000008L; //s8 *(--stk) = (INT32U)0x00000007L; //s7 *(--stk) = (INT32U)0x00000006L; //s6 *(--stk) = (INT32U)0x00000005L; //s5 *(--stk) = (INT32U)0x00000004L; //s4 *(--stk) = (INT32U)0x00000003L; //s3 *(--stk) = (INT32U)0x00000002L; //s2 *(--stk) = (INT32U)0x00000001L; //s1 *(--stk) = (INT32U)0x00000000L; //s0 #endif /* Registers stacked as if auto-saved on exception */ *(stk) = (INT32U)0x01000000L; /* xPSR */ *(--stk) = (INT32U)task; /* Entry Point */ *(--stk) = (INT32U)OS_TaskReturn; /* R14 (LR) (init value will cause fault if ever used)*/ *(--stk) = (INT32U)0x12121212L; /* R12 */ *(--stk) = (INT32U)0x03030303L; /* R3 */ *(--stk) = (INT32U)0x02020202L; /* R2 */ *(--stk) = (INT32U)0x01010101L; /* R1 */ *(--stk) = (INT32U)p_arg; /* R0 : argument */ #if (__FPU_PRESENT==1)&&(__FPU_USED==1) *(--stk) = (INT32U)0x00000031L; //s31 *(--stk) = (INT32U)0x00000030L; //s30 *(--stk) = (INT32U)0x00000029L; //s29 *(--stk) = (INT32U)0x00000028L; //s28 *(--stk) = (INT32U)0x00000027L; //s27 *(--stk) = (INT32U)0x00000026L; //s26 *(--stk) = (INT32U)0x00000025L; //s25 *(--stk) = (INT32U)0x00000024L; //s24 *(--stk) = (INT32U)0x00000023L; //s23 *(--stk) = (INT32U)0x00000022L; //s22 *(--stk) = (INT32U)0x00000021L; //s21 *(--stk) = (INT32U)0x00000020L; //s20 *(--stk) = (INT32U)0x00000019L; //s19 *(--stk) = (INT32U)0x00000018L; //s18 *(--stk) = (INT32U)0x00000017L; //s17 *(--stk) = (INT32U)0x00000016L; //s16 #endif /* Remaining registers saved on process stack */ *(--stk) = (INT32U)0x11111111L; /* R11 */ *(--stk) = (INT32U)0x10101010L; /* R10 */ *(--stk) = (INT32U)0x09090909L; /* R9 */ *(--stk) = (INT32U)0x08080808L; /* R8 */ *(--stk) = (INT32U)0x07070707L; /* R7 */ *(--stk) = (INT32U)0x06060606L; /* R6 */ *(--stk) = (INT32U)0x05050505L; /* R5 */ *(--stk) = (INT32U)0x04040404L; /* R4 */ return (stk); } |
Ê×ÏÈÊÇ´ÓÎÒÃÇ´´½¨ÈÎÎñÊǸø¶¨µÄÕ»¶¥¿ªÊ¼½øÐÐ--stk£¬¸ù¾ÝÊÇ·ñʹÓø¡µãµ¥ÔªÎªÑ¡ÔñÊÇ·ñΪ¸¡µãµ¥Ôª¼Ä´æÆ÷¡°Ô¤ÁôÖᱡ£È»ºó¾Íµ½ÁËÖжÏÏìӦʱ£¨Ò²¾ÍÊÇÏìÓ¦PendSVÖжϣ©ÓÉÓ²¼þ×Ô¶¯±£´æµÄCPU¼Ä´æÆ÷ÁË£¬×¢ÒâÕâÀïµÄλÖ㬽ô½Ó×ÅÏÂÃæÊÇ16¸ö¸¡µãµ¥Ôª¼Ä´æÆ÷£¨Èç¹ûÓõ½¸¡µãµ¥ÔªµÄ»°£©£¬È»ºóÊÇ{r4-r11}¡£Õâ¸ÕºÃºÍPendSV_HandlerÖжÔCPU¼Ä´æÆ÷ºÍ¸¡µãµ¥Ôª¼Ä´æÆ÷±£´æµÄ˳ÐòÒ»Ñù¡£¶øÔÚÓ²¼þ×Ô¶¯±£´æµÄ¼Ä´æÆ÷λÖÃÉÏ£¬ÓÐ*(--stk) = (INT32U)task;ºÍ*(--stk) = (INT32U)p_arg;ËûÃǶÔÓ¦Ó²¼þ×Ô¶¯±£´æ£¨»òÕß³öÕ»£©ÐòÁÐÖеÄPCºÍR0¼Ä´æÆ÷¡£´ó¼Ò¿ÉÒÔ¿´µ½ÕâÀïµÄtaskºÍp_arg¾ÍÊÇÎÒÃÇÔÚ´´½¨ÈÎÎñµÄʱºò¸ø¶¨µÄÈÎÎñº¯ÊýÃû»òÕß˵ÊÇÈÎÎñº¯ÊýµÄÈë¿ÚµØÖ·£¬»¹ÓвÎÊýÁбíµÄÊ×µØÖ·¡£ÕâÁ½´¦µÄ³õʼ»¯ÊÇʹµÃucosiiÔÚÈÎÎñÇл»µÄʱºòÄÜÕÒµ½ÎÒÃÇ´´½¨µÄÈÎÎñÒÔ¼°ÈÎÎñ²ÎÊýµÄ¹Ø¼ü¡£