123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263 |
- #ifndef OS_MASTER_FILE
- #include <ucos_ii.h>
- #endif
- #if OS_TASK_CHANGE_PRIO_EN > 0u
- INT8U OSTaskChangePrio (INT8U oldprio,
- INT8U newprio)
- {
- #if (OS_EVENT_EN)
- OS_EVENT *pevent;
- #if (OS_EVENT_MULTI_EN > 0u)
- OS_EVENT **pevents;
- #endif
- #endif
- OS_TCB *ptcb;
- INT8U y_new;
- INT8U x_new;
- INT8U y_old;
- OS_PRIO bity_new;
- OS_PRIO bitx_new;
- OS_PRIO bity_old;
- OS_PRIO bitx_old;
- #if OS_CRITICAL_METHOD == 3u
- OS_CPU_SR cpu_sr = 0u;
- #endif
- #if OS_ARG_CHK_EN > 0u
- if (oldprio >= OS_LOWEST_PRIO) {
- if (oldprio != OS_PRIO_SELF) {
- return (OS_ERR_PRIO_INVALID);
- }
- }
- if (newprio >= OS_LOWEST_PRIO) {
- return (OS_ERR_PRIO_INVALID);
- }
- #endif
- OS_ENTER_CRITICAL();
- if (OSTCBPrioTbl[newprio] != (OS_TCB *)0) {
- OS_EXIT_CRITICAL();
- return (OS_ERR_PRIO_EXIST);
- }
- if (oldprio == OS_PRIO_SELF) {
- oldprio = OSTCBCur->OSTCBPrio;
- }
- ptcb = OSTCBPrioTbl[oldprio];
- if (ptcb == (OS_TCB *)0) {
- OS_EXIT_CRITICAL();
- return (OS_ERR_PRIO);
- }
- if (ptcb == OS_TCB_RESERVED) {
- OS_EXIT_CRITICAL();
- return (OS_ERR_TASK_NOT_EXIST);
- }
- #if OS_LOWEST_PRIO <= 63u
- y_new = (INT8U)(newprio >> 3u);
- x_new = (INT8U)(newprio & 0x07u);
- #else
- y_new = (INT8U)((INT8U)(newprio >> 4u) & 0x0Fu);
- x_new = (INT8U)(newprio & 0x0Fu);
- #endif
- bity_new = (OS_PRIO)(1uL << y_new);
- bitx_new = (OS_PRIO)(1uL << x_new);
- OSTCBPrioTbl[oldprio] = (OS_TCB *)0;
- OSTCBPrioTbl[newprio] = ptcb;
- y_old = ptcb->OSTCBY;
- bity_old = ptcb->OSTCBBitY;
- bitx_old = ptcb->OSTCBBitX;
- if ((OSRdyTbl[y_old] & bitx_old) != 0u) {
- OSRdyTbl[y_old] &= (OS_PRIO)~bitx_old;
- if (OSRdyTbl[y_old] == 0u) {
- OSRdyGrp &= (OS_PRIO)~bity_old;
- }
- OSRdyGrp |= bity_new;
- OSRdyTbl[y_new] |= bitx_new;
- }
- #if (OS_EVENT_EN)
- pevent = ptcb->OSTCBEventPtr;
- if (pevent != (OS_EVENT *)0) {
- pevent->OSEventTbl[y_old] &= (OS_PRIO)~bitx_old;
- if (pevent->OSEventTbl[y_old] == 0u) {
- pevent->OSEventGrp &= (OS_PRIO)~bity_old;
- }
- pevent->OSEventGrp |= bity_new;
- pevent->OSEventTbl[y_new] |= bitx_new;
- }
- #if (OS_EVENT_MULTI_EN > 0u)
- if (ptcb->OSTCBEventMultiPtr != (OS_EVENT **)0) {
- pevents = ptcb->OSTCBEventMultiPtr;
- pevent = *pevents;
- while (pevent != (OS_EVENT *)0) {
- pevent->OSEventTbl[y_old] &= (OS_PRIO)~bitx_old;
- if (pevent->OSEventTbl[y_old] == 0u) {
- pevent->OSEventGrp &= (OS_PRIO)~bity_old;
- }
- pevent->OSEventGrp |= bity_new;
- pevent->OSEventTbl[y_new] |= bitx_new;
- pevents++;
- pevent = *pevents;
- }
- }
- #endif
- #endif
- ptcb->OSTCBPrio = newprio;
- ptcb->OSTCBY = y_new;
- ptcb->OSTCBX = x_new;
- ptcb->OSTCBBitY = bity_new;
- ptcb->OSTCBBitX = bitx_new;
- OS_EXIT_CRITICAL();
- if (OSRunning == OS_TRUE) {
- OS_Sched();
- }
- return (OS_ERR_NONE);
- }
- #endif
- #if OS_TASK_CREATE_EN > 0u
- INT8U OSTaskCreate (void (*task)(void *p_arg),
- void *p_arg,
- OS_STK *ptos,
- INT8U prio)
- {
- OS_STK *psp;
- INT8U err;
- #if OS_CRITICAL_METHOD == 3u
- OS_CPU_SR cpu_sr = 0u;
- #endif
- #ifdef OS_SAFETY_CRITICAL_IEC61508
- if (OSSafetyCriticalStartFlag == OS_TRUE) {
- OS_SAFETY_CRITICAL_EXCEPTION();
- }
- #endif
- #if OS_ARG_CHK_EN > 0u
- if (prio > OS_LOWEST_PRIO) {
- return (OS_ERR_PRIO_INVALID);
- }
- #endif
- OS_ENTER_CRITICAL();
- if (OSIntNesting > 0u) {
- OS_EXIT_CRITICAL();
- return (OS_ERR_TASK_CREATE_ISR);
- }
- if (OSTCBPrioTbl[prio] == (OS_TCB *)0) {
- OSTCBPrioTbl[prio] = OS_TCB_RESERVED;
-
- OS_EXIT_CRITICAL();
- psp = OSTaskStkInit(task, p_arg, ptos, 0u);
- err = OS_TCBInit(prio, psp, (OS_STK *)0, 0u, 0u, (void *)0, 0u);
- if (err == OS_ERR_NONE) {
- if (OSRunning == OS_TRUE) {
- OS_Sched();
- }
- } else {
- OS_ENTER_CRITICAL();
- OSTCBPrioTbl[prio] = (OS_TCB *)0;
- OS_EXIT_CRITICAL();
- }
- return (err);
- }
- OS_EXIT_CRITICAL();
- return (OS_ERR_PRIO_EXIST);
- }
- #endif
- #if OS_TASK_CREATE_EXT_EN > 0u
- INT8U OSTaskCreateExt (void (*task)(void *p_arg),
- void *p_arg,
- OS_STK *ptos,
- INT8U prio,
- INT16U id,
- OS_STK *pbos,
- INT32U stk_size,
- void *pext,
- INT16U opt)
- {
- OS_STK *psp;
- INT8U err;
- #if OS_CRITICAL_METHOD == 3u
- OS_CPU_SR cpu_sr = 0u;
- #endif
- #ifdef OS_SAFETY_CRITICAL_IEC61508
- if (OSSafetyCriticalStartFlag == OS_TRUE) {
- OS_SAFETY_CRITICAL_EXCEPTION();
- }
- #endif
- #if OS_ARG_CHK_EN > 0u
- if (prio > OS_LOWEST_PRIO) {
- return (OS_ERR_PRIO_INVALID);
- }
- #endif
- OS_ENTER_CRITICAL();
- if (OSIntNesting > 0u) {
- OS_EXIT_CRITICAL();
- return (OS_ERR_TASK_CREATE_ISR);
- }
- if (OSTCBPrioTbl[prio] == (OS_TCB *)0) {
- OSTCBPrioTbl[prio] = OS_TCB_RESERVED;
-
- OS_EXIT_CRITICAL();
- #if (OS_TASK_STAT_STK_CHK_EN > 0u)
- OS_TaskStkClr(pbos, stk_size, opt);
- #endif
- psp = OSTaskStkInit(task, p_arg, ptos, opt);
- err = OS_TCBInit(prio, psp, pbos, id, stk_size, pext, opt);
- if (err == OS_ERR_NONE) {
- if (OSRunning == OS_TRUE) {
- OS_Sched();
- }
- } else {
- OS_ENTER_CRITICAL();
- OSTCBPrioTbl[prio] = (OS_TCB *)0;
- OS_EXIT_CRITICAL();
- }
- return (err);
- }
- OS_EXIT_CRITICAL();
- return (OS_ERR_PRIO_EXIST);
- }
- #endif
- #if OS_TASK_DEL_EN > 0u
- INT8U OSTaskDel (INT8U prio)
- {
- #if (OS_FLAG_EN > 0u) && (OS_MAX_FLAGS > 0u)
- OS_FLAG_NODE *pnode;
- #endif
- OS_TCB *ptcb;
- #if OS_CRITICAL_METHOD == 3u
- OS_CPU_SR cpu_sr = 0u;
- #endif
- if (OSIntNesting > 0u) {
- return (OS_ERR_TASK_DEL_ISR);
- }
- if (prio == OS_TASK_IDLE_PRIO) {
- return (OS_ERR_TASK_DEL_IDLE);
- }
- #if OS_ARG_CHK_EN > 0u
- if (prio >= OS_LOWEST_PRIO) {
- if (prio != OS_PRIO_SELF) {
- return (OS_ERR_PRIO_INVALID);
- }
- }
- #endif
- OS_ENTER_CRITICAL();
- if (prio == OS_PRIO_SELF) {
- prio = OSTCBCur->OSTCBPrio;
- }
- ptcb = OSTCBPrioTbl[prio];
- if (ptcb == (OS_TCB *)0) {
- OS_EXIT_CRITICAL();
- return (OS_ERR_TASK_NOT_EXIST);
- }
- if (ptcb == OS_TCB_RESERVED) {
- OS_EXIT_CRITICAL();
- return (OS_ERR_TASK_DEL);
- }
- OSRdyTbl[ptcb->OSTCBY] &= (OS_PRIO)~ptcb->OSTCBBitX;
- if (OSRdyTbl[ptcb->OSTCBY] == 0u) {
- OSRdyGrp &= (OS_PRIO)~ptcb->OSTCBBitY;
- }
- #if (OS_EVENT_EN)
- if (ptcb->OSTCBEventPtr != (OS_EVENT *)0) {
- OS_EventTaskRemove(ptcb, ptcb->OSTCBEventPtr);
- }
- #if (OS_EVENT_MULTI_EN > 0u)
- if (ptcb->OSTCBEventMultiPtr != (OS_EVENT **)0) {
- OS_EventTaskRemoveMulti(ptcb, ptcb->OSTCBEventMultiPtr);
- }
- #endif
- #endif
- #if (OS_FLAG_EN > 0u) && (OS_MAX_FLAGS > 0u)
- pnode = ptcb->OSTCBFlagNode;
- if (pnode != (OS_FLAG_NODE *)0) {
- OS_FlagUnlink(pnode);
- }
- #endif
- ptcb->OSTCBDly = 0u;
- ptcb->OSTCBStat = OS_STAT_RDY;
- ptcb->OSTCBStatPend = OS_STAT_PEND_OK;
- if (OSLockNesting < 255u) {
- OSLockNesting++;
- }
- OS_EXIT_CRITICAL();
- OS_Dummy();
- OS_ENTER_CRITICAL();
- if (OSLockNesting > 0u) {
- OSLockNesting--;
- }
- OSTaskDelHook(ptcb);
- OSTaskCtr--;
- OSTCBPrioTbl[prio] = (OS_TCB *)0;
- if (ptcb->OSTCBPrev == (OS_TCB *)0) {
- ptcb->OSTCBNext->OSTCBPrev = (OS_TCB *)0;
- OSTCBList = ptcb->OSTCBNext;
- } else {
- ptcb->OSTCBPrev->OSTCBNext = ptcb->OSTCBNext;
- ptcb->OSTCBNext->OSTCBPrev = ptcb->OSTCBPrev;
- }
- ptcb->OSTCBNext = OSTCBFreeList;
- OSTCBFreeList = ptcb;
- #if OS_TASK_NAME_EN > 0u
- ptcb->OSTCBTaskName = (INT8U *)(void *)"?";
- #endif
- OS_EXIT_CRITICAL();
- if (OSRunning == OS_TRUE) {
- OS_Sched();
- }
- return (OS_ERR_NONE);
- }
- #endif
- #if OS_TASK_DEL_EN > 0u
- INT8U OSTaskDelReq (INT8U prio)
- {
- INT8U stat;
- OS_TCB *ptcb;
- #if OS_CRITICAL_METHOD == 3u
- OS_CPU_SR cpu_sr = 0u;
- #endif
- if (prio == OS_TASK_IDLE_PRIO) {
- return (OS_ERR_TASK_DEL_IDLE);
- }
- #if OS_ARG_CHK_EN > 0u
- if (prio >= OS_LOWEST_PRIO) {
- if (prio != OS_PRIO_SELF) {
- return (OS_ERR_PRIO_INVALID);
- }
- }
- #endif
- if (prio == OS_PRIO_SELF) {
- OS_ENTER_CRITICAL();
- stat = OSTCBCur->OSTCBDelReq;
- OS_EXIT_CRITICAL();
- return (stat);
- }
- OS_ENTER_CRITICAL();
- ptcb = OSTCBPrioTbl[prio];
- if (ptcb == (OS_TCB *)0) {
- OS_EXIT_CRITICAL();
- return (OS_ERR_TASK_NOT_EXIST);
- }
- if (ptcb == OS_TCB_RESERVED) {
- OS_EXIT_CRITICAL();
- return (OS_ERR_TASK_DEL);
- }
- ptcb->OSTCBDelReq = OS_ERR_TASK_DEL_REQ;
- OS_EXIT_CRITICAL();
- return (OS_ERR_NONE);
- }
- #endif
- #if OS_TASK_NAME_EN > 0u
- INT8U OSTaskNameGet (INT8U prio,
- INT8U **pname,
- INT8U *perr)
- {
- OS_TCB *ptcb;
- INT8U len;
- #if OS_CRITICAL_METHOD == 3u
- OS_CPU_SR cpu_sr = 0u;
- #endif
- #ifdef OS_SAFETY_CRITICAL
- if (perr == (INT8U *)0) {
- OS_SAFETY_CRITICAL_EXCEPTION();
- }
- #endif
- #if OS_ARG_CHK_EN > 0u
- if (prio > OS_LOWEST_PRIO) {
- if (prio != OS_PRIO_SELF) {
- *perr = OS_ERR_PRIO_INVALID;
- return (0u);
- }
- }
- if (pname == (INT8U **)0) {
- *perr = OS_ERR_PNAME_NULL;
- return (0u);
- }
- #endif
- if (OSIntNesting > 0u) {
- *perr = OS_ERR_NAME_GET_ISR;
- return (0u);
- }
- OS_ENTER_CRITICAL();
- if (prio == OS_PRIO_SELF) {
- prio = OSTCBCur->OSTCBPrio;
- }
- ptcb = OSTCBPrioTbl[prio];
- if (ptcb == (OS_TCB *)0) {
- OS_EXIT_CRITICAL();
- *perr = OS_ERR_TASK_NOT_EXIST;
- return (0u);
- }
- if (ptcb == OS_TCB_RESERVED) {
- OS_EXIT_CRITICAL();
- *perr = OS_ERR_TASK_NOT_EXIST;
- return (0u);
- }
- *pname = ptcb->OSTCBTaskName;
- len = OS_StrLen(*pname);
- OS_EXIT_CRITICAL();
- *perr = OS_ERR_NONE;
- return (len);
- }
- #endif
- #if OS_TASK_NAME_EN > 0u
- void OSTaskNameSet (INT8U prio,
- INT8U *pname,
- INT8U *perr)
- {
- OS_TCB *ptcb;
- #if OS_CRITICAL_METHOD == 3u
- OS_CPU_SR cpu_sr = 0u;
- #endif
- #ifdef OS_SAFETY_CRITICAL
- if (perr == (INT8U *)0) {
- OS_SAFETY_CRITICAL_EXCEPTION();
- }
- #endif
- #if OS_ARG_CHK_EN > 0u
- if (prio > OS_LOWEST_PRIO) {
- if (prio != OS_PRIO_SELF) {
- *perr = OS_ERR_PRIO_INVALID;
- return;
- }
- }
- if (pname == (INT8U *)0) {
- *perr = OS_ERR_PNAME_NULL;
- return;
- }
- #endif
- if (OSIntNesting > 0u) {
- *perr = OS_ERR_NAME_SET_ISR;
- return;
- }
- OS_ENTER_CRITICAL();
- if (prio == OS_PRIO_SELF) {
- prio = OSTCBCur->OSTCBPrio;
- }
- ptcb = OSTCBPrioTbl[prio];
- if (ptcb == (OS_TCB *)0) {
- OS_EXIT_CRITICAL();
- *perr = OS_ERR_TASK_NOT_EXIST;
- return;
- }
- if (ptcb == OS_TCB_RESERVED) {
- OS_EXIT_CRITICAL();
- *perr = OS_ERR_TASK_NOT_EXIST;
- return;
- }
- ptcb->OSTCBTaskName = pname;
- OS_EXIT_CRITICAL();
- *perr = OS_ERR_NONE;
- }
- #endif
- #if OS_TASK_SUSPEND_EN > 0u
- INT8U OSTaskResume (INT8U prio)
- {
- OS_TCB *ptcb;
- #if OS_CRITICAL_METHOD == 3u
- OS_CPU_SR cpu_sr = 0u;
- #endif
- #if OS_ARG_CHK_EN > 0u
- if (prio >= OS_LOWEST_PRIO) {
- return (OS_ERR_PRIO_INVALID);
- }
- #endif
- OS_ENTER_CRITICAL();
- ptcb = OSTCBPrioTbl[prio];
- if (ptcb == (OS_TCB *)0) {
- OS_EXIT_CRITICAL();
- return (OS_ERR_TASK_RESUME_PRIO);
- }
- if (ptcb == OS_TCB_RESERVED) {
- OS_EXIT_CRITICAL();
- return (OS_ERR_TASK_NOT_EXIST);
- }
- if ((ptcb->OSTCBStat & OS_STAT_SUSPEND) != OS_STAT_RDY) {
- ptcb->OSTCBStat &= (INT8U)~(INT8U)OS_STAT_SUSPEND;
- if (ptcb->OSTCBStat == OS_STAT_RDY) {
- if (ptcb->OSTCBDly == 0u) {
- OSRdyGrp |= ptcb->OSTCBBitY;
- OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
- OS_EXIT_CRITICAL();
- if (OSRunning == OS_TRUE) {
- OS_Sched();
- }
- } else {
- OS_EXIT_CRITICAL();
- }
- } else {
- OS_EXIT_CRITICAL();
- }
- return (OS_ERR_NONE);
- }
- OS_EXIT_CRITICAL();
- return (OS_ERR_TASK_NOT_SUSPENDED);
- }
- #endif
- #if (OS_TASK_STAT_STK_CHK_EN > 0u) && (OS_TASK_CREATE_EXT_EN > 0u)
- INT8U OSTaskStkChk (INT8U prio,
- OS_STK_DATA *p_stk_data)
- {
- OS_TCB *ptcb;
- OS_STK *pchk;
- INT32U nfree;
- INT32U size;
- #if OS_CRITICAL_METHOD == 3u
- OS_CPU_SR cpu_sr = 0u;
- #endif
- #if OS_ARG_CHK_EN > 0u
- if (prio > OS_LOWEST_PRIO) {
- if (prio != OS_PRIO_SELF) {
- return (OS_ERR_PRIO_INVALID);
- }
- }
- if (p_stk_data == (OS_STK_DATA *)0) {
- return (OS_ERR_PDATA_NULL);
- }
- #endif
- p_stk_data->OSFree = 0u;
- p_stk_data->OSUsed = 0u;
- OS_ENTER_CRITICAL();
- if (prio == OS_PRIO_SELF) {
- prio = OSTCBCur->OSTCBPrio;
- }
- ptcb = OSTCBPrioTbl[prio];
- if (ptcb == (OS_TCB *)0) {
- OS_EXIT_CRITICAL();
- return (OS_ERR_TASK_NOT_EXIST);
- }
- if (ptcb == OS_TCB_RESERVED) {
- OS_EXIT_CRITICAL();
- return (OS_ERR_TASK_NOT_EXIST);
- }
- if ((ptcb->OSTCBOpt & OS_TASK_OPT_STK_CHK) == 0u) {
- OS_EXIT_CRITICAL();
- return (OS_ERR_TASK_OPT);
- }
- nfree = 0u;
- size = ptcb->OSTCBStkSize;
- pchk = ptcb->OSTCBStkBottom;
- OS_EXIT_CRITICAL();
- #if OS_STK_GROWTH == 1u
- while (*pchk++ == (OS_STK)0) {
- nfree++;
- }
- #else
- while (*pchk-- == (OS_STK)0) {
- nfree++;
- }
- #endif
- p_stk_data->OSFree = nfree * sizeof(OS_STK);
- p_stk_data->OSUsed = (size - nfree) * sizeof(OS_STK);
- return (OS_ERR_NONE);
- }
- #endif
- #if OS_TASK_SUSPEND_EN > 0u
- INT8U OSTaskSuspend (INT8U prio)
- {
- BOOLEAN self;
- OS_TCB *ptcb;
- INT8U y;
- #if OS_CRITICAL_METHOD == 3u
- OS_CPU_SR cpu_sr = 0u;
- #endif
- #if OS_ARG_CHK_EN > 0u
- if (prio == OS_TASK_IDLE_PRIO) {
- return (OS_ERR_TASK_SUSPEND_IDLE);
- }
- if (prio >= OS_LOWEST_PRIO) {
- if (prio != OS_PRIO_SELF) {
- return (OS_ERR_PRIO_INVALID);
- }
- }
- #endif
- OS_ENTER_CRITICAL();
- if (prio == OS_PRIO_SELF) {
- prio = OSTCBCur->OSTCBPrio;
- self = OS_TRUE;
- } else if (prio == OSTCBCur->OSTCBPrio) {
- self = OS_TRUE;
- } else {
- self = OS_FALSE;
- }
- ptcb = OSTCBPrioTbl[prio];
- if (ptcb == (OS_TCB *)0) {
- OS_EXIT_CRITICAL();
- return (OS_ERR_TASK_SUSPEND_PRIO);
- }
- if (ptcb == OS_TCB_RESERVED) {
- OS_EXIT_CRITICAL();
- return (OS_ERR_TASK_NOT_EXIST);
- }
- y = ptcb->OSTCBY;
- OSRdyTbl[y] &= (OS_PRIO)~ptcb->OSTCBBitX;
- if (OSRdyTbl[y] == 0u) {
- OSRdyGrp &= (OS_PRIO)~ptcb->OSTCBBitY;
- }
- ptcb->OSTCBStat |= OS_STAT_SUSPEND;
- OS_EXIT_CRITICAL();
- if (self == OS_TRUE) {
- OS_Sched();
- }
- return (OS_ERR_NONE);
- }
- #endif
- #if OS_TASK_QUERY_EN > 0u
- INT8U OSTaskQuery (INT8U prio,
- OS_TCB *p_task_data)
- {
- OS_TCB *ptcb;
- #if OS_CRITICAL_METHOD == 3u
- OS_CPU_SR cpu_sr = 0u;
- #endif
- #if OS_ARG_CHK_EN > 0u
- if (prio > OS_LOWEST_PRIO) {
- if (prio != OS_PRIO_SELF) {
- return (OS_ERR_PRIO_INVALID);
- }
- }
- if (p_task_data == (OS_TCB *)0) {
- return (OS_ERR_PDATA_NULL);
- }
- #endif
- OS_ENTER_CRITICAL();
- if (prio == OS_PRIO_SELF) {
- prio = OSTCBCur->OSTCBPrio;
- }
- ptcb = OSTCBPrioTbl[prio];
- if (ptcb == (OS_TCB *)0) {
- OS_EXIT_CRITICAL();
- return (OS_ERR_PRIO);
- }
- if (ptcb == OS_TCB_RESERVED) {
- OS_EXIT_CRITICAL();
- return (OS_ERR_TASK_NOT_EXIST);
- }
-
- OS_MemCopy((INT8U *)p_task_data, (INT8U *)ptcb, sizeof(OS_TCB));
- OS_EXIT_CRITICAL();
- return (OS_ERR_NONE);
- }
- #endif
- #if OS_TASK_REG_TBL_SIZE > 0u
- INT32U OSTaskRegGet (INT8U prio,
- INT8U id,
- INT8U *perr)
- {
- #if OS_CRITICAL_METHOD == 3u
- OS_CPU_SR cpu_sr = 0u;
- #endif
- INT32U value;
- OS_TCB *ptcb;
- #if OS_ARG_CHK_EN > 0u
- if (prio >= OS_LOWEST_PRIO) {
- if (prio != OS_PRIO_SELF) {
- *perr = OS_ERR_PRIO_INVALID;
- return (0u);
- }
- }
- if (id >= OS_TASK_REG_TBL_SIZE) {
- *perr = OS_ERR_ID_INVALID;
- return (0u);
- }
- #endif
- OS_ENTER_CRITICAL();
- if (prio == OS_PRIO_SELF) {
- ptcb = OSTCBCur;
- } else {
- ptcb = OSTCBPrioTbl[prio];
- }
- value = ptcb->OSTCBRegTbl[id];
- OS_EXIT_CRITICAL();
- *perr = OS_ERR_NONE;
- return (value);
- }
- #endif
- #if OS_TASK_REG_TBL_SIZE > 0u
- void OSTaskRegSet (INT8U prio,
- INT8U id,
- INT32U value,
- INT8U *perr)
- {
- #if OS_CRITICAL_METHOD == 3u
- OS_CPU_SR cpu_sr = 0u;
- #endif
- OS_TCB *ptcb;
- #if OS_ARG_CHK_EN > 0u
- if (prio >= OS_LOWEST_PRIO) {
- if (prio != OS_PRIO_SELF) {
- *perr = OS_ERR_PRIO_INVALID;
- return;
- }
- }
- if (id >= OS_TASK_REG_TBL_SIZE) {
- *perr = OS_ERR_ID_INVALID;
- return;
- }
- #endif
- OS_ENTER_CRITICAL();
- if (prio == OS_PRIO_SELF) {
- ptcb = OSTCBCur;
- } else {
- ptcb = OSTCBPrioTbl[prio];
- }
- ptcb->OSTCBRegTbl[id] = value;
- OS_EXIT_CRITICAL();
- *perr = OS_ERR_NONE;
- }
- #endif
- void OS_TaskReturn (void)
- {
- OSTaskReturnHook(OSTCBCur);
- #if OS_TASK_DEL_EN > 0u
- (void)OSTaskDel(OS_PRIO_SELF);
- #else
- for (;;) {
- OSTimeDly(OS_TICKS_PER_SEC);
- }
- #endif
- }
- #if (OS_TASK_STAT_STK_CHK_EN > 0u) && (OS_TASK_CREATE_EXT_EN > 0u)
- void OS_TaskStkClr (OS_STK *pbos,
- INT32U size,
- INT16U opt)
- {
- if ((opt & OS_TASK_OPT_STK_CHK) != 0x0000u) {
- if ((opt & OS_TASK_OPT_STK_CLR) != 0x0000u) {
- #if OS_STK_GROWTH == 1u
- while (size > 0u) {
- size--;
- *pbos++ = (OS_STK)0;
- }
- #else
- while (size > 0u) {
- size--;
- *pbos-- = (OS_STK)0;
- }
- #endif
- }
- }
- }
- #endif
-
|