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

📄 os_tmr.lst

📁 编译环境是 iar EWARM ,STM32 下的UCOSII
💻 LST
📖 第 1 页 / 共 5 页
字号:
    160                  return ((OS_TMR *)0);
    161              }
    162              ptmr->OSTmrState       = OS_TMR_STATE_STOPPED;          /* Indicate that timer is not running yet                 */
    163              ptmr->OSTmrDly         = dly;
    164              ptmr->OSTmrPeriod      = period;
    165              ptmr->OSTmrOpt         = opt;
    166              ptmr->OSTmrCallback    = callback;
    167              ptmr->OSTmrCallbackArg = callback_arg;
    168          #if OS_TMR_CFG_NAME_SIZE > 0
    169              if (pname !=(INT8U *)0) {
    170                  len = OS_StrLen(pname);                             /* Copy timer name                                        */
    171                  if (len < OS_TMR_CFG_NAME_SIZE) {
    172                      (void)OS_StrCopy(ptmr->OSTmrName, pname);
    173                  } else {
    174          #if OS_TMR_CFG_NAME_SIZE > 1
    175                      ptmr->OSTmrName[0] = '#';                       /* Invalid size specified                                 */
    176                      ptmr->OSTmrName[1] = OS_ASCII_NUL;
    177          #endif
    178                      *perr              = OS_ERR_TMR_NAME_TOO_LONG;
    179                      OSTmr_Unlock();
    180                      return (ptmr);
    181                  }
    182              }
    183          #endif
    184              OSTmr_Unlock();
    185              *perr = OS_ERR_NONE;
    186              return (ptmr);
    187          }
    188          #endif
    189          
    190          /*$PAGE*/
    191          /*
    192          ************************************************************************************************************************
    193          *                                                   DELETE A TIMER
    194          *
    195          * Description: This function is called by your application code to delete a timer.
    196          *
    197          * Arguments  : ptmr          Is a pointer to the timer to stop and delete.
    198          *
    199          *              perr          Is a pointer to an error code.  '*perr' will contain one of the following:
    200          *                               OS_ERR_NONE
    201          *                               OS_ERR_TMR_INVALID        'ptmr'  is a NULL pointer
    202          *                               OS_ERR_TMR_INVALID_TYPE   'ptmr'  is not pointing to an OS_TMR
    203          *                               OS_ERR_TMR_ISR            if the function was called from an ISR
    204          *                               OS_ERR_TMR_INACTIVE       if the timer was not created
    205          *                               OS_ERR_TMR_INVALID_STATE  the timer is in an invalid state
    206          *
    207          * Returns    : OS_TRUE       If the call was successful
    208          *              OS_FALSE      If not
    209          ************************************************************************************************************************
    210          */
    211          
    212          #if OS_TMR_EN > 0
    213          BOOLEAN  OSTmrDel (OS_TMR  *ptmr,
    214                             INT8U   *perr)
    215          {
    216          #if OS_ARG_CHK_EN > 0
    217              if (perr == (INT8U *)0) {                               /* Validate arguments                                     */
    218                  return (OS_FALSE);
    219              }
    220              if (ptmr == (OS_TMR *)0) {
    221                  *perr = OS_ERR_TMR_INVALID;
    222                  return (OS_FALSE);
    223              }
    224          #endif
    225              if (ptmr->OSTmrType != OS_TMR_TYPE) {                   /* Validate timer structure                               */
    226                  *perr = OS_ERR_TMR_INVALID_TYPE;
    227                  return (OS_FALSE);
    228              }
    229              if (OSIntNesting > 0) {                                 /* See if trying to call from an ISR                      */
    230                  *perr  = OS_ERR_TMR_ISR;
    231                  return (OS_FALSE);
    232              }
    233              OSTmr_Lock();
    234              switch (ptmr->OSTmrState) {
    235                  case OS_TMR_STATE_RUNNING:
    236                       OSTmr_Unlink(ptmr);                            /* Remove from current wheel spoke                        */
    237                       OSTmr_Free(ptmr);                              /* Return timer to free list of timers                    */
    238                       OSTmr_Unlock();
    239                       *perr = OS_ERR_NONE;
    240                       return (OS_TRUE);
    241          
    242                  case OS_TMR_STATE_STOPPED:                          /* Timer has not started or ...                           */
    243                  case OS_TMR_STATE_COMPLETED:                        /* ... timer has completed the ONE-SHOT time              */
    244                       OSTmr_Free(ptmr);                              /* Return timer to free list of timers                    */
    245                       OSTmr_Unlock();
    246                       *perr = OS_ERR_NONE;
    247                       return (OS_TRUE);
    248          
    249                  case OS_TMR_STATE_UNUSED:                           /* Already deleted                                        */
    250                       OSTmr_Unlock();
    251                       *perr = OS_ERR_TMR_INACTIVE;
    252                       return (OS_FALSE);
    253          
    254                  default:
    255                       OSTmr_Unlock();
    256                       *perr = OS_ERR_TMR_INVALID_STATE;
    257                       return (OS_FALSE);
    258              }
    259          }
    260          #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
    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
    288          INT8U  OSTmrNameGet (OS_TMR  *ptmr,
    289                               INT8U   *pdest,
    290                               INT8U   *perr)
    291          {
    292              INT8U  len;
    293          
    294          
    295          #if OS_ARG_CHK_EN > 0
    296              if (perr == (INT8U *)0) {
    297                  return (0);
    298              }
    299              if (pdest == (INT8U *)0) {
    300                  *perr = OS_ERR_TMR_INVALID_DEST;
    301                  return (0);
    302              }
    303              if (ptmr == (OS_TMR *)0) {
    304                  *perr = OS_ERR_TMR_INVALID;
    305                  return (0);
    306              }
    307          #endif
    308              if (ptmr->OSTmrType != OS_TMR_TYPE) {              /* Validate timer structure                                    */
    309                  *perr = OS_ERR_TMR_INVALID_TYPE;
    310                  return (0);
    311              }
    312              if (OSIntNesting > 0) {                            /* See if trying to call from an ISR                           */
    313                  *perr = OS_ERR_NAME_GET_ISR;
    314                  return (0);
    315              }
    316              OSTmr_Lock();
    317              switch (ptmr->OSTmrState) {
    318                  case OS_TMR_STATE_RUNNING:
    319                  case OS_TMR_STATE_STOPPED:
    320                  case OS_TMR_STATE_COMPLETED:
    321                       len   = OS_StrCopy(pdest, ptmr->OSTmrName);
    322                       OSTmr_Unlock();
    323                       *perr = OS_ERR_NONE;
    324                       return (len);
    325          
    326                  case OS_TMR_STATE_UNUSED:                      /* Timer is not allocated                                      */
    327                       OSTmr_Unlock();
    328                       *perr = OS_ERR_TMR_INACTIVE;
    329                       return (0);
    330          
    331                  default:
    332                       OSTmr_Unlock();
    333                       *perr = OS_ERR_TMR_INVALID_STATE;
    334                       return (0);
    335              }
    336          }
    337          #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 other words, if
    357          *              OSTmr_Task() is signaled every 1/10 of a second then the returned value represents the number of 1/10 of
    358          *              a second remaining before the timer expires.
    359          ************************************************************************************************************************
    360          */
    361          
    362          #if OS_TMR_EN > 0
    363          INT32U  OSTmrRemainGet (OS_TMR  *ptmr,
    364                                  INT8U   *perr)
    365          {
    366              INT32U  remain;
    367          
    368          
    369          #if OS_ARG_CHK_EN > 0
    370              if (perr == (INT8U *)0) {
    371                  return (0);
    372              }
    373              if (ptmr == (OS_TMR *)0) {
    374                  *perr = OS_ERR_TMR_INVALID;
    375                  return (0);
    376              }

⌨️ 快捷键说明

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