????д???????????????
???????????? ???????[ 2013/8/14 11:30:19 ] ????????
????OSCurTCB??OSNewTCB??????????????????????????е?????????????
??????????????????????????????δ???????????????????????????????????CPU???????????????????????????????????
??????????CPU????γ???????????????Щ????????????????????????????????????ο???cortexM3????????????????????????
??????????c????д????????????????????λ?????OS_CPU.c?У????????????????????OS_CPU_A.asm????????OS_CPU.c??OS_TYPE.h????????????????????????
????OS_STK???????int32?????stm32?????????32λ??????????????????????????????????????????????????????????
OS_STK *OSTaskStkInit (void (*task)??OS_STK *ptos)
{
OS_STK *stk;
stk = ptos; /* get stack point */
*(stk) = (uint32)0x01000000L; /* xPSR */
*(--stk) = (uint32)task; /* Entry Point */
*(--stk) = (uint32)0xFFFFFFFEL; /* R14 (LR) */
*(--stk) = (uint32)0x12121212L; /* R12 */
*(--stk) = (uint32)0x03030303L; /* R3 */
*(--stk) = (uint32)0x02020202L; /* R2 */
*(--stk) = (uint32)0x01010101L; /* R1 */
*(--stk) = (uint32)0; /* R0 : argument */
/* Remaining registers */
*(--stk) = (uint32)0x11111111L; /* R11 */
*(--stk) = (uint32)0x10101010L; /* R10 */
*(--stk) = (uint32)0x09090909L; /* R9 */
*(--stk) = (uint32)0x08080808L; /* R8 */
*(--stk) = (uint32)0x07070707L; /* R7 */
*(--stk) = (uint32)0x06060606L; /* R6 */
*(--stk) = (uint32)0x05050505L; /* R5 */
*(--stk) = (uint32)0x04040404L; /* R4 */
return (stk);
}
/*
* ?????μ?????
*/
TCB* OSTaskCreate(void* task?? OS_STK *stack??PRIO_TYPE prio)
{
TCB *pTCB;
OS_CPU_SR cpu_sr = 0;
OS_ENTER_CRITICAL();
pTCB = OSGetFreeTCB(prio);
if (NULL == pTCB)
{
OS_EXIT_CRITICAL();
return NULL;
}
pTCB->pStackTop = OSTaskStkInit(task?? stack);
pTCB->CurPriority = prio;
pTCB->TCBDelay = 0;
TaskNUM++;
OS_EXIT_CRITICAL();
return pTCB;
}
???????????????????????????OSGetFreeTCB(prio);?????????????????????????????????????????洢????
????TCB?????????TCB OSTCBTable[MAX_TASK_NUM];??????????У?????OSTCBTable[0]?д????????????????????????????????????????????????????OSTCBTable[0]?д洢????????????????????????????????????????OSTCBTable[1]?С???????????????????????????????????????????????????????????????λ??OSTCBTable[2]?У???????????????????OSTCBTable?????е?????????????????????????????С?
?????????????????????OSGetFreeTCB(prio)??????
/*??TCB???????????е??????????????*/
/*??OSTCBTable????????????в???????*/
/*????????????????????*/
TCB* OSGetFreeTCB(PRIO_TYPE prio)
{
TCB *pTCB;
int32 index=0??orgIndex;
pTCB = &(OSTCBTable[0]);
for (index = 0;index < TaskNUM+1;index++)
{
pTCB = OSTCBTable+index;
/*????????TCB?????????*/
if (NULL == pTCB->pStackTop)
{
return (TCB*)pTCB;
}
/*????????????????????????????????*/
if (pTCB->CurPriority >= prio)
{
continue;
}
else /*pTCB->CurPriority < prio ?????ò????λ????*/
{
/*???浱?λ??*/
orgIndex = index;
/*?????????????????????????*/
for( index = TaskNUM ; index > orgIndex ; index-- )
{
pTCB = OSTCBTable+index;
/*??????????????????浽??????*/
_mem_copy((uint8 *)(pTCB)??(uint8 *)(pTCB-1)??sizeof(TCB));
}
_mem_clr((uint8 *)(pTCB-1)??sizeof(TCB)) ;
return (TCB*)(pTCB-1);
}
}
return (TCB*)NULL;
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11