📄 os_tmr.lst
字号:
#if OS_ARG_CHK_EN > 0
if (perr == (INT8U *)0) { /* Validate arguments
C51 COMPILER V7.50 OS_TMR 12/14/2007 08:25:46 PAGE 5
- */
return (OS_FALSE);
}
if (ptmr == (OS_TMR *)0) {
*perr = OS_ERR_TMR_INVALID;
return (OS_FALSE);
}
#endif
if (ptmr->OSTmrType != OS_TMR_TYPE) { /* Validate timer structure
- */
*perr = OS_ERR_TMR_INVALID_TYPE;
return (OS_FALSE);
}
if (OSIntNesting > 0) { /* See if trying to call from an ISR
- */
*perr = OS_ERR_TMR_ISR;
return (OS_FALSE);
}
OSTmr_Lock();
switch (ptmr->OSTmrState) {
case OS_TMR_STATE_RUNNING:
OSTmr_Unlink(ptmr); /* Remove from current wheel spoke
- */
OSTmr_Free(ptmr); /* Return timer to free list of timers
- */
OSTmr_Unlock();
*perr = OS_ERR_NONE;
return (OS_TRUE);
case OS_TMR_STATE_STOPPED: /* Timer has not started or ...
- */
case OS_TMR_STATE_COMPLETED: /* ... timer has completed the ONE-SHOT time
- */
OSTmr_Free(ptmr); /* Return timer to free list of timers
- */
OSTmr_Unlock();
*perr = OS_ERR_NONE;
return (OS_TRUE);
case OS_TMR_STATE_UNUSED: /* Already deleted
- */
OSTmr_Unlock();
*perr = OS_ERR_TMR_INACTIVE;
return (OS_FALSE);
default:
OSTmr_Unlock();
*perr = OS_ERR_TMR_INVALID_STATE;
return (OS_FALSE);
}
}
#endif
261
262 /*$PAGE*/
263 /*
264 **********************************************************************************************************
-**************
265 * GET THE NAME OF A TIMER
266 *
267 * Description: This function is called to obtain the name of a timer.
268 *
269 * Arguments : ptmr Is a pointer to the timer to obtain the name for
C51 COMPILER V7.50 OS_TMR 12/14/2007 08:25:46 PAGE 6
270 *
271 * pdest Is a pointer to where the name of the timer will be placed. It is the caller
-'s responsibility
272 * to ensure that he has sufficient storage in the destination, i.e. at least OS
-_TMR_CFG_NAME_SIZE
273 *
274 * perr Is a pointer to an error code. '*perr' will contain one of the following:
275 * OS_ERR_NONE The call was successful
276 * OS_ERR_TMR_INVALID_DEST 'pdest' is a NULL pointer
277 * OS_ERR_TMR_INVALID 'ptmr' is a NULL pointer
278 * OS_ERR_TMR_INVALID_TYPE 'ptmr' is not pointing to an OS_TMR
279 * OS_ERR_NAME_GET_ISR if the call was made from an ISR
280 * OS_ERR_TMR_INACTIVE 'ptmr' points to a timer that is not active
281 * OS_ERR_TMR_INVALID_STATE the timer is in an invalid state
282 *
283 * Returns : The length of the string or 0 if the timer does not exist.
284 **********************************************************************************************************
-**************
285 */
286
287 #if OS_TMR_EN > 0 && OS_TMR_CFG_NAME_SIZE > 0
INT8U OSTmrNameGet (OS_TMR *ptmr,
INT8U *pdest,
INT8U *perr) reentrant
{
INT8U len;
#if OS_ARG_CHK_EN > 0
if (perr == (INT8U *)0) {
return (0);
}
if (pdest == (INT8U *)0) {
*perr = OS_ERR_TMR_INVALID_DEST;
return (0);
}
if (ptmr == (OS_TMR *)0) {
*perr = OS_ERR_TMR_INVALID;
return (0);
}
#endif
if (ptmr->OSTmrType != OS_TMR_TYPE) { /* Validate timer structure
- */
*perr = OS_ERR_TMR_INVALID_TYPE;
return (0);
}
if (OSIntNesting > 0) { /* See if trying to call from an ISR
- */
*perr = OS_ERR_NAME_GET_ISR;
return (0);
}
OSTmr_Lock();
switch (ptmr->OSTmrState) {
case OS_TMR_STATE_RUNNING:
case OS_TMR_STATE_STOPPED:
case OS_TMR_STATE_COMPLETED:
len = OS_StrCopy(pdest, ptmr->OSTmrName);
OSTmr_Unlock();
*perr = OS_ERR_NONE;
return (len);
case OS_TMR_STATE_UNUSED: /* Timer is not allocated
C51 COMPILER V7.50 OS_TMR 12/14/2007 08:25:46 PAGE 7
- */
OSTmr_Unlock();
*perr = OS_ERR_TMR_INACTIVE;
return (0);
default:
OSTmr_Unlock();
*perr = OS_ERR_TMR_INVALID_STATE;
return (0);
}
}
#endif
338
339 /*$PAGE*/
340 /*
341 **********************************************************************************************************
-**************
342 * GET HOW MUCH TIME IS LEFT BEFORE A TIMER EXPIRES
343 *
344 * Description: This function is called to get the number of ticks before a timer times out.
345 *
346 * Arguments : ptmr Is a pointer to the timer to obtain the remaining time from.
347 *
348 * perr Is a pointer to an error code. '*perr' will contain one of the following:
349 * OS_ERR_NONE
350 * OS_ERR_TMR_INVALID 'ptmr' is a NULL pointer
351 * OS_ERR_TMR_INVALID_TYPE 'ptmr' is not pointing to an OS_TMR
352 * OS_ERR_TMR_ISR if the call was made from an ISR
353 * OS_ERR_TMR_INACTIVE 'ptmr' points to a timer that is not active
354 * OS_ERR_TMR_INVALID_STATE the timer is in an invalid state
355 *
356 * Returns : The time remaining for the timer to expire. The time represents 'timer' increments. In ot
-her words, if
357 * OSTmr_Task() is signaled every 1/10 of a second then the returned value represents the numb
-er of 1/10 of
358 * a second remaining before the timer expires.
359 **********************************************************************************************************
-**************
360 */
361
362 #if OS_TMR_EN > 0
INT32U OSTmrRemainGet (OS_TMR *ptmr,
INT8U *perr) reentrant
{
INT32U remain;
#if OS_ARG_CHK_EN > 0
if (perr == (INT8U *)0) {
return (0);
}
if (ptmr == (OS_TMR *)0) {
*perr = OS_ERR_TMR_INVALID;
return (0);
}
#endif
if (ptmr->OSTmrType != OS_TMR_TYPE) { /* Validate timer structure
- */
*perr = OS_ERR_TMR_INVALID_TYPE;
return (0);
}
if (OSIntNesting > 0) { /* See if trying to call from an ISR
C51 COMPILER V7.50 OS_TMR 12/14/2007 08:25:46 PAGE 8
- */
*perr = OS_ERR_TMR_ISR;
return (0);
}
OSTmr_Lock();
switch (ptmr->OSTmrState) {
case OS_TMR_STATE_RUNNING:
remain = ptmr->OSTmrMatch - OSTmrTime; /* Determine how much time is left to timeout
- */
OSTmr_Unlock();
*perr = OS_ERR_NONE;
return (remain);
case OS_TMR_STATE_STOPPED: /* It's assumed that the timer has not started yet
- */
switch (ptmr->OSTmrOpt) {
case OS_TMR_OPT_PERIODIC:
if (ptmr->OSTmrDly == 0) {
remain = ptmr->OSTmrPeriod;
} else {
remain = ptmr->OSTmrDly;
}
OSTmr_Unlock();
*perr = OS_ERR_NONE;
break;
case OS_TMR_OPT_ONE_SHOT:
default:
remain = ptmr->OSTmrDly;
OSTmr_Unlock();
*perr = OS_ERR_NONE;
break;
}
return (remain);
case OS_TMR_STATE_COMPLETED: /* Only ONE-SHOT that timed out can be in this stat
-e */
OSTmr_Unlock();
*perr = OS_ERR_NONE;
return (0);
case OS_TMR_STATE_UNUSED:
OSTmr_Unlock();
*perr = OS_ERR_TMR_INACTIVE;
return (0);
default:
OSTmr_Unlock();
*perr = OS_ERR_TMR_INVALID_STATE;
return (0);
}
}
#endif
432
433 /*$PAGE*/
434 /*
435 **********************************************************************************************************
-**************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -