µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
Core & scheduler

C API core & scheduler definitions. More...

Macros

#define os_flags_all   0xFFFFFFFF
 
#define os_flags_any   0
 Special mask to represent any flag.
 

Typedefs

typedef os_port_clock_duration_t os_clock_duration_t
 Type of variables holding clock durations.
 
typedef os_port_clock_offset_t os_clock_offset_t
 Type of variables holding clock offsets.
 
typedef os_port_clock_timestamp_t os_clock_timestamp_t
 Type of variables holding clock time stamps.
 
typedef uint32_t os_flags_mask_t
 Type of variables holding flags masks.
 
typedef uint32_t os_flags_mode_t
 Type of variables holding flags modes.
 
typedef os_port_irq_state_t os_irq_state_t
 Type of variables holding interrupts priority values.
 
typedef void * os_iterator_t
 Generic iterator, implemented as a pointer.
 
typedef uint32_t os_result_t
 Type of values returned by RTOS functions.
 
typedef os_port_scheduler_state_t os_sched_state_t
 Type of variables holding scheduler state codes.
 
typedef uint64_t os_statistics_counter_t
 Type of variables holding context switches counters.
 
typedef uint64_t os_statistics_duration_t
 Type of variables holding durations in CPU cycles.
 

Enumerations

enum  {
  os_flags_mode_all = 1 ,
  os_flags_mode_any = 2 ,
  os_flags_mode_clear = 4
}
 Bits used to specify the flags modes. More...
 

Return Codes

enum  { os_ok = 0 }
 Return codes, in addition to POSIX codes. More...
 

Scheduler Functions

os_result_t os_sched_initialize (void)
 Initialise the RTOS scheduler.
 
void os_sched_start (void)
 Start the RTOS scheduler.
 
bool os_sched_is_started (void)
 Check if the scheduler was started.
 
os_sched_state_t os_sched_lock (void)
 Lock the scheduler.
 
os_sched_state_t os_sched_unlock (void)
 Unlock the scheduler.
 
os_sched_state_t os_sched_set_locked (os_sched_state_t state)
 Lock/unlock the scheduler.
 
bool os_sched_is_locked (void)
 Check if the scheduler is locked.
 
bool os_sched_is_preemptive (void)
 Check if the scheduler is in preemptive mode.
 
bool os_sched_set_preemptive (bool state)
 Set the scheduler preemptive mode.
 

Scheduler Statistics Functions

os_statistics_counter_t os_sched_stat_get_context_switches (void)
 Get the total number of context switches.
 
os_statistics_duration_t os_sched_stat_get_cpu_cycles (void)
 Get the total duration of all threads.
 

Interrupts Functions

bool os_irq_in_handler_mode (void)
 Check if the CPU is in handler mode.
 
os_irq_state_t os_irq_critical_enter (void)
 Enter an interrupts critical section.
 
void os_irq_critical_exit (os_irq_state_t state)
 Exit the interrupts critical section.
 
os_irq_state_t os_irq_uncritical_enter (void)
 Enter an interrupts uncritical section.
 
void os_irq_uncritical_exit (os_irq_state_t state)
 Exit the interrupts uncritical section.
 
os_thread_stack_tos_irq_get_stack (void)
 Get the interrupts stack.
 

Detailed Description

For the complete definition, see
RTOS C++ API
Examples
int
os_main (int argc, char* argv[])
{
{
assert(flag);
// ...
{
// Scheduler critical section
st = os_sched_lock (true);
// ...
flag = os_sched_is_locked ();
assert(flag);
// ...
}
// ...
flag = os_sched_is_locked ();
assert(!flag);
}
{
// Interrupts critical section
// ...
{
// Interrupts uncritical section
// ...
}
// ...
}
}
void os_irq_uncritical_exit(os_irq_state_t state)
Exit the interrupts uncritical section.
bool os_sched_is_locked(void)
Check if the scheduler is locked.
os_irq_state_t os_irq_uncritical_enter(void)
Enter an interrupts uncritical section.
bool os_sched_is_started(void)
Check if the scheduler was started.
os_sched_state_t os_sched_unlock(void)
Unlock the scheduler.
os_sched_state_t os_sched_lock(void)
Lock the scheduler.
os_port_irq_state_t os_irq_state_t
Type of variables holding interrupts priority values.
Definition os-c-decls.h:170
void os_irq_critical_exit(os_irq_state_t state)
Exit the interrupts critical section.
os_port_scheduler_state_t os_sched_state_t
Type of variables holding scheduler state codes.
Definition os-c-decls.h:156
os_irq_state_t os_irq_critical_enter(void)
Enter an interrupts critical section.
int os_main(int argc, char *argv[])
Application entry point, running on the main thread context.

Macro Definition Documentation

◆ os_flags_all

#define os_flags_all   0xFFFFFFFF

Special mask to represent all flags.

Definition at line 142 of file os-c-decls.h.

◆ os_flags_any

#define os_flags_any   0

Definition at line 137 of file os-c-decls.h.

Typedef Documentation

◆ os_clock_duration_t

typedef os_port_clock_duration_t os_clock_duration_t

A numeric type intended to store a clock duration, either in ticks cycles, or seconds.

See also
os::rtos::clock::duration_t

Definition at line 196 of file os-c-decls.h.

◆ os_clock_offset_t

typedef os_port_clock_offset_t os_clock_offset_t

A numeric type intended to store a clock offset (difference to epoch), either in ticks or in seconds.

See also
os::rtos::clock::duration_t

Definition at line 208 of file os-c-decls.h.

◆ os_clock_timestamp_t

typedef os_port_clock_timestamp_t os_clock_timestamp_t

A numeric type intended to store a clock timestamp, either in ticks cycles or seconds.

See also
os::rtos::clock::timestamp_t

Definition at line 185 of file os-c-decls.h.

◆ os_flags_mask_t

typedef uint32_t os_flags_mask_t

An unsigned type large enough to store all the flags, usually 32-bits wide.

Both thread event flags and generic event flags use this definition.

See also
os::rtos::flags::mask_t

Definition at line 120 of file os-c-decls.h.

◆ os_flags_mode_t

typedef uint32_t os_flags_mode_t

An unsigned type used to hold the mode bits passed to functions returning flags.

Both thread event flags and generic event flags use this definition.

See also
os::rtos::flags::mode_t

Definition at line 107 of file os-c-decls.h.

◆ os_irq_state_t

typedef os_port_irq_state_t os_irq_state_t

Usually an integer large enough to hold the CPU register where the interrupt priorities are stored.

Used to temporarily store the CPU register during critical sections.

See also
os::rtos::interrupts::state_t

Definition at line 170 of file os-c-decls.h.

◆ os_iterator_t

typedef void* os_iterator_t

To simplify things, the C implementation of iterators includes a single pointer to a C++ object instance. Internally, the functions used to iterate must cast this pointer properly, but this should be transparent for the user.

Definition at line 222 of file os-c-decls.h.

◆ os_result_t

typedef uint32_t os_result_t

For error processing reasons, most µOS++ RTOS functions return a numeric result, which, according to POSIX, when the call was successful, must be 0 (os_ok) or an error code defined in <errno.h> otherwise.

See also
os::rtos::result_t

Definition at line 94 of file os-c-decls.h.

◆ os_sched_state_t

typedef os_port_scheduler_state_t os_sched_state_t

Usually a boolean telling if the scheduler is locked or not, but for recursive locks it might also be a numeric counter.

See also
os::rtos::scheduler::state_t

Definition at line 156 of file os-c-decls.h.

◆ os_statistics_counter_t

typedef uint64_t os_statistics_counter_t
See also
os::rtos::statistics::counter_t

Definition at line 231 of file os-c-decls.h.

◆ os_statistics_duration_t

typedef uint64_t os_statistics_duration_t
See also
os::rtos::statistics::duration_t

Definition at line 238 of file os-c-decls.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
os_ok 

Function completed; no error or event occurred.

Definition at line 56 of file os-c-api.h.

57 {
61 os_ok = 0
62 };
@ os_ok
Function completed; no error or event occurred.
Definition os-c-api.h:61

◆ anonymous enum

anonymous enum
See also
os::rtos::flags::mode
Enumerator
os_flags_mode_all 
os_flags_mode_any 
os_flags_mode_clear 

Definition at line 127 of file os-c-decls.h.

128 {
129 os_flags_mode_all = 1, //
130 os_flags_mode_any = 2, //
132 };
@ os_flags_mode_clear
Definition os-c-decls.h:131
@ os_flags_mode_all
Definition os-c-decls.h:129
@ os_flags_mode_any
Definition os-c-decls.h:130

Function Documentation

◆ os_irq_critical_enter()

os_irq_state_t os_irq_critical_enter ( void  )
Parameters
None.
Returns
The previous value of the interrupts priority register.
Note
Can be invoked from Interrupt Service Routines.
For the complete definition, see
os::rtos::interrupts::critical_section::enter()

Definition at line 571 of file os-c-wrapper.cpp.

572{
574}
static state_t enter(void)
Enter an interrupts critical section.
Definition os-sched.h:1128

References os::rtos::interrupts::critical_section::enter().

Referenced by __assert_func().

◆ os_irq_critical_exit()

void os_irq_critical_exit ( os_irq_state_t  state)
Parameters
stateThe value to restore the interrupts priority register.
Returns
Nothing.
Note
Can be invoked from Interrupt Service Routines.
For the complete definition, see
os::rtos::interrupts::critical_section::exit()

Definition at line 583 of file os-c-wrapper.cpp.

584{
586}
static void exit(state_t state)
Exit the interrupts critical section.
Definition os-sched.h:1137

References os::rtos::interrupts::critical_section::exit().

◆ os_irq_get_stack()

os_thread_stack_t * os_irq_get_stack ( void  )
Parameters
None.
Returns
A pointer to the interrupts stack object instance.
Warning
Cannot be invoked from Interrupt Service Routines.
For the complete definition, see
os::rtos::interrupts::stack()

Definition at line 624 of file os-c-wrapper.cpp.

625{
626 return reinterpret_cast<os_thread_stack_t*> (rtos::interrupts::stack ());
627}
class thread::stack * stack(void)
Get the interrupts stack.
Definition os-core.cpp:583
Thread stack.
Definition os-c-decls.h:406

References os::rtos::interrupts::stack().

◆ os_irq_in_handler_mode()

bool os_irq_in_handler_mode ( void  )
Parameters
None.
Return values
trueExecution is in an exception handler context.
falseExecution is in a thread context.
Note
Can be invoked from Interrupt Service Routines.
For the complete definition, see
os::rtos::interrupts::in_handler_mode()

Definition at line 557 of file os-c-wrapper.cpp.

558{
560}
bool in_handler_mode(void)
Check if the CPU is in handler mode.
Definition os-sched.h:1101

References os::rtos::interrupts::in_handler_mode().

Referenced by __assert_func().

◆ os_irq_uncritical_enter()

os_irq_state_t os_irq_uncritical_enter ( void  )
Parameters
None.
Returns
The previous value of the interrupts priority register.
Note
Can be invoked from Interrupt Service Routines.
For the complete definition, see
os::rtos::interrupts::uncritical_section::enter()

Definition at line 597 of file os-c-wrapper.cpp.

598{
600}
static state_t enter(void)
Enter interrupts uncritical section.
Definition os-sched.h:1166

References os::rtos::interrupts::uncritical_section::enter().

◆ os_irq_uncritical_exit()

void os_irq_uncritical_exit ( os_irq_state_t  state)
Parameters
stateThe value to restore the interrupts priority register.
Returns
Nothing.
Note
Can be invoked from Interrupt Service Routines.
For the complete definition, see
os::rtos::interrupts::uncritical_section::exit()

Definition at line 609 of file os-c-wrapper.cpp.

610{
612}
static void exit(state_t state)
Exit interrupts uncritical section.
Definition os-sched.h:1175

References os::rtos::interrupts::uncritical_section::exit().

◆ os_sched_initialize()

os_result_t os_sched_initialize ( void  )
Parameters
None.
Return values
os_okThe scheduler was initialised.
EPERMCannot be invoked from an Interrupt Service Routines.
Warning
Cannot be invoked from Interrupt Service Routines.
For the complete definition, see
os::rtos::scheduler::initialize()

Definition at line 413 of file os-c-wrapper.cpp.

414{
416}
uint32_t os_result_t
Type of values returned by RTOS functions.
Definition os-c-decls.h:94
result_t initialize(void)
Initialise the RTOS scheduler.
Definition os-core.cpp:164

References os::rtos::scheduler::initialize().

◆ os_sched_is_locked()

bool os_sched_is_locked ( void  )
Parameters
None.
Return values
trueThe scheduler is locked.
falseThe scheduler is switching threads (not locked).
Note
Can be invoked from Interrupt Service Routines.
For the complete definition, see
os::rtos::scheduler::locked()

Definition at line 485 of file os-c-wrapper.cpp.

486{
487 return scheduler::locked ();
488}
bool locked(void)
Check if the scheduler is locked.
Definition os-sched.h:858

References os::rtos::scheduler::locked().

◆ os_sched_is_preemptive()

bool os_sched_is_preemptive ( void  )
Parameters
None.
Return values
trueThe scheduler is in preemptive mode.
falseThe scheduler is not in preemptive mode.
Note
Can be invoked from Interrupt Service Routines.
For the complete definition, see
os::rtos::scheduler::preemptive()

Definition at line 497 of file os-c-wrapper.cpp.

498{
499 return scheduler::preemptive ();
500}
bool preemptive(void)
Check if the scheduler is in preemptive mode.
Definition os-sched.h:841

References os::rtos::scheduler::preemptive().

◆ os_sched_is_started()

bool os_sched_is_started ( void  )
Parameters
None.
Return values
trueThe scheduler was started.
falseThe scheduler was not started.
Note
Can be invoked from Interrupt Service Routines.
For the complete definition, see
os::rtos::scheduler::started()

Definition at line 437 of file os-c-wrapper.cpp.

438{
439 return scheduler::started ();
440}
bool started(void)
Check if the scheduler was started.
Definition os-sched.h:829

References os::rtos::scheduler::started().

◆ os_sched_lock()

os_sched_state_t os_sched_lock ( void  )
Parameters
None.
Returns
The previous state of the scheduler lock.
Warning
Cannot be invoked from Interrupt Service Routines.
For the complete definition, see
os::rtos::scheduler::lock()

Definition at line 449 of file os-c-wrapper.cpp.

450{
451 return scheduler::lock ();
452}
state_t lock(void)
Lock the scheduler.
Definition os-sched.h:871

References os::rtos::scheduler::lock().

◆ os_sched_set_locked()

os_sched_state_t os_sched_set_locked ( os_sched_state_t  state)
Parameters
[in]stateThe new state of the scheduler lock.
Returns
The previous state of the scheduler lock.
Warning
Cannot be invoked from Interrupt Service Routines.
For the complete definition, see
os::rtos::scheduler::lock()

Definition at line 473 of file os-c-wrapper.cpp.

474{
475 return scheduler::locked (state);
476}

References os::rtos::scheduler::locked().

◆ os_sched_set_preemptive()

bool os_sched_set_preemptive ( bool  state)
Parameters
[in]stateThe new state of the scheduler preemptive mode.
Returns
The previous state of the preemptive mode.
Warning
Cannot be invoked from Interrupt Service Routines.
For the complete definition, see
os::rtos::scheduler::preemptive(bool)

Definition at line 509 of file os-c-wrapper.cpp.

510{
511 return scheduler::preemptive (state);
512}

References os::rtos::scheduler::preemptive().

◆ os_sched_start()

void os_sched_start ( void  )
Parameters
None.
Returns
Nothing.
Warning
Cannot be invoked from Interrupt Service Routines.
For the complete definition, see
os::rtos::scheduler::start()

Definition at line 425 of file os-c-wrapper.cpp.

426{
428}
void start(void)
Start the RTOS scheduler.
Definition os-core.cpp:193

References os::rtos::scheduler::start().

◆ os_sched_stat_get_context_switches()

os_statistics_counter_t os_sched_stat_get_context_switches ( void  )
Returns
Integer with the total number of context switches since scheduler start.
Warning
Cannot be invoked from Interrupt Service Routines.
For the complete definition, see
os::rtos::scheduler::statistics::context_switches()

Definition at line 523 of file os-c-wrapper.cpp.

524{
525 return static_cast<os_statistics_counter_t> (
527}
uint64_t os_statistics_counter_t
Type of variables holding context switches counters.
Definition os-c-decls.h:231
rtos::statistics::counter_t context_switches(void)
Get the total number of context switches.
Definition os-sched.h:1027

References os::rtos::scheduler::statistics::context_switches().

◆ os_sched_stat_get_cpu_cycles()

os_statistics_duration_t os_sched_stat_get_cpu_cycles ( void  )
Returns
Integer with the number of CPU cycles, possibly divided by some prescaller.
Warning
Cannot be invoked from Interrupt Service Routines.
For the complete definition, see
os::rtos::scheduler::statistics::cpu_cycles()

Definition at line 540 of file os-c-wrapper.cpp.

541{
542 return static_cast<os_statistics_duration_t> (
544}
uint64_t os_statistics_duration_t
Type of variables holding durations in CPU cycles.
Definition os-c-decls.h:238
rtos::statistics::duration_t cpu_cycles(void)
Get the total duration of all threads.
Definition os-sched.h:1052

References os::rtos::scheduler::statistics::cpu_cycles().

◆ os_sched_unlock()

os_sched_state_t os_sched_unlock ( void  )
Parameters
None.
Returns
The previous state of the scheduler lock.
Warning
Cannot be invoked from Interrupt Service Routines.
For the complete definition, see
os::rtos::scheduler::unlock()

Definition at line 461 of file os-c-wrapper.cpp.

462{
463 return scheduler::unlock ();
464}
state_t unlock(void)
Unlock the scheduler.
Definition os-sched.h:884

References os::rtos::scheduler::unlock().