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