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-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_UCOS2_H
30 #define _OS_PORT_UCOS2_H
31 
32 //Dependencies
33 #include "ucos_ii.h"
34 
35 //Maximum number of tasks that can be dynamically created
36 #ifndef OS_PORT_MAX_TASKS
37  #define OS_PORT_MAX_TASKS 16
38 #elif (OS_PORT_MAX_TASKS < 1)
39  #error OS_PORT_MAX_TASKS parameter is not valid
40 #endif
41 
42 //Task priority (normal)
43 #ifndef OS_TASK_PRIORITY_NORMAL
44  #define OS_TASK_PRIORITY_NORMAL 0
45 #endif
46 
47 //Task priority (high)
48 #ifndef OS_TASK_PRIORITY_HIGH
49  #define OS_TASK_PRIORITY_HIGH 0
50 #endif
51 
52 //Milliseconds to system ticks
53 #ifndef OS_MS_TO_SYSTICKS
54  #define OS_MS_TO_SYSTICKS(n) (n)
55 #endif
56 
57 //System ticks to milliseconds
58 #ifndef OS_SYSTICKS_TO_MS
59  #define OS_SYSTICKS_TO_MS(n) (n)
60 #endif
61 
62 //Task prologue
63 #define osEnterTask()
64 //Interrupt service routine prologue
65 #define osEnterIsr() OSIntEnter()
66 //Interrupt service routine epilogue
67 #define osExitIsr(flag) OSIntExit()
68 
69 //C++ guard
70 #ifdef __cplusplus
71 extern "C" {
72 #endif
73 
74 
75 /**
76  * @brief Task object
77  **/
78 
79 typedef struct
80 {
81  INT8U prio;
82 } OsTask;
83 
84 
85 /**
86  * @brief Event object
87  **/
88 
89 typedef struct
90 {
91  OS_FLAG_GRP *p;
92 } OsEvent;
93 
94 
95 /**
96  * @brief Semaphore object
97  **/
98 
99 typedef struct
100 {
101  OS_EVENT *p;
102 } OsSemaphore;
103 
104 
105 /**
106  * @brief Mutex object
107  **/
108 
109 typedef struct
110 {
111  OS_EVENT *p;
112 } OsMutex;
113 
114 
115 /**
116  * @brief Task routine
117  **/
118 
119 typedef void (*OsTaskCode)(void *param);
120 
121 
122 //Kernel management
123 void osInitKernel(void);
124 void osStartKernel(void);
125 
126 //Task management
127 bool_t osCreateStaticTask(OsTask *task, const char_t *name, OsTaskCode taskCode,
128  void *param, void *stack, size_t stackSize, int_t priority);
129 
130 OsTask *osCreateTask(const char_t *name, OsTaskCode taskCode,
131  void *param, size_t stackSize, int_t priority);
132 
133 void osDeleteTask(OsTask *task);
134 void osDelayTask(systime_t delay);
135 void osSwitchTask(void);
136 void osSuspendAllTasks(void);
137 void osResumeAllTasks(void);
138 
139 //Event management
141 void osDeleteEvent(OsEvent *event);
142 void osSetEvent(OsEvent *event);
143 void osResetEvent(OsEvent *event);
144 bool_t osWaitForEvent(OsEvent *event, systime_t timeout);
146 
147 //Semaphore management
148 bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count);
149 void osDeleteSemaphore(OsSemaphore *semaphore);
150 bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout);
151 void osReleaseSemaphore(OsSemaphore *semaphore);
152 
153 //Mutex management
155 void osDeleteMutex(OsMutex *mutex);
156 void osAcquireMutex(OsMutex *mutex);
157 void osReleaseMutex(OsMutex *mutex);
158 
159 //System time
161 
162 //Memory management
163 void *osAllocMem(size_t size);
164 void osFreeMem(void *p);
165 
166 //Undefine conflicting definitions
167 #undef TRACE_LEVEL_OFF
168 #undef TRACE_LEVEL_INFO
169 
170 //C++ guard
171 #ifdef __cplusplus
172 }
173 #endif
174 
175 #endif
int bool_t
Definition: compiler_port.h:49
signed int int_t
Definition: compiler_port.h:44
OS_EVENT * p
uint8_t p
Definition: ndp.h:298
systime_t osGetSystemTime(void)
Retrieve system time.
Event object.
char_t name[]
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.
#define OsTask
Task object.
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.
bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout)
Wait for the specified semaphore to be available.
OsTask * osCreateTask(const char_t *name, OsTaskCode taskCode, void *param, size_t stackSize, int_t priority)
Create a new task.
Task object.
void osDelayTask(systime_t delay)
Delay routine.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
Mutex object.
void osDeleteMutex(OsMutex *mutex)
Delete a mutex object.
bool_t osCreateStaticTask(OsTask *task, const char_t *name, OsTaskCode taskCode, void *param, void *stack, size_t stackSize, int_t priority)
Create a static task.
void osSetEvent(OsEvent *event)
Set the specified event object to the signaled state.
char char_t
Definition: compiler_port.h:43
bool_t osCreateMutex(OsMutex *mutex)
Create a mutex object.
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
OS_FLAG_GRP * p
Definition: os_port_ucos2.h:91
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.
void osDeleteEvent(OsEvent *event)
Delete an event object.
unsigned int uint_t
Definition: compiler_port.h:45
void osReleaseSemaphore(OsSemaphore *semaphore)
Release the specified semaphore object.
void osDeleteTask(OsTask *task)
Delete a task.
uint16_t priority
Definition: dns_common.h:221
uint32_t systime_t
Definition: compiler_port.h:46
void osDeleteSemaphore(OsSemaphore *semaphore)
Delete a semaphore object.
INT8U prio
Definition: os_port_ucos2.h:81
semaphore_t OsSemaphore
Semaphore object.