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