cmsis_os.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. QueueHandle_t xQueueCreateStatic(UBaseType_t uxQueueLength,
  40. UBaseType_t uxItemSize,
  41. uint8_t* pucQueueStorageBuffer,
  42. StaticQueue_t* pxQueueBuffer);
  43. SemaphoreHandle_t xSemaphoreCreateCountingStatic(UBaseType_t uxMaxCount,
  44. UBaseType_t uxInitialCount,
  45. StaticSemaphore_t* pxSemaphoreBuffer);
  46. BaseType_t xSemaphoreTake(SemaphoreHandle_t xSemaphore, TickType_t xTicksToWait);
  47. BaseType_t xSemaphoreGive(SemaphoreHandle_t xSemaphore);
  48. BaseType_t xQueueSend(QueueHandle_t xQueue, const void* pvItemToQueue, TickType_t xTicksToWait);
  49. BaseType_t xQueueReceive(QueueHandle_t xQueue, void *pvBuffer, TickType_t xTicksToWait);
  50. void* pvTaskGetThreadLocalStoragePointer(TaskHandle_t xTaskToQuery, BaseType_t xIndex);
  51. void vTaskSetThreadLocalStoragePointer(TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue);
  52. QueueHandle_t xQueueCreate(UBaseType_t uxQueueLength, UBaseType_t uxItemSize);
  53. typedef struct {
  54. const char *name; ///< name of the mutex
  55. uint32_t attr_bits; ///< attribute bits
  56. void *cb_mem; ///< memory for control block
  57. uint32_t cb_size; ///< size of provided memory for control block
  58. } osMutexAttr_t;
  59. typedef SemaphoreHandle_t osMutexId_t;
  60. osMutexId_t osMutexNew(const osMutexAttr_t *attr);
  61. /// Status code values returned by CMSIS-RTOS functions.
  62. typedef enum {
  63. osOK = 0, ///< Operation completed successfully.
  64. osError = -1, ///< Unspecified RTOS error: run-time error but no other error message fits.
  65. osErrorTimeout = -2, ///< Operation not completed within the timeout period.
  66. osErrorResource = -3, ///< Resource not available.
  67. osErrorParameter = -4, ///< Parameter error.
  68. osErrorNoMemory = -5, ///< System is out of memory: it was impossible to allocate or reserve memory for the operation.
  69. osErrorISR = -6, ///< Not allowed in ISR context: the function cannot be called from interrupt service routines.
  70. osStatusReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization.
  71. } osStatus_t;
  72. osStatus_t osMutexAcquire (osMutexId_t mutex_id, uint32_t timeout);
  73. osStatus_t osMutexRelease (osMutexId_t mutex_id);
  74. osStatus_t osMutexDelete (osMutexId_t mutex_id);
  75. #define osWaitForever portMAX_DELAY
  76. typedef StaticSemaphore_t osSemaphoreDef_t;
  77. typedef SemaphoreHandle_t osSemaphoreId_t;
  78. typedef struct {} osSemaphoreAttr_t;
  79. osSemaphoreId_t osSemaphoreNew(uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr);
  80. osStatus_t osSemaphoreAcquire(osSemaphoreId_t semaphore_id, uint32_t timeout);
  81. osStatus_t osSemaphoreRelease(osSemaphoreId_t semaphore_id);
  82. osStatus_t osSemaphoreDelete(osSemaphoreId_t semaphore_id);