luat_msgbus_freertos.c 965 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include "luat_msgbus.h"
  2. #include "FreeRTOS.h"
  3. #include "queue.h"
  4. #define QUEUE_LENGTH 0xFF
  5. #define ITEM_SIZE sizeof(rtos_msg_t)
  6. static StaticQueue_t xStaticQueue = {0};
  7. static QueueHandle_t xQueue = {0};
  8. static uint8_t ucQueueStorageArea[ QUEUE_LENGTH * ITEM_SIZE ];
  9. void luat_msgbus_init(void) {
  10. if (!xQueue) {
  11. xQueue = xQueueCreateStatic( QUEUE_LENGTH,
  12. ITEM_SIZE,
  13. ucQueueStorageArea,
  14. &xStaticQueue );
  15. }
  16. }
  17. uint32_t luat_msgbus_put(rtos_msg_t* msg, size_t timeout) {
  18. if (xQueue == NULL)
  19. return 1;
  20. return xQueueSendFromISR(xQueue, msg, NULL);
  21. }
  22. uint32_t luat_msgbus_get(rtos_msg_t* msg, size_t timeout) {
  23. if (xQueue == NULL)
  24. return 1;
  25. return xQueueReceive(xQueue, msg, timeout); // 要不要除portTICK_RATE_MS呢?
  26. }
  27. uint32_t luat_msgbus_freesize(void) {
  28. if (xQueue == NULL)
  29. return 1;
  30. return 1;
  31. }