os_port_freertos.h
Go to the documentation of this file.
1 /**
2  * @file os_port_freertos.h
3  * @brief RTOS abstraction layer (FreeRTOS)
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_FREERTOS_H
30 #define _OS_PORT_FREERTOS_H
31 
32 //Dependencies
33 #ifdef IDF_VER
34  #include "freertos/FreeRTOS.h"
35  #include "freertos/task.h"
36  #include "freertos/semphr.h"
37 #else
38  #include "FreeRTOS.h"
39  #include "task.h"
40  #include "semphr.h"
41 #endif
42 
43 //Task priority (normal)
44 #ifndef OS_TASK_PRIORITY_NORMAL
45  #define OS_TASK_PRIORITY_NORMAL (tskIDLE_PRIORITY + 1)
46 #endif
47 
48 //Task priority (high)
49 #ifndef OS_TASK_PRIORITY_HIGH
50  #define OS_TASK_PRIORITY_HIGH (tskIDLE_PRIORITY + 2)
51 #endif
52 
53 //Milliseconds to system ticks
54 #ifndef OS_MS_TO_SYSTICKS
55  #define OS_MS_TO_SYSTICKS(n) (n)
56 #endif
57 
58 //System ticks to milliseconds
59 #ifndef OS_SYSTICKS_TO_MS
60  #define OS_SYSTICKS_TO_MS(n) (n)
61 #endif
62 
63 //Task prologue
64 #ifndef osEnterTask
65  #define osEnterTask()
66 #endif
67 
68 //Interrupt service routine prologue
69 #if defined(portENTER_SWITCHING_ISR)
70  #define osEnterIsr() portENTER_SWITCHING_ISR()
71 #else
72  #define osEnterIsr()
73 #endif
74 
75 //Interrupt service routine epilogue
76 #if defined(__XTENSA__)
77  #define osExitIsr(flag) if(flag) portYIELD_FROM_ISR()
78 #elif defined(portEXIT_SWITCHING_ISR)
79  #define osExitIsr(flag) portEXIT_SWITCHING_ISR()
80 #elif defined(portEND_SWITCHING_ISR)
81  #define osExitIsr(flag) portEND_SWITCHING_ISR(flag)
82 #elif defined(portYIELD_FROM_ISR)
83  #define osExitIsr(flag) portYIELD_FROM_ISR(flag)
84 #else
85  #define osExitIsr(flag)
86 #endif
87 
88 //Static object allocation
89 #ifndef configSUPPORT_STATIC_ALLOCATION
90  #define configSUPPORT_STATIC_ALLOCATION 0
91 #endif
92 
93 //C++ guard
94 #ifdef __cplusplus
95 extern "C" {
96 #endif
97 
98 
99 /**
100  * @brief Task object
101  **/
102 
103 //typedef void OsTask;
104 #define OsTask void
105 
106 
107 /**
108  * @brief Event object
109  **/
110 
111 typedef struct
112 {
113  SemaphoreHandle_t handle;
114 #if (configSUPPORT_STATIC_ALLOCATION == 1)
115  StaticSemaphore_t buffer;
116 #endif
117 } OsEvent;
118 
119 
120 /**
121  * @brief Semaphore object
122  **/
123 
124 typedef struct
125 {
126  SemaphoreHandle_t handle;
127 #if (configSUPPORT_STATIC_ALLOCATION == 1)
128  StaticSemaphore_t buffer;
129 #endif
130 } OsSemaphore;
131 
132 
133 /**
134  * @brief Mutex object
135  **/
136 
137 typedef struct
138 {
139  SemaphoreHandle_t handle;
140 #if (configSUPPORT_STATIC_ALLOCATION == 1)
141  StaticSemaphore_t buffer;
142 #endif
143 } OsMutex;
144 
145 
146 /**
147  * @brief Task routine
148  **/
149 
150 typedef void (*OsTaskCode)(void *param);
151 
152 
153 //Kernel management
154 void osInitKernel(void);
155 void osStartKernel(void);
156 
157 //Task management
158 OsTask *osCreateTask(const char_t *name, OsTaskCode taskCode,
159  void *param, size_t stackSize, int_t priority);
160 
161 void osDeleteTask(OsTask *task);
162 void osDelayTask(systime_t delay);
163 void osSwitchTask(void);
164 void osSuspendAllTasks(void);
165 void osResumeAllTasks(void);
166 
167 //Event management
169 void osDeleteEvent(OsEvent *event);
170 void osSetEvent(OsEvent *event);
171 void osResetEvent(OsEvent *event);
172 bool_t osWaitForEvent(OsEvent *event, systime_t timeout);
174 
175 //Semaphore management
176 bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count);
177 void osDeleteSemaphore(OsSemaphore *semaphore);
178 bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout);
179 void osReleaseSemaphore(OsSemaphore *semaphore);
180 
181 //Mutex management
183 void osDeleteMutex(OsMutex *mutex);
184 void osAcquireMutex(OsMutex *mutex);
185 void osReleaseMutex(OsMutex *mutex);
186 
187 //System time
189 
190 //Memory management
191 void *osAllocMem(size_t size);
192 void osFreeMem(void *p);
193 
194 //C++ guard
195 #ifdef __cplusplus
196 }
197 #endif
198 
199 #endif
systime_t osGetSystemTime(void)
Retrieve system time.
int bool_t
Definition: compiler_port.h:49
void osReleaseSemaphore(OsSemaphore *semaphore)
Release the specified semaphore object.
signed int int_t
Definition: compiler_port.h:44
SemaphoreHandle_t handle
uint8_t p
Definition: ndp.h:298
Event object.
void osDeleteSemaphore(OsSemaphore *semaphore)
Delete a semaphore object.
char_t name[]
bool_t osSetEventFromIsr(OsEvent *event)
Set an event object to the signaled state from an interrupt service routine.
Semaphore object.
void * osAllocMem(size_t size)
Allocate a memory block.
void osSuspendAllTasks(void)
Suspend scheduler activity.
mutex_t OsMutex
Mutex object.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
binary_semaphore_t OsEvent
Event object.
void osSwitchTask(void)
Yield control to the next task.
Task object.
bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout)
Wait for the specified semaphore to be available.
void osDelayTask(systime_t delay)
Delay routine.
OsTask * osCreateTask(const char_t *name, OsTaskCode taskCode, void *param, size_t stackSize, int_t priority)
Create a new task.
Mutex object.
char char_t
Definition: compiler_port.h:43
void osInitKernel(void)
Kernel initialization.
SemaphoreHandle_t handle
void osSetEvent(OsEvent *event)
Set the specified event object to the signaled state.
bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count)
Create a semaphore object.
void(* OsTaskCode)(void *param)
Task routine.
void osDeleteMutex(OsMutex *mutex)
Delete a mutex object.
void osResetEvent(OsEvent *event)
Set the specified event object to the nonsignaled state.
void osStartKernel(void)
Start kernel.
void osDeleteEvent(OsEvent *event)
Delete an event object.
void osResumeAllTasks(void)
Resume scheduler activity.
void osFreeMem(void *p)
Release a previously allocated memory block.
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
void osDeleteTask(OsTask *task)
Delete a task.
unsigned int uint_t
Definition: compiler_port.h:45
uint16_t priority
Definition: dns_common.h:221
bool_t osWaitForEvent(OsEvent *event, systime_t timeout)
Wait until the specified event is in the signaled state.
bool_t osCreateMutex(OsMutex *mutex)
Create a mutex object.
uint32_t systime_t
Definition: compiler_port.h:46
bool_t osCreateEvent(OsEvent *event)
Create an event object.
SemaphoreHandle_t handle
semaphore_t OsSemaphore
Semaphore object.