mailbox.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2023-09-23 GuEe-GUI first version
  9. */
  10. #ifndef __MAILBOX_H__
  11. #define __MAILBOX_H__
  12. #include <rtdef.h>
  13. #include <drivers/ofw.h>
  14. struct rt_mbox_chan;
  15. struct rt_mbox_client;
  16. struct rt_mbox_controller_ops;
  17. struct rt_mbox_controller
  18. {
  19. rt_list_t list;
  20. struct rt_device *dev;
  21. const struct rt_mbox_controller_ops *ops;
  22. rt_size_t num_chans;
  23. struct rt_mbox_chan *chans;
  24. };
  25. struct rt_mbox_controller_ops
  26. {
  27. rt_err_t (*request)(struct rt_mbox_chan *);
  28. void (*release)(struct rt_mbox_chan *);
  29. rt_err_t (*send)(struct rt_mbox_chan *, const void *data);
  30. rt_bool_t (*peek)(struct rt_mbox_chan *);
  31. int (*ofw_parse)(struct rt_mbox_controller *, struct rt_ofw_cell_args *);
  32. };
  33. struct rt_mbox_chan
  34. {
  35. struct rt_mbox_controller *ctrl;
  36. struct rt_mbox_client *client;
  37. void *data;
  38. rt_bool_t complete;
  39. struct rt_timer timer;
  40. struct rt_spinlock lock;
  41. void *priv;
  42. };
  43. struct rt_mbox_client
  44. {
  45. struct rt_device *dev;
  46. void (*rx_callback)(struct rt_mbox_client *, void *data);
  47. void (*tx_prepare)(struct rt_mbox_client *, const void *data);
  48. void (*tx_done)(struct rt_mbox_client *, const void *data, rt_err_t err);
  49. };
  50. rt_err_t rt_mbox_controller_register(struct rt_mbox_controller *ctrl);
  51. rt_err_t rt_mbox_controller_unregister(struct rt_mbox_controller *ctrl);
  52. rt_err_t rt_mbox_send(struct rt_mbox_chan *chan, const void *data,
  53. rt_uint32_t timeout_ms);
  54. void rt_mbox_send_done(struct rt_mbox_chan *chan, rt_err_t err);
  55. rt_bool_t rt_mbox_peek(struct rt_mbox_chan *chan);
  56. rt_err_t rt_mbox_recv(struct rt_mbox_chan *chan, void *data);
  57. struct rt_mbox_chan *rt_mbox_request_by_index(struct rt_mbox_client *client, int index);
  58. struct rt_mbox_chan *rt_mbox_request_by_name(struct rt_mbox_client *client, char *name);
  59. rt_err_t rt_mbox_release(struct rt_mbox_chan *chan);
  60. #endif /* __MAILBOX_H__ */