forked from ROMEO/obsw
added freeRTOS on linux build
This commit is contained in:
@ -2,15 +2,17 @@
|
||||
#include "semphr.h"
|
||||
#include "task.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
// TODO namespace the names
|
||||
|
||||
SemaphoreHandle_t global_threading_semaphore = NULL;
|
||||
|
||||
uint8_t global_threading_available_c() {
|
||||
if (global_threading_semaphore == NULL) {
|
||||
|
||||
|
||||
global_threading_semaphore = xSemaphoreCreateBinary();
|
||||
//xSemaphoreGive(global_threading_semaphore);
|
||||
// xSemaphoreGive(global_threading_semaphore);
|
||||
}
|
||||
if (uxSemaphoreGetCount(global_threading_semaphore) == 1) {
|
||||
return 1;
|
||||
@ -19,22 +21,42 @@ uint8_t global_threading_available_c() {
|
||||
}
|
||||
}
|
||||
|
||||
void enable_global_threading_c() {
|
||||
xSemaphoreGive(global_threading_semaphore);
|
||||
}
|
||||
void enable_global_threading_c() { xSemaphoreGive(global_threading_semaphore); }
|
||||
|
||||
void disable_global_threading_c() {
|
||||
xSemaphoreTake(global_threading_semaphore, portMAX_DELAY);
|
||||
}
|
||||
|
||||
const char *get_task_name() { return pcTaskGetName(NULL); }
|
||||
const char *INVALID_TASK = "invalid task";
|
||||
|
||||
const char *get_task_name() {
|
||||
/* this function is called from rust's panic,
|
||||
* so we need to be extra sure to not cause another
|
||||
* one. pcTaskGetName will trigger an assertion
|
||||
* on debug builds if no task is running so we
|
||||
* check if the current task is valid before using it.
|
||||
* xTaskGetCurrentTaskHandle seems to be a lightweight
|
||||
* way to do that */
|
||||
void *task_handle = xTaskGetCurrentTaskHandle();
|
||||
if (task_handle == NULL) {
|
||||
return INVALID_TASK;
|
||||
}
|
||||
const char *name = pcTaskGetName(NULL);
|
||||
if (name == NULL) {
|
||||
return INVALID_TASK;
|
||||
}
|
||||
if (strlen(name) > configMAX_TASK_NAME_LEN) {
|
||||
return INVALID_TASK;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
void stop_it() { taskENTER_CRITICAL(); }
|
||||
|
||||
// TODO return some error code?
|
||||
void *create_task(TaskFunction_t taskFunction, void *parameter,
|
||||
uint32_t stack_size) {
|
||||
//TODO verify uint32_t vs configSTACK_DEPTH_TYPE
|
||||
// TODO verify uint32_t vs configSTACK_DEPTH_TYPE
|
||||
TaskHandle_t newTask;
|
||||
BaseType_t result =
|
||||
xTaskCreate(taskFunction, "rust", stack_size, parameter, 4, &newTask);
|
||||
@ -46,16 +68,18 @@ void *create_task(TaskFunction_t taskFunction, void *parameter,
|
||||
}
|
||||
|
||||
void task_delay(uint32_t milliseconds) {
|
||||
//TODO verify uint32_t vs TickType_t
|
||||
// TODO verify uint32_t vs TickType_t
|
||||
vTaskDelay(pdMS_TO_TICKS(milliseconds));
|
||||
}
|
||||
|
||||
void delete_task(void * task){
|
||||
vTaskSuspend(task); //we can not use vDeleteTask as it would free the allocated memory which is forbidden using heap1 (which we use)
|
||||
void delete_task(void *task) {
|
||||
vTaskSuspend(
|
||||
task); // we can not use vDeleteTask as it would free the allocated memory
|
||||
// which is forbidden using heap1 (which we use)
|
||||
}
|
||||
|
||||
void *create_queue(uint32_t length, uint32_t element_size) {
|
||||
//TODO verify uint32_t vs UBaseType_t
|
||||
// TODO verify uint32_t vs UBaseType_t
|
||||
QueueHandle_t newQueue = xQueueCreate(length, element_size);
|
||||
return newQueue;
|
||||
}
|
||||
@ -76,11 +100,9 @@ uint8_t queue_send(void *queue, void *message) {
|
||||
}
|
||||
}
|
||||
|
||||
void *create_mutex() {
|
||||
return xSemaphoreCreateRecursiveMutex();
|
||||
}
|
||||
void *create_mutex() { return xSemaphoreCreateRecursiveMutex(); }
|
||||
|
||||
uint8_t take_mutex(void * handle) {
|
||||
uint8_t take_mutex(void *handle) {
|
||||
// TODO check if global semaphore is free (ie, we are doing multitasking)
|
||||
// if not, pointers are invalid, bail out
|
||||
if (xSemaphoreTakeRecursive(handle, portMAX_DELAY) == pdPASS) {
|
||||
@ -90,7 +112,7 @@ uint8_t take_mutex(void * handle) {
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t give_mutex(void * handle) {
|
||||
uint8_t give_mutex(void *handle) {
|
||||
// TODO check if global semaphore is free (ie, we are doing multitasking)
|
||||
// if not, pointers are invalid, bail out
|
||||
if (xSemaphoreGiveRecursive(handle) == pdPASS) {
|
||||
|
Reference in New Issue
Block a user