cmsis_os.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #pragma once
  2. #include "main.h"
  3. #include <stdbool.h>
  4. #include <pthread.h>
  5. void osDelay(uint32_t ms);
  6. // some FreeRTOS types
  7. typedef void (*TaskFunction_t)(void*);
  8. typedef size_t UBaseType_t;
  9. typedef uint32_t StackType_t;
  10. typedef uint32_t StaticTask_t;
  11. typedef pthread_t* TaskHandle_t;
  12. typedef enum {
  13. SemaphoreTypeMutex,
  14. SemaphoreTypeCounting,
  15. } SemaphoreType;
  16. typedef struct {
  17. SemaphoreType type;
  18. pthread_mutex_t mutex;
  19. uint8_t take_counter;
  20. uint8_t give_counter;
  21. } StaticSemaphore_t;
  22. typedef StaticSemaphore_t* SemaphoreHandle_t;
  23. typedef uint32_t StaticQueue_t;
  24. typedef StaticQueue_t* QueueHandle_t;
  25. #define portMAX_DELAY -1
  26. typedef enum { pdTRUE = 1, pdFALSE = 0 } BaseType_t;
  27. typedef int32_t TickType_t;
  28. #define tskIDLE_PRIORITY 0
  29. TaskHandle_t xTaskCreateStatic(TaskFunction_t pxTaskCode,
  30. const char* const pcName,
  31. const uint32_t ulStackDepth,
  32. void* const pvParameters,
  33. UBaseType_t uxPriority,
  34. StackType_t* const puxStackBuffer,
  35. StaticTask_t* const pxTaskBuffer);
  36. void vTaskDelete(TaskHandle_t xTask);
  37. TaskHandle_t xTaskGetCurrentTaskHandle(void);
  38. SemaphoreHandle_t xSemaphoreCreateMutexStatic(StaticSemaphore_t* pxMutexBuffer);
  39. bool task_equal(TaskHandle_t a, TaskHandle_t b);
  40. QueueHandle_t xQueueCreateStatic(UBaseType_t uxQueueLength,
  41. UBaseType_t uxItemSize,
  42. uint8_t* pucQueueStorageBuffer,
  43. StaticQueue_t* pxQueueBuffer);
  44. SemaphoreHandle_t xSemaphoreCreateCountingStatic(UBaseType_t uxMaxCount,
  45. UBaseType_t uxInitialCount,
  46. StaticSemaphore_t* pxSemaphoreBuffer);
  47. BaseType_t xSemaphoreTake(SemaphoreHandle_t xSemaphore, TickType_t xTicksToWait);
  48. BaseType_t xSemaphoreGive(SemaphoreHandle_t xSemaphore);
  49. BaseType_t xQueueSend(QueueHandle_t xQueue, const void* pvItemToQueue, TickType_t xTicksToWait);
  50. BaseType_t xQueueReceive(QueueHandle_t xQueue, void *pvBuffer, TickType_t xTicksToWait);
  51. void* pvTaskGetThreadLocalStoragePointer(TaskHandle_t xTaskToQuery, BaseType_t xIndex);
  52. void vTaskSetThreadLocalStoragePointer(TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue);
  53. QueueHandle_t xQueueCreate(UBaseType_t uxQueueLength, UBaseType_t uxItemSize);
  54. typedef struct {
  55. const char *name; ///< name of the mutex
  56. uint32_t attr_bits; ///< attribute bits
  57. void *cb_mem; ///< memory for control block
  58. uint32_t cb_size; ///< size of provided memory for control block
  59. } osMutexAttr_t;
  60. typedef SemaphoreHandle_t osMutexId_t;
  61. osMutexId_t osMutexNew(const osMutexAttr_t *attr);
  62. /// Status code values returned by CMSIS-RTOS functions.
  63. typedef enum {
  64. osOK = 0, ///< Operation completed successfully.
  65. osError = -1, ///< Unspecified RTOS error: run-time error but no other error message fits.
  66. osErrorTimeout = -2, ///< Operation not completed within the timeout period.
  67. osErrorResource = -3, ///< Resource not available.
  68. osErrorParameter = -4, ///< Parameter error.
  69. osErrorNoMemory = -5, ///< System is out of memory: it was impossible to allocate or reserve memory for the operation.
  70. osErrorISR = -6, ///< Not allowed in ISR context: the function cannot be called from interrupt service routines.
  71. osStatusReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization.
  72. } osStatus_t;
  73. osStatus_t osMutexAcquire (osMutexId_t mutex_id, uint32_t timeout);
  74. osStatus_t osMutexRelease (osMutexId_t mutex_id);
  75. osStatus_t osMutexDelete (osMutexId_t mutex_id);
  76. #define osWaitForever portMAX_DELAY