module ti.sysbios.knl.Mailbox

Mailbox Manager

The Mailbox module makes available a set of functions that manipulate mailbox objects accessed through handles of type Mailbox_Handle. [ more ... ]
C synopsis target-domain sourced in ti/sysbios/knl/Mailbox.xdc
#include <ti/sysbios/knl/Mailbox.h>
Functions
Void
Void
Void
SizeT 
Int 
Int 
Void
Bool 
Bool 
Functions common to all target instances
Functions common to all target modules
Typedefs
typedef Mailbox_Object *
typedef struct
typedef struct
typedef struct
typedef struct
Constants
extern const Assert_Id 
 
DETAILS
The Mailbox module makes available a set of functions that manipulate mailbox objects accessed through handles of type Mailbox_Handle.
pend() is used to wait for a message from a mailbox. The timeout parameter to Mailbox_pend allows the task to wait until a timeout specified in terms of system clock ticks. A timeout value of BIOS_WAIT_FOREVER causes the task to wait indefinitely for a message. A timeout value of BIOS_NO_WAIT causes Mailbox_pend to return immediately. Mailbox_pend's return value indicates whether the mailbox was signaled successfully.
When a Mailbox has been configured with a readerEvent Event object and a task has returned from Event.pend() with the corresponding readerEventId, then BIOS_NO_WAIT should be passed to Mailbox_pend() to retrieve the message.
NOTE: Since only a single reader can pend on a readerEvent Event object, a Mailbox configured with a readerEvent Event object does not support multiple readers.
post() is used to send a message to a mailbox. The timeout parameter to Mailbox_post specifies the amount of time the calling task waits if the mailbox is full.
When a Mailbox has been configured with a writerEvent Event object and a task has returned from Event.pend() with the corresponding writerEventId, then BIOS_NO_WAIT should be passed to Mailbox_post() knowing that the message will be successfully posted.
NOTE: Since only a single writer can pend on a writerEvent Event object, a Mailbox configured with a writerEvent Event object does not support multiple writers.

Calling Context

Function Hwi Swi Task Main Startup
Params_init Y Y Y Y Y
construct N N Y Y N
create N N Y Y N
delete N N Y Y N
destruct N N Y Y N
getNumFreeMsgs Y Y Y N N
getNumPendingMsgs Y Y Y N N
pend N* N* Y N* N
post N* N* Y N* N
Definitions: (N* means OK to call iff the timeout parameter is set to '0'.)
  • Hwi: API is callable from a Hwi thread.
  • Swi: API is callable from a Swi thread.
  • Task: API is callable from a Task thread.
  • Main: API is callable during any of these phases:
    • In your module startup after this module is started (e.g. Mailbox_Module_startupDone() returns TRUE).
    • During xdc.runtime.Startup.lastFxns.
    • During main().
    • During BIOS.startupFxns.
  • Startup: API is callable during any of these phases:
    • During xdc.runtime.Startup.firstFxns.
    • In your module startup before this module is started (e.g. Mailbox_Module_startupDone() returns FALSE).
 
struct Mailbox_MbxElem

The header used to save each Mailbox message

C synopsis target-domain
typedef struct Mailbox_MbxElem {
    Queue_Elem elem;
} Mailbox_MbxElem;
 
DETAILS
Mailbox messages are stored in a queue that requires a header in front of each message. This structure defines that header and its size must be factored into the total data size requirements for a mailbox instance.
 
config Mailbox_A_invalidBufSize  // module-wide

Assert raised when the bufSize parameter is too small

C synopsis target-domain
extern const Assert_Id Mailbox_A_invalidBufSize;
 
DETAILS
This assert is raised when bufSize is too small to handle (size of messages + sizeof(MbxElem)) * number of messages. See ti.sysbios.knl.MailBox.buf for more information on the buf parameter.
Module-Wide Built-Ins

C synopsis target-domain
Types_ModuleId Mailbox_Module_id();
// Get this module's unique id
 
Bool Mailbox_Module_startupDone();
// Test if this module has completed startup
 
IHeap_Handle Mailbox_Module_heap();
// The heap from which this module allocates memory
 
Bool Mailbox_Module_hasMask();
// Test whether this module has a diagnostics mask
 
Bits16 Mailbox_Module_getMask();
// Returns the diagnostics mask for this module
 
Void Mailbox_Module_setMask(Bits16 mask);
// Set the diagnostics mask for this module
Instance Object Types

C synopsis target-domain
typedef struct Mailbox_Object Mailbox_Object;
// Opaque internal representation of an instance object
 
typedef Mailbox_Object *Mailbox_Handle;
// Client reference to an instance object
 
typedef struct Mailbox_Struct Mailbox_Struct;
// Opaque client structure large enough to hold an instance object
 
Mailbox_Handle Mailbox_handle(Mailbox_Struct *structP);
// Convert this instance structure pointer into an instance handle
 
Mailbox_Struct *Mailbox_struct(Mailbox_Handle handle);
// Convert this instance handle into an instance structure pointer
Instance Config Parameters

C synopsis target-domain
typedef struct Mailbox_Params {
// Instance config-params structure
    IInstance_Params *instance;
    // Common per-instance configs
    Ptr buf;
    // The address of the buffer used for creating messages
    UInt bufSize;
    // The size of the buffer that 'buf' references
    IHeap_Handle heap;
    // The IHeap instance used for dynamic creates
    Event_Handle readerEvent;
    // Mailbox not empty event if using Events. Default is null
    UInt readerEventId;
    // Mailbox not empty event Id if using Events. Default is 1
    Event_Handle writerEvent;
    // Mailbox not full event if using Events. Default is null
    UInt writerEventId;
    // Mailbox not full event Id if using Events
} Mailbox_Params;
 
Void Mailbox_Params_init(Mailbox_Params *params);
// Initialize this config-params structure with supplier-specified defaults before instance creation
 
config Mailbox_buf  // instance

The address of the buffer used for creating messages

C synopsis target-domain
struct Mailbox_Params {
      ...
    Ptr buf;
 
DETAILS
This property is only used for dynamically created Mailboxes. If set to 'null', the messages will be allocated from the heap during runtime, otherwise the user may set this to a buffer of their creation to be used for allocating the messages.
The module will split the buf into ti.sysbios.knl.Mailbox.numMsgs number of blocks (one block per Mailbox message).
Please note that if the buffer is user supplied, then it is the user's responsibility to ensure that it is aligned properly and is also large enough to contain ti.sysbios.knl.Mailbox.numMsgs number of blocks. The size of each block is defined as follows:
      sizeof(Mailbox_MbxElem) + msgSize
Since the buffer must be a aligned properly, it may be necessary to 'round up' the total size of the buffer to the next multiple of the alignment for odd sized messages.
SEE
 
config Mailbox_bufSize  // instance

The size of the buffer that 'buf' references

C synopsis target-domain
struct Mailbox_Params {
      ...
    UInt bufSize;
 
DETAILS
This property is only used for dynamically created Mailboxes.
 
config Mailbox_heap  // instance

The IHeap instance used for dynamic creates

C synopsis target-domain
struct Mailbox_Params {
      ...
    IHeap_Handle heap;
 
DETAILS
This heap is used only for dynamic instances is ignored for static instances.
 
config Mailbox_readerEvent  // instance

Mailbox not empty event if using Events. Default is null

C synopsis target-domain
struct Mailbox_Params {
      ...
    Event_Handle readerEvent;
 
DETAILS
Posted whenever a mailbox is written to. Reader task pends on this event. Note that Semaphore.supportsEvents has to be set to true for Mailbox to support Events.
 
config Mailbox_readerEventId  // instance

Mailbox not empty event Id if using Events. Default is 1

C synopsis target-domain
struct Mailbox_Params {
      ...
    UInt readerEventId;
 
DETAILS
Posted whenever a mailbox is written to. Reader task pends on this eventId. Note that Semaphore.supportsEvents has to be set to true for Mailbox to support Events.
 
config Mailbox_writerEvent  // instance

Mailbox not full event if using Events. Default is null

C synopsis target-domain
struct Mailbox_Params {
      ...
    Event_Handle writerEvent;
 
DETAILS
Posted whenever a mailbox is read from. Writer task pends on this event. Note that Semaphore.supportsEvents has to be set to true for Mailbox to support Events.
 
config Mailbox_writerEventId  // instance

Mailbox not full event Id if using Events

C synopsis target-domain
struct Mailbox_Params {
      ...
    UInt writerEventId;
 
DETAILS
Posted whenever a mailbox is read from. Writer task pends on this eventId. Note that Semaphore.supportsEvents has to be set to true for Mailbox to support Events.
Instance Creation

C synopsis target-domain
Mailbox_Handle Mailbox_create(SizeT msgSize, UInt numMsgs, const Mailbox_Params *params, Error_Block *eb);
// Allocate and initialize a new instance object and return its handle
 
Void Mailbox_construct(Mailbox_Struct *structP, SizeT msgSize, UInt numMsgs, const Mailbox_Params *params, Error_Block *eb);
// Initialize a new instance object inside the provided structure
ARGUMENTS
msgSize — size of message
numMsgs — length of mailbox
params — per-instance config params, or NULL to select default values (target-domain only)
eb — active error-handling block, or NULL to select default policy (target-domain only)
DETAILS
Mailbox_create creates a mailbox object which is initialized to contain numMsgs messages of size msgSize.
Instance Deletion

C synopsis target-domain
Void Mailbox_delete(Mailbox_Handle *handleP);
// Finalize and free this previously allocated instance object, setting the referenced handle to NULL
 
Void Mailbox_destruct(Mailbox_Struct *structP);
// Finalize the instance object inside the provided structure
 
Mailbox_getMsgSize()  // instance

Get the message size

C synopsis target-domain
SizeT Mailbox_getMsgSize(Mailbox_Handle handle);
 
ARGUMENTS
handle — handle of a previously-created Mailbox instance object
 
Mailbox_getNumFreeMsgs()  // instance

Get the number messages available for use

C synopsis target-domain
Int Mailbox_getNumFreeMsgs(Mailbox_Handle handle);
 
ARGUMENTS
handle — handle of a previously-created Mailbox instance object
 
Mailbox_getNumPendingMsgs()  // instance

Get the number of messages that are ready to be read

C synopsis target-domain
Int Mailbox_getNumPendingMsgs(Mailbox_Handle handle);
 
ARGUMENTS
handle — handle of a previously-created Mailbox instance object
 
Mailbox_pend()  // instance

Wait for a message from mailbox

C synopsis target-domain
Bool Mailbox_pend(Mailbox_Handle handle, Ptr msg, UInt timeout);
 
ARGUMENTS
handle — handle of a previously-created Mailbox instance object
msg — message pointer
timeout — maximum duration in system clock ticks
RETURNS
TRUE if successful, FALSE if timeout
DETAILS
If the mailbox is not empty, Mailbox_pend copies the first message into msg and returns TRUE. Otherwise, Mailbox_pend suspends the execution of the current task until Mailbox_post is called or the timeout expires.
A timeout value of BIOS_WAIT_FOREVER causes the task to wait indefinitely for a message.
A timeout value of BIOS_NO_WAIT causes Mailbox_pend to return immediately.
The timeout value of BIOS_NO_WAIT should be passed to Mailbox_pend() to retrieve a message after Event_pend() is called outside of Mailbox_pend to wait on an incoming message.
Mailbox_pend's return value indicates whether the mailbox was signaled successfully.
 
Mailbox_post()  // instance

Post a message to mailbox

C synopsis target-domain
Bool Mailbox_post(Mailbox_Handle handle, Ptr msg, UInt timeout);
 
ARGUMENTS
handle — handle of a previously-created Mailbox instance object
msg — message pointer
timeout — maximum duration in system clock ticks
RETURNS
TRUE if successful, FALSE if timeout
DETAILS
Mailbox_post checks to see if there are any free message slots before copying msg into the mailbox. Mailbox_post readies the first task (if any) waiting on the mailbox. If the mailbox is full and a timeout is specified the task remains suspended until Mailbox_pend is called or the timeout expires.
A timeout value of BIOS_WAIT_FOREVER causes the task to wait indefinitely for a free slot.
A timeout value of BIOS_NO_WAIT causes Mailbox_post to return immediately.
The timeout value of BIOS_NO_WAIT should be passed to Mailbox_post() to post a message after Event_pend() is called outside of Mailbox_post to wait on an available message buffer.
Mailbox_post's return value indicates whether the msg was copied or not.
Instance Built-Ins

C synopsis target-domain
Int Mailbox_Object_count();
// The number of statically-created instance objects
 
Mailbox_Handle Mailbox_Object_get(Mailbox_Object *array, Int i);
// The handle of the i-th statically-created instance object (array == NULL)
 
Mailbox_Handle Mailbox_Object_first();
// The handle of the first dynamically-created instance object, or NULL
 
Mailbox_Handle Mailbox_Object_next(Mailbox_Handle handle);
// The handle of the next dynamically-created instance object, or NULL
 
IHeap_Handle Mailbox_Object_heap();
// The heap used to allocate dynamically-created instance objects
 
Types_Label *Mailbox_Handle_label(Mailbox_Handle handle, Types_Label *buf);
// The label associated with this instance object
 
String Mailbox_Handle_name(Mailbox_Handle handle);
// The name of this instance object
 
XDCscript usage meta-domain sourced in ti/sysbios/knl/Mailbox.xdc
var Mailbox = xdc.useModule('ti.sysbios.knl.Mailbox');
module-wide constants & types
        obj.elem = Queue.Elem  ...
module-wide config parameters
        msg: "Mailbox_create's bufSize parameter is invalid (too small)"
    };
 
per-instance config parameters
    var params = new Mailbox.Params// Instance config-params object;
per-instance creation
    var inst = Mailbox.create// Create an instance-object(SizeT msgSize, UInt numMsgs, params);
 
 
struct Mailbox.MbxElem

The header used to save each Mailbox message

XDCscript usage meta-domain
var obj = new Mailbox.MbxElem;
 
    obj.elem = Queue.Elem  ...
 
DETAILS
Mailbox messages are stored in a queue that requires a header in front of each message. This structure defines that header and its size must be factored into the total data size requirements for a mailbox instance.
C SYNOPSIS
 
config Mailbox.A_invalidBufSize  // module-wide

Assert raised when the bufSize parameter is too small

XDCscript usage meta-domain
Mailbox.A_invalidBufSize = Assert.Desc {
    msg: "Mailbox_create's bufSize parameter is invalid (too small)"
};
 
DETAILS
This assert is raised when bufSize is too small to handle (size of messages + sizeof(MbxElem)) * number of messages. See ti.sysbios.knl.MailBox.buf for more information on the buf parameter.
C SYNOPSIS
 
metaonly config Mailbox.common$  // module-wide

Common module configuration parameters

XDCscript usage meta-domain
Mailbox.common$ = Types.Common$ undefined;
 
DETAILS
All modules have this configuration parameter. Its name contains the '$' character to ensure it does not conflict with configuration parameters declared by the module. This allows new configuration parameters to be added in the future without any chance of breaking existing modules.
Instance Config Parameters

XDCscript usage meta-domain
var params = new Mailbox.Params;
// Instance config-params object
    params.buf = Ptr null;
    // The address of the buffer used for creating messages
    params.bufSize = UInt 0;
    // The size of the buffer that 'buf' references
    params.heap = IHeap.Handle null;
    // The IHeap instance used for dynamic creates
    params.readerEvent = Event.Handle null;
    // Mailbox not empty event if using Events. Default is null
    params.readerEventId = UInt 1;
    // Mailbox not empty event Id if using Events. Default is 1
    params.sectionName = String null;
    // Section name for the buffer managed by the instance
    params.writerEvent = Event.Handle null;
    // Mailbox not full event if using Events. Default is null
    params.writerEventId = UInt 1;
    // Mailbox not full event Id if using Events
 
config Mailbox.buf  // instance

The address of the buffer used for creating messages

XDCscript usage meta-domain
var params = new Mailbox.Params;
  ...
params.buf = Ptr null;
 
DETAILS
This property is only used for dynamically created Mailboxes. If set to 'null', the messages will be allocated from the heap during runtime, otherwise the user may set this to a buffer of their creation to be used for allocating the messages.
The module will split the buf into ti.sysbios.knl.Mailbox.numMsgs number of blocks (one block per Mailbox message).
Please note that if the buffer is user supplied, then it is the user's responsibility to ensure that it is aligned properly and is also large enough to contain ti.sysbios.knl.Mailbox.numMsgs number of blocks. The size of each block is defined as follows:
      sizeof(Mailbox_MbxElem) + msgSize
Since the buffer must be a aligned properly, it may be necessary to 'round up' the total size of the buffer to the next multiple of the alignment for odd sized messages.
SEE
C SYNOPSIS
 
config Mailbox.bufSize  // instance

The size of the buffer that 'buf' references

XDCscript usage meta-domain
var params = new Mailbox.Params;
  ...
params.bufSize = UInt 0;
 
DETAILS
This property is only used for dynamically created Mailboxes.
C SYNOPSIS
 
config Mailbox.heap  // instance

The IHeap instance used for dynamic creates

XDCscript usage meta-domain
var params = new Mailbox.Params;
  ...
params.heap = IHeap.Handle null;
 
DETAILS
This heap is used only for dynamic instances is ignored for static instances.
C SYNOPSIS
 
config Mailbox.readerEvent  // instance

Mailbox not empty event if using Events. Default is null

XDCscript usage meta-domain
var params = new Mailbox.Params;
  ...
params.readerEvent = Event.Handle null;
 
DETAILS
Posted whenever a mailbox is written to. Reader task pends on this event. Note that Semaphore.supportsEvents has to be set to true for Mailbox to support Events.
C SYNOPSIS
 
config Mailbox.readerEventId  // instance

Mailbox not empty event Id if using Events. Default is 1

XDCscript usage meta-domain
var params = new Mailbox.Params;
  ...
params.readerEventId = UInt 1;
 
DETAILS
Posted whenever a mailbox is written to. Reader task pends on this eventId. Note that Semaphore.supportsEvents has to be set to true for Mailbox to support Events.
C SYNOPSIS
 
config Mailbox.writerEvent  // instance

Mailbox not full event if using Events. Default is null

XDCscript usage meta-domain
var params = new Mailbox.Params;
  ...
params.writerEvent = Event.Handle null;
 
DETAILS
Posted whenever a mailbox is read from. Writer task pends on this event. Note that Semaphore.supportsEvents has to be set to true for Mailbox to support Events.
C SYNOPSIS
 
config Mailbox.writerEventId  // instance

Mailbox not full event Id if using Events

XDCscript usage meta-domain
var params = new Mailbox.Params;
  ...
params.writerEventId = UInt 1;
 
DETAILS
Posted whenever a mailbox is read from. Writer task pends on this eventId. Note that Semaphore.supportsEvents has to be set to true for Mailbox to support Events.
C SYNOPSIS
 
metaonly config Mailbox.sectionName  // instance

Section name for the buffer managed by the instance

XDCscript usage meta-domain
var params = new Mailbox.Params;
  ...
params.sectionName = String null;
 
DETAILS
The default section is the 'dataSection' in the platform.
Instance Creation

XDCscript usage meta-domain
var params = new Mailbox.Params;
// Allocate instance config-params
params.config =   ...
// Assign individual configs
 
var inst = Mailbox.create(SizeT msgSize, UInt numMsgs, params);
// Create an instance-object
ARGUMENTS
msgSize — size of message
numMsgs — length of mailbox
params — per-instance config params, or NULL to select default values (target-domain only)
eb — active error-handling block, or NULL to select default policy (target-domain only)
DETAILS
Mailbox_create creates a mailbox object which is initialized to contain numMsgs messages of size msgSize.
generated on Thu, 01 Mar 2012 16:58:10 GMT