yarf 0.1
Yet Another RepRap Firmware
Defines | Functions | Variables
src/scheduling/realtime_timer.c File Reference

The real-time timer is a high resolution, high priority timer which is used for controlling the rate at which the stepper motors are stepped. More...

#include "realtime_timer.h"
#include "hardware/fastio.h"
#include "yarf.h"
#include "util/math.h"
#include <stdint.h>
#include <stdlib.h>
#include <avr/interrupt.h>
#include <util/atomic.h>

Go to the source code of this file.

Defines

#define RTTIMER_TICKS_PER_US   (((float)F_CPU)/8/1000000)
 The number of ticks the real-time timer takes in one microsecond.

Functions

static void timer2_set (long ticks)
 Sets the hardware timer 2 to raise an interrupt after a specified number of timer ticks.
 ISR (TIMER2_COMPA_vect, ISR_BLOCK)
 Interrupt service routine for the hardware timer.
void rttimer_init (void)
 Initializes the real-time timer component.
int rttimer_schedule_ticks (realtime_task_t *t, uint16_t ticks)
 Schedules a task to be executed after a specified number of ticks.
int rttimer_cancel (void)
 Cancels the currently scheduled task.

Variables

static volatile realtime_task_tpending_task
 A pointer to a realtime_task_t structure indicating the task to be executed when the timer rings.

Detailed Description

The real-time timer is a high resolution, high priority timer which is used for controlling the rate at which the stepper motors are stepped.

Author:
Pieter Agten (pieter.agten@gmail.com)
Date:
9 okt 2011 This component uses hardware timer 2 with a /8 prescaler. Timer 2 has the highest interrupt priority of all timers, which guarantees this timer's interrupts will be executed very shortly after they are raised. The /8 prescaler provides a resolution of 0,4 us and a maximum interval of 102 us. Time intervals beyond this maximum hardware interval are implemented in software by repeatedly setting the timer with the maximum hardware interval until the remaining interval is within range.

Definition in file realtime_timer.c.


Function Documentation

ISR ( TIMER2_COMPA_vect  ,
ISR_BLOCK   
)

Interrupt service routine for the hardware timer.

This routine executes the scheduled task if the specified number of ticks have passed, or reschedules the timer if more ticks must elapse before the task must be executed.

Definition at line 97 of file realtime_timer.c.

int rttimer_cancel ( void  )

Cancels the currently scheduled task.

Returns:
RTTIMER_SUCCESS on success or RTTIMER_NOT_RUNNING if the timer does not currently have any task scheduled.

Definition at line 153 of file realtime_timer.c.

void rttimer_init ( void  )

Initializes the real-time timer component.

This should only be called once on boot.

Definition at line 121 of file realtime_timer.c.

int rttimer_schedule_ticks ( realtime_task_t t,
uint16_t  ticks 
)

Schedules a task to be executed after a specified number of ticks.

Parameters:
tpointer to the task to be executed
ticksthe number of ticks to wait before executing the task
Returns:
RTTIMER_SUCCESS on success or RTTIMER_BUSY if the timer already has a scheduled task to be executed.

Definition at line 138 of file realtime_timer.c.

static void timer2_set ( long  ticks) [inline, static]

Sets the hardware timer 2 to raise an interrupt after a specified number of timer ticks.

Parameters:
ticksthe number of timer ticks after which the interrupt should be raised.
Note:
The hardware timer should be disabled when calling this function.

If ticks is greater than the maximum possible hardware time interval, an interrupt will be raised after the maximum possible hardware time interval.

Definition at line 74 of file realtime_timer.c.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines