OSTmrStateGet

Description

OSTmrStateGet() allows the user to obtain the current state of a timer. A timer can be in one of four states:

OS_TMR_STATE_UNUSED

the timer has not been created

OS_TMR_STATE_STOPPED

the timer is created but has not yet started, or has been stopped.

OS_TMR_STATE_COMPLETED

the timer is in one-shot mode, and has completed its delay.

OS_TMR_STATE_RUNNING

the timer is currently running

Files

os.h/os_tmr.c

Prototype

OS_STATE  OSTmrStateGet (OS_TMR  *p_tmr,
                         OS_ERR  *p_err)

Arguments

p_tmr

is a pointer to the timer that the user is inquiring about.

p_err

a pointer to an error code and can be any of the following:

OS_ERR_NONE

If the function returned the state of the timer.

OS_ERR_OBJ_TYPE

If OS_CFG_OBJ_TYPE_CHK_EN is set to DEF_ENABLED in os_cfg.h: p_tmr is not pointing to a timer.

OS_ERR_OS_NOT_RUNNING

If OS_CFG_INVALID_OS_CALLS_CHK_EN is set to DEF_ENABLED in os_cfg.h: if µC/OS-III is not running yet.

OS_ERR_TMR_INVALID

If OS_CFG_ARG_CHK_EN is set to DEF_ENABLED in os_cfg.h: if p_tmr is a NULL pointer.

OS_ERR_TMR_INVALID_STATE

If the timer is in an invalid state.

OS_ERR_TMR_ISR

If OS_CFG_CALLED_FROM_ISR_CHK_EN set to DEF_ENABLED in os_cfg.h: This function was called from an ISR, which is not allowed.

Returned Values

The state of the timer (see description).

Required Configuration

OS_CFG_TMR_EN must be enabled in os_cfg.h. Refer to µC-OS-III Configuration Manual.

Callers

Application.

Notes/Warnings

  1. Do not call this function from an ISR.

Example Usage

OSTmrStateGet() example usage
          OS_STATE   CloseDoorTmrState;
          OS_TMR     CloseDoorTmr;
           
           
          void Task (void *p_arg)
          {
              OS_ERR  err;
           
           
              (void)&p_arg;
              while (DEF_ON) {
                  CloseDoorTmrState = OSTmrStateGet(&CloseDoorTmr,
                                                    &err);
                  /* Check "err" */
                  :
                  :
              }
          }