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-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_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 //Invalid task identifier
40 #define OS_INVALID_TASK_ID 0
41 //Self task identifier
42 #define OS_SELF_TASK_ID 0
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 //Retrieve 64-bit system time (not implemented)
65 #ifndef osGetSystemTime64
66  #define osGetSystemTime64() osGetSystemTime()
67 #endif
68 
69 //Task prologue
70 #define osEnterTask()
71 //Task epilogue
72 #define osExitTask()
73 //Interrupt service routine prologue
74 #define osEnterIsr()
75 //Interrupt service routine epilogue
76 #define osExitIsr(flag)
77 
78 //C++ guard
79 #ifdef __cplusplus
80 extern "C" {
81 #endif
82 
83 
84 /**
85  * @brief System time
86  **/
87 
88 typedef uint32_t systime_t;
89 
90 
91 /**
92  * @brief Task identifier
93  **/
94 
95 typedef OS_TID OsTaskId;
96 
97 
98 /**
99  * @brief Task parameters
100  **/
101 
102 typedef struct
103 {
104  uint32_t *stack;
105  size_t stackSize;
108 
109 
110 /**
111  * @brief Event object
112  **/
113 
114 typedef OS_SEM OsEvent;
115 
116 
117 /**
118  * @brief Semaphore object
119  **/
120 
121 typedef OS_SEM OsSemaphore;
122 
123 
124 /**
125  * @brief Mutex object
126  **/
127 
128 typedef OS_MUT OsMutex;
129 
130 
131 /**
132  * @brief Task routine
133  **/
134 
135 typedef void (*OsTaskCode)(void *arg);
136 
137 
138 /**
139  * @brief Initialization task
140  **/
141 
142 typedef void (*OsInitTaskCode)(void);
143 
144 
145 //Default task parameters
147 
148 //Kernel management
149 void osInitKernel(void);
150 void osStartKernel(OsInitTaskCode task);
151 
152 //Task management
153 OsTaskId osCreateTask(const char_t *name, OsTaskCode taskCode, void *arg,
154  const OsTaskParameters *params);
155 
156 void osDeleteTask(OsTaskId taskId);
157 void osDelayTask(systime_t delay);
158 void osSwitchTask(void);
159 void osSuspendAllTasks(void);
160 void osResumeAllTasks(void);
161 
162 //Event management
164 void osDeleteEvent(OsEvent *event);
165 void osSetEvent(OsEvent *event);
166 void osResetEvent(OsEvent *event);
167 bool_t osWaitForEvent(OsEvent *event, systime_t timeout);
169 
170 //Semaphore management
171 bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count);
172 void osDeleteSemaphore(OsSemaphore *semaphore);
173 bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout);
174 void osReleaseSemaphore(OsSemaphore *semaphore);
175 
176 //Mutex management
178 void osDeleteMutex(OsMutex *mutex);
179 void osAcquireMutex(OsMutex *mutex);
180 void osReleaseMutex(OsMutex *mutex);
181 
182 //System time
184 
185 //Memory management
186 void *osAllocMem(size_t size);
187 void osFreeMem(void *p);
188 
189 //Undefine conflicting definitions
190 #undef htons
191 #undef htonl
192 #undef ntohs
193 #undef ntohl
194 #undef TCP_STATE_CLOSED
195 #undef TCP_STATE_LISTEN
196 #undef TCP_STATE_SYN_SENT
197 #undef TCP_STATE_CLOSING
198 #undef TCP_STATE_LAST_ACK
199 
200 //C++ guard
201 #ifdef __cplusplus
202 }
203 #endif
204 
205 #endif
void osDelayTask(systime_t delay)
Delay routine.
OS_SEM OsSemaphore
Semaphore object.
Definition: os_port_rtx.h:121
int bool_t
Definition: compiler_port.h:53
void osResumeAllTasks(void)
Resume scheduler activity.
uint8_t p
Definition: ndp.h:300
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.
void(* OsTaskCode)(void *arg)
Task routine.
Definition: os_port_rtx.h:135
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.
OsTaskId osCreateTask(const char_t *name, OsTaskCode taskCode, void *arg, const OsTaskParameters *params)
Create a task.
bool_t osSetEventFromIsr(OsEvent *event)
Set an event object to the signaled state from an interrupt service routine.
Task parameters.
bool_t osCreateMutex(OsMutex *mutex)
Create a mutex object.
void osStartKernel(OsInitTaskCode task)
Start kernel.
Definition: os_port_rtx.c:68
void osDeleteTask(OsTaskId taskId)
Delete a task.
const OsTaskParameters OS_TASK_DEFAULT_PARAMS
Mutex object.
uint32_t systime_t
System time.
void osSuspendAllTasks(void)
Suspend scheduler activity.
char char_t
Definition: compiler_port.h:48
OS_MUT OsMutex
Mutex object.
Definition: os_port_rtx.h:128
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:142
OS_SEM OsEvent
Event object.
Definition: os_port_rtx.h:114
uint32_t systime_t
System time.
Definition: os_port_rtx.h:88
thread_t * OsTaskId
Task identifier.
unsigned int uint_t
Definition: compiler_port.h:50
uint16_t priority
Definition: dns_common.h:265
OS_TID OsTaskId
Task identifier.
Definition: os_port_rtx.h:95
void osResetEvent(OsEvent *event)
Set the specified event object to the nonsignaled state.
void * osAllocMem(size_t size)
Allocate a memory block.