You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
#pragma once
#include "basic/zlog.h"
#include "cmsis_os.h"
namespace iflytop { template <typename T> class ZQueue { private: int32_t m_num = 0; int32_t m_eachsize = 0; QueueHandle_t xQueue;
public: void initialize(int32_t num, int32_t eachsize) { xQueue = xQueueCreate(num, eachsize); ZASSERT(xQueue); } void clear() { xQueueReset(xQueue); }
bool send(T *data, int32_t overtime) { return _send((uint8_t *)data, sizeof(T), overtime); } bool receive(T *data, int32_t overtime) { return _receive((uint8_t *)data, overtime); }
bool isFull() { BaseType_t xStatus = xQueueIsQueueFullFromISR(xQueue); return xStatus == pdTRUE; } bool isEmpty() { BaseType_t xStatus = xQueueIsQueueEmptyFromISR(xQueue); return xStatus == pdTRUE; }
private: bool _send(uint8_t *data, int32_t len, int32_t overtime) { if (xPortIsInsideInterrupt()) { BaseType_t xHigherPriorityTaskWoken = pdFALSE; BaseType_t xStatus = xQueueSendToFrontFromISR(xQueue, data, &xHigherPriorityTaskWoken); return xStatus == pdPASS; } else { BaseType_t xStatus = xQueueSend(xQueue, data, overtime); return xStatus == pdPASS; } } bool _receive(uint8_t *data, int32_t overtime) { BaseType_t xStatus = xQueueReceive(xQueue, data, overtime); return xStatus == pdPASS; } };
} // namespace iflytop
|