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-2019 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 1.9.6
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 //Task priority (normal)
40 #ifndef OS_TASK_PRIORITY_NORMAL
41  #define OS_TASK_PRIORITY_NORMAL osPriorityNormal
42 #endif
43 
44 //Task priority (high)
45 #ifndef OS_TASK_PRIORITY_HIGH
46  #define OS_TASK_PRIORITY_HIGH osPriorityAboveNormal
47 #endif
48 
49 //Milliseconds to system ticks
50 #ifndef OS_MS_TO_SYSTICKS
51  #define OS_MS_TO_SYSTICKS(n) (n)
52 #endif
53 
54 //System ticks to milliseconds
55 #ifndef OS_SYSTICKS_TO_MS
56  #define OS_SYSTICKS_TO_MS(n) (n)
57 #endif
58 
59 //Task prologue
60 #define osEnterTask()
61 //Interrupt service routine prologue
62 #define osEnterIsr()
63 //Interrupt service routine epilogue
64 #define osExitIsr(flag)
65 
66 //C++ guard
67 #ifdef __cplusplus
68 extern "C" {
69 #endif
70 
71 
72 /**
73  * @brief Task object
74  **/
75 
76 typedef void OsTask;
77 
78 
79 /**
80  * @brief Event object
81  **/
82 
83 typedef struct
84 {
85  osEventFlagsId_t id;
86 #if defined(os_CMSIS_RTX)
87  os_event_flags_t cb;
88 #endif
89 #if defined(osRtxVersionKernel)
90  osRtxEventFlags_t cb;
91 #endif
92 } OsEvent;
93 
94 
95 /**
96  * @brief Semaphore object
97  **/
98 
99 typedef struct
100 {
101  osSemaphoreId_t id;
102 #if defined(os_CMSIS_RTX)
103  os_semaphore_t cb;
104 #endif
105 #if defined(osRtxVersionKernel)
106  osRtxSemaphore_t cb;
107 #endif
108 } OsSemaphore;
109 
110 
111 /**
112  * @brief Mutex object
113  **/
114 
115 typedef struct
116 {
117  osMutexId_t id;
118 #if defined(os_CMSIS_RTX)
119  os_mutex_t cb;
120 #endif
121 #if defined(osRtxVersionKernel)
122  osRtxMutex_t cb;
123 #endif
124 } OsMutex;
125 
126 
127 /**
128  * @brief Task routine
129  **/
130 
131 typedef void (*OsTaskCode)(void *param);
132 
133 
134 //Kernel management
135 void osInitKernel(void);
136 void osStartKernel(void);
137 
138 //Task management
139 OsTask *osCreateTask(const char_t *name, OsTaskCode taskCode,
140  void *param, size_t stackSize, int_t priority);
141 
142 void osDeleteTask(OsTask *task);
143 void osDelayTask(systime_t delay);
144 void osSwitchTask(void);
145 void osSuspendAllTasks(void);
146 void osResumeAllTasks(void);
147 
148 //Event management
150 void osDeleteEvent(OsEvent *event);
151 void osSetEvent(OsEvent *event);
152 void osResetEvent(OsEvent *event);
153 bool_t osWaitForEvent(OsEvent *event, systime_t timeout);
155 
156 //Semaphore management
157 bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count);
158 void osDeleteSemaphore(OsSemaphore *semaphore);
159 bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout);
160 void osReleaseSemaphore(OsSemaphore *semaphore);
161 
162 //Mutex management
164 void osDeleteMutex(OsMutex *mutex);
165 void osAcquireMutex(OsMutex *mutex);
166 void osReleaseMutex(OsMutex *mutex);
167 
168 //System time
170 
171 //Memory management
172 void *osAllocMem(size_t size);
173 void osFreeMem(void *p);
174 
175 //C++ guard
176 #ifdef __cplusplus
177 }
178 #endif
179 
180 #endif
int bool_t
Definition: compiler_port.h:49
signed int int_t
Definition: compiler_port.h:44
osEventFlagsId_t id
void osDeleteMutex(OsMutex *mutex)
Delete a mutex object.
uint8_t p
Definition: ndp.h:298
void osDelayTask(systime_t delay)
Delay routine.
Event object.
void osDeleteSemaphore(OsSemaphore *semaphore)
Delete a semaphore object.
OsTask * osCreateTask(const char_t *name, OsTaskCode taskCode, void *param, size_t stackSize, int_t priority)
Create a new task.
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.
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
Task object.
void osReleaseSemaphore(OsSemaphore *semaphore)
Release the specified semaphore object.
bool_t osCreateEvent(OsEvent *event)
Create an event object.
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.
char char_t
Definition: compiler_port.h:43
void(* OsTaskCode)(void *param)
Task routine.
bool_t osCreateMutex(OsMutex *mutex)
Create a mutex object.
void osDeleteTask(OsTask *task)
Delete a task.
void osSwitchTask(void)
Yield control to the next task.
unsigned int uint_t
Definition: compiler_port.h:45
void OsTask
Task object.
uint16_t priority
Definition: dns_common.h:221
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.
uint32_t systime_t
Definition: compiler_port.h:46
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.