| 123456789101112131415161718192021222324252627282930313233343536 |
- #include "luat_msgbus.h"
- #include "FreeRTOS.h"
- #include "queue.h"
- #define QUEUE_LENGTH 0xFF
- #define ITEM_SIZE sizeof(rtos_msg_t)
- static StaticQueue_t xStaticQueue = {0};
- static QueueHandle_t xQueue = {0};
- static uint8_t ucQueueStorageArea[ QUEUE_LENGTH * ITEM_SIZE ];
- void luat_msgbus_init(void) {
- if (!xQueue) {
- xQueue = xQueueCreateStatic( QUEUE_LENGTH,
- ITEM_SIZE,
- ucQueueStorageArea,
- &xStaticQueue );
- }
- }
- uint32_t luat_msgbus_put(rtos_msg_t* msg, size_t timeout) {
- if (xQueue == NULL)
- return 1;
- return xQueueSendFromISR(xQueue, msg, NULL);
- }
- uint32_t luat_msgbus_get(rtos_msg_t* msg, size_t timeout) {
- if (xQueue == NULL)
- return 1;
- return xQueueReceive(xQueue, msg, timeout); // 要不要除portTICK_RATE_MS呢?
- }
- uint32_t luat_msgbus_freesize(void) {
- if (xQueue == NULL)
- return 1;
- return 1;
- }
|