#ifOS_TMR_EN >0u&& OS_TMR_CFG_NAME_EN >0u
INT8U OSTmrNameGet(OS_TMR *ptmr,
INT8U **pdest,
INT8U *perr){
INT8U len;#ifdefOS_SAFETY_CRITICALif(perr ==(INT8U *)0){OS_SAFETY_CRITICAL_EXCEPTION();return(0u);}#endif#ifOS_ARG_CHK_EN >0uif(pdest ==(INT8U **)0){*perr = OS_ERR_TMR_INVALID_DEST;return(0u);}if(ptmr ==(OS_TMR *)0){*perr = OS_ERR_TMR_INVALID;return(0u);}#endifif(ptmr->OSTmrType != OS_TMR_TYPE)/* Validate timer structure */{*perr = OS_ERR_TMR_INVALID_TYPE;return(0u);}if(OSIntNesting >0u)/* See if trying to call from an ISR */{*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:/* Timer is not allocated */OSSchedUnlock();*perr = OS_ERR_TMR_INACTIVE;return(0u);default:OSSchedUnlock();*perr = OS_ERR_TMR_INVALID_STATE;return(0u);}}#endif
获取计时器到期前剩余的时间
#ifOS_TMR_EN >0u
INT32U OSTmrRemainGet(OS_TMR *ptmr,
INT8U *perr){
INT32U remain;#ifdefOS_SAFETY_CRITICALif(perr ==(INT8U *)0){OS_SAFETY_CRITICAL_EXCEPTION();return(0u);}#endif#ifOS_ARG_CHK_EN >0uif(ptmr ==(OS_TMR *)0){*perr = OS_ERR_TMR_INVALID;return(0u);}#endifif(ptmr->OSTmrType != OS_TMR_TYPE)/* Validate timer structure */{*perr = OS_ERR_TMR_INVALID_TYPE;return(0u);}if(OSIntNesting >0u)/* See if trying to call from an ISR */{*perr = OS_ERR_TMR_ISR;return(0u);}OSSchedLock();switch(ptmr->OSTmrState){case OS_TMR_STATE_RUNNING:
remain = ptmr->OSTmrMatch - OSTmrTime;/* Determine how much time is left to timeout */OSSchedUnlock();*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 ==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:/* Only ONE-SHOT that timed out can be in this state */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
查看计时器的状态
#ifOS_TMR_EN >0u
INT8U OSTmrStateGet(OS_TMR *ptmr,
INT8U *perr){
INT8U state;#ifdefOS_SAFETY_CRITICALif(perr ==(INT8U *)0){OS_SAFETY_CRITICAL_EXCEPTION();return(0u);}#endif#ifOS_ARG_CHK_EN >0uif(ptmr ==(OS_TMR *)0){*perr = OS_ERR_TMR_INVALID;return(0u);}#endifif(ptmr->OSTmrType != OS_TMR_TYPE)/* Validate timer structure */{*perr = OS_ERR_TMR_INVALID_TYPE;return(0u);}if(OSIntNesting >0u)/* See if trying to call from an ISR */{*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