6#ifndef ZEPHYR_INCLUDE_DRIVERS_MBOX_H_
7#define ZEPHYR_INCLUDE_DRIVERS_MBOX_H_
122#define MBOX_DT_SPEC_GET(node_id, name) \
124 .dev = DEVICE_DT_GET(DT_MBOX_CTLR_BY_NAME(node_id, name)), \
125 .channel_id = DT_MBOX_CHANNEL_BY_NAME(node_id, name), \
136#define MBOX_DT_SPEC_INST_GET(inst, name) \
137 MBOX_DT_SPEC_GET(DT_DRV_INST(inst), name)
155typedef void (*mbox_callback_t)(
const struct device *dev,
169typedef int (*mbox_send_t)(
const struct device *dev,
181typedef int (*mbox_mtu_get_t)(
const struct device *dev);
195typedef int (*mbox_register_callback_t)(
const struct device *dev,
197 mbox_callback_t cb,
void *user_data);
209typedef int (*mbox_set_enabled_t)(
const struct device *dev,
220typedef uint32_t (*mbox_max_channels_get_t)(
const struct device *dev);
222__subsystem
struct mbox_driver_api {
224 mbox_register_callback_t register_callback;
225 mbox_mtu_get_t mtu_get;
226 mbox_max_channels_get_t max_channels_get;
227 mbox_set_enabled_t set_enabled;
266static inline int z_impl_mbox_send(
const struct device *dev,
270 const struct mbox_driver_api *api =
271 (
const struct mbox_driver_api *)dev->
api;
273 if (api->send == NULL) {
277 return api->send(dev, channel_id, msg);
315 const struct mbox_driver_api *api =
316 (
const struct mbox_driver_api *)dev->
api;
318 if (api->register_callback == NULL) {
322 return api->register_callback(dev, channel_id, cb, user_data);
337 mbox_callback_t cb,
void *user_data)
365static inline int z_impl_mbox_mtu_get(
const struct device *dev)
367 const struct mbox_driver_api *api =
368 (
const struct mbox_driver_api *)dev->
api;
370 if (api->mtu_get == NULL) {
374 return api->mtu_get(dev);
418static inline int z_impl_mbox_set_enabled(
const struct device *dev,
422 const struct mbox_driver_api *api =
423 (
const struct mbox_driver_api *)dev->
api;
425 if (api->set_enabled == NULL) {
429 return api->set_enabled(dev, channel_id, enabled);
459static inline uint32_t z_impl_mbox_max_channels_get(
const struct device *dev)
461 const struct mbox_driver_api *api =
462 (
const struct mbox_driver_api *)dev->
api;
464 if (api->max_channels_get == NULL) {
468 return api->max_channels_get(dev);
489#include <zephyr/syscalls/mbox.h>
static ssize_t send(int sock, const void *buf, size_t len, int flags)
POSIX wrapper for zsock_send.
Definition socket.h:867
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:441
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:288
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:385
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:336
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:239
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:310
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:478
uint32_t mbox_channel_id_t
Type for MBOX channel identifiers.
Definition mbox.h:76
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
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
Runtime device structure (in ROM) per driver instance.
Definition device.h:412
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:418
MBOX specification from DT.
Definition mbox.h:87
const struct device * dev
MBOX device pointer.
Definition mbox.h:89
mbox_channel_id_t channel_id
Channel ID.
Definition mbox.h:91
Message struct (to hold data and its size).
Definition mbox.h:79
size_t size
Size of the data.
Definition mbox.h:83
const void * data
Pointer to the data sent in the message.
Definition mbox.h:81