- Main Page
- Modules
- Data Structures
- Files

# Timer Functions
[User API: Pico Layer]

## Defines
#define | HZ (timerticks per second)
#define | POS_TIMEAFTER(x, y) ((((SJIF_t)(x)) - ((SJIF_t)(y))) >= 0)
## Functions
POSEXTERN POSTIMER_t | posTimerCreate (void)
POSEXTERN VAR_t | posTimerSet (POSTIMER_t tmr, POSSEMA_t sema, UINT_t waitticks, UINT_t periodticks)
POSEXTERN VAR_t | posTimerStart (POSTIMER_t tmr)
POSEXTERN VAR_t | posTimerStop (POSTIMER_t tmr)
POSEXTERN void | posTimerDestroy (POSTIMER_t tmr)
POSEXTERN VAR_t | posTimerFired (POSTIMER_t tmr)
## Variables
POSEXTERN volatile JIF_t | jiffies
| Global timer variable. The jiffies counter variable is incremented HZ times per second.

## Detailed Description

A timer object is a counting variable that is counted down by the system timer interrupt tick rate. If the variable reaches zero, a semaphore, that is bound to the timer, will be signaled. If the timer is in auto reload mode, the timer is restarted and will signal the semaphore again and again, depending on the period rate the timer is set to.

## Define Documentation

#define HZ (timerticks per second)

| Hertz, timer ticks per second. HZ is a define that is set to the number of ticks the timer interrupt does in a second. For example, the jiffies variable is incremented HZ times per second. Also, much OS functions take timeout parameters measured in timer ticks; thus the HZ define can be taken as time base: HZ = 1 second, 10*HZ = 10s, HZ/10 = 100ms, etc. See also: jiffies, MS

#define POS_TIMEAFTER | ( | x,
|  | y |  | ) | ((((SJIF_t)(x)) - ((SJIF_t)(y))) >= 0)

| This macro is used to test if a specified time has expired. It handles timer variable wrap arounds correctly. The macro is used in conjunction with the jiffies variable, the current jiffies should be passed as first parameter to the macro. Example: exptime = jiffies + HZ/2; if (POS_TIMEAFTER(jiffies, exptime)) printf("500ms expired!\n"); See also: jiffies, HZ

## Function Documentation

POSEXTERN POSTIMER_t posTimerCreate | ( | void |  | ) |

| Timer function. Allocates a timer object. After a timer is allocated with this function, it must be set up with posTimerSet and than started with posTimerStart. Returns: handle to the new timer object. NULL is returned on error. Note: POSCFG_FEATURE_TIMER must be defined to 1 to have timer support compiled in. See also: posTimerSet, posTimerStart, posTimerDestroy

POSEXTERN void posTimerDestroy | ( | POSTIMER_t | tmr | ) |

  | Timer function. Deletes a timer object and free its resources. Parameters:
  | tmr | handle to the timer object.
Note: POSCFG_FEATURE_TIMER must be defined to 1 to have timer support compiled in. POSCFG_FEATURE_TIMERDESTROY must be defined to 1 to have this function compiled in. See also: posTimerCreate

POSEXTERN VAR_t posTimerFired | ( | POSTIMER_t | tmr | ) |

  | Timer function. The function is used to test if a timer has fired. Parameters:
  | tmr | handle to the timer object.
Returns: 1 when the timer has fired, otherwise 0. A negative value is returned on error. Note: POSCFG_FEATURE_TIMER must be defined to 1 to have timer support compiled in. POSCFG_FEATURE_TIMERFIRED must be defined to 1 to have this function compiled in. See also: posTimerCreate, posTimerSet, posTimerStart

POSEXTERN VAR_t posTimerSet | ( | POSTIMER_t | tmr,
|  | POSSEMA_t | sema,
|  | UINT_t | waitticks,
|  | UINT_t | periodticks
| ) |

  | Timer function. Sets up a timer object. Parameters:
  | tmr | handle to the timer object.
  | sema | seaphore object that shall be signaled when timer fires.
  | waitticks | number of initial wait ticks. The timer fires the first time when this ticks has been expired.
  | periodticks | After the timer has fired, it is reloaded with this value, and will fire again when this count of ticks has been expired (auto reload mode). If this value is set to zero, the timer won't be restarted (= one shot mode).
Returns: zero on success. Note: POSCFG_FEATURE_TIMER must be defined to 1 to have timer support compiled in. See also: posTimerCreate, posTimerStart

POSEXTERN VAR_t posTimerStart | ( | POSTIMER_t | tmr | ) |

  | Timer function. Starts a timer. The timer will fire first time when the waitticks counter has been reached zero. If the periodticks were set, the timer will be reloaded with this value. Parameters:
  | tmr | handle to the timer object.
Returns: zero on success. Note: POSCFG_FEATURE_TIMER must be defined to 1 to have timer support compiled in. See also: posTimerStop, posTimerFired

POSEXTERN VAR_t posTimerStop | ( | POSTIMER_t | tmr | ) |

  | Timer function. Stops a timer. The timer will no more fire. The timer can be reenabled with posTimerStart. Parameters:
  | tmr | handle to the timer object.
Returns: zero on success. Note: POSCFG_FEATURE_TIMER must be defined to 1 to have timer support compiled in. See also: posTimerStart, posTimerDestroy

## Variable Documentation

POSEXTERN volatile JIF_t jiffies

| Global timer variable. The jiffies counter variable is incremented HZ times per second. The maximum count the jiffie counter can reach until it wraps around is system dependent. Note: POSCFG_FEATURE_JIFFIES must be defined to 1 to have jiffies support compiled in. See also: HZ, POS_TIMEAFTER