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-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_UCOS2_H
30 #define _OS_PORT_UCOS2_H
31 
32 //Dependencies
33 #include "ucos_ii.h"
34 
35 //Invalid task identifier
36 #define OS_INVALID_TASK_ID 255
37 //Self task identifier
38 #define OS_SELF_TASK_ID OS_PRIO_SELF
39 
40 //Task priority (normal)
41 #ifndef OS_TASK_PRIORITY_NORMAL
42  #define OS_TASK_PRIORITY_NORMAL 0
43 #endif
44 
45 //Task priority (high)
46 #ifndef OS_TASK_PRIORITY_HIGH
47  #define OS_TASK_PRIORITY_HIGH 0
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 #define osEnterTask()
67 //Task epilogue
68 #define osExitTask()
69 //Interrupt service routine prologue
70 #define osEnterIsr() OSIntEnter()
71 //Interrupt service routine epilogue
72 #define osExitIsr(flag) OSIntExit()
73 
74 //C++ guard
75 #ifdef __cplusplus
76 extern "C" {
77 #endif
78 
79 
80 /**
81  * @brief System time
82  **/
83 
84 typedef uint32_t systime_t;
85 
86 
87 /**
88  * @brief Task identifier
89  **/
90 
91 typedef INT8U OsTaskId;
92 
93 
94 /**
95  * @brief Task parameters
96  **/
97 
98 typedef struct
99 {
100  OS_STK *stack;
101  size_t stackSize;
104 
105 
106 /**
107  * @brief Event object
108  **/
109 
110 typedef struct
111 {
112  OS_FLAG_GRP *p;
113 } OsEvent;
114 
115 
116 /**
117  * @brief Semaphore object
118  **/
119 
120 typedef struct
121 {
122  OS_EVENT *p;
123 } OsSemaphore;
124 
125 
126 /**
127  * @brief Mutex object
128  **/
129 
130 typedef struct
131 {
132  OS_EVENT *p;
133 } OsMutex;
134 
135 
136 /**
137  * @brief Task routine
138  **/
139 
140 typedef void (*OsTaskCode)(void *arg);
141 
142 
143 //Default task parameters
145 
146 //Kernel management
147 void osInitKernel(void);
148 void osStartKernel(void);
149 
150 //Task management
151 OsTaskId osCreateTask(const char_t *name, OsTaskCode taskCode, void *arg,
152  const OsTaskParameters *params);
153 
154 void osDeleteTask(OsTaskId taskId);
155 void osDelayTask(systime_t delay);
156 void osSwitchTask(void);
157 void osSuspendAllTasks(void);
158 void osResumeAllTasks(void);
159 
160 //Event management
162 void osDeleteEvent(OsEvent *event);
163 void osSetEvent(OsEvent *event);
164 void osResetEvent(OsEvent *event);
165 bool_t osWaitForEvent(OsEvent *event, systime_t timeout);
167 
168 //Semaphore management
169 bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count);
170 void osDeleteSemaphore(OsSemaphore *semaphore);
171 bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout);
172 void osReleaseSemaphore(OsSemaphore *semaphore);
173 
174 //Mutex management
176 void osDeleteMutex(OsMutex *mutex);
177 void osAcquireMutex(OsMutex *mutex);
178 void osReleaseMutex(OsMutex *mutex);
179 
180 //System time
182 
183 //Memory management
184 void *osAllocMem(size_t size);
185 void osFreeMem(void *p);
186 
187 //Undefine conflicting definitions
188 #undef TRACE_LEVEL_OFF
189 #undef TRACE_LEVEL_INFO
190 
191 //C++ guard
192 #ifdef __cplusplus
193 }
194 #endif
195 
196 #endif
int bool_t
Definition: compiler_port.h:53
INT8U OsTaskId
Task identifier.
Definition: os_port_ucos2.h:91
OS_EVENT * p
uint8_t p
Definition: ndp.h:300
systime_t osGetSystemTime(void)
Retrieve system time.
Event object.
char_t name[]
uint32_t systime_t
System time.
Definition: os_port_ucos2.h:84
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.
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.
bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout)
Wait for the specified semaphore to be available.
void osDelayTask(systime_t delay)
Delay routine.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
Task parameters.
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(* OsTaskCode)(void *arg)
Task routine.
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.
const OsTaskParameters OS_TASK_DEFAULT_PARAMS
thread_t * OsTaskId
Task identifier.
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.
OsTaskId osCreateTask(const char_t *name, OsTaskCode taskCode, void *arg, const OsTaskParameters *params)
Create a task.
uint16_t priority
Definition: dns_common.h:265
void osDeleteSemaphore(OsSemaphore *semaphore)
Delete a semaphore object.
semaphore_t OsSemaphore
Semaphore object.