Zephyr API Documentation 4.0.0-rc2
A Scalable Open Source RTOS
|
MBOX Interface . More...
Data Structures | |
struct | mbox_msg |
Message struct (to hold data and its size). More... | |
struct | mbox_dt_spec |
MBOX specification from DT. More... | |
Macros | |
#define | MBOX_DT_SPEC_GET(node_id, name) |
Structure initializer for struct mbox_dt_spec from devicetree. | |
#define | MBOX_DT_SPEC_INST_GET(inst, name) |
Instance version of MBOX_DT_CHANNEL_GET() | |
Typedefs | |
typedef uint32_t | mbox_channel_id_t |
Type for MBOX channel identifiers. | |
Functions | |
static bool | mbox_is_ready_dt (const struct mbox_dt_spec *spec) |
Validate if MBOX device instance from a struct mbox_dt_spec is ready. | |
int | mbox_send (const struct device *dev, mbox_channel_id_t channel_id, const struct mbox_msg *msg) |
Try to send a message over the MBOX device. | |
static int | mbox_send_dt (const struct mbox_dt_spec *spec, const struct mbox_msg *msg) |
Try to send a message over the MBOX device from a struct mbox_dt_spec. | |
static int | mbox_register_callback (const struct device *dev, mbox_channel_id_t channel_id, mbox_callback_t cb, void *user_data) |
Register a callback function on a channel for incoming messages. | |
static int | mbox_register_callback_dt (const struct mbox_dt_spec *spec, mbox_callback_t cb, void *user_data) |
Register a callback function on a channel for incoming messages from a struct mbox_dt_spec. | |
int | mbox_mtu_get (const struct device *dev) |
Return the maximum number of bytes possible in an outbound message. | |
static int | mbox_mtu_get_dt (const struct mbox_dt_spec *spec) |
Return the maximum number of bytes possible in an outbound message from struct mbox_dt_spec. | |
int | mbox_set_enabled (const struct device *dev, mbox_channel_id_t channel_id, bool enabled) |
Enable (disable) interrupts and callbacks for inbound channels. | |
static int | mbox_set_enabled_dt (const struct mbox_dt_spec *spec, bool enabled) |
Enable (disable) interrupts and callbacks for inbound channels from a struct mbox_dt_spec. | |
uint32_t | mbox_max_channels_get (const struct device *dev) |
Return the maximum number of channels. | |
static int | mbox_max_channels_get_dt (const struct mbox_dt_spec *spec) |
Return the maximum number of channels from a struct mbox_dt_spec. | |
MBOX Interface .
An MBOX device is a peripheral capable of passing signals (and data depending on the peripheral) between CPUs and clusters in the system. Each MBOX instance is providing one or more channels, each one targeting one other CPU cluster (multiple channels can target the same cluster).
For example in the plot the device 'dev A' is using the TX channel 9 to signal (or send data to) the CPU #2 and it's expecting data or signals on the RX channel 8. Thus it can send the message through the channel 9, and it can register a callback on the channel 8 of the MBOX device.
This API supports two modes: signalling mode and data transfer mode.
In signalling mode:
In data transfer mode:
#define MBOX_DT_SPEC_GET | ( | node_id, | |
name ) |
#include <zephyr/drivers/mbox.h>
Structure initializer for struct mbox_dt_spec from devicetree.
This helper macro expands to a static initializer for a struct mbox_dt_spec by reading the relevant device controller and channel number from the devicetree.
Example devicetree fragment:
Example usage:
node_id | Devicetree node identifier for the MBOX device |
name | lowercase-and-underscores name of the mboxes element |
#define MBOX_DT_SPEC_INST_GET | ( | inst, | |
name ) |
#include <zephyr/drivers/mbox.h>
Instance version of MBOX_DT_CHANNEL_GET()
inst | DT_DRV_COMPAT instance number |
name | lowercase-and-underscores name of the mboxes element |
typedef uint32_t mbox_channel_id_t |
#include <zephyr/drivers/mbox.h>
Type for MBOX channel identifiers.
|
inlinestatic |
#include <zephyr/drivers/mbox.h>
Validate if MBOX device instance from a struct mbox_dt_spec is ready.
spec | MBOX specification from devicetree |
#include <zephyr/drivers/mbox.h>
Return the maximum number of channels.
Return the maximum number of channels supported by the hardware.
dev | MBOX device instance. |
|
inlinestatic |
#include <zephyr/drivers/mbox.h>
Return the maximum number of channels from a struct mbox_dt_spec.
spec | MBOX specification from devicetree |
int mbox_mtu_get | ( | const struct device * | dev | ) |
#include <zephyr/drivers/mbox.h>
Return the maximum number of bytes possible in an outbound message.
Returns the actual number of bytes that it is possible to send through an outgoing channel.
This number can be 0 when the driver only supports signalling or when on the receiving side the content and size of the message must be retrieved in an indirect way (i.e. probing some other peripheral, reading memory regions, etc...).
If this function returns 0, the msg parameter in mbox_send() is expected to be NULL.
dev | MBOX device instance. |
>0 | Maximum possible size of a message in bytes |
0 | Indicates signalling |
-errno | Negative errno on error. |
|
inlinestatic |
#include <zephyr/drivers/mbox.h>
Return the maximum number of bytes possible in an outbound message from struct mbox_dt_spec.
spec | MBOX specification from devicetree |
|
inlinestatic |
#include <zephyr/drivers/mbox.h>
Register a callback function on a channel for incoming messages.
This function doesn't assume anything concerning the status of the interrupts. Use mbox_set_enabled() to enable or to disable the interrupts if needed.
dev | MBOX device instance |
channel_id | MBOX channel identifier |
cb | Callback function to execute on incoming message interrupts. |
user_data | Application-specific data pointer which will be passed to the callback function when executed. |
0 | On success. |
-errno | Negative errno on error. |
|
inlinestatic |
#include <zephyr/drivers/mbox.h>
Register a callback function on a channel for incoming messages from a struct mbox_dt_spec.
spec | MBOX specification from devicetree |
cb | Callback function to execute on incoming message interrupts. |
user_data | Application-specific data pointer which will be passed to the callback function when executed. |
int mbox_send | ( | const struct device * | dev, |
mbox_channel_id_t | channel_id, | ||
const struct mbox_msg * | msg ) |
#include <zephyr/drivers/mbox.h>
Try to send a message over the MBOX device.
Send a message over an struct mbox_channel. The msg parameter must be NULL when the driver is used for signalling.
If the msg parameter is not NULL, this data is expected to be delivered on the receiving side using the data parameter of the receiving callback.
dev | MBOX device instance |
channel_id | MBOX channel identifier |
msg | Message |
0 | On success. |
-EBUSY | If the remote hasn't yet read the last data sent. |
-EMSGSIZE | If the supplied data size is unsupported by the driver. |
-EINVAL | If there was a bad parameter, such as: too-large channel descriptor or the device isn't an outbound MBOX channel. |
|
inlinestatic |
#include <zephyr/drivers/mbox.h>
Try to send a message over the MBOX device from a struct mbox_dt_spec.
spec | MBOX specification from devicetree |
msg | Message |
int mbox_set_enabled | ( | const struct device * | dev, |
mbox_channel_id_t | channel_id, | ||
bool | enabled ) |
#include <zephyr/drivers/mbox.h>
Enable (disable) interrupts and callbacks for inbound channels.
Enable interrupt for the channel when the parameter 'enable' is set to true. Disable it otherwise.
Immediately after calling this function with 'enable' set to true, the channel is considered enabled and ready to receive signal and messages (even already pending), so the user must take care of installing a proper callback (if needed) using mbox_register_callback() on the channel before enabling it. For this reason it is recommended that all the channels are disabled at probe time.
Enabling a channel for which there is no installed callback is considered undefined behavior (in general the driver must take care of gracefully handling spurious interrupts with no installed callback).
dev | MBOX device instance |
channel_id | MBOX channel identifier |
enabled | Enable (true) or disable (false) the channel. |
0 | On success. |
-EINVAL | If it isn't an inbound channel. |
-EALREADY | If channel is already enabled . |
|
inlinestatic |
#include <zephyr/drivers/mbox.h>
Enable (disable) interrupts and callbacks for inbound channels from a struct mbox_dt_spec.
spec | MBOX specification from devicetree |
enabled | Enable (true) or disable (false) the channel. |