-ne Timer module
Friedrich-Alexander-Universität UnivisSuche FAU-Logo
Techn. Fakultšt Willkommen am Department Informatik FAU-Logo
Logo I4
Lehrstuhl für Informatik 4
    - UnivIS-Infos
    - Inhalt
    - Folien
    - Inhalt
    - Ergänzendes Material
    - Aufgaben
    - UnivIS-Infos
    - libspicboard-Doku
    - FSI-Forum für Fragen
Department Informatik  >  Informatik 4  >  Lehre  >  SS 2014  >  GSPiC  >  Übungen  >  Doku  >  Timer module

SPiCboard library (libspicboard, revision exportiert) API documentation

Found a bug or something ambiguous? Mail us to get it fixed!

Timer module

The timer module provides an event interface to the hardware timers. More...


file  timer.h


typedef struct ALARM ALARM
 ALARM type This is type of a struct containing information about an alarm.
typedef void(* alarmcallback_t )(void)
 Type for alarm callback functions.


int8_t sb_timer_cancelAlarm (ALARM *alrm)
 Cancel an alarm.
ALARMsb_timer_setAlarm (alarmcallback_t callback, uint16_t alarmtime, uint16_t cycle)
 Create a new alarm.
int8_t sb_timer_delay (uint16_t waittime)
 waits for a specific number of ms
void sb_timer_delay_abort ()
 Aborts an active sb_timer_delay.

Detailed Description

The timer module provides an event interface to the hardware timers.

The module uses the 16-bit timer 1 of the ATmega32. The timer is dynamically configured as needed by the registered alarms and should always be clocked as slow as possible to keep the interrupt load low. When no alarms are registered, the timer clock is disabled.

The timer module uses dynamic memory management (malloc()/free()) for the allocation of the ALARM types. This is also done from within ISRs. Thus care must be taken when calling malloc()/free() with interrupts enabled.
Interrupts must be enabled for the timer to work.

Typedef Documentation

typedef struct ALARM ALARM

ALARM type This is type of a struct containing information about an alarm.

typedef void(* alarmcallback_t)(void)

Type for alarm callback functions.

Alarm callback functions are invoked on the interrupt level whenever the associated alarm expires. The programming model for callback functions is similar to that of interrupt service routines.

Function Documentation

int8_t sb_timer_cancelAlarm ( ALARM alrm)

Cancel an alarm.

alrmidentifier of the alarm that should be canceled
Return values
-1an error occurred
See Also
alarms must not be canceled twice
int8_t sb_timer_delay ( uint16_t  waittime)

waits for a specific number of ms

This function must not be invoked with interrupts disabled, i.e. from an interrupt handler (or generally, from the ISR level) or a critical section of the application.

The CPU is set in sleep mode while waiting.

waittimewait time in ms
Return values
-1alarm could not be activated
-2sb_timer_delay invoked while interrupts disabled
See Also
void sb_timer_delay_abort ( )

Aborts an active sb_timer_delay.

This function must be invoked on the ISR level.

See Also
ALARM* sb_timer_setAlarm ( alarmcallback_t  callback,
uint16_t  alarmtime,
uint16_t  cycle 

Create a new alarm.

This function can be used to set single shot, as well as repeating timers.

  • Single shot: Set cycle to 0. This alarm must not be canceled after being fired.
  • Repetitive: The first shot can be adjusted be setting alarmtime > 0. Otherwise cycle is used.
The callback function is called from within the ISR-context.
callbackcallback function that will be invoked whenever the alarm expires
alarmtimetime in ms relative to the current time when the alarm shall expire the first time. If set to 0 cycle time will be used.
cycletime in ms for alarms that periodically expire after the first regular expiry. Set to 0 for single shot timers.
the identifier of the alarm, or NULL if creating the alarm failed.
Canceling a timer twice or canceling a single shot timer after its expiry may cause unexpected results.
See Also
  Impressum   Datenschutz Stand: 2014-05-23 19:23   MS