os_port_cmsis_rtos2.h
Go to the documentation of this file.
1 /**
2  * @file os_port_cmsis_rtos2.h
3  * @brief RTOS abstraction layer (CMSIS-RTOS 2 / RTX v5)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24  *
25  * @author Oryx Embedded SARL (www.oryx-embedded.com)
26  * @version 2.4.4
27  **/
28 
29 #ifndef _OS_PORT_CMSIS_RTOS2_H
30 #define _OS_PORT_CMSIS_RTOS2_H
31 
32 //Dependencies
33 #include "cmsis_os2.h"
34 
35 #ifdef RTE_CMSIS_RTOS2_RTX5
36  #include "rtx_os.h"
37 #endif
38 
39 #ifdef RTE_CMSIS_RTOS2_FreeRTOS
40  #include "freertos.h"
41 #endif
42 
43 //Invalid task identifier
44 #define OS_INVALID_TASK_ID NULL
45 //Self task identifier
46 #define OS_SELF_TASK_ID NULL
47 
48 //Task priority (normal)
49 #ifndef OS_TASK_PRIORITY_NORMAL
50  #define OS_TASK_PRIORITY_NORMAL osPriorityNormal
51 #endif
52 
53 //Task priority (high)
54 #ifndef OS_TASK_PRIORITY_HIGH
55  #define OS_TASK_PRIORITY_HIGH osPriorityAboveNormal
56 #endif
57 
58 //Milliseconds to system ticks
59 #ifndef OS_MS_TO_SYSTICKS
60  #define OS_MS_TO_SYSTICKS(n) (n)
61 #endif
62 
63 //System ticks to milliseconds
64 #ifndef OS_SYSTICKS_TO_MS
65  #define OS_SYSTICKS_TO_MS(n) (n)
66 #endif
67 
68 //Retrieve 64-bit system time (not implemented)
69 #ifndef osGetSystemTime64
70  #define osGetSystemTime64() osGetSystemTime()
71 #endif
72 
73 //Task prologue
74 #define osEnterTask()
75 //Task epilogue
76 #define osExitTask()
77 //Interrupt service routine prologue
78 #define osEnterIsr()
79 //Interrupt service routine epilogue
80 #define osExitIsr(flag)
81 
82 //C++ guard
83 #ifdef __cplusplus
84 extern "C" {
85 #endif
86 
87 
88 /**
89  * @brief System time
90  **/
91 
92 typedef uint32_t systime_t;
93 
94 
95 /**
96  * @brief Task identifier
97  **/
98 
99 typedef osThreadId_t OsTaskId;
100 
101 
102 /**
103  * @brief Task parameters
104  **/
105 
106 typedef struct
107 {
108 #if defined(os_CMSIS_RTX)
109  os_thread_t *cb;
110 #endif
111 #if defined(osRtxVersionKernel)
112  osRtxThread_t *cb;
113 #endif
114 #if defined(configSUPPORT_STATIC_ALLOCATION)
115  StaticTask_t *cb;
116 #endif
117  uint32_t *stack;
118  size_t stackSize;
121 
122 
123 /**
124  * @brief Event object
125  **/
126 
127 typedef struct
128 {
129  osEventFlagsId_t id;
130 #if defined(os_CMSIS_RTX)
131  os_event_flags_t cb;
132 #endif
133 #if defined(osRtxVersionKernel)
134  osRtxEventFlags_t cb;
135 #endif
136 } OsEvent;
137 
138 
139 /**
140  * @brief Semaphore object
141  **/
142 
143 typedef struct
144 {
145  osSemaphoreId_t id;
146 #if defined(os_CMSIS_RTX)
147  os_semaphore_t cb;
148 #endif
149 #if defined(osRtxVersionKernel)
150  osRtxSemaphore_t cb;
151 #endif
152 } OsSemaphore;
153 
154 
155 /**
156  * @brief Mutex object
157  **/
158 
159 typedef struct
160 {
161  osMutexId_t id;
162 #if defined(os_CMSIS_RTX)
163  os_mutex_t cb;
164 #endif
165 #if defined(osRtxVersionKernel)
166  osRtxMutex_t cb;
167 #endif
168 } OsMutex;
169 
170 
171 /**
172  * @brief Task routine
173  **/
174 
175 typedef void (*OsTaskCode)(void *arg);
176 
177 
178 //Default task parameters
180 
181 //Kernel management
182 void osInitKernel(void);
183 void osStartKernel(void);
184 
185 //Task management
186 OsTaskId osCreateTask(const char_t *name, OsTaskCode taskCode, void *arg,
187  const OsTaskParameters *params);
188 
189 void osDeleteTask(OsTaskId taskId);
190 void osDelayTask(systime_t delay);
191 void osSwitchTask(void);
192 void osSuspendAllTasks(void);
193 void osResumeAllTasks(void);
194 
195 //Event management
197 void osDeleteEvent(OsEvent *event);
198 void osSetEvent(OsEvent *event);
199 void osResetEvent(OsEvent *event);
200 bool_t osWaitForEvent(OsEvent *event, systime_t timeout);
202 
203 //Semaphore management
204 bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count);
205 void osDeleteSemaphore(OsSemaphore *semaphore);
206 bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout);
207 void osReleaseSemaphore(OsSemaphore *semaphore);
208 
209 //Mutex management
211 void osDeleteMutex(OsMutex *mutex);
212 void osAcquireMutex(OsMutex *mutex);
213 void osReleaseMutex(OsMutex *mutex);
214 
215 //System time
217 
218 //Memory management
219 void *osAllocMem(size_t size);
220 void osFreeMem(void *p);
221 
222 //C++ guard
223 #ifdef __cplusplus
224 }
225 #endif
226 
227 #endif
int bool_t
Definition: compiler_port.h:53
osEventFlagsId_t id
void osDeleteMutex(OsMutex *mutex)
Delete a mutex object.
uint8_t p
Definition: ndp.h:300
void osDelayTask(systime_t delay)
Delay routine.
void osDeleteTask(OsTaskId taskId)
Delete a task.
Event object.
void osDeleteSemaphore(OsSemaphore *semaphore)
Delete a semaphore object.
void(* OsTaskCode)(void *arg)
Task routine.
void osSuspendAllTasks(void)
Suspend scheduler activity.
osMutexId_t id
char_t name[]
bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count)
Create a semaphore object.
osSemaphoreId_t id
void * osAllocMem(size_t size)
Allocate a memory block.
Semaphore object.
void osStartKernel(void)
Start kernel.
void osDeleteEvent(OsEvent *event)
Delete an event object.
bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout)
Wait for the specified semaphore to be available.
mutex_t OsMutex
Mutex object.
void osInitKernel(void)
Kernel initialization.
binary_semaphore_t OsEvent
Event object.
uint32_t systime_t
System time.
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
const OsTaskParameters OS_TASK_DEFAULT_PARAMS
osThreadId_t OsTaskId
Task identifier.
void osReleaseSemaphore(OsSemaphore *semaphore)
Release the specified semaphore object.
bool_t osCreateEvent(OsEvent *event)
Create an event object.
Task parameters.
void osSetEvent(OsEvent *event)
Set the specified event object to the signaled state.
void osFreeMem(void *p)
Release a previously allocated memory block.
Mutex object.
uint32_t systime_t
System time.
char char_t
Definition: compiler_port.h:48
bool_t osCreateMutex(OsMutex *mutex)
Create a mutex object.
OsTaskId osCreateTask(const char_t *name, OsTaskCode taskCode, void *arg, const OsTaskParameters *params)
Create a task.
thread_t * OsTaskId
Task identifier.
void osSwitchTask(void)
Yield control to the next task.
unsigned int uint_t
Definition: compiler_port.h:50
uint16_t priority
Definition: dns_common.h:265
systime_t osGetSystemTime(void)
Retrieve system time.
bool_t osWaitForEvent(OsEvent *event, systime_t timeout)
Wait until the specified event is in the signaled state.
void osResetEvent(OsEvent *event)
Set the specified event object to the nonsignaled state.
bool_t osSetEventFromIsr(OsEvent *event)
Set an event object to the signaled state from an interrupt service routine.
void osResumeAllTasks(void)
Resume scheduler activity.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
semaphore_t OsSemaphore
Semaphore object.