luat_msgbus_freertos.c 897 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include "luat_base.h"
  2. #include "luat_msgbus.h"
  3. #ifdef LUAT_FREERTOS_FULL_INCLUDE
  4. #include "freertos/FreeRTOS.h"
  5. #include "freertos/queue.h"
  6. #else
  7. #include "FreeRTOS.h"
  8. #include "queue.h"
  9. #endif
  10. static QueueHandle_t xQueue = {0};
  11. void luat_msgbus_init(void) {
  12. if (!xQueue) {
  13. xQueue = xQueueCreate(256, sizeof(rtos_msg_t));
  14. }
  15. }
  16. uint32_t luat_msgbus_put(rtos_msg_t* msg, size_t timeout) {
  17. if (xQueue == NULL)
  18. return 1;
  19. return xQueueSendFromISR(xQueue, msg, NULL) == pdTRUE ? 0 : 1;
  20. }
  21. uint32_t luat_msgbus_get(rtos_msg_t* msg, size_t timeout) {
  22. if (xQueue == NULL)
  23. return 1;
  24. return xQueueReceive(xQueue, msg, timeout) == pdTRUE ? 0 : 1;
  25. }
  26. uint32_t luat_msgbus_freesize(void) {
  27. return 1;
  28. }
  29. uint8_t luat_msgbus_is_empty(void) {
  30. return uxQueueMessagesWaiting(xQueue) == 0 ? 1 : 0;
  31. }
  32. uint8_t luat_msgbus_is_ready(void) {
  33. return xQueue?1:0;
  34. }