Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
Mail< T, queue_sz > Class Template Reference
[Mail class]
The Mail class allows you to control, send, receive or wait for mail. More...
#include <Mail.h>
Inherits NonCopyable< Mail< T, queue_sz > >.
Public Member Functions | |
Mail () | |
Create and initialize Mail queue. | |
bool | empty () const |
Check if the mail queue is empty. | |
bool | full () const |
Check if the mail queue is full. | |
T * | alloc (MBED_UNUSED uint32_t millisec=0) |
Allocate a memory block of type T, without blocking. | |
T * | alloc_for (uint32_t millisec) |
Allocate a memory block of type T, optionally blocking. | |
T * | alloc_until (uint64_t millisec) |
Allocate a memory block of type T, blocking. | |
T * | calloc (MBED_UNUSED uint32_t millisec=0) |
Allocate a memory block of type T, and set memory block to zero. | |
T * | calloc_for (uint32_t millisec) |
Allocate a memory block of type T, optionally blocking, and set memory block to zero. | |
T * | calloc_until (uint64_t millisec) |
Allocate a memory block of type T, blocking, 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 the queue. | |
osStatus | free (T *mptr) |
Free a memory block from a mail. | |
Private Member Functions | |
MBED_DEPRECATED ("Invalid copy construction of a NonCopyable resource.") NonCopyable(const NonCopyable &) | |
NonCopyable copy constructor. | |
MBED_DEPRECATED ("Invalid copy assignment of a NonCopyable resource.") NonCopyable &operator | |
NonCopyable copy assignment operator. |
Detailed Description
template<typename T, uint32_t queue_sz>
class rtos::Mail< T, queue_sz >
The Mail class allows you to control, send, receive or wait for mail.
A mail is a memory block that is sent to a thread or interrupt service routine (ISR).
- Template Parameters:
-
T Data type of a single mail message element. queue_sz Maximum number of mail messages in queue.
- Note:
- Memory considerations: The mail data store and control structures are part of this class - they do not (themselves) allocate memory on the heap, both for the Mbed OS and underlying RTOS objects (static or dynamic RTOS memory pools are not being used).
Definition at line 63 of file Mail.h.
Constructor & Destructor Documentation
( | ) |
Member Function Documentation
T* alloc | ( | MBED_UNUSED uint32_t | millisec = 0 ) |
Allocate a memory block of type T, without blocking.
- Parameters:
-
millisec Not used (see note).
- Returns:
- Pointer to memory block that you can fill with mail or nullptr in case error.
- Note:
- You may call this function from ISR context.
- If blocking is required, use Mail::alloc_for or Mail::alloc_until
T* alloc_for | ( | uint32_t | millisec ) |
Allocate a memory block of type T, optionally blocking.
- Parameters:
-
millisec Timeout value, or osWaitForever.
- Returns:
- Pointer to memory block that you can fill with mail or nullptr in case error.
- Note:
- You may call this function from ISR context if the millisec parameter is set to 0.
T* alloc_until | ( | uint64_t | millisec ) |
Allocate a memory block of type T, blocking.
- Parameters:
-
millisec Absolute timeout time, referenced to Kernel::get_ms_count().
- Returns:
- Pointer to memory block that you can fill with mail or nullptr in case error.
- Note:
- You cannot call this function from ISR context.
- the underlying RTOS may have a limit to the maximum wait time due to internal 32-bit computations, but this is guaranteed to work if the wait is <= 0x7fffffff milliseconds (~24 days). If the limit is exceeded, the wait will time out earlier than specified.
T* calloc | ( | MBED_UNUSED uint32_t | millisec = 0 ) |
Allocate a memory block of type T, and set memory block to zero.
- Parameters:
-
millisec Not used (see note).
- Returns:
- Pointer to memory block that you can fill with mail or nullptr in case error.
- Note:
- You may call this function from ISR context if the millisec parameter is set to 0.
- If blocking is required, use Mail::calloc_for or Mail::calloc_until
T* calloc_for | ( | uint32_t | millisec ) |
Allocate a memory block of type T, optionally blocking, and set memory block to zero.
- Parameters:
-
millisec Timeout value, or osWaitForever.
- Returns:
- Pointer to memory block that you can fill with mail or nullptr in case error.
- Note:
- You may call this function from ISR context if the millisec parameter is set to 0.
T* calloc_until | ( | uint64_t | millisec ) |
Allocate a memory block of type T, blocking, and set memory block to zero.
- Parameters:
-
millisec Absolute timeout time, referenced to Kernel::get_ms_count().
- Returns:
- Pointer to memory block that you can fill with mail or nullptr in case error.
- Note:
- You cannot call this function from ISR context.
- the underlying RTOS may have a limit to the maximum wait time due to internal 32-bit computations, but this is guaranteed to work if the wait is <= 0x7fffffff milliseconds (~24 days). If the limit is exceeded, the wait will time out earlier than specified.
bool empty | ( | ) | const |
osStatus free | ( | T * | mptr ) |
bool full | ( | ) | const |
osEvent get | ( | uint32_t | millisec = osWaitForever ) |
Get a mail from the queue.
- Parameters:
-
millisec Timeout value (default: osWaitForever).
- Returns:
- Event that contains mail information or error code.
- Return values:
-
osEventMessage Message received. osOK No mail is available (and no timeout was specified). osEventTimeout No mail has arrived during the given timeout period. osErrorParameter A parameter is invalid or outside of a permitted range.
- Note:
- You may call this function from ISR context if the millisec parameter is set to 0.
osStatus put | ( | T * | mptr ) |
Put a mail in the queue.
- Parameters:
-
mptr Memory block previously allocated with Mail::alloc or Mail::calloc.
- Returns:
- Status code that indicates the execution status of the function (osOK on success).
- Note:
- You may call this function from ISR context.
Generated on Tue Jul 12 2022 13:55:45 by
