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

📄 os_tmr.lst

📁 编译环境是 iar EWARM ,STM32 下的UCOSII
💻 LST
📖 第 1 页 / 共 5 页
字号:
    594          *
    595          *              perr          Is a pointer to an error code.  '*perr' will contain one of the following:
    596          *                               OS_ERR_NONE
    597          *                               OS_ERR_TMR_INVALID         'ptmr' is a NULL pointer
    598          *                               OS_ERR_TMR_INVALID_TYPE    'ptmr'  is not pointing to an OS_TMR
    599          *                               OS_ERR_TMR_ISR             if the function was called from an ISR
    600          *                               OS_ERR_TMR_INACTIVE        if the timer was not created
    601          *                               OS_ERR_TMR_INVALID_OPT     if you specified an invalid option for 'opt'
    602          *                               OS_ERR_TMR_STOPPED         if the timer was already stopped
    603          *                               OS_ERR_TMR_INVALID_STATE   the timer is in an invalid state
    604          *                               OS_ERR_TMR_NO_CALLBACK     if the timer does not have a callback function defined
    605          *
    606          * Returns    : OS_TRUE       If we stopped the timer (if the timer is already stopped, we also return OS_TRUE)
    607          *              OS_FALSE      If not
    608          ************************************************************************************************************************
    609          */
    610          
    611          #if OS_TMR_EN > 0
    612          BOOLEAN  OSTmrStop (OS_TMR  *ptmr,
    613                              INT8U    opt,
    614                              void    *callback_arg,
    615                              INT8U   *perr)
    616          {
    617              OS_TMR_CALLBACK  pfnct;
    618          
    619          
    620          #if OS_ARG_CHK_EN > 0
    621              if (perr == (INT8U *)0) {                                     /* Validate arguments                               */
    622                  return (OS_FALSE);
    623              }
    624              if (ptmr == (OS_TMR *)0) {
    625                  *perr = OS_ERR_TMR_INVALID;
    626                  return (OS_FALSE);
    627              }
    628          #endif
    629              if (ptmr->OSTmrType != OS_TMR_TYPE) {                         /* Validate timer structure                         */
    630                  *perr = OS_ERR_TMR_INVALID_TYPE;
    631                  return (OS_FALSE);
    632              }
    633              if (OSIntNesting > 0) {                                       /* See if trying to call from an ISR                */
    634                  *perr  = OS_ERR_TMR_ISR;
    635                  return (OS_FALSE);
    636              }
    637              OSTmr_Lock();
    638              switch (ptmr->OSTmrState) {
    639                  case OS_TMR_STATE_RUNNING:
    640                       OSTmr_Unlink(ptmr);                                  /* Remove from current wheel spoke                  */
    641                       *perr = OS_ERR_NONE;
    642                       switch (opt) {
    643                           case OS_TMR_OPT_CALLBACK:
    644                                pfnct = ptmr->OSTmrCallback;                /* Execute callback function if available ...       */
    645                                if (pfnct != (OS_TMR_CALLBACK)0) {
    646                                    (*pfnct)((void *)ptmr, ptmr->OSTmrCallbackArg);  /* Use callback arg when timer was created */
    647                                } else {
    648                                    *perr = OS_ERR_TMR_NO_CALLBACK;
    649                                }
    650                                break;
    651          
    652                           case OS_TMR_OPT_CALLBACK_ARG:
    653                                pfnct = ptmr->OSTmrCallback;                /* Execute callback function if available ...       */
    654                                if (pfnct != (OS_TMR_CALLBACK)0) {
    655                                    (*pfnct)((void *)ptmr, callback_arg);   /* ... using the 'callback_arg' provided in call    */
    656                                } else {
    657                                    *perr = OS_ERR_TMR_NO_CALLBACK;
    658                                }
    659                                break;
    660          
    661                           case OS_TMR_OPT_NONE:
    662                                break;
    663          
    664                           default:
    665                               *perr = OS_ERR_TMR_INVALID_OPT;
    666                               break;
    667                       }
    668                       OSTmr_Unlock();
    669                       return (OS_TRUE);
    670          
    671                  case OS_TMR_STATE_COMPLETED:                              /* Timer has already completed the ONE-SHOT or ...  */
    672                  case OS_TMR_STATE_STOPPED:                                /* ... timer has not started yet.                   */
    673                       OSTmr_Unlock();
    674                       *perr = OS_ERR_TMR_STOPPED;
    675                       return (OS_TRUE);
    676          
    677                  case OS_TMR_STATE_UNUSED:                                 /* Timer was not created                            */
    678                       OSTmr_Unlock();
    679                       *perr = OS_ERR_TMR_INACTIVE;
    680                       return (OS_FALSE);
    681          
    682                  default:
    683                       OSTmr_Unlock();
    684                       *perr = OS_ERR_TMR_INVALID_STATE;
    685                       return (OS_FALSE);
    686              }
    687          }
    688          #endif
    689          
    690          /*$PAGE*/
    691          /*
    692          ************************************************************************************************************************
    693          *                                      SIGNAL THAT IT'S TIME TO UPDATE THE TIMERS
    694          *
    695          * Description: This function is typically called by the ISR that occurs at the timer tick rate and is used to signal to
    696          *              OSTmr_Task() that it's time to update the timers.
    697          *
    698          * Arguments  : none
    699          *
    700          * Returns    : OS_ERR_NONE         The call was successful and the timer task was signaled.
    701          *              OS_ERR_SEM_OVF      If OSTmrSignal() was called more often than OSTmr_Task() can handle the timers.  
    702          *                                  This would indicate that your system is heavily loaded.
    703          *              OS_ERR_EVENT_TYPE   Unlikely you would get this error because the semaphore used for signaling is created 
    704          *                                  by uC/OS-II.
    705          *              OS_ERR_PEVENT_NULL  Again, unlikely you would ever get this error because the semaphore used for signaling 
    706          *                                  is created by uC/OS-II.
    707          ************************************************************************************************************************
    708          */
    709          
    710          #if OS_TMR_EN > 0
    711          INT8U  OSTmrSignal (void)
    712          {
    713              INT8U  err;
    714          
    715          
    716              err = OSSemPost(OSTmrSemSignal);
    717              return (err);
    718          }
    719          #endif
    720          
    721          /*$PAGE*/
    722          /*
    723          ************************************************************************************************************************
    724          *                                               ALLOCATE AND FREE A TIMER
    725          *
    726          * Description: This function is called to allocate a timer.
    727          *
    728          * Arguments  : none
    729          *
    730          * Returns    : a pointer to a timer if one is available
    731          ************************************************************************************************************************
    732          */
    733          
    734          #if OS_TMR_EN > 0
    735          static  OS_TMR  *OSTmr_Alloc (void)
    736          {
    737              OS_TMR *ptmr;
    738          
    739          
    740              if (OSTmrFreeList == (OS_TMR *)0) {
    741                  return ((OS_TMR *)0);
    742              }
    743              ptmr            = (OS_TMR *)OSTmrFreeList;
    744              OSTmrFreeList   = (OS_TMR *)ptmr->OSTmrNext;
    745              ptmr->OSTmrNext = (OS_TCB *)0;
    746              ptmr->OSTmrPrev = (OS_TCB *)0;
    747              OSTmrUsed++;
    748              OSTmrFree--;
    749              return (ptmr);
    750          }
    751          #endif
    752          
    753          
    754          /*
    755          ************************************************************************************************************************
    756          *                                             RETURN A TIMER TO THE FREE LIST
    757          *
    758          * Description: This function is called to return a timer object to the free list of timers.
    759          *
    760          * Arguments  : ptmr     is a pointer to the timer to free
    761          *
    762          * Returns    : none
    763          ************************************************************************************************************************
    764          */
    765          
    766          #if OS_TMR_EN > 0
    767          static  void  OSTmr_Free (OS_TMR *ptmr)
    768          {
    769              ptmr->OSTmrState       = OS_TMR_STATE_UNUSED;      /* Clear timer object fields                                   */
    770              ptmr->OSTmrOpt         = OS_TMR_OPT_NONE;
    771              ptmr->OSTmrPeriod      = 0;
    772              ptmr->OSTmrMatch       = 0;
    773              ptmr->OSTmrCallback    = (OS_TMR_CALLBACK)0;
    774              ptmr->OSTmrCallbackArg = (void *)0;
    775          #if OS_TMR_CFG_NAME_SIZE > 1
    776              ptmr->OSTmrName[0]     = '?';                      /* Unknown name                                                */
    777              ptmr->OSTmrName[1]     = OS_ASCII_NUL;
    778          #endif
    779          
    780              ptmr->OSTmrPrev        = (OS_TCB *)0;              /* Chain timer to free list                                    */
    781              ptmr->OSTmrNext        = OSTmrFreeList;
    782              OSTmrFreeList          = ptmr;
    783          
    784              OSTmrUsed--;                                       /* Update timer object statistics                              */
    785              OSTmrFree++;
    786          }
    787          #endif
    788          
    789          /*$PAGE*/
    790          /*
    791          ************************************************************************************************************************
    792          *                                                    INITIALIZATION
    793          *                                          INITIALIZE THE FREE LIST OF TIMERS
    794          *
    795          * Description: This function is called by OSInit() to initialize the free list of OS_TMRs.
    796          *
    797          * Arguments  : none
    798          *
    799          * Returns    : none
    800          ************************************************************************************************************************
    801          */
    802          
    803          #if OS_TMR_EN > 0
    804          void  OSTmr_Init (void)
    805          {
    806          #if OS_EVENT_NAME_SIZE > 10
    807              INT8U    err;
    808          #endif
    809              INT16U   i;
    810              OS_TMR  *ptmr1;

⌨️ 快捷键说明

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