openchronos-ng
opensource firmware for the ez430 chronos
Enumerations | Functions | Variables
timer.h File Reference

openchronos-ng timer driver More...

#include <openchronos.h>

Go to the source code of this file.

Enumerations

enum  timer0_event { TIMER0_EVENT_1HZ = BIT0, TIMER0_EVENT_20HZ = BIT1, TIMER0_EVENT_PROG = BIT2 }
 Bitfield of events produced by this driver. More...

Functions

void timer0_init (void)
 Initializes the timer.
void timer0_create_prog_timer (uint16_t duration)
 creates a 1000Hz - 1Hz programmable timer
void timer0_destroy_prog_timer ()
 destroys a running programmable timer
void timer0_delay (uint16_t duration, uint16_t LPM_bits)
 1ms - 1s programmable delay

Variables

volatile uint16_t timer0_20hz_counter
 20Hz counter.
enum timer0_event timer0_last_event
 Bitfield holding the last generated (timer) event.

Detailed Description

openchronos-ng timer driver

This driver takes care of the Timer0 hardware timer. From this hardware timer the driver produces two hardware-based timers running at 20Hz and 1Hz. The events produced by those timers are available in sys_message. Beyound the fixed frequency timers, this driver also implements a programmable timer and a programmable delay.

Note:
If you are looking to timer events, then see sys_message

Enumeration Type Documentation

Bitfield of events produced by this driver.

Enumerator:
TIMER0_EVENT_1HZ 

1Hz event

TIMER0_EVENT_20HZ 

20Hz event

TIMER0_EVENT_PROG 

programmable timer event


Function Documentation

void timer0_create_prog_timer ( uint16_t  duration)

creates a 1000Hz - 1Hz programmable timer

Creates a timer programmable from 1Hz up to 1000Hz. The timer event is available in sys_message.

Note:
You should check what modules are using this function because it cannot be used by more than one module at same time. We recommend you use one of the available fixed timers. If you really need another ticking frequency, contact the openchronos-ng developers for a better solution.
See also:
timer0_destroy_prog_timer
Parameters:
durationtimer period between 1 and 1000 milliseconds.
void timer0_delay ( uint16_t  duration,
uint16_t  LPM_bits 
)

1ms - 1s programmable delay

delays execution for duration milliseconds. During the delay, interrupts are still generated but sys_message only broadcasts the events after the delay has finished. The second argument is put directly into the _STATUS_ register. This could of course disrupt the state of the watch. Please be careful and take a look at http://mspgcc.sourceforge.net/manual/x1028.html for information regarding the _STATUS_ register.

Note:
Please avoid using this. No processing is done in the background during the delay, which can have impact in modules that require a responsive system.
Parameters:
durationdelay duration between 1 and 1000 milliseconds
LPM_bitsLPM bits to put in the status register, so the user can choose LPM level

destroys a running programmable timer

See also:
timer0_create_prog_timer
void timer0_init ( void  )

Initializes the timer.

This functions is called once upon system initialization.

Note:
Modules are strictly forbidden to call this function.

Variable Documentation

volatile uint16_t timer0_20hz_counter

20Hz counter.

This is a counter variable, its value is updated at 20Hz. You can use this to measure timings.

Note:
counter overflows should be relatively safe since they only happen once each 3276.8 seconds. However you should handle overflows if your application cannot accept sporadic failures in measurement.

Bitfield holding the last generated (timer) event.

Timer0 interrupt routines update this variable with the last happening events. Inside the mainloop, the system then clears this variable after reading it. Read events are broadcasted in sys_message.

Note:
This function is to be used exclusively by the system. No module is allowed to read or write to this variable.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines