📄 os_tmr.lst
字号:
} else {
*perr = OS_ERR_TMR_NO_CALLBACK;
}
break;
case OS_TMR_OPT_CALLBACK_ARG:
C51 COMPILER V8.17 OS_TMR 03/26/2009 14:24:25 PAGE 13
pfnct = ptmr->OSTmrCallback; /* Execute callback function if availabl
-e ... */
if (pfnct != (OS_TMR_CALLBACK)0) {
//(*pfnct)((void *)ptmr, callback_arg); /* ... using the 'callback_arg' provid
-ed in call */
(*pfnct)((void *)ptmr); /* ... using the 'callback_arg' provided in call */
} else {
*perr = OS_ERR_TMR_NO_CALLBACK;
}
break;
case OS_TMR_OPT_NONE:
break;
default:
*perr = OS_ERR_TMR_INVALID_OPT;
break;
}
OSTmr_Unlock();
return (OS_TRUE);
case OS_TMR_STATE_COMPLETED: /* Timer has already completed the ONE-S
-HOT or ... */
case OS_TMR_STATE_STOPPED: /* ... timer has not started yet.
- */
OSTmr_Unlock();
*perr = OS_ERR_TMR_STOPPED;
return (OS_TRUE);
case OS_TMR_STATE_UNUSED: /* Timer was not created
- */
OSTmr_Unlock();
*perr = OS_ERR_TMR_INACTIVE;
return (OS_FALSE);
default:
OSTmr_Unlock();
*perr = OS_ERR_TMR_INVALID_STATE;
return (OS_FALSE);
}
}
#endif
696
697 /*$PAGE*/
698 /*
699 **********************************************************************************************************
-**************
700 * SIGNAL THAT IT'S TIME TO UPDATE THE TIMERS
701 *
702 * Description: This function is typically called by the ISR that occurs at the timer tick rate and is used
- to signal to
703 * OSTmr_Task() that it's time to update the timers.
704 *
705 * Arguments : none
706 *
707 * Returns : OS_ERR_NONE The call was successful and the timer task was signaled.
708 * OS_ERR_SEM_OVF If OSTmrSignal() was called more often than OSTmr_Task() can handle the
- timers.
709 * This would indicate that your system is heavily loaded.
710 * OS_ERR_EVENT_TYPE Unlikely you would get this error because the semaphore used for signal
-ing is created
C51 COMPILER V8.17 OS_TMR 03/26/2009 14:24:25 PAGE 14
711 * by uC/OS-II.
712 * OS_ERR_PEVENT_NULL Again, unlikely you would ever get this error because the semaphore use
-d for signaling
713 * is created by uC/OS-II.
714 **********************************************************************************************************
-**************
715 */
716
717 #if OS_TMR_EN > 0
INT8U OSTmrSignal (void) reentrant
{
INT8U err;
err = OSSemPost(OSTmrSemSignal);
return (err);
}
#endif
727
728 /*$PAGE*/
729 /*
730 **********************************************************************************************************
-**************
731 * ALLOCATE AND FREE A TIMER
732 *
733 * Description: This function is called to allocate a timer.
734 *
735 * Arguments : none
736 *
737 * Returns : a pointer to a timer if one is available
738 **********************************************************************************************************
-**************
739 */
740
741 #if OS_TMR_EN > 0
static OS_TMR *OSTmr_Alloc (void) reentrant
{
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
759
760
761 /*
762 **********************************************************************************************************
-**************
763 * RETURN A TIMER TO THE FREE LIST
764 *
765 * Description: This function is called to return a timer object to the free list of timers.
766 *
767 * Arguments : ptmr is a pointer to the timer to free
C51 COMPILER V8.17 OS_TMR 03/26/2009 14:24:25 PAGE 15
768 *
769 * Returns : none
770 **********************************************************************************************************
-**************
771 */
772
773 #if OS_TMR_EN > 0 && OS_TMR_FREE_EN >0
static void OSTmr_Free (OS_TMR *ptmr) reentrant
{
ptmr->OSTmrState = OS_TMR_STATE_UNUSED; /* Clear timer object fields
- */
ptmr->OSTmrOpt = OS_TMR_OPT_NONE;
ptmr->OSTmrPeriod = 0;
ptmr->OSTmrMatch = 0;
ptmr->OSTmrCallback = (OS_TMR_CALLBACK)0;
ptmr->OSTmrCallbackArg = (void *)0;
#if OS_TMR_CFG_NAME_SIZE > 1
ptmr->OSTmrName[0] = '?'; /* Unknown name
- */
ptmr->OSTmrName[1] = OS_ASCII_NUL;
#endif
ptmr->OSTmrPrev = (OS_TCB *)0; /* Chain timer to free list
- */
ptmr->OSTmrNext = OSTmrFreeList;
OSTmrFreeList = ptmr;
OSTmrUsed--; /* Update timer object statistics
- */
OSTmrFree++;
}
#endif
795
796 /*$PAGE*/
797 /*
798 **********************************************************************************************************
-**************
799 * INITIALIZATION
800 * INITIALIZE THE FREE LIST OF TIMERS
801 *
802 * Description: This function is called by OSInit() to initialize the free list of OS_TMRs.
803 *
804 * Arguments : none
805 *
806 * Returns : none
807 **********************************************************************************************************
-**************
808 */
809
810 #if OS_TMR_EN > 0
void OSTmr_Init (void) reentrant
{
#if OS_EVENT_NAME_SIZE > 10
INT8U err;
#endif
INT16U i;
OS_TMR *ptmr1;
OS_TMR *ptmr2;
OS_MemClr((INT8U *)&OSTmrTbl[0], sizeof(OSTmrTbl)); /* Clear all the TMRs
- */
C51 COMPILER V8.17 OS_TMR 03/26/2009 14:24:25 PAGE 16
OS_MemClr((INT8U *)&OSTmrWheelTbl[0], sizeof(OSTmrWheelTbl)); /* Clear the timer wheel
- */
ptmr1 = &OSTmrTbl[0];
ptmr2 = &OSTmrTbl[1];
for (i = 0; i < (OS_TMR_CFG_MAX - 1); i++) { /* Init. list of free TMRs
- */
ptmr1->OSTmrType = OS_TMR_TYPE;
ptmr1->OSTmrState = OS_TMR_STATE_UNUSED; /* Indicate that timer is inactive
- */
ptmr1->OSTmrNext = (void *)ptmr2; /* Link to next timer
- */
#if OS_TMR_CFG_NAME_SIZE > 1
ptmr1->OSTmrName[0] = '?'; /* Unknown name
- */
ptmr1->OSTmrName[1] = OS_ASCII_NUL;
#endif
ptmr1++;
ptmr2++;
}
ptmr1->OSTmrType = OS_TMR_TYPE;
ptmr1->OSTmrState = OS_TMR_STATE_UNUSED; /* Indicate that timer is inactive
- */
ptmr1->OSTmrNext = (void *)0; /* Last OS_TMR
- */
#if OS_TMR_CFG_NAME_SIZE > 1
ptmr1->OSTmrName[0] = '?'; /* Unknown name
- */
ptmr1->OSTmrName[1] = OS_ASCII_NUL;
#endif
OSTmrTime = 0;
OSTmrUsed = 0;
OSTmrFree = OS_TMR_CFG_MAX;
OSTmrFreeList = &OSTmrTbl[0];
OSTmrSem = OSSemCreate(1);
OSTmrSemSignal = OSSemCreate(0);
#if OS_EVENT_NAME_SIZE > 18
OSEventNameSet(OSTmrSem, (INT8U *)"uC/OS-II TmrLock", &err);/* Assign names to semaphores
- */
#else
#if OS_EVENT_NAME_SIZE > 10
OSEventNameSet(OSTmrSem, (INT8U *)"OS-TmrLock", &err);
#endif
#endif
#if OS_EVENT_NAME_SIZE > 18
OSEventNameSet(OSTmrSemSignal, (INT8U *)"uC/OS-II TmrSignal", &err);
#else
#if OS_EVENT_NAME_SIZE > 10
OSEventNameSet(OSTmrSemSignal, (INT8U *)"OS-TmrSig", &err);
#endif
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -