forked from ROMEO/obsw
implemented queues, broke threads on the way :/
This commit is contained in:
@ -2,9 +2,11 @@
|
||||
#include "semphr.h"
|
||||
#include "task.h"
|
||||
|
||||
//TODO namespace the names
|
||||
|
||||
/**
|
||||
* Task descriptors
|
||||
*/
|
||||
*/
|
||||
#define NUMBER_OF_TASKS 100
|
||||
SemaphoreHandle_t taskMutex = NULL;
|
||||
StaticSemaphore_t taskMutexDescriptor;
|
||||
@ -13,7 +15,7 @@ StaticTask_t taskDescriptors[NUMBER_OF_TASKS];
|
||||
|
||||
/**
|
||||
* Queue descriptors
|
||||
*/
|
||||
*/
|
||||
#define NUMBER_OF_QUEUES 300
|
||||
SemaphoreHandle_t queueMutex = NULL;
|
||||
StaticSemaphore_t queueMutexDescriptor;
|
||||
@ -26,17 +28,13 @@ void initFreeRTOSHelper() {
|
||||
queueMutex = xSemaphoreCreateRecursiveMutexStatic(&queueMutexDescriptor);
|
||||
}
|
||||
|
||||
const char * get_task_name() {
|
||||
return pcTaskGetName( NULL );
|
||||
}
|
||||
const char *get_task_name() { return pcTaskGetName(NULL); }
|
||||
|
||||
void stop_it() {
|
||||
taskENTER_CRITICAL();
|
||||
}
|
||||
void stop_it() { taskENTER_CRITICAL(); }
|
||||
|
||||
// TODO return some error code?
|
||||
void *create_task(TaskFunction_t taskFunction, void *parameter, void *buffer,
|
||||
size_t buffersize) {
|
||||
size_t buffersize) {
|
||||
if (xSemaphoreTakeRecursive(taskMutex, portMAX_DELAY) != pdTRUE) {
|
||||
return NULL;
|
||||
}
|
||||
@ -60,8 +58,8 @@ void task_delay(uint32_t milliseconds) {
|
||||
vTaskDelay(pdMS_TO_TICKS(milliseconds));
|
||||
}
|
||||
|
||||
void * create_queue(size_t length, size_t element_size, uint8_t * buffer) {
|
||||
if (xSemaphoreTakeRecursive(queueMutex, portMAX_DELAY) != pdTRUE) {
|
||||
void *create_queue(size_t length, size_t element_size, uint8_t *buffer) {
|
||||
if (xSemaphoreTakeRecursive(queueMutex, portMAX_DELAY) != pdTRUE) {
|
||||
return NULL;
|
||||
}
|
||||
// we hold the queue mutex and are now allowed to access the taskDescriptors
|
||||
@ -69,8 +67,25 @@ void * create_queue(size_t length, size_t element_size, uint8_t * buffer) {
|
||||
sizeof(queueDescriptors) / sizeof(*queueDescriptors)) {
|
||||
return NULL;
|
||||
}
|
||||
QueueHandle_t newQueue = xQueueCreateStatic(length, element_size, buffer, queueDescriptors + nextFreeQueueDescriptor);
|
||||
nextFreeQueueDescriptor++;
|
||||
xSemaphoreGiveRecursive(queueMutex);
|
||||
QueueHandle_t newQueue = xQueueCreateStatic(
|
||||
length, element_size, buffer, queueDescriptors + nextFreeQueueDescriptor);
|
||||
nextFreeQueueDescriptor++;
|
||||
xSemaphoreGiveRecursive(queueMutex);
|
||||
return newQueue;
|
||||
}
|
||||
|
||||
uint8_t queue_receive(void *queue, void *message) {
|
||||
if (xQueueReceive(queue, message, portMAX_DELAY) == pdPASS) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t queue_send(void *queue, void *message) {
|
||||
if (xQueueSend(queue, message, 0) != pdPASS) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user