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  * 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_RTOS_H
28 #define _OS_PORT_CMSIS_RTOS_H
29 
30 //Dependencies
31 #include "cmsis_os.h"
32 
33 //Task priority (normal)
34 #ifndef OS_TASK_PRIORITY_NORMAL
35  #define OS_TASK_PRIORITY_NORMAL osPriorityNormal
36 #endif
37 
38 //Task priority (high)
39 #ifndef OS_TASK_PRIORITY_HIGH
40  #define OS_TASK_PRIORITY_HIGH osPriorityAboveNormal
41 #endif
42 
43 //Milliseconds to system ticks
44 #ifndef OS_MS_TO_SYSTICKS
45  #define OS_MS_TO_SYSTICKS(n) (n)
46 #endif
47 
48 //System ticks to milliseconds
49 #ifndef OS_SYSTICKS_TO_MS
50  #define OS_SYSTICKS_TO_MS(n) (n)
51 #endif
52 
53 //Enter interrupt service routine
54 #define osEnterIsr()
55 
56 //Leave interrupt service routine
57 #define osExitIsr(flag)
58 
59 //C++ guard
60 #ifdef __cplusplus
61  extern "C" {
62 #endif
63 
64 
65 /**
66  * @brief Task object
67  **/
68 
69 typedef void OsTask;
70 
71 
72 /**
73  * @brief Event object
74  **/
75 
76 typedef struct
77 {
78  osSemaphoreId id;
79 #if defined(osCMSIS_RTX)
80  uint32_t cb[2];
81 #endif
82 } OsEvent;
83 
84 
85 /**
86  * @brief Semaphore object
87  **/
88 
89 typedef struct
90 {
91  osSemaphoreId id;
92 #if defined(osCMSIS_RTX)
93  uint32_t cb[2];
94 #endif
95 } OsSemaphore;
96 
97 
98 /**
99  * @brief Mutex object
100  **/
101 
102 typedef struct
103 {
104  osMutexId id;
105 #if defined(osCMSIS_RTX)
106  uint32_t cb[4];
107 #endif
108 } OsMutex;
109 
110 
111 /**
112  * @brief Task routine
113  **/
114 
115 typedef void (*OsTaskCode)(void *param);
116 
117 
118 //Kernel management
119 void osInitKernel(void);
120 void osStartKernel(void);
121 
122 //Task management
123 OsTask *osCreateTask(const char_t *name, OsTaskCode taskCode,
124  void *param, size_t stackSize, int_t priority);
125 
126 void osDeleteTask(OsTask *task);
127 void osDelayTask(systime_t delay);
128 void osSwitchTask(void);
129 void osSuspendAllTasks(void);
130 void osResumeAllTasks(void);
131 
132 //Event management
134 void osDeleteEvent(OsEvent *event);
135 void osSetEvent(OsEvent *event);
136 void osResetEvent(OsEvent *event);
137 bool_t osWaitForEvent(OsEvent *event, systime_t timeout);
139 
140 //Semaphore management
141 bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count);
142 void osDeleteSemaphore(OsSemaphore *semaphore);
143 bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout);
144 void osReleaseSemaphore(OsSemaphore *semaphore);
145 
146 //Mutex management
148 void osDeleteMutex(OsMutex *mutex);
149 void osAcquireMutex(OsMutex *mutex);
150 void osReleaseMutex(OsMutex *mutex);
151 
152 //System time
154 
155 //Memory management
156 void *osAllocMem(size_t size);
157 void osFreeMem(void *p);
158 
159 //C++ guard
160 #ifdef __cplusplus
161  }
162 #endif
163 
164 #endif
void osSuspendAllTasks(void)
Suspend scheduler activity.
uint16_t priority
Definition: dns_common.h:219
uint32_t systime_t
Definition: compiler_port.h:44
char char_t
Definition: compiler_port.h:41
bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout)
Wait for the specified semaphore to be available.
void osDeleteTask(OsTask *task)
Delete a task.
bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count)
Create a semaphore object.
void * osAllocMem(size_t size)
Allocate a memory block.
uint8_t p
Definition: ndp.h:295
void osDeleteEvent(OsEvent *event)
Delete an event object.
binary_semaphore_t OsEvent
Event object.
osSemaphoreId id
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
void osReleaseSemaphore(OsSemaphore *semaphore)
Release the specified semaphore object.
Event object.
void(* OsTaskCode)(void *param)
Task routine.
void osStartKernel(void)
Start kernel.
void osSetEvent(OsEvent *event)
Set the specified event object to the signaled state.
void osDelayTask(systime_t delay)
Delay routine.
Task object.
signed int int_t
Definition: compiler_port.h:42
void osResetEvent(OsEvent *event)
Set the specified event object to the nonsignaled state.
char_t name[]
void OsTask
Task object.
OsTask * osCreateTask(const char_t *name, OsTaskCode taskCode, void *param, size_t stackSize, int_t priority)
Create a new task.
systime_t osGetSystemTime(void)
Retrieve system time.
void osInitKernel(void)
Kernel initialization.
mutex_t OsMutex
Mutex object.
void osFreeMem(void *p)
Release a previously allocated memory block.
void osResumeAllTasks(void)
Resume scheduler activity.
void osDeleteMutex(OsMutex *mutex)
Delete a mutex object.
void osDeleteSemaphore(OsSemaphore *semaphore)
Delete a semaphore object.
unsigned int uint_t
Definition: compiler_port.h:43
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
bool_t osCreateEvent(OsEvent *event)
Create an event object.
semaphore_t OsSemaphore
Semaphore object.
Mutex object.
bool_t osWaitForEvent(OsEvent *event, systime_t timeout)
Wait until the specified event is in the signaled state.
bool_t osSetEventFromIsr(OsEvent *event)
Set an event object to the signaled state from an interrupt service routine.
osSemaphoreId id
void osSwitchTask(void)
Yield control to the next task.
bool_t osCreateMutex(OsMutex *mutex)
Create a mutex object.
Semaphore object.
int bool_t
Definition: compiler_port.h:47
osMutexId id