luat_msgbus_air101.c 883 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include "luat_base.h"
  2. #include "luat_msgbus.h"
  3. #include "luat_malloc.h"
  4. #include "wm_osal.h"
  5. #include "FreeRTOS.h"
  6. #include "rtosqueue.h"
  7. #define QUEUE_MAX_SIZE (1024)
  8. static xQueueHandle queue = NULL;
  9. static u8 queue_buff[sizeof(rtos_msg_t) * QUEUE_MAX_SIZE];
  10. void luat_msgbus_init(void)
  11. {
  12. if (queue == NULL)
  13. {
  14. queue = xQueueCreateExt(queue_buff, QUEUE_MAX_SIZE, sizeof(rtos_msg_t));
  15. }
  16. }
  17. uint32_t luat_msgbus_put(rtos_msg_t *msg, size_t timeout)
  18. {
  19. if (queue == NULL)
  20. {
  21. return 1;
  22. }
  23. portBASE_TYPE pxHigherPriorityTaskWoken = pdFALSE;
  24. xQueueSendFromISR(queue, msg, &pxHigherPriorityTaskWoken);
  25. return 0;
  26. }
  27. uint32_t luat_msgbus_get(rtos_msg_t *msg, size_t timeout)
  28. {
  29. if (queue == NULL)
  30. {
  31. return 1;
  32. }
  33. xQueueReceive(queue, msg, timeout);
  34. return 0;
  35. }
  36. uint32_t luat_msgbus_freesize(void)
  37. {
  38. return 1;
  39. }