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  * Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22  *
23  * @author Oryx Embedded SARL (www.oryx-embedded.com)
24  * @version 1.9.0
25  **/
26 
27 #ifndef _OS_PORT_CMSIS_RTOS2_H
28 #define _OS_PORT_CMSIS_RTOS2_H
29 
30 //Dependencies
31 #include "cmsis_os2.h"
32 
33 #ifdef RTE_CMSIS_RTOS2_RTX5
34 #include "rtx_os.h"
35 #endif
36 
37 //Task priority (normal)
38 #ifndef OS_TASK_PRIORITY_NORMAL
39  #define OS_TASK_PRIORITY_NORMAL osPriorityNormal
40 #endif
41 
42 //Task priority (high)
43 #ifndef OS_TASK_PRIORITY_HIGH
44  #define OS_TASK_PRIORITY_HIGH osPriorityAboveNormal
45 #endif
46 
47 //Milliseconds to system ticks
48 #ifndef OS_MS_TO_SYSTICKS
49  #define OS_MS_TO_SYSTICKS(n) (n)
50 #endif
51 
52 //System ticks to milliseconds
53 #ifndef OS_SYSTICKS_TO_MS
54  #define OS_SYSTICKS_TO_MS(n) (n)
55 #endif
56 
57 //Enter interrupt service routine
58 #define osEnterIsr()
59 
60 //Leave interrupt service routine
61 #define osExitIsr(flag)
62 
63 //C++ guard
64 #ifdef __cplusplus
65  extern "C" {
66 #endif
67 
68 
69 /**
70  * @brief Task object
71  **/
72 
73 typedef void OsTask;
74 
75 
76 /**
77  * @brief Event object
78  **/
79 
80 typedef struct
81 {
82  osSemaphoreId_t id;
83 #if defined(os_CMSIS_RTX)
84  os_semaphore_t cb;
85 #endif
86 } OsEvent;
87 
88 
89 /**
90  * @brief Semaphore object
91  **/
92 
93 typedef struct
94 {
95  osSemaphoreId_t id;
96 #if defined(os_CMSIS_RTX)
97  os_semaphore_t cb;
98 #endif
99 } OsSemaphore;
100 
101 
102 /**
103  * @brief Mutex object
104  **/
105 
106 typedef struct
107 {
108  osMutexId_t id;
109 #if defined(os_CMSIS_RTX)
110  os_mutex_t cb;
111 #endif
112 } OsMutex;
113 
114 
115 /**
116  * @brief Task routine
117  **/
118 
119 typedef void (*OsTaskCode)(void *param);
120 
121 
122 //Kernel management
123 void osInitKernel(void);
124 void osStartKernel(void);
125 
126 //Task management
127 OsTask *osCreateTask(const char_t *name, OsTaskCode taskCode,
128  void *param, size_t stackSize, int_t priority);
129 
130 void osDeleteTask(OsTask *task);
131 void osDelayTask(systime_t delay);
132 void osSwitchTask(void);
133 void osSuspendAllTasks(void);
134 void osResumeAllTasks(void);
135 
136 //Event management
138 void osDeleteEvent(OsEvent *event);
139 void osSetEvent(OsEvent *event);
140 void osResetEvent(OsEvent *event);
141 bool_t osWaitForEvent(OsEvent *event, systime_t timeout);
143 
144 //Semaphore management
145 bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count);
146 void osDeleteSemaphore(OsSemaphore *semaphore);
147 bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout);
148 void osReleaseSemaphore(OsSemaphore *semaphore);
149 
150 //Mutex management
152 void osDeleteMutex(OsMutex *mutex);
153 void osAcquireMutex(OsMutex *mutex);
154 void osReleaseMutex(OsMutex *mutex);
155 
156 //System time
158 
159 //Memory management
160 void *osAllocMem(size_t size);
161 void osFreeMem(void *p);
162 
163 //C++ guard
164 #ifdef __cplusplus
165  }
166 #endif
167 
168 #endif
void osReleaseSemaphore(OsSemaphore *semaphore)
Release the specified semaphore object.
uint16_t priority
Definition: dns_common.h:219
uint32_t systime_t
Definition: compiler_port.h:44
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
char char_t
Definition: compiler_port.h:41
void osDeleteEvent(OsEvent *event)
Delete an event object.
osSemaphoreId_t id
void * osAllocMem(size_t size)
Allocate a memory block.
uint8_t p
Definition: ndp.h:295
void osInitKernel(void)
Kernel initialization.
bool_t osCreateMutex(OsMutex *mutex)
Create a mutex object.
void osFreeMem(void *p)
Release a previously allocated memory block.
binary_semaphore_t OsEvent
Event object.
void(* OsTaskCode)(void *param)
Task routine.
Event object.
void osResumeAllTasks(void)
Resume scheduler activity.
bool_t osWaitForEvent(OsEvent *event, systime_t timeout)
Wait until the specified event is in the signaled state.
systime_t osGetSystemTime(void)
Retrieve system time.
void osResetEvent(OsEvent *event)
Set the specified event object to the nonsignaled state.
osSemaphoreId_t id
Task object.
signed int int_t
Definition: compiler_port.h:42
void osDeleteTask(OsTask *task)
Delete a task.
char_t name[]
bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count)
Create a semaphore object.
void osSwitchTask(void)
Yield control to the next task.
mutex_t OsMutex
Mutex object.
void osDeleteSemaphore(OsSemaphore *semaphore)
Delete a semaphore object.
bool_t osSetEventFromIsr(OsEvent *event)
Set an event object to the signaled state from an interrupt service routine.
void OsTask
Task object.
void osSuspendAllTasks(void)
Suspend scheduler activity.
OsTask * osCreateTask(const char_t *name, OsTaskCode taskCode, void *param, size_t stackSize, int_t priority)
Create a new task.
osMutexId_t id
void osDelayTask(systime_t delay)
Delay routine.
unsigned int uint_t
Definition: compiler_port.h:43
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
semaphore_t OsSemaphore
Semaphore object.
Mutex object.
bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout)
Wait for the specified semaphore to be available.
void osStartKernel(void)
Start kernel.
void osDeleteMutex(OsMutex *mutex)
Delete a mutex object.
void osSetEvent(OsEvent *event)
Set the specified event object to the signaled state.
Semaphore object.
int bool_t
Definition: compiler_port.h:47
bool_t osCreateEvent(OsEvent *event)
Create an event object.