12#ifndef ZEPHYR_INCLUDE_DRIVERS_MBOX_H_
13#define ZEPHYR_INCLUDE_DRIVERS_MBOX_H_
128#define MBOX_DT_SPEC_GET(node_id, name) \
130 .dev = DEVICE_DT_GET(DT_MBOX_CTLR_BY_NAME(node_id, name)), \
131 .channel_id = DT_MBOX_CHANNEL_BY_NAME(node_id, name), \
142#define MBOX_DT_SPEC_INST_GET(inst, name) \
143 MBOX_DT_SPEC_GET(DT_DRV_INST(inst), name)
161typedef void (*mbox_callback_t)(
const struct device *dev,
175typedef int (*mbox_send_t)(
const struct device *dev,
187typedef int (*mbox_mtu_get_t)(
const struct device *dev);
201typedef int (*mbox_register_callback_t)(
const struct device *dev,
203 mbox_callback_t cb,
void *user_data);
215typedef int (*mbox_set_enabled_t)(
const struct device *dev,
226typedef uint32_t (*mbox_max_channels_get_t)(
const struct device *dev);
228__subsystem
struct mbox_driver_api {
230 mbox_register_callback_t register_callback;
231 mbox_mtu_get_t mtu_get;
232 mbox_max_channels_get_t max_channels_get;
233 mbox_set_enabled_t set_enabled;
272static inline int z_impl_mbox_send(
const struct device *dev,
278 if (api->send ==
NULL) {
282 return api->send(dev, channel_id, msg);
322 if (api->register_callback ==
NULL) {
326 return api->register_callback(dev, channel_id, cb, user_data);
341 mbox_callback_t cb,
void *user_data)
369static inline int z_impl_mbox_mtu_get(
const struct device *dev)
373 if (api->mtu_get ==
NULL) {
377 return api->mtu_get(dev);
421static inline int z_impl_mbox_set_enabled(
const struct device *dev,
427 if (api->set_enabled ==
NULL) {
431 return api->set_enabled(dev, channel_id, enabled);
461static inline uint32_t z_impl_mbox_max_channels_get(
const struct device *dev)
465 if (api->max_channels_get ==
NULL) {
469 return api->max_channels_get(dev);
490#include <zephyr/syscalls/mbox.h>
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1375
bool device_is_ready(const struct device *dev)
Verify that a device is ready for use.
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.
Definition mbox.h:443
int mbox_mtu_get(const struct device *dev)
Return the maximum number of bytes possible in an outbound message.
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.
Definition mbox.h:293
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.
Definition mbox.h:388
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.
Definition mbox.h:340
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 bool mbox_is_ready_dt(const struct mbox_dt_spec *spec)
Validate if MBOX device instance from a struct mbox_dt_spec is ready.
Definition mbox.h:245
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.
Definition mbox.h:315
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.
Definition mbox.h:479
uint32_t mbox_channel_id_t
Type for MBOX channel identifiers.
Definition mbox.h:82
uint32_t mbox_max_channels_get(const struct device *dev)
Return the maximum number of channels.
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.
#define ENOSYS
Function not implemented.
Definition errno.h:82
#define NULL
Definition iar_missing_defs.h:20
ssize_t send(int sock, const void *buf, size_t len, int flags)
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
MBOX specification from DT.
Definition mbox.h:93
const struct device * dev
MBOX device pointer.
Definition mbox.h:95
mbox_channel_id_t channel_id
Channel ID.
Definition mbox.h:97
Message struct (to hold data and its size).
Definition mbox.h:85
size_t size
Size of the data.
Definition mbox.h:89
const void * data
Pointer to the data sent in the message.
Definition mbox.h:87