queue-manager: wrap send & receive

This commit is contained in:
Vasily Davydov 2023-04-26 00:56:18 +03:00
parent 34f6b5b694
commit 4a553e3093
3 changed files with 17 additions and 3 deletions

View File

@ -27,7 +27,7 @@ int main(void)
QueueHandle_t master_event_all_q = qmanager->getQueue(ThreadCommon::QueueManager::master_event_all); QueueHandle_t master_event_all_q = qmanager->getQueue(ThreadCommon::QueueManager::master_event_all);
ThreadCommon::Event* e = new ThreadCommon::Event(ThreadCommon::Null, 0); ThreadCommon::Event* e = new ThreadCommon::Event(ThreadCommon::Null, 0);
xQueueSend(master_event_all_q, static_cast<void *>(e), 0); qmanager->send<ThreadCommon::Event>(ThreadCommon::QueueManager::master_event_all, e, 1000);
//</Queue_test> //</Queue_test>
// Start the real time kernel with preemption. // Start the real time kernel with preemption.

View File

@ -76,6 +76,21 @@ namespace ThreadCommon
~QueueManager() = default; ~QueueManager() = default;
bool createQueue(size_t queue_length, size_t item_size, Queue_id qid); bool createQueue(size_t queue_length, size_t item_size, Queue_id qid);
QueueHandle_t getQueue(Queue_id qid); QueueHandle_t getQueue(Queue_id qid);
template<class T> bool send(Queue_id qid, T* data, TickType_t timeout){
QueueHandle_t q = this->getQueue(qid);
BaseType_t qCheck = xQueueSend(q,
static_cast<void*>(data),
timeout);
return (qCheck == pdTRUE);
}
template<class T> bool receive(Queue_id qid, T* data, TickType_t timeout){
QueueHandle_t q = this->getQueue(qid);
BaseType_t qCheck = xQueueReceive(q,
static_cast<void*>(data),
timeout);
return (qCheck == pdTRUE);
}
private: private:
std::map <Queue_id, QueueHandle_t> queues; std::map <Queue_id, QueueHandle_t> queues;
}; };

View File

@ -13,12 +13,11 @@ Master::Master(ThreadCommon::QueueManager* qm) : _qm(qm)
} }
void Master::taskFunction() { void Master::taskFunction() {
QueueHandle_t master_event_all_q = _qm->getQueue(ThreadCommon::QueueManager::master_event_all);
ThreadCommon::Event data(ThreadCommon::Null, 0); ThreadCommon::Event data(ThreadCommon::Null, 0);
int led = 0; int led = 0;
bool LedState = true; bool LedState = true;
for (;;) { for (;;) {
xQueueReceive(master_event_all_q, static_cast<void*>(&data), portMAX_DELAY); _qm->receive<ThreadCommon::Event>(ThreadCommon::QueueManager::master_event_all, &data, portMAX_DELAY);
Board_LED_Set(led, LedState); Board_LED_Set(led, LedState);
LedState = (bool) !LedState; LedState = (bool) !LedState;
led++; led++;