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  * 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_UCOS2_H
28 #define _OS_PORT_UCOS2_H
29 
30 //Dependencies
31 #include "ucos_ii.h"
32 
33 //Maximum number of tasks that can be dynamically created
34 #ifndef OS_PORT_MAX_TASKS
35  #define OS_PORT_MAX_TASKS 16
36 #elif (OS_PORT_MAX_TASKS < 1)
37  #error OS_PORT_MAX_TASKS parameter is not valid
38 #endif
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 //Enter interrupt service routine
61 #define osEnterIsr() OSIntEnter()
62 
63 //Leave interrupt service routine
64 #define osExitIsr(flag) OSIntExit()
65 
66 //C++ guard
67 #ifdef __cplusplus
68  extern "C" {
69 #endif
70 
71 
72 /**
73  * @brief Task object
74  **/
75 
76 typedef struct
77 {
78  INT8U prio;
79 } OsTask;
80 
81 
82 /**
83  * @brief Event object
84  **/
85 
86 typedef struct
87 {
88  OS_FLAG_GRP *p;
89 } OsEvent;
90 
91 
92 /**
93  * @brief Semaphore object
94  **/
95 
96 typedef struct
97 {
98  OS_EVENT *p;
99 } OsSemaphore;
100 
101 
102 /**
103  * @brief Mutex object
104  **/
105 
106 typedef struct
107 {
108  OS_EVENT *p;
109 } OsMutex;
110 
111 
112 /**
113  * @brief Task routine
114  **/
115 
116 typedef void (*OsTaskCode)(void *param);
117 
118 
119 //Kernel management
120 void osInitKernel(void);
121 void osStartKernel(void);
122 
123 //Task management
124 bool_t osCreateStaticTask(OsTask *task, const char_t *name, OsTaskCode taskCode,
125  void *param, void *stack, size_t stackSize, int_t priority);
126 
127 OsTask *osCreateTask(const char_t *name, OsTaskCode taskCode,
128  void *param, size_t stackSize, int_t priority);
129 
130 void osDeleteTask(OsTask *task);
131 void osDelayTask(systime_t delay);
132 void osSwitchTask(void);
133 void osSuspendAllTasks(void);
134 void osResumeAllTasks(void);
135 
136 //Event management
138 void osDeleteEvent(OsEvent *event);
139 void osSetEvent(OsEvent *event);
140 void osResetEvent(OsEvent *event);
141 bool_t osWaitForEvent(OsEvent *event, systime_t timeout);
143 
144 //Semaphore management
145 bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count);
146 void osDeleteSemaphore(OsSemaphore *semaphore);
147 bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout);
148 void osReleaseSemaphore(OsSemaphore *semaphore);
149 
150 //Mutex management
152 void osDeleteMutex(OsMutex *mutex);
153 void osAcquireMutex(OsMutex *mutex);
154 void osReleaseMutex(OsMutex *mutex);
155 
156 //System time
158 
159 //Memory management
160 void *osAllocMem(size_t size);
161 void osFreeMem(void *p);
162 
163 //Undefine conflicting definitions
164 #undef TRACE_LEVEL_OFF
165 #undef TRACE_LEVEL_INFO
166 
167 //C++ guard
168 #ifdef __cplusplus
169  }
170 #endif
171 
172 #endif
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
void osResumeAllTasks(void)
Resume scheduler activity.
uint16_t priority
Definition: dns_common.h:219
bool_t osCreateEvent(OsEvent *event)
Create an event object.
uint32_t systime_t
Definition: compiler_port.h:44
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
char char_t
Definition: compiler_port.h:41
INT8U prio
Definition: os_port_ucos2.h:78
void osDeleteSemaphore(OsSemaphore *semaphore)
Delete a semaphore object.
void osDeleteMutex(OsMutex *mutex)
Delete a mutex object.
uint8_t p
Definition: ndp.h:295
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.
bool_t osCreateMutex(OsMutex *mutex)
Create a mutex object.
bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count)
Create a semaphore object.
void osDeleteTask(OsTask *task)
Delete a task.
binary_semaphore_t OsEvent
Event object.
void osSetEvent(OsEvent *event)
Set the specified event object to the signaled state.
Event object.
OsTask * osCreateTask(const char_t *name, OsTaskCode taskCode, void *param, size_t stackSize, int_t priority)
Create a new task.
void osReleaseSemaphore(OsSemaphore *semaphore)
Release the specified semaphore object.
void osDeleteEvent(OsEvent *event)
Delete an event object.
void * osAllocMem(size_t size)
Allocate a memory block.
Task object.
signed int int_t
Definition: compiler_port.h:42
char_t name[]
bool_t osSetEventFromIsr(OsEvent *event)
Set an event object to the signaled state from an interrupt service routine.
mutex_t OsMutex
Mutex object.
OS_EVENT * p
Definition: os_port_ucos2.h:98
OS_EVENT * p
void osStartKernel(void)
Start kernel.
systime_t osGetSystemTime(void)
Retrieve system time.
void osSwitchTask(void)
Yield control to the next task.
OS_FLAG_GRP * p
Definition: os_port_ucos2.h:88
void(* OsTaskCode)(void *param)
Task routine.
unsigned int uint_t
Definition: compiler_port.h:43
void osResetEvent(OsEvent *event)
Set the specified event object to the nonsignaled state.
semaphore_t OsSemaphore
Semaphore object.
Mutex object.
bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout)
Wait for the specified semaphore to be available.
void osDelayTask(systime_t delay)
Delay routine.
bool_t osWaitForEvent(OsEvent *event, systime_t timeout)
Wait until the specified event is in the signaled state.
void osSuspendAllTasks(void)
Suspend scheduler activity.
void osFreeMem(void *p)
Release a previously allocated memory block.
Semaphore object.
void osInitKernel(void)
Kernel initialization.
int bool_t
Definition: compiler_port.h:47
#define OsTask
Task object.