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,
276 const struct mbox_driver_api *api =
277 (
const struct mbox_driver_api *)dev->
api;
279 if (api->send ==
NULL) {
283 return api->send(dev, channel_id, msg);
321 const struct mbox_driver_api *api =
322 (
const struct mbox_driver_api *)dev->
api;
324 if (api->register_callback ==
NULL) {
328 return api->register_callback(dev, channel_id, cb, user_data);
343 mbox_callback_t cb,
void *user_data)
371static inline int z_impl_mbox_mtu_get(
const struct device *dev)
373 const struct mbox_driver_api *api =
374 (
const struct mbox_driver_api *)dev->
api;
376 if (api->mtu_get ==
NULL) {
380 return api->mtu_get(dev);
424static inline int z_impl_mbox_set_enabled(
const struct device *dev,
428 const struct mbox_driver_api *api =
429 (
const struct mbox_driver_api *)dev->
api;
431 if (api->set_enabled ==
NULL) {
435 return api->set_enabled(dev, channel_id, enabled);
465static inline uint32_t z_impl_mbox_max_channels_get(
const struct device *dev)
467 const struct mbox_driver_api *api =
468 (
const struct mbox_driver_api *)dev->
api;
470 if (api->max_channels_get ==
NULL) {
474 return api->max_channels_get(dev);
495#include <zephyr/syscalls/mbox.h>
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:447
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:294
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:391
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:342
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:316
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:484
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:510
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:516
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