µracoli Manual Version foo

- µracoli
- User Guide
- Reference Guide

Data Structures
Timer/RTC API

Starting, stopping and execution of time triggered actions.
More...

## Data Structures
struct | time_stamp_t

## Detailed Description

### Overview

Timer and RTC API in liburacoli_<board>.a

Usage

The timer module is inspired by Jörg Wunschs timer implementation, which can be found here: http://sax.sax.de/~joerg/avr-timer/RTC functions are implemented by use of the asynchronous clock facilities of the microcontroller.

Examples

- xmpl_timer.c
- xmpl_timer_callback.c
- xmpl_rtc.c

## Functions

void rtc_init | ( | void(*)(void) | tickfunc | ) |

RTC initialisation

Parameters

  tf | pointer to rtc callback function.

Examples:
  xmpl_rtc.c.

void rtc_start | ( | void |  | ) |

This function starts the RTC

Examples:
  xmpl_rtc.c.

void rtc_stop | ( | void |  | ) |

This function stops the RTC

void timer_get_tstamp | ( | time_stamp_t * | ts | ) |

Function that returns the internal system time counters as "libpcap" compatible time stamp.

Note
  This routine takes ~548 cycles for execution. In case of a 8Mhz driven system, this is a 68.5 us.

Parameters

  ts | timestamp data structure

void timer_init | ( | void |  | ) |

This function is responsible for the setup of the hardware timers.

Examples:
  xmpl_radio_range.c, and xmpl_timer_callback.c.

timer_hdl_t timer_restart | ( | timer_hdl_t | th,
|  | time_t | duration
| ) |  |

If the timer is found in the timer queue, then it is rstarted with the new duration value.

Parameters

  th | Handle of the timer. The timer needs to exist in the timer queue, e.g. it is started with timer_start() and not yet expired.
  duration | time in system ticks from now, when the timer expires.

Returns
  the value of NONE_TIMER if the timer could not be found in the timer queue. Otherwise the value of th.

timer_hdl_t timer_start | ( | timer_handler_t * | thfunc,
|  | time_t | duration,
|  | timer_arg_t | arg
| ) |  |

This function initially creates a timer and assigns a timer handle to it. The timer handle is reference number, which identifies the timer uniquely and is needed for restart and stop a running timer.

Parameters

  thfunc | pointer to a function, which is called when the timer expires.
  duration | time in system ticks from now, when the timer expires.
  arg | argument, which is passed to the timer function.

Returns
  the value of NONE_TIMER if the timer could not be started. Otherwise a handle != NONE_TIMER, which is needed for restarting and stopping the timer.

Examples:
  xmpl_radio_range.c, and xmpl_timer_callback.c.

timer_hdl_t timer_stop | ( | timer_hdl_t | th | ) |

Parameters

  th | Handle of the timer. The timer needs to exist in the timer queue, e.g. it is started with timer_start() and not yet expired.

Returns
  the value of NONE_TIMER if the timer could not be found in the timer queue. Otherwise the value of th.

## Data Structure Documentation

struct time_stamp_t

High resolution time stamp in seconds and micro seconds

Definition at line 70 of file timer.h.

## Typedefs

typedef uint32_t time_t

Data type for time values (measured in number of system ticks).

Definition at line 64 of file timer.h.

typedef uint32_t timer_arg_t

Data type for the argument of a timer handler function.

Definition at line 80 of file timer.h.

typedef time_t( timer_handler_t) (timer_arg_t p)

Data type for timer expiration action function. This function is called, when the expiration time is over. When luanched, the function is called with a parameter p of type .timer_arg_t. If the function returns a value, which is greate then 0, the timer is restarted again.

Definition at line 95 of file timer.h.

typedef uint16_t timer_hdl_t

Data type for a timer handle (a reference number to identify a running timer).

Definition at line 86 of file timer.h.

## Defines

#define MSEC | ( |  | v | ) | ((time_t)(v / (1.0e3 * TIMER_TICK)))

Macro that converts the millisecond value v into TIMER_IRQ_vect ticts

Examples:
  xmpl_timer.c, and xmpl_timer_callback.c.

Definition at line 48 of file timer.h.

#define NONE_TIMER (0)

Symbolic name for invalid timer handle

Definition at line 98 of file timer.h.

#define USEC | ( |  | v | ) | ((time_t)(v / (1.0e6 * TIMER_TICK)))

Macro that converts the microsecond value v into TIMER_IRQ_vect ticts

Definition at line 50 of file timer.h.