Lee Shen / FTHR_USB_serial_qSPI
Embed: (wiki syntax)

« Back to documentation index

Rtos

Data Structures

class  EventFlags
 The EventFlags class is used to signal or wait for an arbitrary event or events. More...
class  Mail< T, queue_sz >
 The Mail class allow to control, send, receive, or wait for mail. More...
class  MemoryPool< T, pool_sz >
 Define and manage fixed-size memory pools of objects of a given type. More...
class  Mutex
 The Mutex class is used to synchronize the execution of threads. More...
class  Queue< T, queue_sz >
 The Queue class allow to control, send, receive, or wait for messages. More...
class  RtosTimer
 The RtosTimer class allow creating and and controlling of timer functions in the system. More...
class  Semaphore
 The Semaphore class is used to manage and protect access to a set of shared resources. More...
class  Thread
 The Thread class allow defining, creating, and controlling thread functions in the system. More...

Enumerations

enum  State {
  Inactive, Ready, Running, WaitingDelay,
  WaitingJoin, WaitingThreadFlag, WaitingEventFlag, WaitingMutex,
  WaitingSemaphore, WaitingMemoryPool, WaitingMessageGet, WaitingMessagePut,
  WaitingInterval, WaitingOr, WaitingAnd, WaitingMailbox,
  Deleted
}
 

State of the Thread.

More...

Functions

 EventFlags (const char *name)
 Create and Initialize a EventFlags object.
uint32_t set (uint32_t flags)
 Set the specified Event Flags.
uint32_t clear (uint32_t flags=0x7fffffff)
 Clear the specified Event Flags.
uint32_t get () const
 Get the currently set Event Flags.
uint32_t wait_all (uint32_t flags=0, uint32_t timeout=osWaitForever, bool clear=true)
 Wait for all of the specified event flags to become signaled.
uint32_t wait_any (uint32_t flags=0, uint32_t timeout=osWaitForever, bool clear=true)
 Wait for any of the specified event flags to become signaled.
T * alloc (uint32_t millisec=0)
 Allocate a memory block of type T.
T * calloc (uint32_t millisec=0)
 Allocate a memory block of type T and set memory block to zero.
osStatus put (T *mptr)
 Put a mail in the queue.
osEvent get (uint32_t millisec=osWaitForever)
 Get a mail from a queue.
osStatus free (T *mptr)
 Free a memory block from a mail.
 MemoryPool ()
 Create and Initialize a memory pool.
 ~MemoryPool ()
 Destroy a memory pool.
T * alloc (void)
 Allocate a memory block of type T from a memory pool.
T * calloc (void)
 Allocate a memory block of type T from a memory pool and set memory block to zero.
osStatus free (T *block)
 Free a memory block.
 Mutex (const char *name)
 Create and Initialize a Mutex object.
osStatus lock (uint32_t millisec=osWaitForever)
 Wait until a Mutex becomes available.
bool trylock ()
 Try to lock the mutex, and return immediately.
osStatus unlock ()
 Unlock the mutex that has previously been locked by the same thread.
osStatus put (T *data, uint32_t millisec=0, uint8_t prio=0)
 Put a message in a Queue.
osEvent get (uint32_t millisec=osWaitForever)
 Get a message or Wait for a message from a Queue.
 MBED_DEPRECATED_SINCE ("mbed-os-5.2","The RtosTimer has been superseded by the EventQueue. See RtosTimer.h for more details") RtosTimer(mbed
 Create timer.
template<typename T , typename M >
 MBED_DEPRECATED_SINCE ("mbed-os-5.1","The RtosTimer constructor does not support cv-qualifiers. Replaced by ""RtosTimer(callback(obj, method), os_timer_type).") MBED_DEPRECATED_SINCE("mbed-os-5.2"
 Create timer.
osStatus stop (void)
 Stop the timer.
osStatus start (uint32_t millisec)
 Start or restart the timer.
 Semaphore (int32_t count, uint16_t max_count)
 Create and Initialize a Semaphore object used for managing resources.
int32_t wait (uint32_t millisec=osWaitForever)
 Wait until a Semaphore resource becomes available.
osStatus release (void)
 Release a Semaphore resource that was obtain with Semaphore::wait.
 MBED_DEPRECATED_SINCE ("mbed-os-5.1","Thread-spawning constructors hide errors. ""Replaced by thread.start(task).") Thread(mbed
 Create a new thread, and start it executing the specified function.
template<typename T >
 MBED_DEPRECATED_SINCE ("mbed-os-5.1","Thread-spawning constructors hide errors. ""Replaced by thread.start(callback(task, argument)).") Thread(T *argument
 Create a new thread, and start it executing the specified function.
template<typename T , typename M >
 MBED_DEPRECATED_SINCE ("mbed-os-5.1","The start function does not support cv-qualifiers. ""Replaced by thread.start(callback(obj, method)).") osStatus start(T *obj
 Starts a thread executing the specified function.
osStatus join ()
 Wait for thread to terminate.
osStatus terminate ()
 Terminate execution of a thread and remove it from Active Threads.
osStatus set_priority (osPriority priority)
 Set priority of an active thread.
osPriority get_priority ()
 Get priority of an active thread.
int32_t signal_set (int32_t signals)
 Set the specified Thread Flags for the thread.
State get_state ()
 State of this Thread.
uint32_t stack_size ()
 Get the total stack memory size for this Thread.
uint32_t free_stack ()
 Get the currently unused stack memory for this Thread.
uint32_t used_stack ()
 Get the currently used stack memory for this Thread.
uint32_t max_stack ()
 Get the maximum stack memory usage to date for this Thread.
const char * get_name ()
 Get thread name.
static int32_t signal_clr (int32_t signals)
 Clears the specified Thread Flags of the currently running thread.
static osEvent signal_wait (int32_t signals, uint32_t millisec=osWaitForever)
 Wait for one or more Thread Flags to become signaled for the current RUNNING thread.
static osStatus wait (uint32_t millisec)
 Wait for a specified time period in millisec:
static osStatus yield ()
 Pass control to next thread that is in state READY.
static osThreadId gettid ()
 Get the thread id of the current running thread.
static void attach_idle_hook (void(*fptr)(void))
 Attach a function to be called by the RTOS idle task.
static void attach_terminate_hook (void(*fptr)(osThreadId id))
 Attach a function to be called when a task is killed.

Enumeration Type Documentation

enum State [inherited]

State of the Thread.

Enumerator:
Inactive 

NOT USED.

Ready 

Ready to run.

Running 

Running.

WaitingDelay 

Waiting for a delay to occur.

WaitingJoin 

Waiting for thread to join.

Only happens when using RTX directly.

WaitingThreadFlag 

Waiting for a thread flag to be set.

WaitingEventFlag 

Waiting for a event flag to be set.

WaitingMutex 

Waiting for a mutex event to occur.

WaitingSemaphore 

Waiting for a semaphore event to occur.

WaitingMemoryPool 

Waiting for a memory pool.

WaitingMessageGet 

Waiting for message to arrive.

WaitingMessagePut 

Waiting for message to be send.

WaitingInterval 

NOT USED.

WaitingOr 

NOT USED.

WaitingAnd 

NOT USED.

WaitingMailbox 

NOT USED (Mail is implemented as MemoryPool and Queue)

Deleted 

The task has been deleted or not started.

Definition at line 254 of file Thread.h.


Function Documentation

T* alloc ( uint32_t  millisec = 0 ) [inherited]

Allocate a memory block of type T.

Parameters:
millisectimeout value or 0 in case of no time-out. (default: 0).
Returns:
pointer to memory block that can be filled with mail or NULL in case error.

Definition at line 61 of file Mail.h.

T* alloc ( void   ) [inherited]

Allocate a memory block of type T from a memory pool.

Returns:
address of the allocated memory block or NULL in case of no memory available.

Definition at line 70 of file MemoryPool.h.

void attach_idle_hook ( void(*)(void)  fptr ) [static, inherited]

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

Parameters:
fptrpointer to the function to be called

Definition at line 360 of file Thread.cpp.

static void attach_terminate_hook ( void(*)(osThreadId id)  fptr ) [static, inherited]

Attach a function to be called when a task is killed.

Parameters:
fptrpointer to the function to be called
T* calloc ( uint32_t  millisec = 0 ) [inherited]

Allocate a memory block of type T and set memory block to zero.

Parameters:
millisectimeout value or 0 in case of no time-out. (default: 0).
Returns:
pointer to memory block that can be filled with mail or NULL in case error.

Definition at line 69 of file Mail.h.

T* calloc ( void   ) [inherited]

Allocate a memory block of type T from a memory pool and set memory block to zero.

Returns:
address of the allocated memory block or NULL in case of no memory available.

Definition at line 77 of file MemoryPool.h.

uint32_t clear ( uint32_t  flags = 0x7fffffff ) [inherited]

Clear the specified Event Flags.

Parameters:
flagsspecifies the flags that shall be cleared. (default: 0x7fffffff - all flags)
Returns:
event flags before clearing or error code if highest bit set (osFlagsError).

Definition at line 55 of file EventFlags.cpp.

EventFlags ( const char *  name ) [inherited]

Create and Initialize a EventFlags object.

Parameters:
namename to be used for this EventFlags. It has to stay allocated for the lifetime of the thread.

Definition at line 34 of file EventFlags.cpp.

osStatus free ( T *  block ) [inherited]

Free a memory block.

Parameters:
blockaddress of the allocated memory block to be freed.
Returns:
osOK on successful deallocation, osErrorParameter if given memory block id is NULL or invalid, or osErrorResource if given memory block is in an invalid memory pool state.

Definition at line 92 of file MemoryPool.h.

osStatus free ( T *  mptr ) [inherited]

Free a memory block from a mail.

Parameters:
mptrpointer to the memory block that was obtained with Mail::get.
Returns:
status code that indicates the execution status of the function.

Definition at line 97 of file Mail.h.

uint32_t free_stack (  ) [inherited]

Get the currently unused stack memory for this Thread.

Returns:
the currently unused stack memory in bytes

Definition at line 257 of file Thread.cpp.

uint32_t get (  ) const [inherited]

Get the currently set Event Flags.

Returns:
set event flags.

Definition at line 60 of file EventFlags.cpp.

osEvent get ( uint32_t  millisec = osWaitForever ) [inherited]

Get a mail from a queue.

Parameters:
millisectimeout value or 0 in case of no time-out. (default: osWaitForever).
Returns:
event that contains mail information or error code.

Definition at line 85 of file Mail.h.

osEvent get ( uint32_t  millisec = osWaitForever ) [inherited]

Get a message or Wait for a message from a Queue.

Messages are retrieved in a descending priority order or first in first out when the priorities are the same.

Parameters:
millisectimeout value or 0 in case of no time-out. (default: osWaitForever).
Returns:
event information that includes the message in event.value and the status code in event.status: osEventMessage message received. osOK no message is available in the queue and no timeout was specified. osEventTimeout no message has arrived during the given timeout period. osErrorParameter a parameter is invalid or outside of a permitted range.

Definition at line 90 of file Queue.h.

const char * get_name (  ) [inherited]

Get thread name.

Returns:
thread name or NULL if the name was not set.

Definition at line 307 of file Thread.cpp.

osPriority get_priority (  ) [inherited]

Get priority of an active thread.

Returns:
current priority value of the thread function.

Definition at line 166 of file Thread.cpp.

Thread::State get_state (  ) [inherited]

State of this Thread.

Returns:
the State of this Thread

Definition at line 180 of file Thread.cpp.

osThreadId gettid (  ) [static, inherited]

Get the thread id of the current running thread.

Returns:
thread ID for reference by other functions or NULL in case of error.

Definition at line 356 of file Thread.cpp.

osStatus join (  ) [inherited]

Wait for thread to terminate.

Returns:
status code that indicates the execution status of the function.
Note:
not callable from interrupt

Definition at line 138 of file Thread.cpp.

osStatus lock ( uint32_t  millisec = osWaitForever ) [inherited]

Wait until a Mutex becomes available.

Parameters:
millisectimeout value or 0 in case of no time-out. (default: osWaitForever)
Returns:
status code that indicates the execution status of the function: osOK the mutex has been obtained. osErrorTimeout the mutex could not be obtained in the given time. osErrorParameter internal error. osErrorResource the mutex could not be obtained when no timeout was specified. osErrorISR this function cannot be called from the interrupt service routine.

Definition at line 52 of file Mutex.cpp.

uint32_t max_stack (  ) [inherited]

Get the maximum stack memory usage to date for this Thread.

Returns:
the maximum stack memory usage to date in bytes

Definition at line 287 of file Thread.cpp.

MBED_DEPRECATED_SINCE ( "mbed-os-5.1"  ,
"The RtosTimer constructor does not support cv-qualifiers. Replaced by ""RtosTimer(callback(obj, method), os_timer_type)."   
) [inherited]

Create timer.

Parameters:
objpointer to the object to call the member function on.
methodmember function to be executed by this timer.
typeosTimerOnce for one-shot or osTimerPeriodic for periodic behaviour. (default: osTimerPeriodic)
MBED_DEPRECATED_SINCE ( "mbed-os-5.1"  ,
"Thread-spawning constructors hide errors. ""Replaced by thread.start(task)."   
) [inherited]

Create a new thread, and start it executing the specified function.

Parameters:
taskfunction to be executed by this thread.
priorityinitial priority of the thread function. (default: osPriorityNormal).
stack_sizestack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE).
stack_mempointer to the stack area to be used by this thread (default: NULL).
        Thread thread(priority, stack_size, stack_mem);

        osStatus status = thread.start(task);
        if (status != osOK) {
            error("oh no!");
        }

Definition at line 103 of file Thread.h.

MBED_DEPRECATED_SINCE ( "mbed-os-5.1"  ,
"Thread-spawning constructors hide errors. ""Replaced by thread.start(callback(task, argument))."   
) [inherited]

Create a new thread, and start it executing the specified function.

Parameters:
argumentpointer that is passed to the thread function as start argument. (default: NULL).
taskargument to task.
priorityinitial priority of the thread function. (default: osPriorityNormal).
stack_sizestack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE).
stack_mempointer to the stack area to be used by this thread (default: NULL).
        Thread thread(priority, stack_size, stack_mem);

        osStatus status = thread.start(callback(task, argument));
        if (status != osOK) {
            error("oh no!");
        }
MBED_DEPRECATED_SINCE ( "mbed-os-5.1"  ,
"The start function does not support cv-qualifiers. ""Replaced by thread.start(callback(obj, method))."   
) [inherited]

Starts a thread executing the specified function.

Parameters:
objargument to task
methodfunction to be executed by this thread.
Returns:
status code that indicates the execution status of the function.
MBED_DEPRECATED_SINCE ( "mbed-os-5.2"  ,
"The RtosTimer has been superseded by the EventQueue. See RtosTimer.h for more details"   
) [inherited]

Create timer.

Parameters:
funcfunction to be executed by this timer.
typeosTimerOnce for one-shot or osTimerPeriodic for periodic behaviour. (default: osTimerPeriodic)

Definition at line 107 of file RtosTimer.h.

MemoryPool (  ) [inherited]

Create and Initialize a memory pool.

Definition at line 50 of file MemoryPool.h.

Mutex ( const char *  name ) [inherited]

Create and Initialize a Mutex object.

Parameters:
namename to be used for this mutex. It has to stay allocated for the lifetime of the thread.

Definition at line 35 of file Mutex.cpp.

osStatus put ( T *  mptr ) [inherited]

Put a mail in the queue.

Parameters:
mptrmemory block previously allocated with Mail::alloc or Mail::calloc.
Returns:
status code that indicates the execution status of the function.

Definition at line 77 of file Mail.h.

osStatus put ( T *  data,
uint32_t  millisec = 0,
uint8_t  prio = 0 
) [inherited]

Put a message in a Queue.

Parameters:
datamessage pointer.
millisectimeout value or 0 in case of no time-out. (default: 0)
priopriority value or 0 in case of default. (default: 0)
Returns:
status code that indicates the execution status of the function: osOK the message has been put into the queue. osErrorTimeout the message could not be put into the queue in the given time. osErrorResource not enough space in the queue. osErrorParameter internal error or non-zero timeout specified in an ISR.

Definition at line 77 of file Queue.h.

osStatus release ( void   ) [inherited]

Release a Semaphore resource that was obtain with Semaphore::wait.

Returns:
status code that indicates the execution status of the function: osOK the token has been correctly released. osErrorResource the maximum token count has been reached. osErrorParameter internal error.

Definition at line 60 of file Semaphore.cpp.

Semaphore ( int32_t  count,
uint16_t  max_count 
) [inherited]

Create and Initialize a Semaphore object used for managing resources.

Parameters:
countnumber of available resources
max_countmaximum number of available resources

Definition at line 33 of file Semaphore.cpp.

uint32_t set ( uint32_t  flags ) [inherited]

Set the specified Event Flags.

Parameters:
flagsspecifies the flags that shall be set.
Returns:
event flags after setting or error code if highest bit set (osFlagsError).

Definition at line 50 of file EventFlags.cpp.

osStatus set_priority ( osPriority  priority ) [inherited]

Set priority of an active thread.

Parameters:
prioritynew priority value for the thread function.
Returns:
status code that indicates the execution status of the function.

Definition at line 156 of file Thread.cpp.

int32_t signal_clr ( int32_t  signals ) [static, inherited]

Clears the specified Thread Flags of the currently running thread.

Parameters:
signalsspecifies the signal flags of the thread that should be cleared.
Returns:
signal flags before clearing or osFlagsError in case of incorrect parameters.

Definition at line 311 of file Thread.cpp.

int32_t signal_set ( int32_t  signals ) [inherited]

Set the specified Thread Flags for the thread.

Parameters:
signalsspecifies the signal flags of the thread that should be set.
Returns:
signal flags after setting or osFlagsError in case of incorrect parameters.

Definition at line 176 of file Thread.cpp.

osEvent signal_wait ( int32_t  signals,
uint32_t  millisec = osWaitForever 
) [static, inherited]

Wait for one or more Thread Flags to become signaled for the current RUNNING thread.

Parameters:
signalswait until all specified signal flags are set or 0 for any single signal flag.
millisectimeout value or 0 in case of no time-out. (default: osWaitForever).
Returns:
event flag information or error code.
Note:
if millisec is set to 0 and flag is no set the event carries osOK value.
not callable from interrupt

Definition at line 315 of file Thread.cpp.

uint32_t stack_size (  ) [inherited]

Get the total stack memory size for this Thread.

Returns:
the total stack memory size in bytes
osStatus start ( uint32_t  millisec ) [inherited]

Start or restart the timer.

Parameters:
millisecnon-zero value of the timer.
Returns:
status code that indicates the execution status of the function: osOK the timer has been started or restarted. osErrorISR start cannot be called from interrupt service routines. osErrorParameter internal error or incorrect parameter value. osErrorResource internal error (the timer is in an invalid timer state).

Definition at line 41 of file RtosTimer.cpp.

osStatus stop ( void   ) [inherited]

Stop the timer.

Returns:
status code that indicates the execution status of the function: osOK the timer has been stopped. osErrorISR stop cannot be called from interrupt service routines. osErrorParameter internal error. osErrorResource the timer is not running.

Definition at line 45 of file RtosTimer.cpp.

osStatus terminate ( void   ) [inherited]

Terminate execution of a thread and remove it from Active Threads.

Returns:
status code that indicates the execution status of the function.

Definition at line 120 of file Thread.cpp.

bool trylock (  ) [inherited]

Try to lock the mutex, and return immediately.

Returns:
true if the mutex was acquired, false otherwise.

Definition at line 56 of file Mutex.cpp.

osStatus unlock ( void   ) [inherited]

Unlock the mutex that has previously been locked by the same thread.

Returns:
status code that indicates the execution status of the function: osOK the mutex has been released. osErrorParameter internal error. osErrorResource the mutex was not locked or the current thread wasn't the owner. osErrorISR this function cannot be called from the interrupt service routine.

Definition at line 60 of file Mutex.cpp.

uint32_t used_stack (  ) [inherited]

Get the currently used stack memory for this Thread.

Returns:
the currently used stack memory in bytes

Definition at line 272 of file Thread.cpp.

osStatus wait ( uint32_t  millisec ) [static, inherited]

Wait for a specified time period in millisec:

Parameters:
millisectime delay value
Returns:
status code that indicates the execution status of the function.
Note:
not callable from interrupt

Definition at line 348 of file Thread.cpp.

int32_t wait ( uint32_t  millisec = osWaitForever ) [inherited]

Wait until a Semaphore resource becomes available.

Parameters:
millisectimeout value or 0 in case of no time-out. (default: osWaitForever).
Returns:
number of available tokens, before taking one; or -1 in case of incorrect parameters

Definition at line 46 of file Semaphore.cpp.

uint32_t wait_all ( uint32_t  flags = 0,
uint32_t  timeout = osWaitForever,
bool  clear = true 
) [inherited]

Wait for all of the specified event flags to become signaled.

Parameters:
flagsspecifies the flags to wait for.
timeouttimeout value or 0 in case of no time-out. (default: osWaitForever)
clearspecifies wether to clear the flags after waiting for them. (default: true)
Returns:
event flags before clearing or error code if highest bit set (osFlagsError).

Definition at line 65 of file EventFlags.cpp.

uint32_t wait_any ( uint32_t  flags = 0,
uint32_t  timeout = osWaitForever,
bool  clear = true 
) [inherited]

Wait for any of the specified event flags to become signaled.

Parameters:
flagsspecifies the flags to wait for. (default: 0)
timeouttimeout value or 0 in case of no time-out. (default: osWaitForever)
clearspecifies wether to clear the flags after waiting for them. (default: true)
Returns:
event flags before clearing or error code if highest bit set (osFlagsError).

Definition at line 70 of file EventFlags.cpp.

osStatus yield (  ) [static, inherited]

Pass control to next thread that is in state READY.

Returns:
status code that indicates the execution status of the function.
Note:
not callable from interrupt

Definition at line 352 of file Thread.cpp.

~MemoryPool (  ) [inherited]

Destroy a memory pool.

Definition at line 63 of file MemoryPool.h.