Mistake on this page?
Report an issue in GitHub or email us
Modules | Namespaces | Data Structures | Typedefs | Functions
Rtos

Modules

 EventFlags class
 
 Mail class
 
 MemoryPool class
 
 Mutex class
 
 Queue class
 
 RTOS hook functions
 
 Idle hook function
 
 RtosTimer class
 
 Semaphore class
 
 ThisThread namespace
 
 Thread class
 

Namespaces

 rtos::Kernel
 Functions in the Kernel namespace control RTOS kernel information.
 

Data Structures

class  ConditionVariable
 The ConditionVariable class is a synchronization primitive that allows threads to wait until a particular condition occurs. More...
 

Typedefs

typedef mbed::ScopedLock< Mutex > ScopedMutexLock
 Typedef for the mutex lock. More...
 
typedef osRtxMutex_t mbed_rtos_storage_mutex_t
 RTOS primitives storage types for RTX. More...
 

Functions

 ConditionVariable (Mutex &mutex)
 Create and initialize a ConditionVariable object. More...
 
void wait ()
 Wait for a notification. More...
 
bool wait_until (uint64_t millisec)
 Wait for a notification until the specified time. More...
 
bool wait_for (uint32_t millisec)
 Wait for a notification or timeout. More...
 
void notify_one ()
 Notify one waiter on this condition variable that a condition changed. More...
 
void notify_all ()
 Notify all waiters on this condition variable that a condition changed. More...
 
 ~ConditionVariable ()
 ConditionVariable destructor. More...
 
uint64_t get_ms_count ()
 Read the current RTOS kernel millisecond tick count. More...
 
void attach_idle_hook (void(*fptr)(void))
 Attach a function to be called by the RTOS idle task. More...
 
void attach_thread_terminate_hook (void(*fptr)(osThreadId_t id))
 Attach a function to be called when a thread terminates. More...
 

Detailed Description

Typedef Documentation

typedef osRtxMutex_t mbed_rtos_storage_mutex_t

RTOS primitives storage types for RTX.

Types defined in this file should be utilized, when the direct RTOS C API usage is required, to provide backing memory for internal RTX data. Allocated object should be wrapped in attribute struct and passed to os*New call, for details see CMSIS-RTOS2 documentation.

Note
This file breaks abstraction layers and uses RTX internal types, but it limits the contamination to single, RTOS implementation specific, header file, therefore limiting scope of possible changes.

Definition at line 46 of file mbed_rtos_storage.h.

typedef mbed::ScopedLock<Mutex> ScopedMutexLock

Typedef for the mutex lock.

Usage:

void foo(Mutex &m) {
ScopedMutexLock lock(m);
// Mutex lock protects code in this block
}

Definition at line 38 of file Mutex.h.

Function Documentation

void rtos::Kernel::attach_idle_hook ( void(*)(void)  fptr)

Attach a function to be called by the RTOS idle task.

Parameters
fptrpointer to the function to be called
Note
You may call this function from ISR context.
void rtos::Kernel::attach_thread_terminate_hook ( void(*)(osThreadId_t id)  fptr)

Attach a function to be called when a thread terminates.

Parameters
fptrpointer to the function to be called
Note
You may call this function from ISR context.
ConditionVariable ( Mutex mutex)

Create and initialize a ConditionVariable object.

Note
You cannot call this function from ISR context.
uint64_t rtos::Kernel::get_ms_count ( )

Read the current RTOS kernel millisecond tick count.

The tick count corresponds to the tick count the RTOS uses for timing purposes. It increments monotonically from 0 at boot, so it effectively never wraps. If the underlying RTOS only provides a 32-bit tick count, this method expands it to 64 bits.

Returns
RTOS kernel current tick count
Note
Mbed OS always uses millisecond RTOS ticks, and this could only wrap after half a billion years.
You cannot call this function from ISR context.
void notify_all ( )

Notify all waiters on this condition variable that a condition changed.

This function unblocks all of the threads waiting for the condition variable.

Note
- The thread calling this function must be the owner of the ConditionVariable's mutex.
- If there are one or more waiters and one or more threads attempting to acquire the condition variable's mutex the order in which the mutex is acquired is undefined.
You cannot call this function from ISR context.
void notify_one ( )

Notify one waiter on this condition variable that a condition changed.

This function unblocks one of the threads waiting for the condition variable.

Note
- The thread calling this function must be the owner of the ConditionVariable's mutex.
- The thread that is unblocked on ConditionVariable::notify_one is undefined if there are multiple waiters.
You cannot call this function from ISR context.
void wait ( )

Wait for a notification.

Wait causes the current thread to block until the condition variable receives a notification from another thread.

Note
- The thread calling this function must be the owner of the ConditionVariable's mutex, and it must be locked exactly once.
- Spurious notifications can occur, so the caller of this API should check to make sure the condition the caller is waiting on has been met.
- The current thread releases the lock while inside the wait function and reacquires it upon exiting the function.

Example:

mutex.lock();
while (!condition_met) {
cond.wait();
}
function_to_handle_condition();
mutex.unlock();
Note
You cannot call this function from ISR context.
bool wait_for ( uint32_t  millisec)

Wait for a notification or timeout.

Wait for causes the current thread to block until the condition variable receives a notification from another thread, or the timeout specified by the millisec parameter is reached.

Parameters
millisecTimeout value or osWaitForever in case of no timeout.
Returns
true if a timeout occurred, false otherwise.
Note
- The thread calling this function must be the owner of the ConditionVariable's mutex, and it must be locked exactly once.
- Spurious notifications can occur, so the caller of this API should check to make sure the condition the caller is waiting on has been met.
- The current thread releases the lock while inside the wait function and reacquire it upon exiting the function.

Example:

mutex.lock();
while (!condition_met) {
cond.wait_for(MAX_SLEEP_TIME);
if (!condition_met) {
do_other_work_while_condition_false();
}
}
if (condition_met) {
function_to_handle_condition();
}
mutex.unlock();
Note
You cannot call this function from ISR context.
bool wait_until ( uint64_t  millisec)

Wait for a notification until the specified time.

Wait until causes the current thread to block until the condition variable is notified, or a specific time given by millisec parameter is reached.

Parameters
millisecAbsolute end time referenced to Kernel::get_ms_count()
Returns
true if a timeout occurred, false otherwise.
Note
- The thread calling this function must be the owner of the ConditionVariable's mutex, and it must be locked exactly once.
- Spurious notifications can occur, so the caller of this API should check to make sure the condition the caller is waiting on has been met.
- The current thread releases the lock while inside the wait function and reacquires it upon exiting the function.

Example:

mutex.lock();
uint64_t end_time = Kernel::get_ms_count() + COND_WAIT_TIMEOUT;
while (!condition_met) {
if (cond.wait_until(end_time)) {
break;
}
}
if (condition_met) {
function_to_handle_condition();
}
mutex.unlock();
Note
You cannot call this function from ISR context.
~ConditionVariable ( )

ConditionVariable destructor.

Note
You cannot call this function from ISR context.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.