os_port_ucos2.h
Go to the documentation of this file.
1 /**
2  * @file os_port_ucos2.h
3  * @brief RTOS abstraction layer (Micrium uC/OS-II)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2023 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.2.4
27  **/
28 
29 #ifndef _OS_PORT_UCOS2_H
30 #define _OS_PORT_UCOS2_H
31 
32 //Dependencies
33 #include "ucos_ii.h"
34 
35 //Use static memory allocation for tasks
36 #define OS_STATIC_TASK_SUPPORT ENABLED
37 
38 //Invalid task identifier
39 #define OS_INVALID_TASK_ID 255
40 //Self task identifier
41 #define OS_SELF_TASK_ID OS_PRIO_SELF
42 
43 //Task priority (normal)
44 #ifndef OS_TASK_PRIORITY_NORMAL
45  #define OS_TASK_PRIORITY_NORMAL 0
46 #endif
47 
48 //Task priority (high)
49 #ifndef OS_TASK_PRIORITY_HIGH
50  #define OS_TASK_PRIORITY_HIGH 0
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 //Retrieve 64-bit system time (not implemented)
64 #ifndef osGetSystemTime64
65  #define osGetSystemTime64() osGetSystemTime()
66 #endif
67 
68 //Task prologue
69 #define osEnterTask()
70 //Task epilogue
71 #define osExitTask()
72 //Interrupt service routine prologue
73 #define osEnterIsr() OSIntEnter()
74 //Interrupt service routine epilogue
75 #define osExitIsr(flag) OSIntExit()
76 
77 //C++ guard
78 #ifdef __cplusplus
79 extern "C" {
80 #endif
81 
82 
83 /**
84  * @brief System time
85  **/
86 
87 typedef uint32_t systime_t;
88 
89 
90 /**
91  * @brief Task identifier
92  **/
93 
94 typedef INT8U OsTaskId;
95 
96 
97 /**
98  * @brief Task control block
99  **/
100 
101 typedef struct
102 {
103  uint32_t dummy;
104 } OsTaskTcb;
105 
106 
107 /**
108  * @brief Stack data type
109  **/
110 
111 typedef OS_STK OsStackType;
112 
113 
114 /**
115  * @brief Event object
116  **/
117 
118 typedef struct
119 {
120  OS_FLAG_GRP *p;
121 } OsEvent;
122 
123 
124 /**
125  * @brief Semaphore object
126  **/
127 
128 typedef struct
129 {
130  OS_EVENT *p;
131 } OsSemaphore;
132 
133 
134 /**
135  * @brief Mutex object
136  **/
137 
138 typedef struct
139 {
140  OS_EVENT *p;
141 } OsMutex;
142 
143 
144 /**
145  * @brief Task routine
146  **/
147 
148 typedef void (*OsTaskCode)(void *param);
149 
150 
151 //Kernel management
152 void osInitKernel(void);
153 void osStartKernel(void);
154 
155 //Task management
157  void *param, OsTaskTcb *tcb, OsStackType *stack, size_t stackSize,
158  int_t priority);
159 
160 void osDeleteTask(OsTaskId taskId);
161 void osDelayTask(systime_t delay);
162 void osSwitchTask(void);
163 void osSuspendAllTasks(void);
164 void osResumeAllTasks(void);
165 
166 //Event management
168 void osDeleteEvent(OsEvent *event);
169 void osSetEvent(OsEvent *event);
170 void osResetEvent(OsEvent *event);
171 bool_t osWaitForEvent(OsEvent *event, systime_t timeout);
173 
174 //Semaphore management
175 bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count);
176 void osDeleteSemaphore(OsSemaphore *semaphore);
177 bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout);
178 void osReleaseSemaphore(OsSemaphore *semaphore);
179 
180 //Mutex management
182 void osDeleteMutex(OsMutex *mutex);
183 void osAcquireMutex(OsMutex *mutex);
184 void osReleaseMutex(OsMutex *mutex);
185 
186 //System time
188 
189 //Memory management
190 void *osAllocMem(size_t size);
191 void osFreeMem(void *p);
192 
193 //Undefine conflicting definitions
194 #undef TRACE_LEVEL_OFF
195 #undef TRACE_LEVEL_INFO
196 
197 //C++ guard
198 #ifdef __cplusplus
199 }
200 #endif
201 
202 #endif
int bool_t
Definition: compiler_port.h:53
signed int int_t
Definition: compiler_port.h:49
INT8U OsTaskId
Task identifier.
Definition: os_port_ucos2.h:94
OS_EVENT * p
uint8_t p
Definition: ndp.h:298
systime_t osGetSystemTime(void)
Retrieve system time.
Event object.
char_t name[]
OsTaskId osCreateStaticTask(const char_t *name, OsTaskCode taskCode, void *param, OsTaskTcb *tcb, OsStackType *stack, size_t stackSize, int_t priority)
Create a task with statically allocated memory.
uint32_t systime_t
System time.
Definition: os_port_ucos2.h:87
void osResetEvent(OsEvent *event)
Set the specified event object to the nonsignaled state.
Semaphore object.
void osSwitchTask(void)
Yield control to the next task.
OS_EVENT * p
void osResumeAllTasks(void)
Resume scheduler activity.
bool_t osCreateEvent(OsEvent *event)
Create an event object.
void(* OsTaskCode)(void *param)
Task routine.
mutex_t OsMutex
Mutex object.
void osSuspendAllTasks(void)
Suspend scheduler activity.
bool_t osSetEventFromIsr(OsEvent *event)
Set an event object to the signaled state from an interrupt service routine.
void osFreeMem(void *p)
Release a previously allocated memory block.
binary_semaphore_t OsEvent
Event object.
void osInitKernel(void)
Kernel initialization.
Task control block.
bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout)
Wait for the specified semaphore to be available.
void osDelayTask(systime_t delay)
Delay routine.
uint32_t OsStackType
Stack data type.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
OS_STK OsStackType
Stack data type.
Mutex object.
void osDeleteMutex(OsMutex *mutex)
Delete a 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
bool_t osCreateMutex(OsMutex *mutex)
Create a mutex object.
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
OS_FLAG_GRP * p
bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count)
Create a semaphore object.
bool_t osWaitForEvent(OsEvent *event, systime_t timeout)
Wait until the specified event is in the signaled state.
void osStartKernel(void)
Start kernel.
void * osAllocMem(size_t size)
Allocate a memory block.
thread_t * OsTaskId
Task identifier.
OS_TASK OsTaskTcb
Task control block.
void osDeleteEvent(OsEvent *event)
Delete an event object.
unsigned int uint_t
Definition: compiler_port.h:50
void osReleaseSemaphore(OsSemaphore *semaphore)
Release the specified semaphore object.
void osDeleteTask(OsTaskId taskId)
Delete a task.
uint16_t priority
Definition: dns_common.h:249
void osDeleteSemaphore(OsSemaphore *semaphore)
Delete a semaphore object.
semaphore_t OsSemaphore
Semaphore object.