drivers/timer/timer_tc.c File Reference

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

#include <debug.h>
#include <timer_tc.h>
#include <softirq.h>
#include <chip/clk.h>
#include <chip/irq-map.h>
#include <app/softirq.h>
#include "tc_regs.h"

Include dependency graph for timer_tc.c:

Go to the source code of this file.

Defines

#define COUNTER_LOW_MASK   ((1UL << 16)-1)
#define COUNTER_HIGH_OFFSET   16

Functions

static void timer_do_pending (void *context)
 Run pending tasks.
static void timer_irq_handler (void *data)
 Timer IRQ handler.
static void timer_set_alarm (struct timer *timer, counter_t time_stamp)
 Set alarm.
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.


Detailed Description

Simple timer able to perform tasks after a given delay.

This is a simple timer which can be used to execute tasks after specific delays. Numerous tasks can be added and they will be executed in the order of their time stamps.

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

Definition in file timer_tc.c.


Define Documentation

#define COUNTER_HIGH_OFFSET   16

Offset to the high part of the counter

Definition at line 58 of file timer_tc.c.

Referenced by timer_set_alarm().

#define COUNTER_LOW_MASK   ((1UL << 16)-1)

Mask for the low part of the counter

Definition at line 56 of file timer_tc.c.

Referenced by timer_set_alarm().


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_do_pending ( void *  context  )  [static]

Run pending tasks.

This function will check the task list of the timer for pending tasks and execute them. When all pending tasks have been executed, the alarm will be set on the timestamp of the next task in the list.

Parameters:
context Pointer to timer control structure.

Definition at line 261 of file timer_tc.c.

References assert, cpu_irq_restore(), cpu_irq_save(), and timer_set_alarm().

Referenced by timer_init(), and timer_set_alarm().

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_irq_handler ( void *  data  )  [static]

Timer IRQ handler.

This handler will be executed whenever the timer either overflows or hit the compare level. If it was an overflow the top part of the counter is incremented. If the compare level is hit, that interrupt is disabled (will be reenabled if a new alarm is set)

The timer_do_pending() function will be called regardless of what caused the interrupt. If an alarm did trigger, its callback will be called from there, if we had an overflow, the first alarm in the next period will be set up.

Parameters:
data Pointer to timer control structure.

Definition at line 91 of file timer_tc.c.

References softirq_raise(), tc_read_reg, and tc_write_reg.

Here is the call graph for this function:

static void timer_set_alarm ( struct timer *  timer,
counter_t  time_stamp 
) [static]

Set alarm.

For internal use only.

Set a alarm at the given time. This function will only set up alarms in the near future (before next low overflow), if the alarm is after the next low overflow, this function needs to be called again.

If the time_stamp has already expired, the pending action flag will be raised direcly, if the timer is stopped, it will be restarted.

Parameters:
timer Pointer to timer control structure.
time_stamp Time of the alarm

Definition at line 174 of file timer_tc.c.

References COUNTER_HIGH_OFFSET, COUNTER_LOW_MASK, tc_write_reg, and timer_do_pending().

Referenced by timer_add_task_ticks(), and timer_do_pending().

Here is the call graph for this function:


Generated on Tue Sep 15 10:19:53 2009 for libavr32 by  doxygen 1.5.8