⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timer.c

📁 基于MDK的LPC1100处理器开发应用例程
💻 C
📖 第 1 页 / 共 2 页
字号:
        return E_INVALID_ID;
    }
#endif
    
    if(TmrTbl[tmrID].tmrState == TMR_STATE_RUNNING)   /* Is timer running?    */
    {
        return E_OK;                              /* Yes,do nothing,return OK */
    }
    
    /* No,set timer status as TMR_STATE_RUNNING */
    TmrTbl[tmrID].tmrState = TMR_STATE_RUNNING; 
    InsertTmrList(tmrID);               /* Insert this timer into timer list  */
    return E_OK;                        /* Return OK                          */
}



/**
 *******************************************************************************
 * @brief      Stop countering for a spcify timer	  
 * @param[in]  tmrID    Specify a timer which stopped.	 
 * @param[out] None  	 
 * @retval     E_INVALID_ID  The timer id passed was invalid, stop failure.
 * @retval     E_OK          Stop a timer countering successful.
 *
 * @par Description
 * @details    This function is called to stop a timer from counting. 
 *******************************************************************************
 */
StatusType CoStopTmr(OS_TCID tmrID)
{	
#if CFG_PAR_CHECKOUT_EN >0              /* Check validity of parameter        */
    if(tmrID >= CFG_MAX_TMR)
    {
        return E_INVALID_ID;
    }
    if((TmrIDVessel & (1<<tmrID)) == 0)
    {
        return E_INVALID_ID;
    }
#endif
    
    
    if(TmrTbl[tmrID].tmrState == TMR_STATE_STOPPED)/* Does timer stop running?*/
    {
        return E_OK;                    /* Yes,do nothing,return OK           */
    }
    RemoveTmrList(tmrID);             /* No,remove this timer from timer list */
    
    /* Set timer status as TMR_STATE_STOPPED  */
    TmrTbl[tmrID].tmrState = TMR_STATE_STOPPED;	
    return E_OK;                        /* Return OK                          */
}


/**
 *******************************************************************************
 * @brief      Delete a timer	 
 * @param[in]  tmrID     Specify a timer which deleted.		 
 * @param[out] None   
 * @retval     E_INVALID_ID  The timer id passed was invalid,deleted failure.	
 * @retval     E_OK          Delete a timer successful.
 *
 * @par Description
 * @details    This function is called to delete a timer which created before.	
 *******************************************************************************
 */
StatusType CoDelTmr(OS_TCID tmrID)
{
#if CFG_PAR_CHECKOUT_EN >0              /* Check validity of parameter        */
    if(tmrID >= CFG_MAX_TMR)
    {
        return E_INVALID_ID;
    }
    if( (TmrIDVessel & (1<<tmrID)) == 0)
    {
        return E_INVALID_ID;
    }
#endif
	
    if(TmrTbl[tmrID].tmrState == TMR_STATE_RUNNING) /* Is timer running?      */
    {
        RemoveTmrList(tmrID);         /* Yes,remove this timer from timer list*/
    }
    TmrIDVessel &=~(1<<tmrID);        /* Release resource that this timer hold*/
    return E_OK;                      /* Return OK                            */
}

 
/**
 *******************************************************************************
 * @brief      Get current counter of specify timer	 
 * @param[in]  tmrID          Specify timer by ID.		 
 * @param[out] E_INVALID_ID   Invalid ID was passed and get counter failure.	  
 * @param[out] E_OK           Get current counter successful.	 
 * @retval     Current counter of a timer which specify by id.			 
 *
 * @par Description
 * @details    This function is called to obtain current counter of specify timer.
 *******************************************************************************
 */
U32 CoGetCurTmrCnt(OS_TCID tmrID,StatusType* perr)
{
#if CFG_PAR_CHECKOUT_EN >0              /* Check validity of parameter        */
    if(tmrID >= CFG_MAX_TMR)
    {
        *perr = E_INVALID_ID;
        return 0;
    }
    if((TmrIDVessel & (1<<tmrID)) == 0)
    {
        *perr = E_INVALID_ID;
        return 0;
    }
#endif
    *perr = E_OK;
    return TmrTbl[tmrID].tmrCnt;        /* Return timer counter               */
}


/**
 *******************************************************************************
 * @brief      Setting for a specify timer	  		   	
 * @param[in]  tmrID       Specify timer by ID.
 * @param[in]  tmrCnt      Specify timer counter which need to be set.
 * @param[in]  tmrReload   Specify timer reload value which need to be set.		 
 * @param[out] None  
 * @retval     E_INVALID_ID  The ID passed was invalid,set fail.
 * @retval     E_OK          Set timer counter successful.				 
 *
 * @par Description
 * @details    This function is called to set timer counter and reload value.
 *******************************************************************************
 */
StatusType CoSetTmrCnt(OS_TCID tmrID,U32 tmrCnt,U32 tmrReload)
{
#if CFG_PAR_CHECKOUT_EN >0              /* Check validity of parameter        */
    if(tmrID >= CFG_MAX_TMR)
    {
        return E_INVALID_ID;
    }
    if( (TmrIDVessel & (1<<tmrID)) == 0)
    {
        return E_INVALID_ID;
    }
#endif
    TmrTbl[tmrID].tmrCnt    = tmrCnt; /* Reset timer counter and reload value */
    TmrTbl[tmrID].tmrReload = tmrReload;
    								
    if(TmrTbl[tmrID].tmrState == TMR_STATE_RUNNING)   /* Is timer running?    */
    {
        RemoveTmrList(tmrID);           /* Yes,reorder timer in timer list    */
        InsertTmrList(tmrID);	
    }
    return E_OK;                        /* Return OK                          */
}


/**
 *******************************************************************************
 * @brief      Timer counter dispose	   
 * @param[in]  None 	 
 * @param[out] None	 
 * @retval     None	 
 *
 * @par Description
 * @details    This function is called to dispose timer counter.
 *******************************************************************************
 */
void TmrDispose(void)
{
    P_TmrCtrl	pTmr;
    
    pTmr = TmrList;                     /* Get first item of timer list       */
    while((pTmr != NULL) && (pTmr->tmrCnt == 0) )
    {	
        if(pTmr->tmrType == TMR_TYPE_ONE_SHOT)    /* Is a One-shot timer?     */
        {
            /* Yes,remove this timer from timer list                          */
            RemoveTmrList(pTmr->tmrID);
            
            /* Set timer status as TMR_STATE_STOPPED                          */
            pTmr->tmrState = TMR_STATE_STOPPED;
            (pTmr->tmrCallBack)();          /* Call timer callback function   */
        }
        else if(pTmr->tmrType == TMR_TYPE_PERIODIC)   /* Is a periodic timer? */
        {
            /* Yes,remove this timer from timer list                          */
            RemoveTmrList(pTmr->tmrID); 
            pTmr->tmrCnt = pTmr->tmrReload;   /* Reset timer tick             */
            InsertTmrList(pTmr->tmrID);       /* Insert timer into timer list */
            (pTmr->tmrCallBack)();            /* Call timer callback function */
        }
        pTmr = TmrList;	                      /* Get first item of timer list */
    }
}


/**
 *******************************************************************************
 * @brief      Timer counter dispose in ISR	   
 * @param[in]  None 	 
 * @param[out] None	 
 * @retval     None	 
 *
 * @par Description
 * @details    This function is called to dispose timer counter.
 *******************************************************************************
 */
void isr_TmrDispose(void)
{
    if(OSSchedLock > 1)                 /* Is schedule lock?                  */
    {
        IsrReq = TRUE;
        TimerReq  = TRUE;               /* Yes,set timer request true         */
    }
    else
    {
        TmrDispose();                   /* No,call handler                    */
    }
}	 

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -