os_port_threadx.h
Go to the documentation of this file.
1 /**
2  * @file os_port_threadx.h
3  * @brief RTOS abstraction layer (Eclipse ThreadX)
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_THREADX_H
30 #define _OS_PORT_THREADX_H
31 
32 //Dependencies
33 #include "tx_port.h"
34 #include "tx_user.h"
35 #include "tx_api.h"
36 #include "tx_thread.h"
37 #include "tx_semaphore.h"
38 #include "tx_event_flags.h"
39 #include "tx_mutex.h"
40 #include "tx_initialize.h"
41 
42 //Invalid task identifier
43 #define OS_INVALID_TASK_ID NULL
44 //Self task identifier
45 #define OS_SELF_TASK_ID NULL
46 
47 //Task priority (normal)
48 #ifndef OS_TASK_PRIORITY_NORMAL
49  #define OS_TASK_PRIORITY_NORMAL (TX_MAX_PRIORITIES / 2)
50 #endif
51 
52 //Task priority (high)
53 #ifndef OS_TASK_PRIORITY_HIGH
54  #define OS_TASK_PRIORITY_HIGH (OS_TASK_PRIORITY_NORMAL - 1)
55 #endif
56 
57 //Milliseconds to system ticks
58 #ifndef OS_MS_TO_SYSTICKS
59  #define OS_MS_TO_SYSTICKS(n) (n)
60 #endif
61 
62 //System ticks to milliseconds
63 #ifndef OS_SYSTICKS_TO_MS
64  #define OS_SYSTICKS_TO_MS(n) (n)
65 #endif
66 
67 //Retrieve 64-bit system time (not implemented)
68 #ifndef osGetSystemTime64
69  #define osGetSystemTime64() osGetSystemTime()
70 #endif
71 
72 //Task prologue
73 #define osEnterTask()
74 //Task epilogue
75 #define osExitTask()
76 //Interrupt service routine prologue
77 #define osEnterIsr()
78 //Interrupt service routine epilogue
79 #define osExitIsr(flag)
80 
81 //C++ guard
82 #ifdef __cplusplus
83 extern "C" {
84 #endif
85 
86 
87 /**
88  * @brief Task function
89  **/
90 
91 typedef VOID (*OsTaskFunction)(ULONG param);
92 
93 
94 /**
95  * @brief System time
96  **/
97 
98 typedef uint32_t systime_t;
99 
100 
101 /**
102  * @brief Task identifier
103  **/
104 
105 typedef TX_THREAD *OsTaskId;
106 
107 
108 /**
109  * @brief Task parameters
110  **/
111 
112 typedef struct
113 {
114  TX_THREAD *tcb;
115  uint32_t *stack;
116  size_t stackSize;
119 
120 
121 /**
122  * @brief Event object
123  **/
124 
125 typedef TX_EVENT_FLAGS_GROUP OsEvent;
126 
127 
128 /**
129  * @brief Semaphore object
130  **/
131 
132 typedef TX_SEMAPHORE OsSemaphore;
133 
134 
135 /**
136  * @brief Mutex object
137  **/
138 
139 typedef TX_MUTEX OsMutex;
140 
141 
142 /**
143  * @brief Task routine
144  **/
145 
146 typedef void (*OsTaskCode)(void *arg);
147 
148 
149 //Default task parameters
151 
152 //Kernel management
153 void osInitKernel(void);
154 void osStartKernel(void);
155 
156 //Task management
157 OsTaskId osCreateTask(const char_t *name, OsTaskCode taskCode, void *arg,
158  const OsTaskParameters *params);
159 
160 void osDeleteTask(OsTaskId taskId);
161 void osDelayTask(systime_t delay);
162 void osSwitchTask(void);
163 void osSuspendAllTasks(void);
164 void osResumeAllTasks(void);
165 
166 //Event management
168 void osDeleteEvent(OsEvent *event);
169 void osSetEvent(OsEvent *event);
170 void osResetEvent(OsEvent *event);
171 bool_t osWaitForEvent(OsEvent *event, systime_t timeout);
173 
174 //Semaphore management
175 bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count);
176 void osDeleteSemaphore(OsSemaphore *semaphore);
177 bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout);
178 void osReleaseSemaphore(OsSemaphore *semaphore);
179 
180 //Mutex management
182 void osDeleteMutex(OsMutex *mutex);
183 void osAcquireMutex(OsMutex *mutex);
184 void osReleaseMutex(OsMutex *mutex);
185 
186 //System time
188 
189 //Memory management
190 void *osAllocMem(size_t size);
191 void osFreeMem(void *p);
192 
193 //C++ guard
194 #ifdef __cplusplus
195 }
196 #endif
197 
198 #endif
bool_t osCreateEvent(OsEvent *event)
Create an event object.
int bool_t
Definition: compiler_port.h:53
void osResetEvent(OsEvent *event)
Set the specified event object to the nonsignaled state.
void osSwitchTask(void)
Yield control to the next task.
void * osAllocMem(size_t size)
Allocate a memory block.
uint8_t p
Definition: ndp.h:300
Event object.
VOID(* OsTaskFunction)(ULONG param)
Task function.
systime_t osGetSystemTime(void)
Retrieve system time.
char_t name[]
Semaphore object.
const OsTaskParameters OS_TASK_DEFAULT_PARAMS
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
void osInitKernel(void)
Kernel initialization.
void(* OsTaskCode)(void *arg)
Task routine.
void osDeleteTask(OsTaskId taskId)
Delete a task.
void osStartKernel(void)
Start kernel.
void osSuspendAllTasks(void)
Suspend scheduler activity.
Task parameters.
TX_EVENT_FLAGS_GROUP OsEvent
Event object.
bool_t osCreateMutex(OsMutex *mutex)
Create a mutex object.
void osFreeMem(void *p)
Release a previously allocated memory block.
uint32_t systime_t
System time.
TX_THREAD * OsTaskId
Task identifier.
Mutex object.
uint32_t systime_t
System time.
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.
char char_t
Definition: compiler_port.h:48
TX_MUTEX OsMutex
Mutex object.
void osResumeAllTasks(void)
Resume scheduler activity.
bool_t osWaitForEvent(OsEvent *event, systime_t timeout)
Wait until the specified event is in the signaled state.
OsTaskId osCreateTask(const char_t *name, OsTaskCode taskCode, void *arg, const OsTaskParameters *params)
Create a task.
thread_t * OsTaskId
Task identifier.
void osSetEvent(OsEvent *event)
Set the specified event object to the signaled state.
bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count)
Create a semaphore object.
void osDeleteMutex(OsMutex *mutex)
Delete a mutex object.
void osDelayTask(systime_t delay)
Delay routine.
void osDeleteEvent(OsEvent *event)
Delete an event object.
unsigned int uint_t
Definition: compiler_port.h:50
TX_SEMAPHORE OsSemaphore
Semaphore object.
uint16_t priority
Definition: dns_common.h:265
void osReleaseSemaphore(OsSemaphore *semaphore)
Release the specified semaphore object.
void osDeleteSemaphore(OsSemaphore *semaphore)
Delete a semaphore object.