os_port_rtx.h
Go to the documentation of this file.
1 /**
2  * @file os_port_rtx.h
3  * @brief RTOS abstraction layer (Keil RTX)
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_RTX_H
28 #define _OS_PORT_RTX_H
29 
30 //Dependencies
31 #ifdef RTX_CUSTOM_HEADER
32  #include RTX_CUSTOM_HEADER
33 #else
34  #include "rtl.h"
35 #endif
36 
37 //Maximum number of tasks that can be dynamically created
38 #ifndef OS_PORT_MAX_TASKS
39  #define OS_PORT_MAX_TASKS 16
40 #elif (OS_PORT_MAX_TASKS < 1)
41  #error OS_PORT_MAX_TASKS parameter is not valid
42 #endif
43 
44 //Task priority (normal)
45 #ifndef OS_TASK_PRIORITY_NORMAL
46  #define OS_TASK_PRIORITY_NORMAL 1
47 #endif
48 
49 //Task priority (high)
50 #ifndef OS_TASK_PRIORITY_HIGH
51  #define OS_TASK_PRIORITY_HIGH 2
52 #endif
53 
54 //Milliseconds to system ticks
55 #ifndef OS_MS_TO_SYSTICKS
56  #define OS_MS_TO_SYSTICKS(n) (n)
57 #endif
58 
59 //System ticks to milliseconds
60 #ifndef OS_SYSTICKS_TO_MS
61  #define OS_SYSTICKS_TO_MS(n) (n)
62 #endif
63 
64 //Enter interrupt service routine
65 #define osEnterIsr()
66 
67 //Leave interrupt service routine
68 #define osExitIsr(flag)
69 
70 //C++ guard
71 #ifdef __cplusplus
72  extern "C" {
73 #endif
74 
75 
76 /**
77  * @brief Task object
78  **/
79 
80 typedef struct
81 {
82  OS_TID tid;
83 } OsTask;
84 
85 
86 /**
87  * @brief Event object
88  **/
89 
90 typedef OS_SEM OsEvent;
91 
92 
93 /**
94  * @brief Semaphore object
95  **/
96 
97 typedef OS_SEM OsSemaphore;
98 
99 
100 /**
101  * @brief Mutex object
102  **/
103 
104 typedef OS_MUT OsMutex;
105 
106 
107 /**
108  * @brief Task routine
109  **/
110 
111 typedef void (*OsTaskCode)(void *param);
112 
113 
114 /**
115  * @brief Initialization task
116  **/
117 
118 typedef void (*OsInitTaskCode)(void);
119 
120 
121 //Kernel management
122 void osInitKernel(void);
123 void osStartKernel(OsInitTaskCode task);
124 
125 //Task management
126 bool_t osCreateStaticTask(OsTask *task, const char_t *name, OsTaskCode taskCode,
127  void *param, void *stack, size_t stackSize, int_t priority);
128 
129 OsTask *osCreateTask(const char_t *name, OsTaskCode taskCode,
130  void *param, size_t stackSize, int_t priority);
131 
132 void osDeleteTask(OsTask *task);
133 void osDelayTask(systime_t delay);
134 void osSwitchTask(void);
135 void osSuspendAllTasks(void);
136 void osResumeAllTasks(void);
137 
138 //Event management
140 void osDeleteEvent(OsEvent *event);
141 void osSetEvent(OsEvent *event);
142 void osResetEvent(OsEvent *event);
143 bool_t osWaitForEvent(OsEvent *event, systime_t timeout);
145 
146 //Semaphore management
147 bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count);
148 void osDeleteSemaphore(OsSemaphore *semaphore);
149 bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout);
150 void osReleaseSemaphore(OsSemaphore *semaphore);
151 
152 //Mutex management
154 void osDeleteMutex(OsMutex *mutex);
155 void osAcquireMutex(OsMutex *mutex);
156 void osReleaseMutex(OsMutex *mutex);
157 
158 //System time
160 
161 //Memory management
162 void *osAllocMem(size_t size);
163 void osFreeMem(void *p);
164 
165 //Undefine conflicting definitions
166 #undef htons
167 #undef htonl
168 #undef ntohs
169 #undef ntohl
170 #undef TCP_STATE_CLOSED
171 #undef TCP_STATE_LISTEN
172 #undef TCP_STATE_SYN_SENT
173 #undef TCP_STATE_CLOSING
174 #undef TCP_STATE_LAST_ACK
175 
176 //C++ guard
177 #ifdef __cplusplus
178  }
179 #endif
180 
181 #endif
uint16_t priority
Definition: dns_common.h:219
uint32_t systime_t
Definition: compiler_port.h:44
void osResumeAllTasks(void)
Resume scheduler activity.
char char_t
Definition: compiler_port.h:41
void osDeleteMutex(OsMutex *mutex)
Delete a mutex object.
void osResetEvent(OsEvent *event)
Set the specified event object to the nonsignaled state.
void(* OsTaskCode)(void *param)
Task routine.
Definition: os_port_rtx.h:111
uint8_t p
Definition: ndp.h:295
void * osAllocMem(size_t size)
Allocate a memory block.
OS_SEM OsSemaphore
Semaphore object.
Definition: os_port_rtx.h:97
void osInitKernel(void)
Kernel initialization.
void osDeleteSemaphore(OsSemaphore *semaphore)
Delete a semaphore object.
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
bool_t osWaitForEvent(OsEvent *event, systime_t timeout)
Wait until the specified event is in the signaled state.
Event object.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
void osDeleteEvent(OsEvent *event)
Delete an event object.
systime_t osGetSystemTime(void)
Retrieve system time.
void osStartKernel(OsInitTaskCode task)
Start kernel.
Definition: os_port_rtx.c:61
Task object.
signed int int_t
Definition: compiler_port.h:42
void osSetEvent(OsEvent *event)
Set the specified event object to the signaled state.
char_t name[]
OsTask * osCreateTask(const char_t *name, OsTaskCode taskCode, void *param, size_t stackSize, int_t priority)
Create a new task.
void osFreeMem(void *p)
Release a previously allocated memory block.
bool_t osSetEventFromIsr(OsEvent *event)
Set an event object to the signaled state from an interrupt service routine.
bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout)
Wait for the specified semaphore to be available.
void osSuspendAllTasks(void)
Suspend scheduler activity.
bool_t osCreateMutex(OsMutex *mutex)
Create a mutex object.
unsigned int uint_t
Definition: compiler_port.h:43
OS_MUT OsMutex
Mutex object.
Definition: os_port_rtx.h:104
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(* OsInitTaskCode)(void)
Initialization task.
Definition: os_port_rtx.h:118
Mutex object.
void osDeleteTask(OsTask *task)
Delete a task.
bool_t osCreateEvent(OsEvent *event)
Create an event object.
bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count)
Create a semaphore object.
OS_SEM OsEvent
Event object.
Definition: os_port_rtx.h:90
void osSwitchTask(void)
Yield control to the next task.
Semaphore object.
int bool_t
Definition: compiler_port.h:47
void osDelayTask(systime_t delay)
Delay routine.
OS_TID tid
Definition: os_port_rtx.h:82
#define OsTask
Task object.
void osReleaseSemaphore(OsSemaphore *semaphore)
Release the specified semaphore object.