# include/timer_tc.h File Reference

Simple timer able to perform tasks after a given delay. More...

`#include <types.h>`
`#include <assert.h>`
`#include <interrupt.h>`
`#include <irq_handler.h>`

Include dependency graph for timer_tc.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Defines
#define | TIMER_MAX_DELAY (1UL << ((8*sizeof(counter_t))-1))
## Typedefs
typedef uint16_t | counter_high_t
## Functions
static void | timer_reset_task (struct timer_task *task)
| Reset a used task.
static void | timer_init_task (struct timer_task *task, timer_callback_t callback, void *data)
| Initialize a new task.
void | timer_init (struct timer *timer, void *port, uint32_t resolution)
| Initialize a timer.
void | timer_add_task_ticks (struct timer *timer, struct timer_task *task, counter_t delay)
| Add new task with delay given in timer ticks.
static void | timer_add_task_us (struct timer *timer, struct timer_task *task, uint32_t delay_us)
| Add new task with delay given in microsecond.

## Detailed Description

Simple timer able to perform tasks after a given delay.

This is the interface of a timer designed to perform given tasks after a given delay.

- Compiler: IAR EWAVR32 and GNU GCC for AVR32
- Supported devices: All devices
- AppNote:

Author:
  Atmel Corporation: http://www.atmel.com
  Support and FAQ: http://support.atmel.no/

Definition in file timer_tc.h.

## Define Documentation

#define TIMER_MAX_DELAY (1UL << ((8*sizeof(counter_t))-1))

Half the range of the counter, maximum delay possible

Definition at line 58 of file timer_tc.h.

Referenced by timer_add_task_ticks().

## Typedef Documentation

typedef uint16_t counter_high_t

Higher part of the counter, handled in software

Definition at line 56 of file timer_tc.h.

## Function Documentation

void timer_add_task_ticks | ( | struct timer * | timer,
|  | struct timer_task * | task,
|  | counter_t | delay |
| ) |  |  |

Add new task with delay given in timer ticks.

Add a new task to the be executed after a given delay (given in timer ticks).

A task must always be completed before resubmitting it to the timer, but as tasks are considered completed when the callback is called, they can be resubmitted from their own callback.

Parameters:

  | timer | Pointer to timer control structure
  | task | Pointer to task structure.
  | delay | Delay given in timer ticks

Definition at line 323 of file timer_tc.c.

References assert, TIMER_MAX_DELAY, and timer_set_alarm().

Referenced by timer_add_task_us().

Here is the call graph for this function:

static void timer_add_task_us | ( | struct timer * | timer,
|  | struct timer_task * | task,
|  | uint32_t | delay_us |
| ) |  |  | `[inline, static]`

Add new task with delay given in microsecond.

Add a new task to the be executed after a given delay (given in micro seconds). This is a wrapper around timer_add_task_ticks.

A task must always be completed before resubmitting it to the timer, but as tasks are considered completed when the callback is called, they can be resubmitted from their own callback.

Parameters:

  | timer | Pointer to timer control structure
  | task | Pointer to task structure.
  | delay_us | Delay given in microseconds

Definition at line 174 of file timer_tc.h.

References timer_add_task_ticks().

Referenced by delayed_work_run_us(), and led_blink_start().

Here is the call graph for this function:

void timer_init | ( | struct timer * | timer,
|  | void * | port,
|  | uint32_t | resolution |
| ) |  |  |

Initialize a timer.

This function will initialize the timer. It will leave it stopped with interrupts disabled. The timer will automatically start when an task is added. Global interrupts need to be enabled elsewhere.

This function will set the timer resolution/frequency as close to the requested resolution as possible; the real frequency can be read with the timer_get_frequency() function.

Parameters:

  | timer | Pointer to timer control structure.
  | port | Pointer to TC register block
  | resolution | Requested resolution of the timer (given in ticks pr. sec)

Definition at line 216 of file timer_tc.c.

References assert, build_assert, get_pba_clock_rate(), setup_irq_handler, softirq_set_handler(), tc_write_reg, and timer_do_pending().

Here is the call graph for this function:

static void timer_init_task | ( | struct timer_task * | task,
|  | timer_callback_t | callback,
|  | void * | data |
| ) |  |  | `[inline, static]`

Initialize a new task.

Set up callback and data for a task. If the same task should be added multiple times to a timer, different task structs MUST be used, wait for the first task to complete before reusing the struct.

Parameters:

  | task | Pointer to task structure.
  | callback | Function to be executed when the timer expires
  | data | Arbitrary data to be passed to callback

Definition at line 140 of file timer_tc.h.

References timer_reset_task().

Referenced by delayed_work_init(), and led_blink_init().

Here is the call graph for this function:

static void timer_reset_task | ( | struct timer_task * | task | ) | `[inline, static]`

Reset a used task.

This function will reset a used task, making it ready for re-use. The callback and data will be kept intact.

Parameters:

  | task | Pointer to the task to be reset

Definition at line 121 of file timer_tc.h.

References assert.

Referenced by timer_init_task().