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