os_port_cmsis_rtos.h
Go to the documentation of this file.
1 /**
2  * @file os_port_cmsis_rtos.h
3  * @brief RTOS abstraction layer (CMSIS-RTOS)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2022 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.2.0
27  **/
28 
29 #ifndef _OS_PORT_CMSIS_RTOS_H
30 #define _OS_PORT_CMSIS_RTOS_H
31 
32 //Dependencies
33 #include "cmsis_os.h"
34 
35 //Use dynamic memory allocation for tasks
36 #define OS_STATIC_TASK_SUPPORT DISABLED
37 
38 //Invalid task identifier
39 #define OS_INVALID_TASK_ID NULL
40 //Self task identifier
41 #define OS_SELF_TASK_ID NULL
42 
43 //Task priority (normal)
44 #ifndef OS_TASK_PRIORITY_NORMAL
45  #define OS_TASK_PRIORITY_NORMAL osPriorityNormal
46 #endif
47 
48 //Task priority (high)
49 #ifndef OS_TASK_PRIORITY_HIGH
50  #define OS_TASK_PRIORITY_HIGH osPriorityAboveNormal
51 #endif
52 
53 //Milliseconds to system ticks
54 #ifndef OS_MS_TO_SYSTICKS
55  #define OS_MS_TO_SYSTICKS(n) (n)
56 #endif
57 
58 //System ticks to milliseconds
59 #ifndef OS_SYSTICKS_TO_MS
60  #define OS_SYSTICKS_TO_MS(n) (n)
61 #endif
62 
63 //Retrieve 64-bit system time (not implemented)
64 #ifndef osGetSystemTime64
65  #define osGetSystemTime64() osGetSystemTime()
66 #endif
67 
68 //Task prologue
69 #define osEnterTask()
70 //Task epilogue
71 #define osExitTask()
72 //Interrupt service routine prologue
73 #define osEnterIsr()
74 //Interrupt service routine epilogue
75 #define osExitIsr(flag)
76 
77 //C++ guard
78 #ifdef __cplusplus
79 extern "C" {
80 #endif
81 
82 
83 /**
84  * @brief System time
85  **/
86 
87 typedef uint32_t systime_t;
88 
89 
90 /**
91  * @brief Task identifier
92  **/
93 
94 typedef osThreadId OsTaskId;
95 
96 
97 /**
98  * @brief Event object
99  **/
100 
101 typedef struct
102 {
103  osSemaphoreId id;
104 #if defined(osCMSIS_RTX)
105  uint32_t cb[2];
106 #endif
107 } OsEvent;
108 
109 
110 /**
111  * @brief Semaphore object
112  **/
113 
114 typedef struct
115 {
116  osSemaphoreId id;
117 #if defined(osCMSIS_RTX)
118  uint32_t cb[2];
119 #endif
120 } OsSemaphore;
121 
122 
123 /**
124  * @brief Mutex object
125  **/
126 
127 typedef struct
128 {
129  osMutexId id;
130 #if defined(osCMSIS_RTX)
131  uint32_t cb[4];
132 #endif
133 } OsMutex;
134 
135 
136 /**
137  * @brief Task routine
138  **/
139 
140 typedef void (*OsTaskCode)(void *param);
141 
142 
143 //Kernel management
144 void osInitKernel(void);
145 void osStartKernel(void);
146 
147 //Task management
148 OsTaskId osCreateTask(const char_t *name, OsTaskCode taskCode,
149  void *param, size_t stackSize, int_t priority);
150 
151 void osDeleteTask(OsTaskId taskId);
152 void osDelayTask(systime_t delay);
153 void osSwitchTask(void);
154 void osSuspendAllTasks(void);
155 void osResumeAllTasks(void);
156 
157 //Event management
159 void osDeleteEvent(OsEvent *event);
160 void osSetEvent(OsEvent *event);
161 void osResetEvent(OsEvent *event);
162 bool_t osWaitForEvent(OsEvent *event, systime_t timeout);
164 
165 //Semaphore management
166 bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count);
167 void osDeleteSemaphore(OsSemaphore *semaphore);
168 bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout);
169 void osReleaseSemaphore(OsSemaphore *semaphore);
170 
171 //Mutex management
173 void osDeleteMutex(OsMutex *mutex);
174 void osAcquireMutex(OsMutex *mutex);
175 void osReleaseMutex(OsMutex *mutex);
176 
177 //System time
179 
180 //Memory management
181 void *osAllocMem(size_t size);
182 void osFreeMem(void *p);
183 
184 //C++ guard
185 #ifdef __cplusplus
186 }
187 #endif
188 
189 #endif
uint32_t systime_t
System time.
void osFreeMem(void *p)
Release a previously allocated memory block.
int bool_t
Definition: compiler_port.h:48
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
void * osAllocMem(size_t size)
Allocate a memory block.
void osDeleteTask(OsTaskId taskId)
Delete a task.
signed int int_t
Definition: compiler_port.h:44
void osDeleteSemaphore(OsSemaphore *semaphore)
Delete a semaphore object.
void(* OsTaskCode)(void *param)
Task routine.
uint8_t p
Definition: ndp.h:298
bool_t osCreateEvent(OsEvent *event)
Create an event object.
Event object.
bool_t osCreateMutex(OsMutex *mutex)
Create a mutex object.
char_t name[]
osSemaphoreId id
Semaphore object.
void osSetEvent(OsEvent *event)
Set the specified event object to the signaled state.
void osStartKernel(void)
Start kernel.
systime_t osGetSystemTime(void)
Retrieve system time.
mutex_t OsMutex
Mutex object.
binary_semaphore_t OsEvent
Event object.
bool_t osSetEventFromIsr(OsEvent *event)
Set an event object to the signaled state from an interrupt service routine.
void osDelayTask(systime_t delay)
Delay routine.
osSemaphoreId id
osMutexId id
void osDeleteEvent(OsEvent *event)
Delete an event object.
void osResumeAllTasks(void)
Resume scheduler activity.
void osSuspendAllTasks(void)
Suspend scheduler activity.
Mutex object.
uint32_t systime_t
System time.
char char_t
Definition: compiler_port.h:43
void osSwitchTask(void)
Yield control to the next task.
void osResetEvent(OsEvent *event)
Set the specified event object to the nonsignaled state.
bool_t osWaitForEvent(OsEvent *event, systime_t timeout)
Wait until the specified event is in the signaled state.
bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout)
Wait for the specified semaphore to be available.
void osDeleteMutex(OsMutex *mutex)
Delete a mutex object.
thread_t * OsTaskId
Task identifier.
void osReleaseSemaphore(OsSemaphore *semaphore)
Release the specified semaphore object.
osThreadId OsTaskId
Task identifier.
unsigned int uint_t
Definition: compiler_port.h:45
uint16_t priority
Definition: dns_common.h:249
OsTaskId osCreateTask(const char_t *name, OsTaskCode taskCode, void *param, size_t stackSize, int_t priority)
Create a task.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count)
Create a semaphore object.
void osInitKernel(void)
Kernel initialization.
semaphore_t OsSemaphore
Semaphore object.