2020-09-01 10:34:23 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-08-17 09:45:53 +00:00
|
|
|
#include "main.h"
|
2020-08-24 15:31:22 +00:00
|
|
|
#include <stdbool.h>
|
2020-10-07 09:37:43 +00:00
|
|
|
#include <pthread.h>
|
2020-08-17 09:45:53 +00:00
|
|
|
|
2020-08-24 15:31:22 +00:00
|
|
|
void osDelay(uint32_t ms);
|
|
|
|
|
|
|
|
// some FreeRTOS types
|
2020-09-29 23:18:30 +00:00
|
|
|
typedef void (*TaskFunction_t)(void*);
|
2020-09-01 10:34:23 +00:00
|
|
|
typedef size_t UBaseType_t;
|
2020-08-24 15:31:22 +00:00
|
|
|
typedef uint32_t StackType_t;
|
|
|
|
typedef uint32_t StaticTask_t;
|
|
|
|
typedef pthread_t* TaskHandle_t;
|
2020-09-01 10:34:23 +00:00
|
|
|
|
|
|
|
typedef enum {
|
2020-09-07 14:35:18 +00:00
|
|
|
SemaphoreTypeMutex,
|
|
|
|
SemaphoreTypeCounting,
|
2020-09-01 10:34:23 +00:00
|
|
|
} SemaphoreType;
|
|
|
|
typedef struct {
|
|
|
|
SemaphoreType type;
|
2020-09-07 14:35:18 +00:00
|
|
|
pthread_mutex_t mutex;
|
2020-09-01 10:34:23 +00:00
|
|
|
uint8_t take_counter;
|
|
|
|
uint8_t give_counter;
|
|
|
|
} StaticSemaphore_t;
|
|
|
|
typedef StaticSemaphore_t* SemaphoreHandle_t;
|
|
|
|
|
|
|
|
typedef uint32_t StaticQueue_t;
|
|
|
|
typedef StaticQueue_t* QueueHandle_t;
|
|
|
|
|
|
|
|
#define portMAX_DELAY -1
|
|
|
|
|
2020-09-29 23:18:30 +00:00
|
|
|
typedef enum { pdTRUE = 1, pdFALSE = 0 } BaseType_t;
|
2020-09-01 10:34:23 +00:00
|
|
|
|
|
|
|
typedef int32_t TickType_t;
|
2020-08-24 15:31:22 +00:00
|
|
|
|
|
|
|
#define tskIDLE_PRIORITY 0
|
|
|
|
|
2020-09-29 23:18:30 +00:00
|
|
|
TaskHandle_t xTaskCreateStatic(TaskFunction_t pxTaskCode,
|
|
|
|
const char* const pcName,
|
|
|
|
const uint32_t ulStackDepth,
|
|
|
|
void* const pvParameters,
|
|
|
|
UBaseType_t uxPriority,
|
|
|
|
StackType_t* const puxStackBuffer,
|
|
|
|
StaticTask_t* const pxTaskBuffer);
|
2020-08-24 15:31:22 +00:00
|
|
|
|
|
|
|
void vTaskDelete(TaskHandle_t xTask);
|
|
|
|
TaskHandle_t xTaskGetCurrentTaskHandle(void);
|
|
|
|
SemaphoreHandle_t xSemaphoreCreateMutexStatic(StaticSemaphore_t* pxMutexBuffer);
|
|
|
|
bool task_equal(TaskHandle_t a, TaskHandle_t b);
|
2020-09-01 10:34:23 +00:00
|
|
|
|
2020-09-29 23:18:30 +00:00
|
|
|
QueueHandle_t xQueueCreateStatic(UBaseType_t uxQueueLength,
|
|
|
|
UBaseType_t uxItemSize,
|
|
|
|
uint8_t* pucQueueStorageBuffer,
|
|
|
|
StaticQueue_t* pxQueueBuffer);
|
|
|
|
|
|
|
|
SemaphoreHandle_t xSemaphoreCreateCountingStatic(UBaseType_t uxMaxCount,
|
|
|
|
UBaseType_t uxInitialCount,
|
|
|
|
StaticSemaphore_t* pxSemaphoreBuffer);
|
2020-09-01 10:34:23 +00:00
|
|
|
BaseType_t xSemaphoreTake(SemaphoreHandle_t xSemaphore, TickType_t xTicksToWait);
|
|
|
|
BaseType_t xSemaphoreGive(SemaphoreHandle_t xSemaphore);
|
|
|
|
|
2020-09-29 23:18:30 +00:00
|
|
|
BaseType_t xQueueSend(QueueHandle_t xQueue, const void* pvItemToQueue, TickType_t xTicksToWait);
|
2020-09-01 10:34:23 +00:00
|
|
|
|
|
|
|
BaseType_t xQueueReceive(QueueHandle_t xQueue, void *pvBuffer, TickType_t xTicksToWait);
|
2020-09-16 21:12:00 +00:00
|
|
|
|
|
|
|
void* pvTaskGetThreadLocalStoragePointer(TaskHandle_t xTaskToQuery, BaseType_t xIndex);
|
|
|
|
void vTaskSetThreadLocalStoragePointer(TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue);
|
2020-10-08 14:37:19 +00:00
|
|
|
|
|
|
|
QueueHandle_t xQueueCreate(UBaseType_t uxQueueLength, UBaseType_t uxItemSize);
|
2020-10-13 08:22:43 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
const char *name; ///< name of the mutex
|
|
|
|
uint32_t attr_bits; ///< attribute bits
|
|
|
|
void *cb_mem; ///< memory for control block
|
|
|
|
uint32_t cb_size; ///< size of provided memory for control block
|
|
|
|
} osMutexAttr_t;
|
|
|
|
|
|
|
|
typedef SemaphoreHandle_t osMutexId_t;
|
|
|
|
|
|
|
|
osMutexId_t osMutexNew(const osMutexAttr_t *attr);
|
|
|
|
|
|
|
|
/// Status code values returned by CMSIS-RTOS functions.
|
|
|
|
typedef enum {
|
|
|
|
osOK = 0, ///< Operation completed successfully.
|
|
|
|
osError = -1, ///< Unspecified RTOS error: run-time error but no other error message fits.
|
|
|
|
osErrorTimeout = -2, ///< Operation not completed within the timeout period.
|
|
|
|
osErrorResource = -3, ///< Resource not available.
|
|
|
|
osErrorParameter = -4, ///< Parameter error.
|
|
|
|
osErrorNoMemory = -5, ///< System is out of memory: it was impossible to allocate or reserve memory for the operation.
|
|
|
|
osErrorISR = -6, ///< Not allowed in ISR context: the function cannot be called from interrupt service routines.
|
|
|
|
osStatusReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization.
|
|
|
|
} osStatus_t;
|
|
|
|
|
|
|
|
osStatus_t osMutexAcquire (osMutexId_t mutex_id, uint32_t timeout);
|
|
|
|
osStatus_t osMutexRelease (osMutexId_t mutex_id);
|
|
|
|
|
|
|
|
#define osWaitForever portMAX_DELAY
|