Contiki-NG
Data Structures | Macros | Enumerations | Functions
Real-time task scheduling

The real-time module handles the scheduling and execution of real-time tasks (with predictable execution times). More...

Data Structures

struct  rtimer
 Representation of a real-time task. More...
 

Macros

#define RTIMER_CLOCK_SIZE   4
 The rtimer size (in bytes)
 
#define RTIMER_SECOND   RTIMER_ARCH_SECOND
 Number of rtimer ticks for 1 second.
 
#define RTIMER_NOW()
 Get the current clock time. More...
 
#define RTIMER_TIME(task)
 Get the time that a task last was executed. More...
 
#define RTIMER_BUSYWAIT_UNTIL_ABS(cond, t0, max_time)
 Busy-wait until a condition. More...
 
#define RTIMER_BUSYWAIT_UNTIL(cond, max_time)
 Busy-wait until a condition for at most max_time.
 
#define RTIMER_BUSYWAIT(duration)   RTIMER_BUSYWAIT_UNTIL(0, duration)
 Busy-wait for a fixed duration.
 

Enumerations

enum  { RTIMER_OK }
 TODO: we need to document meanings of these symbols. More...
 

Functions

void rtimer_init (void)
 Initialize the real-time scheduler. More...
 
int rtimer_set (struct rtimer *task, rtimer_clock_t time, rtimer_clock_t duration, rtimer_callback_t func, void *ptr)
 Post a real-time task. More...
 
void rtimer_run_next (void)
 Execute the next real-time task and schedule the next task, if any. More...
 

Architecture-dependent symbols

The functions declared in this section must be defined in architecture-dependent implementation of rtimer.

Alternatively, they can be defined as macros in rtimer-arch.h.

In addition, the architecture-dependent header (rtimer-arch.h) must define the following macros.

  • RTIMER_ARCH_SECOND
  • US_TO_RTIMERTICKS(us)
  • RTIMERTICKS_TO_US(t)
  • RTIMERTICKS_TO_US_64(t)
void rtimer_arch_init (void)
 Initialized the architecture-dependent part of rtimer. More...
 
void rtimer_arch_schedule (rtimer_clock_t t)
 Schedule the call to rtimer_run_next at the time t. More...
 

Detailed Description

The real-time module handles the scheduling and execution of real-time tasks (with predictable execution times).

Macro Definition Documentation

◆ RTIMER_BUSYWAIT_UNTIL_ABS

#define RTIMER_BUSYWAIT_UNTIL_ABS (   cond,
  t0,
  max_time 
)
Value:
({ \
bool c; \
while(!(c = cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), (t0) + (max_time))); \
c; \
})
#define RTIMER_NOW()
Get the current clock time.
Definition: rtimer.h:185

Busy-wait until a condition.

Start time is t0, max wait time is max_time

Definition at line 202 of file rtimer.h.

◆ RTIMER_NOW

#define RTIMER_NOW ( )

Get the current clock time.

Returns
The current time
        This function returns what the real-time module thinks
        is the current time. The current time is used to set
        the timeouts for real-time tasks.

Definition at line 185 of file rtimer.h.

Referenced by update_ticks().

◆ RTIMER_TIME

#define RTIMER_TIME (   task)

Get the time that a task last was executed.

Parameters
taskThe task
Returns
The time that a task last was executed
        This function returns the time that the task was last
        executed. This typically is used to get a periodic
        execution of a task without clock drift.

Definition at line 198 of file rtimer.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

TODO: we need to document meanings of these symbols.

Enumerator
RTIMER_OK 

rtimer task is scheduled successfully

Definition at line 142 of file rtimer.h.

Function Documentation

◆ rtimer_arch_init()

void rtimer_arch_init ( void  )

Initialized the architecture-dependent part of rtimer.

Initialized the architecture-dependent part of rtimer.

The Sleep Timer starts ticking automatically as soon as the device turns on. We don't need to turn on interrupts before the first call to rtimer_arch_schedule()

Initialized the architecture-dependent part of rtimer.

The RTC is initialised elsewhere

Initialized the architecture-dependent part of rtimer.

Definition at line 59 of file rtimer-arch.c.

Referenced by rtimer_init().

◆ rtimer_arch_schedule()

void rtimer_arch_schedule ( rtimer_clock_t  t)

Schedule the call to rtimer_run_next at the time t.

Schedule the call to rtimer_run_next at the time t.

Parameters
tThe time when the task will need executed. This is an absolute time, in other words the task will be executed AT time t, not IN t ticks

Schedule the call to rtimer_run_next at the time t.

Parameters
tThe time when the task will need executed.

t is an absolute time, in other words the task will be executed AT time t, not IN t rtimer ticks.

This function schedules a one-shot event with the AON RTC.

This functions converts to a value suitable for the AON RTC.

Schedule the call to rtimer_run_next at the time t.

Parameters
tThe time when the task will need executed.

t is an absolute time, in other words the task will be executed AT time t, not IN t rtimer ticks.

This function schedules a one-shot event with the nRF RTC.

Schedule the call to rtimer_run_next at the time t.

Parameters
tThe time when the task will need executed.
      \p t is an absolute time, in other words the task will be
      executed AT time \p t, not IN \p t rtimer ticks.

      This function schedules a one-shot event with the AON RTC.

      This functions converts \p t to a value suitable for the AON RTC.

Definition at line 71 of file rtimer-arch.c.

◆ rtimer_init()

void rtimer_init ( void  )

Initialize the real-time scheduler.

This function initializes the real-time scheduler and must be called at boot-up, before any other functions from the real-time scheduler is called.

Definition at line 61 of file rtimer.c.

References rtimer_arch_init().

Referenced by soc_init().

◆ rtimer_run_next()

void rtimer_run_next ( void  )

Execute the next real-time task and schedule the next task, if any.

This function is called by the architecture dependent code to execute and schedule the next real-time task.

Definition at line 92 of file rtimer.c.

Referenced by timer_event_handler().

◆ rtimer_set()

int rtimer_set ( struct rtimer task,
rtimer_clock_t  time,
rtimer_clock_t  duration,
rtimer_callback_t  func,
void *  ptr 
)

Post a real-time task.

Parameters
taskA pointer to the task variable allocated somewhere.
timeThe time when the task is to be executed.
durationUnused argument.
funcA function to be called when the task is executed.
ptrAn opaque pointer that will be supplied as an argument to the callback function.
Returns
RTIMER_OK if the task could be scheduled. Any other value indicates the task could not be scheduled.

This function schedules a real-time task at a specified time in the future.

Definition at line 67 of file rtimer.c.