FastArduino  v1.7
C++ library to build fast but small Arduino/AVR projects
realtime_timer.h File Reference

Real-time Timer API. More...

#include "boards/io.h"
#include <avr/interrupt.h>
#include "interrupts.h"
#include "timer.h"
#include "time.h"
#include "events.h"
Include dependency graph for realtime_timer.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  timer::RTTRawTime< T >
 Utility class to avoid costly instantiation of time::RTTTime from an interrupt routine. More...
 
class  timer::RTT< NTIMER_ >
 API to handle a real-time timer. More...
 
class  timer::RTTEventCallback< EVENT, PERIOD_MS >
 Utility to generate events from an RTT instance at a given period. More...
 

Namespaces

 timer
 Defines all API to manipulate AVR Timers.
 

Macros

#define REGISTER_RTT_ISR(TIMER_NUM)
 Register the necessary ISR (Interrupt Service Routine) for a timer::RTT to work properly. More...
 
#define REGISTER_RTT_ISR_METHOD(TIMER_NUM, HANDLER, CALLBACK)
 Register the necessary ISR (Interrupt Service Routine) for a timer::RTT to work properly, along with a callback method that will be notified every millisecond. More...
 
#define REGISTER_RTT_ISR_FUNCTION(TIMER_NUM, CALLBACK)
 Register the necessary ISR (Interrupt Service Routine) for a timer::RTT to work properly, along with a callback function that will be notified every millisecond. More...
 
#define REGISTER_RTT_EVENT_ISR(TIMER_NUM, EVENT, PERIOD)
 Register the necessary ISR (Interrupt Service Routine) for a timer::RTT to work properly, along with a callback to timer::RTTEventCallback. More...
 
#define DECL_RTT_ISR_HANDLERS_FRIEND
 This macro shall be used in a class containing a private callback method, registered by REGISTER_RTT_ISR_METHOD. More...
 

Detailed Description

Real-time Timer API.

Definition in file realtime_timer.h.

Macro Definition Documentation

◆ REGISTER_RTT_ISR

#define REGISTER_RTT_ISR (   TIMER_NUM)
Value:
ISR(CAT3(TIMER, TIMER_NUM, _COMPA_vect)) \
{ \
timer::isr_handler_rtt::rtt<TIMER_NUM>(); \
}

Register the necessary ISR (Interrupt Service Routine) for a timer::RTT to work properly.

This will not register any user callback though; if you need to register a method or function to be called back every time one millsiecond has elapsed, you need to use REGISTER_RTT_ISR_METHOD or REGISTER_RTT_ISR_FUNCTION instead.

Parameters
TIMER_NUMthe number of the TIMER feature for the target MCU
See also
REGISTER_RTT_ISR_METHOD
REGISTER_RTT_ISR_FUNCTION

Definition at line 44 of file realtime_timer.h.

◆ REGISTER_RTT_ISR_METHOD

#define REGISTER_RTT_ISR_METHOD (   TIMER_NUM,
  HANDLER,
  CALLBACK 
)
Value:
ISR(CAT3(TIMER, TIMER_NUM, _COMPA_vect)) \
{ \
timer::isr_handler_rtt::rtt_method<TIMER_NUM, HANDLER, CALLBACK>(); \
}

Register the necessary ISR (Interrupt Service Routine) for a timer::RTT to work properly, along with a callback method that will be notified every millisecond.

Parameters
TIMER_NUMthe number of the TIMER feature for the target MCU
HANDLERthe class holding the callback method
CALLBACKthe method of HANDLER that will be called when the interrupt is triggered; this must be a proper PTMF (pointer to member function) that takes an uint32_t argument that will receive the total number of milliseconds elapsed since the RTT has started.
See also
REGISTER_RTT_ISR_FUNCTION
REGISTER_RTT_ISR

Definition at line 64 of file realtime_timer.h.

◆ REGISTER_RTT_ISR_FUNCTION

#define REGISTER_RTT_ISR_FUNCTION (   TIMER_NUM,
  CALLBACK 
)
Value:
ISR(CAT3(TIMER, TIMER_NUM, _COMPA_vect)) \
{ \
timer::isr_handler_rtt::rtt_function<TIMER_NUM, CALLBACK>(); \
}

Register the necessary ISR (Interrupt Service Routine) for a timer::RTT to work properly, along with a callback function that will be notified every millisecond.

Parameters
TIMER_NUMthe number of the TIMER feature for the target MCU
CALLBACKthe function that will be called when the interrupt is triggered; this function must accept an uint32_t argument that will receive the total number of milliseconds elapsed since the RTT has started.
See also
REGISTER_RTT_ISR_METHOD
REGISTER_RTT_ISR

Definition at line 82 of file realtime_timer.h.

◆ REGISTER_RTT_EVENT_ISR

#define REGISTER_RTT_EVENT_ISR (   TIMER_NUM,
  EVENT,
  PERIOD 
)
Value:
ISR(CAT3(TIMER, TIMER_NUM, _COMPA_vect)) \
{ \
timer::isr_handler_rtt::rtt_event<TIMER_NUM, EVENT, PERIOD>(); \
}

Register the necessary ISR (Interrupt Service Routine) for a timer::RTT to work properly, along with a callback to timer::RTTEventCallback.

Parameters
TIMER_NUMthe number of the TIMER feature for the target MCU
EVENTthe events::Event<T> type to be generated by RTTEventCallback
PERIODthe period, in ms, at which RTTEventCallback will generate events; this must be a power of 2.

NOTE: it is important that EVENT and PERIOD match an RTTEventCallback<EVENT, PERIOD> instance in your code.

See also
RTTEventCallback

Definition at line 102 of file realtime_timer.h.

◆ DECL_RTT_ISR_HANDLERS_FRIEND

#define DECL_RTT_ISR_HANDLERS_FRIEND
Value:
friend struct timer::isr_handler_rtt; \
DECL_TIMER_COMP_FRIENDS

This macro shall be used in a class containing a private callback method, registered by REGISTER_RTT_ISR_METHOD.

It declares the class where it is used as a friend of all necessary functions so that the private callback method can be called properly.

Definition at line 114 of file realtime_timer.h.