12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073 |
- #include <ucos_ii.h>
- #define OS_TMR_LINK_DLY 0u
- #define OS_TMR_LINK_PERIODIC 1u
- #if OS_TMR_EN > 0u
- static OS_TMR *OSTmr_Alloc (void);
- static void OSTmr_Free (OS_TMR *ptmr);
- static void OSTmr_InitTask (void);
- static void OSTmr_Link (OS_TMR *ptmr, INT8U type);
- static void OSTmr_Unlink (OS_TMR *ptmr);
- static void OSTmr_Task (void *p_arg);
- #endif
- #if OS_TMR_EN > 0u
- OS_TMR *OSTmrCreate (INT32U dly,
- INT32U period,
- INT8U opt,
- OS_TMR_CALLBACK callback,
- void *callback_arg,
- INT8U *pname,
- INT8U *perr)
- {
- OS_TMR *ptmr;
- #ifdef OS_SAFETY_CRITICAL
- if (perr == (INT8U *)0) {
- OS_SAFETY_CRITICAL_EXCEPTION();
- }
- #endif
- #ifdef OS_SAFETY_CRITICAL_IEC61508
- if (OSSafetyCriticalStartFlag == OS_TRUE) {
- OS_SAFETY_CRITICAL_EXCEPTION();
- }
- #endif
- #if OS_ARG_CHK_EN > 0u
- switch (opt) {
- case OS_TMR_OPT_PERIODIC:
- if (period == 0u) {
- *perr = OS_ERR_TMR_INVALID_PERIOD;
- return ((OS_TMR *)0);
- }
- break;
- case OS_TMR_OPT_ONE_SHOT:
- if (dly == 0u) {
- *perr = OS_ERR_TMR_INVALID_DLY;
- return ((OS_TMR *)0);
- }
- break;
- default:
- *perr = OS_ERR_TMR_INVALID_OPT;
- return ((OS_TMR *)0);
- }
- #endif
- if (OSIntNesting > 0u) {
- *perr = OS_ERR_TMR_ISR;
- return ((OS_TMR *)0);
- }
- OSSchedLock();
- ptmr = OSTmr_Alloc();
- if (ptmr == (OS_TMR *)0) {
- OSSchedUnlock();
- *perr = OS_ERR_TMR_NON_AVAIL;
- return ((OS_TMR *)0);
- }
- ptmr->OSTmrState = OS_TMR_STATE_STOPPED;
- ptmr->OSTmrDly = dly;
- ptmr->OSTmrPeriod = period;
- ptmr->OSTmrOpt = opt;
- ptmr->OSTmrCallback = callback;
- ptmr->OSTmrCallbackArg = callback_arg;
- #if OS_TMR_CFG_NAME_EN > 0u
- ptmr->OSTmrName = pname;
- #endif
- OSSchedUnlock();
- *perr = OS_ERR_NONE;
- return (ptmr);
- }
- #endif
- #if OS_TMR_EN > 0u
- BOOLEAN OSTmrDel (OS_TMR *ptmr,
- INT8U *perr)
- {
- #ifdef OS_SAFETY_CRITICAL
- if (perr == (INT8U *)0) {
- OS_SAFETY_CRITICAL_EXCEPTION();
- }
- #endif
- #if OS_ARG_CHK_EN > 0u
- if (ptmr == (OS_TMR *)0) {
- *perr = OS_ERR_TMR_INVALID;
- return (OS_FALSE);
- }
- #endif
- if (ptmr->OSTmrType != OS_TMR_TYPE) {
- *perr = OS_ERR_TMR_INVALID_TYPE;
- return (OS_FALSE);
- }
- if (OSIntNesting > 0u) {
- *perr = OS_ERR_TMR_ISR;
- return (OS_FALSE);
- }
- OSSchedLock();
- switch (ptmr->OSTmrState) {
- case OS_TMR_STATE_RUNNING:
- OSTmr_Unlink(ptmr);
- OSTmr_Free(ptmr);
- OSSchedUnlock();
- *perr = OS_ERR_NONE;
- return (OS_TRUE);
- case OS_TMR_STATE_STOPPED:
- case OS_TMR_STATE_COMPLETED:
- OSTmr_Free(ptmr);
- OSSchedUnlock();
- *perr = OS_ERR_NONE;
- return (OS_TRUE);
- case OS_TMR_STATE_UNUSED:
- OSSchedUnlock();
- *perr = OS_ERR_TMR_INACTIVE;
- return (OS_FALSE);
- default:
- OSSchedUnlock();
- *perr = OS_ERR_TMR_INVALID_STATE;
- return (OS_FALSE);
- }
- }
- #endif
- #if OS_TMR_EN > 0u && OS_TMR_CFG_NAME_EN > 0u
- INT8U OSTmrNameGet (OS_TMR *ptmr,
- INT8U **pdest,
- INT8U *perr)
- {
- INT8U len;
- #ifdef OS_SAFETY_CRITICAL
- if (perr == (INT8U *)0) {
- OS_SAFETY_CRITICAL_EXCEPTION();
- }
- #endif
- #if OS_ARG_CHK_EN > 0u
- if (pdest == (INT8U **)0) {
- *perr = OS_ERR_TMR_INVALID_DEST;
- return (0u);
- }
- if (ptmr == (OS_TMR *)0) {
- *perr = OS_ERR_TMR_INVALID;
- return (0u);
- }
- #endif
- if (ptmr->OSTmrType != OS_TMR_TYPE) {
- *perr = OS_ERR_TMR_INVALID_TYPE;
- return (0u);
- }
- if (OSIntNesting > 0u) {
- *perr = OS_ERR_NAME_GET_ISR;
- return (0u);
- }
- OSSchedLock();
- switch (ptmr->OSTmrState) {
- case OS_TMR_STATE_RUNNING:
- case OS_TMR_STATE_STOPPED:
- case OS_TMR_STATE_COMPLETED:
- *pdest = ptmr->OSTmrName;
- len = OS_StrLen(*pdest);
- OSSchedUnlock();
- *perr = OS_ERR_NONE;
- return (len);
- case OS_TMR_STATE_UNUSED:
- OSSchedUnlock();
- *perr = OS_ERR_TMR_INACTIVE;
- return (0u);
- default:
- OSSchedUnlock();
- *perr = OS_ERR_TMR_INVALID_STATE;
- return (0u);
- }
- }
- #endif
- #if OS_TMR_EN > 0u
- INT32U OSTmrRemainGet (OS_TMR *ptmr,
- INT8U *perr)
- {
- INT32U remain;
- #ifdef OS_SAFETY_CRITICAL
- if (perr == (INT8U *)0) {
- OS_SAFETY_CRITICAL_EXCEPTION();
- }
- #endif
- #if OS_ARG_CHK_EN > 0u
- if (ptmr == (OS_TMR *)0) {
- *perr = OS_ERR_TMR_INVALID;
- return (0u);
- }
- #endif
- if (ptmr->OSTmrType != OS_TMR_TYPE) {
- *perr = OS_ERR_TMR_INVALID_TYPE;
- return (0u);
- }
- if (OSIntNesting > 0u) {
- *perr = OS_ERR_TMR_ISR;
- return (0u);
- }
- OSSchedLock();
- switch (ptmr->OSTmrState) {
- case OS_TMR_STATE_RUNNING:
- remain = ptmr->OSTmrMatch - OSTmrTime;
- OSSchedUnlock();
- *perr = OS_ERR_NONE;
- return (remain);
- case OS_TMR_STATE_STOPPED:
- switch (ptmr->OSTmrOpt) {
- case OS_TMR_OPT_PERIODIC:
- if (ptmr->OSTmrDly == 0u) {
- remain = ptmr->OSTmrPeriod;
- } else {
- remain = ptmr->OSTmrDly;
- }
- OSSchedUnlock();
- *perr = OS_ERR_NONE;
- break;
- case OS_TMR_OPT_ONE_SHOT:
- default:
- remain = ptmr->OSTmrDly;
- OSSchedUnlock();
- *perr = OS_ERR_NONE;
- break;
- }
- return (remain);
- case OS_TMR_STATE_COMPLETED:
- OSSchedUnlock();
- *perr = OS_ERR_NONE;
- return (0u);
- case OS_TMR_STATE_UNUSED:
- OSSchedUnlock();
- *perr = OS_ERR_TMR_INACTIVE;
- return (0u);
- default:
- OSSchedUnlock();
- *perr = OS_ERR_TMR_INVALID_STATE;
- return (0u);
- }
- }
- #endif
- #if OS_TMR_EN > 0u
- INT8U OSTmrStateGet (OS_TMR *ptmr,
- INT8U *perr)
- {
- INT8U state;
- #ifdef OS_SAFETY_CRITICAL
- if (perr == (INT8U *)0) {
- OS_SAFETY_CRITICAL_EXCEPTION();
- }
- #endif
- #if OS_ARG_CHK_EN > 0u
- if (ptmr == (OS_TMR *)0) {
- *perr = OS_ERR_TMR_INVALID;
- return (0u);
- }
- #endif
- if (ptmr->OSTmrType != OS_TMR_TYPE) {
- *perr = OS_ERR_TMR_INVALID_TYPE;
- return (0u);
- }
- if (OSIntNesting > 0u) {
- *perr = OS_ERR_TMR_ISR;
- return (0u);
- }
- OSSchedLock();
- state = ptmr->OSTmrState;
- switch (state) {
- case OS_TMR_STATE_UNUSED:
- case OS_TMR_STATE_STOPPED:
- case OS_TMR_STATE_COMPLETED:
- case OS_TMR_STATE_RUNNING:
- *perr = OS_ERR_NONE;
- break;
- default:
- *perr = OS_ERR_TMR_INVALID_STATE;
- break;
- }
- OSSchedUnlock();
- return (state);
- }
- #endif
- #if OS_TMR_EN > 0u
- BOOLEAN OSTmrStart (OS_TMR *ptmr,
- INT8U *perr)
- {
- #ifdef OS_SAFETY_CRITICAL
- if (perr == (INT8U *)0) {
- OS_SAFETY_CRITICAL_EXCEPTION();
- }
- #endif
- #if OS_ARG_CHK_EN > 0u
- if (ptmr == (OS_TMR *)0) {
- *perr = OS_ERR_TMR_INVALID;
- return (OS_FALSE);
- }
- #endif
- if (ptmr->OSTmrType != OS_TMR_TYPE) {
- *perr = OS_ERR_TMR_INVALID_TYPE;
- return (OS_FALSE);
- }
- if (OSIntNesting > 0u) {
- *perr = OS_ERR_TMR_ISR;
- return (OS_FALSE);
- }
- OSSchedLock();
- switch (ptmr->OSTmrState) {
- case OS_TMR_STATE_RUNNING:
- OSTmr_Unlink(ptmr);
- OSTmr_Link(ptmr, OS_TMR_LINK_DLY);
- OSSchedUnlock();
- *perr = OS_ERR_NONE;
- return (OS_TRUE);
- case OS_TMR_STATE_STOPPED:
- case OS_TMR_STATE_COMPLETED:
- OSTmr_Link(ptmr, OS_TMR_LINK_DLY);
- OSSchedUnlock();
- *perr = OS_ERR_NONE;
- return (OS_TRUE);
- case OS_TMR_STATE_UNUSED:
- OSSchedUnlock();
- *perr = OS_ERR_TMR_INACTIVE;
- return (OS_FALSE);
- default:
- OSSchedUnlock();
- *perr = OS_ERR_TMR_INVALID_STATE;
- return (OS_FALSE);
- }
- }
- #endif
- #if OS_TMR_EN > 0u
- BOOLEAN OSTmrStop (OS_TMR *ptmr,
- INT8U opt,
- void *callback_arg,
- INT8U *perr)
- {
- OS_TMR_CALLBACK pfnct;
- #ifdef OS_SAFETY_CRITICAL
- if (perr == (INT8U *)0) {
- OS_SAFETY_CRITICAL_EXCEPTION();
- }
- #endif
- #if OS_ARG_CHK_EN > 0u
- if (ptmr == (OS_TMR *)0) {
- *perr = OS_ERR_TMR_INVALID;
- return (OS_FALSE);
- }
- #endif
- if (ptmr->OSTmrType != OS_TMR_TYPE) {
- *perr = OS_ERR_TMR_INVALID_TYPE;
- return (OS_FALSE);
- }
- if (OSIntNesting > 0u) {
- *perr = OS_ERR_TMR_ISR;
- return (OS_FALSE);
- }
- OSSchedLock();
- switch (ptmr->OSTmrState) {
- case OS_TMR_STATE_RUNNING:
- OSTmr_Unlink(ptmr);
- *perr = OS_ERR_NONE;
- switch (opt) {
- case OS_TMR_OPT_CALLBACK:
- pfnct = ptmr->OSTmrCallback;
- if (pfnct != (OS_TMR_CALLBACK)0) {
- (*pfnct)((void *)ptmr, ptmr->OSTmrCallbackArg);
- } else {
- *perr = OS_ERR_TMR_NO_CALLBACK;
- }
- break;
- case OS_TMR_OPT_CALLBACK_ARG:
- pfnct = ptmr->OSTmrCallback;
- if (pfnct != (OS_TMR_CALLBACK)0) {
- (*pfnct)((void *)ptmr, callback_arg);
- } else {
- *perr = OS_ERR_TMR_NO_CALLBACK;
- }
- break;
- case OS_TMR_OPT_NONE:
- break;
- default:
- *perr = OS_ERR_TMR_INVALID_OPT;
- break;
- }
- OSSchedUnlock();
- return (OS_TRUE);
- case OS_TMR_STATE_COMPLETED:
- case OS_TMR_STATE_STOPPED:
- OSSchedUnlock();
- *perr = OS_ERR_TMR_STOPPED;
- return (OS_TRUE);
- case OS_TMR_STATE_UNUSED:
- OSSchedUnlock();
- *perr = OS_ERR_TMR_INACTIVE;
- return (OS_FALSE);
- default:
- OSSchedUnlock();
- *perr = OS_ERR_TMR_INVALID_STATE;
- return (OS_FALSE);
- }
- }
- #endif
- #if OS_TMR_EN > 0u
- INT8U OSTmrSignal (void)
- {
- INT8U err;
- err = OSSemPost(OSTmrSemSignal);
- return (err);
- }
- #endif
- #if OS_TMR_EN > 0u
- static OS_TMR *OSTmr_Alloc (void)
- {
- OS_TMR *ptmr;
- if (OSTmrFreeList == (OS_TMR *)0) {
- return ((OS_TMR *)0);
- }
- ptmr = (OS_TMR *)OSTmrFreeList;
- OSTmrFreeList = (OS_TMR *)ptmr->OSTmrNext;
- ptmr->OSTmrNext = (OS_TCB *)0;
- ptmr->OSTmrPrev = (OS_TCB *)0;
- OSTmrUsed++;
- OSTmrFree--;
- return (ptmr);
- }
- #endif
- #if OS_TMR_EN > 0u
- static void OSTmr_Free (OS_TMR *ptmr)
- {
- ptmr->OSTmrState = OS_TMR_STATE_UNUSED;
- ptmr->OSTmrOpt = OS_TMR_OPT_NONE;
- ptmr->OSTmrPeriod = 0u;
- ptmr->OSTmrMatch = 0u;
- ptmr->OSTmrCallback = (OS_TMR_CALLBACK)0;
- ptmr->OSTmrCallbackArg = (void *)0;
- #if OS_TMR_CFG_NAME_EN > 0u
- ptmr->OSTmrName = (INT8U *)(void *)"?";
- #endif
- ptmr->OSTmrPrev = (OS_TCB *)0;
- ptmr->OSTmrNext = OSTmrFreeList;
- OSTmrFreeList = ptmr;
- OSTmrUsed--;
- OSTmrFree++;
- }
- #endif
- #if OS_TMR_EN > 0u
- void OSTmr_Init (void)
- {
- #if OS_EVENT_NAME_EN > 0u
- INT8U err;
- #endif
- INT16U ix;
- INT16U ix_next;
- OS_TMR *ptmr1;
- OS_TMR *ptmr2;
- OS_MemClr((INT8U *)&OSTmrTbl[0], sizeof(OSTmrTbl));
- OS_MemClr((INT8U *)&OSTmrWheelTbl[0], sizeof(OSTmrWheelTbl));
- for (ix = 0u; ix < (OS_TMR_CFG_MAX - 1u); ix++) {
- ix_next = ix + 1u;
- ptmr1 = &OSTmrTbl[ix];
- ptmr2 = &OSTmrTbl[ix_next];
- ptmr1->OSTmrType = OS_TMR_TYPE;
- ptmr1->OSTmrState = OS_TMR_STATE_UNUSED;
- ptmr1->OSTmrNext = (void *)ptmr2;
- #if OS_TMR_CFG_NAME_EN > 0u
- ptmr1->OSTmrName = (INT8U *)(void *)"?";
- #endif
- }
- ptmr1 = &OSTmrTbl[ix];
- ptmr1->OSTmrType = OS_TMR_TYPE;
- ptmr1->OSTmrState = OS_TMR_STATE_UNUSED;
- ptmr1->OSTmrNext = (void *)0;
- #if OS_TMR_CFG_NAME_EN > 0u
- ptmr1->OSTmrName = (INT8U *)(void *)"?";
- #endif
- OSTmrTime = 0u;
- OSTmrUsed = 0u;
- OSTmrFree = OS_TMR_CFG_MAX;
- OSTmrFreeList = &OSTmrTbl[0];
- OSTmrSem = OSSemCreate(1u);
- OSTmrSemSignal = OSSemCreate(0u);
- #if OS_EVENT_NAME_EN > 0u
- OSEventNameSet(OSTmrSem, (INT8U *)(void *)"uC/OS-II TmrLock", &err);
- OSEventNameSet(OSTmrSemSignal, (INT8U *)(void *)"uC/OS-II TmrSignal", &err);
- #endif
- OSTmr_InitTask();
- }
- #endif
- #if OS_TMR_EN > 0u
- static void OSTmr_InitTask (void)
- {
- #if OS_TASK_NAME_EN > 0u
- INT8U err;
- #endif
- #if OS_TASK_CREATE_EXT_EN > 0u
- #if OS_STK_GROWTH == 1u
- (void)OSTaskCreateExt(OSTmr_Task,
- (void *)0,
- &OSTmrTaskStk[OS_TASK_TMR_STK_SIZE - 1u],
- OS_TASK_TMR_PRIO,
- OS_TASK_TMR_ID,
- &OSTmrTaskStk[0],
- OS_TASK_TMR_STK_SIZE,
- (void *)0,
- OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
- #else
- (void)OSTaskCreateExt(OSTmr_Task,
- (void *)0,
- &OSTmrTaskStk[0],
- OS_TASK_TMR_PRIO,
- OS_TASK_TMR_ID,
- &OSTmrTaskStk[OS_TASK_TMR_STK_SIZE - 1u],
- OS_TASK_TMR_STK_SIZE,
- (void *)0,
- OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
- #endif
- #else
- #if OS_STK_GROWTH == 1u
- (void)OSTaskCreate(OSTmr_Task,
- (void *)0,
- &OSTmrTaskStk[OS_TASK_TMR_STK_SIZE - 1u],
- OS_TASK_TMR_PRIO);
- #else
- (void)OSTaskCreate(OSTmr_Task,
- (void *)0,
- &OSTmrTaskStk[0],
- OS_TASK_TMR_PRIO);
- #endif
- #endif
- #if OS_TASK_NAME_EN > 0u
- OSTaskNameSet(OS_TASK_TMR_PRIO, (INT8U *)(void *)"uC/OS-II Tmr", &err);
- #endif
- }
- #endif
- #if OS_TMR_EN > 0u
- static void OSTmr_Link (OS_TMR *ptmr,
- INT8U type)
- {
- OS_TMR *ptmr1;
- OS_TMR_WHEEL *pspoke;
- INT16U spoke;
- ptmr->OSTmrState = OS_TMR_STATE_RUNNING;
- if (type == OS_TMR_LINK_PERIODIC) {
- ptmr->OSTmrMatch = ptmr->OSTmrPeriod + OSTmrTime;
- } else {
- if (ptmr->OSTmrDly == 0u) {
- ptmr->OSTmrMatch = ptmr->OSTmrPeriod + OSTmrTime;
- } else {
- ptmr->OSTmrMatch = ptmr->OSTmrDly + OSTmrTime;
- }
- }
- spoke = (INT16U)(ptmr->OSTmrMatch % OS_TMR_CFG_WHEEL_SIZE);
- pspoke = &OSTmrWheelTbl[spoke];
- if (pspoke->OSTmrFirst == (OS_TMR *)0) {
- pspoke->OSTmrFirst = ptmr;
- ptmr->OSTmrNext = (OS_TMR *)0;
- pspoke->OSTmrEntries = 1u;
- } else {
- ptmr1 = pspoke->OSTmrFirst;
- pspoke->OSTmrFirst = ptmr;
- ptmr->OSTmrNext = (void *)ptmr1;
- ptmr1->OSTmrPrev = (void *)ptmr;
- pspoke->OSTmrEntries++;
- }
- ptmr->OSTmrPrev = (void *)0;
- }
- #endif
- #if OS_TMR_EN > 0u
- static void OSTmr_Unlink (OS_TMR *ptmr)
- {
- OS_TMR *ptmr1;
- OS_TMR *ptmr2;
- OS_TMR_WHEEL *pspoke;
- INT16U spoke;
- spoke = (INT16U)(ptmr->OSTmrMatch % OS_TMR_CFG_WHEEL_SIZE);
- pspoke = &OSTmrWheelTbl[spoke];
- if (pspoke->OSTmrFirst == ptmr) {
- ptmr1 = (OS_TMR *)ptmr->OSTmrNext;
- pspoke->OSTmrFirst = (OS_TMR *)ptmr1;
- if (ptmr1 != (OS_TMR *)0) {
- ptmr1->OSTmrPrev = (void *)0;
- }
- } else {
- ptmr1 = (OS_TMR *)ptmr->OSTmrPrev;
- ptmr2 = (OS_TMR *)ptmr->OSTmrNext;
- ptmr1->OSTmrNext = ptmr2;
- if (ptmr2 != (OS_TMR *)0) {
- ptmr2->OSTmrPrev = (void *)ptmr1;
- }
- }
- ptmr->OSTmrState = OS_TMR_STATE_STOPPED;
- ptmr->OSTmrNext = (void *)0;
- ptmr->OSTmrPrev = (void *)0;
- pspoke->OSTmrEntries--;
- }
- #endif
- #if OS_TMR_EN > 0u
- static void OSTmr_Task (void *p_arg)
- {
- INT8U err;
- OS_TMR *ptmr;
- OS_TMR *ptmr_next;
- OS_TMR_CALLBACK pfnct;
- OS_TMR_WHEEL *pspoke;
- INT16U spoke;
- p_arg = p_arg;
- for (;;) {
- OSSemPend(OSTmrSemSignal, 0u, &err);
- OSSchedLock();
- OSTmrTime++;
- spoke = (INT16U)(OSTmrTime % OS_TMR_CFG_WHEEL_SIZE);
- pspoke = &OSTmrWheelTbl[spoke];
- ptmr = pspoke->OSTmrFirst;
- while (ptmr != (OS_TMR *)0) {
- ptmr_next = (OS_TMR *)ptmr->OSTmrNext;
-
- if (OSTmrTime == ptmr->OSTmrMatch) {
- OSTmr_Unlink(ptmr);
- if (ptmr->OSTmrOpt == OS_TMR_OPT_PERIODIC) {
- OSTmr_Link(ptmr, OS_TMR_LINK_PERIODIC);
- } else {
- ptmr->OSTmrState = OS_TMR_STATE_COMPLETED;
- }
- pfnct = ptmr->OSTmrCallback;
- if (pfnct != (OS_TMR_CALLBACK)0) {
- (*pfnct)((void *)ptmr, ptmr->OSTmrCallbackArg);
- }
- }
- ptmr = ptmr_next;
- }
- OSSchedUnlock();
- }
- }
- #endif
-
|