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

📄 os_tmr.lst

📁 uCos-ii 2.86 在C8051F410单片机上移植成功!!! 其中包括:UART驱动
💻 LST
📖 第 1 页 / 共 5 页
字号:
 436          **********************************************************************************************************
             -**************
 437          *                                    FIND OUT WHAT STATE A TIMER IS IN
 438          *
C51 COMPILER V8.17   OS_TMR                                                                03/26/2009 14:24:25 PAGE 9   

 439          * Description: This function is called to determine what state the timer is in:
 440          *
 441          *                  OS_TMR_STATE_UNUSED     the timer has not been created
 442          *                  OS_TMR_STATE_STOPPED    the timer has been created but has not been started or has been
             - stopped
 443          *                  OS_TMR_COMPLETED        the timer is in ONE-SHOT mode and has completed it's timeout
 444          *                  OS_TMR_RUNNING          the timer is currently running
 445          *
 446          * Arguments  : ptmr          Is a pointer to the desired timer
 447          *
 448          *              perr          Is a pointer to an error code.  '*perr' will contain one of the following:
 449          *                               OS_ERR_NONE
 450          *                               OS_ERR_TMR_INVALID        'ptmr' is a NULL pointer
 451          *                               OS_ERR_TMR_INVALID_TYPE   'ptmr'  is not pointing to an OS_TMR
 452          *                               OS_ERR_TMR_ISR            if the call was made from an ISR
 453          *                               OS_ERR_TMR_INACTIVE       'ptmr' points to a timer that is not active
 454          *                               OS_ERR_TMR_INVALID_STATE  if the timer is not in a valid state
 455          *
 456          * Returns    : The current state of the timer (see description).
 457          **********************************************************************************************************
             -**************
 458          */
 459          
 460          #if OS_TMR_EN > 0 && OS_TMR_STATEGET_EN >0
              INT8U  OSTmrStateGet (OS_TMR  *ptmr,
                                    INT8U   *perr) reentrant
              {
                  INT8U  state;
              
              
              #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               
             -            */
                      *perr = OS_ERR_TMR_ISR;
                      return (0);
                  }
                  OSTmr_Lock();
                  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;
C51 COMPILER V8.17   OS_TMR                                                                03/26/2009 14:24:25 PAGE 10  

                  }
                  OSTmr_Unlock();
                  return (state);
              }
              #endif
 502          
 503          /*$PAGE*/
 504          /*
 505          **********************************************************************************************************
             -**************
 506          *                                                   START A TIMER
 507          *
 508          * Description: This function is called by your application code to start a timer.
 509          *
 510          * Arguments  : ptmr          Is a pointer to an OS_TMR
 511          *
 512          *              perr          Is a pointer to an error code.  '*perr' will contain one of the following:
 513          *                               OS_ERR_NONE
 514          *                               OS_ERR_TMR_INVALID
 515          *                               OS_ERR_TMR_INVALID_TYPE    'ptmr'  is not pointing to an OS_TMR
 516          *                               OS_ERR_TMR_ISR             if the call was made from an ISR
 517          *                               OS_ERR_TMR_INACTIVE        if the timer was not created
 518          *                               OS_ERR_TMR_INVALID_STATE   the timer is in an invalid state
 519          *
 520          * Returns    : OS_TRUE    if the timer was started
 521          *              OS_FALSE   if an error was detected
 522          **********************************************************************************************************
             -**************
 523          */
 524          
 525          #if OS_TMR_EN > 0
              BOOLEAN  OSTmrStart (OS_TMR   *ptmr,
                                   INT8U    *perr) reentrant
              {
              #if OS_ARG_CHK_EN > 0
                  if (perr == (INT8U *)0) {                               /* Validate arguments                         
             -            */
                      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:                          /* Restart the timer                          
             -            */
                           OSTmr_Unlink(ptmr);                            /* ... Stop the timer                         
             -            */
                           OSTmr_Link(ptmr, OS_TMR_LINK_DLY);             /* ... Link timer to timer wheel              
             -            */
C51 COMPILER V8.17   OS_TMR                                                                03/26/2009 14:24:25 PAGE 11  

                           OSTmr_Unlock();
                           *perr = OS_ERR_NONE;
                           return (OS_TRUE);
              
                      case OS_TMR_STATE_STOPPED:                          /* Start the timer                            
             -            */
                      case OS_TMR_STATE_COMPLETED:
                           OSTmr_Link(ptmr, OS_TMR_LINK_DLY);             /* ... Link timer to timer wheel              
             -            */
                           OSTmr_Unlock();
                           *perr = OS_ERR_NONE;
                           return (OS_TRUE);
              
                      case OS_TMR_STATE_UNUSED:                           /* Timer not created                          
             -            */
                           OSTmr_Unlock();
                           *perr = OS_ERR_TMR_INACTIVE;
                           return (OS_FALSE);
              
                      default:
                           OSTmr_Unlock();
                           *perr = OS_ERR_TMR_INVALID_STATE;
                           return (OS_FALSE);
                  }
              }
              #endif
 574          
 575          /*$PAGE*/
 576          /*
 577          **********************************************************************************************************
             -**************
 578          *                                                   STOP A TIMER
 579          *
 580          * Description: This function is called by your application code to stop a timer.
 581          *
 582          * Arguments  : ptmr          Is a pointer to the timer to stop.
 583          *
 584          *              opt           Allows you to specify an option to this functions which can be:
 585          *
 586          *                               OS_TMR_OPT_NONE          Do nothing special but stop the timer
 587          *                               OS_TMR_OPT_CALLBACK      Execute the callback function, pass it the callba
             -ck argument
 588          *                                                        specified when the timer was created.
 589          *                               OS_TMR_OPT_CALLBACK_ARG  Execute the callback function, pass it the callba
             -ck argument
 590          *                                                        specified in THIS function call
 591          *
 592          *              callback_arg  Is a pointer to a 'new' callback argument that can be passed to the callback 
             -function
 593          *                               instead of the timer's callback argument.  In other words, use 'callback_a
             -rg' passed in
 594          *                               THIS function INSTEAD of ptmr->OSTmrCallbackArg
 595          *
 596          *              perr          Is a pointer to an error code.  '*perr' will contain one of the following:
 597          *                               OS_ERR_NONE
 598          *                               OS_ERR_TMR_INVALID         'ptmr' is a NULL pointer
 599          *                               OS_ERR_TMR_INVALID_TYPE    'ptmr'  is not pointing to an OS_TMR
 600          *                               OS_ERR_TMR_ISR             if the function was called from an ISR
 601          *                               OS_ERR_TMR_INACTIVE        if the timer was not created
 602          *                               OS_ERR_TMR_INVALID_OPT     if you specified an invalid option for 'opt'
 603          *                               OS_ERR_TMR_STOPPED         if the timer was already stopped
 604          *                               OS_ERR_TMR_INVALID_STATE   the timer is in an invalid state
C51 COMPILER V8.17   OS_TMR                                                                03/26/2009 14:24:25 PAGE 12  

 605          *                               OS_ERR_TMR_NO_CALLBACK     if the timer does not have a callback function 
             -defined
 606          *
 607          * Returns    : OS_TRUE       If we stopped the timer (if the timer is already stopped, we also return OS_T
             -RUE)
 608          *              OS_FALSE      If not
 609          **********************************************************************************************************
             -**************
 610          */
 611          
 612          #if OS_TMR_EN > 0 && OS_TMR_STOP_EN >0
              BOOLEAN  OSTmrStop (OS_TMR  *ptmr,
                                  INT8U    opt,
                                  void    *callback_arg,
                                  INT8U   *perr) reentrant
              {
                  OS_TMR_CALLBACK  pfnct;
              
                  callback_arg  = callback_arg;
              
              
              #if OS_ARG_CHK_EN > 0
                  if (perr == (INT8U *)0) {                                     /* Validate arguments                   
             -            */
                      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      
             -            */
                           *perr = OS_ERR_NONE;
                           switch (opt) {
                               case OS_TMR_OPT_CALLBACK:
                                    pfnct = ptmr->OSTmrCallback;                /* Execute callback function if availabl
             -e ...       */
                                    if (pfnct != (OS_TMR_CALLBACK)0) {
                                        //(*pfnct)((void *)ptmr, ptmr->OSTmrCallbackArg);  /* Use callback arg when time
             -r was created */
                                        (*pfnct)((void *)ptmr);    /* ... using the 'callback_arg' provided in call    */
              

⌨️ 快捷键说明

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