os_port_safertos.h
Go to the documentation of this file.
1 /**
2  * @file os_port_safertos.h
3  * @brief RTOS abstraction layer (SafeRTOS)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 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.4.4
27  **/
28 
29 #ifndef _OS_PORT_SAFERTOS_H
30 #define _OS_PORT_SAFERTOS_H
31 
32 //Dependencies
33 #include "SafeRTOS_API.h"
34 
35 //Invalid task identifier
36 #define OS_INVALID_TASK_ID NULL
37 //Self task identifier
38 #define OS_SELF_TASK_ID NULL
39 
40 //Task priority (normal)
41 #ifndef OS_TASK_PRIORITY_NORMAL
42  #define OS_TASK_PRIORITY_NORMAL (taskIDLE_PRIORITY + 1)
43 #endif
44 
45 //Task priority (high)
46 #ifndef OS_TASK_PRIORITY_HIGH
47  #define OS_TASK_PRIORITY_HIGH (taskIDLE_PRIORITY + 2)
48 #endif
49 
50 //Milliseconds to system ticks
51 #ifndef OS_MS_TO_SYSTICKS
52  #define OS_MS_TO_SYSTICKS(n) (n)
53 #endif
54 
55 //System ticks to milliseconds
56 #ifndef OS_SYSTICKS_TO_MS
57  #define OS_SYSTICKS_TO_MS(n) (n)
58 #endif
59 
60 //Retrieve 64-bit system time (not implemented)
61 #ifndef osGetSystemTime64
62  #define osGetSystemTime64() osGetSystemTime()
63 #endif
64 
65 //Task prologue
66 #ifndef osEnterTask
67  #define osEnterTask()
68 #endif
69 
70 //Interrupt service routine prologue
71 #if defined(portENTER_SWITCHING_ISR)
72  #define osEnterIsr() portENTER_SWITCHING_ISR()
73 #else
74  #define osEnterIsr()
75 #endif
76 
77 //Interrupt service routine epilogue
78 #if defined(__XTENSA__)
79  #define osExitIsr(flag) if(flag) portYIELD_FROM_ISR()
80 #elif defined(portEXIT_SWITCHING_ISR)
81  #define osExitIsr(flag) portEXIT_SWITCHING_ISR()
82 #elif defined(portEND_SWITCHING_ISR)
83  #define osExitIsr(flag) portEND_SWITCHING_ISR(flag)
84 #elif defined(portYIELD_FROM_ISR)
85  #define osExitIsr(flag) portYIELD_FROM_ISR(flag)
86 #else
87  #define osExitIsr(flag)
88 #endif
89 
90 //Static object allocation
91 #ifndef configSUPPORT_STATIC_ALLOCATION
92  #define configSUPPORT_STATIC_ALLOCATION 0
93 #endif
94 
95 //C++ guard
96 #ifdef __cplusplus
97 extern "C" {
98 #endif
99 
100 
101 /**
102  * @brief System time
103  **/
104 
105 typedef uint32_t systime_t;
106 
107 
108 /**
109  * @brief Task identifier
110  **/
111 
112 typedef portTaskHandleType OsTaskId;
113 
114 
115 /**
116  * @brief Task parameters
117  **/
118 
119 typedef struct
120 {
121  xTCB *tcb;
122  portInt8Type *stack;
123  portUInt32Type stackSize;
124  portUnsignedBaseType priority;
125 #ifdef OS_TASK_PRIVATE_PARAMS
126  OS_TASK_PRIVATE_PARAMS
127 #endif
129 
130 
131 /**
132  * @brief Event object
133  **/
134 
135 typedef struct
136 {
137  xSemaphoreHandle handle;
138  portInt8Type buffer[portQUEUE_OVERHEAD_BYTES * 2];
139 } OsEvent;
140 
141 
142 /**
143  * @brief Semaphore object
144  **/
145 
146 typedef struct
147 {
148  xSemaphoreHandle handle;
149  portInt8Type buffer[portQUEUE_OVERHEAD_BYTES * 2];
150 } OsSemaphore;
151 
152 
153 /**
154  * @brief Mutex object
155  **/
156 
157 typedef struct
158 {
159  xSemaphoreHandle handle;
160  portInt8Type buffer[portQUEUE_OVERHEAD_BYTES * 2];
161 } OsMutex;
162 
163 
164 /**
165  * @brief Task routine
166  **/
167 
168 typedef void (*OsTaskCode)(void *arg);
169 
170 
171 //Default task parameters
173 
174 //Kernel management
175 void osInitKernel(void);
176 void osStartKernel(void);
177 
178 //Task management
179 OsTaskId osCreateTask(const char_t *name, OsTaskCode taskCode, void *arg,
180  const OsTaskParameters *params);
181 
182 void osDeleteTask(OsTaskId taskId);
183 void osDelayTask(systime_t delay);
184 void osSwitchTask(void);
185 void osSuspendAllTasks(void);
186 void osResumeAllTasks(void);
187 
188 //Event management
190 void osDeleteEvent(OsEvent *event);
191 void osSetEvent(OsEvent *event);
192 void osResetEvent(OsEvent *event);
193 bool_t osWaitForEvent(OsEvent *event, systime_t timeout);
195 
196 //Semaphore management
197 bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count);
198 void osDeleteSemaphore(OsSemaphore *semaphore);
199 bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout);
200 void osReleaseSemaphore(OsSemaphore *semaphore);
201 
202 //Mutex management
204 void osDeleteMutex(OsMutex *mutex);
205 void osAcquireMutex(OsMutex *mutex);
206 void osReleaseMutex(OsMutex *mutex);
207 
208 //System time
210 
211 //Memory management
212 void *osAllocMem(size_t size);
213 void osFreeMem(void *p);
214 
215 //C++ guard
216 #ifdef __cplusplus
217 }
218 #endif
219 
220 #endif
void osDelayTask(systime_t delay)
Delay routine.
void osStartKernel(void)
Start kernel.
void osDeleteTask(OsTaskId taskId)
Delete a task.
void osReleaseSemaphore(OsSemaphore *semaphore)
Release the specified semaphore object.
int bool_t
Definition: compiler_port.h:53
uint8_t p
Definition: ndp.h:300
Event object.
void osResumeAllTasks(void)
Resume scheduler activity.
bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout)
Wait for the specified semaphore to be available.
void osResetEvent(OsEvent *event)
Set the specified event object to the nonsignaled state.
char_t name[]
bool_t osWaitForEvent(OsEvent *event, systime_t timeout)
Wait until the specified event is in the signaled state.
void * osAllocMem(size_t size)
Allocate a memory block.
bool_t osCreateMutex(OsMutex *mutex)
Create a mutex object.
Semaphore object.
bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count)
Create a semaphore object.
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
OsTaskId osCreateTask(const char_t *name, OsTaskCode taskCode, void *arg, const OsTaskParameters *params)
Create a task.
mutex_t OsMutex
Mutex object.
void(* OsTaskCode)(void *arg)
Task routine.
void osDeleteSemaphore(OsSemaphore *semaphore)
Delete a semaphore object.
void osSwitchTask(void)
Yield control to the next task.
binary_semaphore_t OsEvent
Event object.
void osDeleteMutex(OsMutex *mutex)
Delete a mutex object.
xSemaphoreHandle handle
bool_t osCreateEvent(OsEvent *event)
Create an event object.
void osDeleteEvent(OsEvent *event)
Delete an event object.
bool_t osSetEventFromIsr(OsEvent *event)
Set an event object to the signaled state from an interrupt service routine.
Task parameters.
portTaskHandleType OsTaskId
Task identifier.
const OsTaskParameters OS_TASK_DEFAULT_PARAMS
void osInitKernel(void)
Kernel initialization.
Mutex object.
uint32_t systime_t
System time.
void osSetEvent(OsEvent *event)
Set the specified event object to the signaled state.
char char_t
Definition: compiler_port.h:48
void osFreeMem(void *p)
Release a previously allocated memory block.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
xSemaphoreHandle handle
portUInt32Type stackSize
portUnsignedBaseType priority
thread_t * OsTaskId
Task identifier.
void osSuspendAllTasks(void)
Suspend scheduler activity.
portInt8Type * stack
unsigned int uint_t
Definition: compiler_port.h:50
uint32_t systime_t
System time.
xSemaphoreHandle handle
systime_t osGetSystemTime(void)
Retrieve system time.
semaphore_t OsSemaphore
Semaphore object.