Contiki-NG
Loading...
Searching...
No Matches
Real-time task scheduling

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_init()
 Initialize the real-time scheduler.
 
#define RTIMER_NOW()
 Get the current clock time.
 
#define RTIMER_TIME(task)
 Get the time that a task last was executed.
 
#define RTIMER_BUSYWAIT_UNTIL_ABS(cond, t0, max_time)
 Busy-wait until a condition.
 
#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 , RTIMER_ERR_FULL , RTIMER_ERR_TIME , RTIMER_ERR_ALREADY_SCHEDULED }
 TODO: we need to document meanings of these symbols. More...
 

Functions

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.
 
void rtimer_run_next (void)
 Execute the next real-time task and schedule the next task, if any.
 

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.
 
void rtimer_arch_schedule (rtimer_clock_t t)
 Schedules an rtimer task to be triggered at time t.
 

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:187

Busy-wait until a condition.

Start time is t0, max wait time is max_time

Definition at line 204 of file rtimer.h.

◆ rtimer_init

#define rtimer_init ( )

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 123 of file rtimer.h.

Referenced by soc_init().

◆ 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 187 of file rtimer.h.

Referenced by read(), rf_core_check_rat_overflow(), rf_core_convert_rat_to_rtimer(), rtimer_arch_schedule(), tsch_get_lock(), update_ticks(), and value().

◆ 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 200 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 144 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.

References rtimer_clock_stub(), and rtimer_isr_hook().

◆ rtimer_arch_schedule()

void rtimer_arch_schedule ( rtimer_clock_t t)

Schedules an rtimer task to be triggered at 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.

Schedules an rtimer task to be triggered at time t.

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

Schedules an rtimer task to be triggered at time t.

Schedules an rtimer task to be triggered at time t.

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

< Compare value load status

< STx upload status signal

< ST count/compare value 3

< ST count/compare value 2

< ST count/compare value 1

< ST count/compare value 0

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

References CLOCK_SECOND, clock_time(), INTERRUPTS_DISABLE, INTERRUPTS_ENABLE, RTIMER_NOW, SMT_IRQn, SMWDTHROSC_ST0, SMWDTHROSC_ST1, SMWDTHROSC_ST2, SMWDTHROSC_ST3, SMWDTHROSC_STLOAD, SMWDTHROSC_STLOAD_STLOAD, and soc_rtc_schedule_one_shot().

Referenced by rtimer_set().

◆ 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 78 of file rtimer.c.

Referenced by rtimer_isr(), and rtimer_isr_hook().

◆ 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 57 of file rtimer.c.

References rtimer_arch_schedule(), and RTIMER_OK.