forked from Oryx-Embedded/Common
-
Notifications
You must be signed in to change notification settings - Fork 0
/
os_port_threadx.h
200 lines (151 loc) · 4.11 KB
/
os_port_threadx.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/**
* @file os_port_threadx.h
* @brief RTOS abstraction layer (Azure RTOS ThreadX)
*
* @section License
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* Copyright (C) 2010-2022 Oryx Embedded SARL. All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @author Oryx Embedded SARL (www.oryx-embedded.com)
* @version 2.1.4
**/
#ifndef _OS_PORT_THREADX_H
#define _OS_PORT_THREADX_H
//Dependencies
#include "tx_port.h"
#include "tx_user.h"
#include "tx_api.h"
#include "tx_thread.h"
#include "tx_semaphore.h"
#include "tx_event_flags.h"
#include "tx_mutex.h"
#include "tx_initialize.h"
//Use static memory allocation for tasks
#define OS_STATIC_TASK_SUPPORT ENABLED
//Invalid task identifier
#define OS_INVALID_TASK_ID NULL
//Self task identifier
#define OS_SELF_TASK_ID NULL
//Task priority (normal)
#ifndef OS_TASK_PRIORITY_NORMAL
#define OS_TASK_PRIORITY_NORMAL (TX_MAX_PRIORITIES / 2)
#endif
//Task priority (high)
#ifndef OS_TASK_PRIORITY_HIGH
#define OS_TASK_PRIORITY_HIGH (OS_TASK_PRIORITY_NORMAL - 1)
#endif
//Milliseconds to system ticks
#ifndef OS_MS_TO_SYSTICKS
#define OS_MS_TO_SYSTICKS(n) (n)
#endif
//System ticks to milliseconds
#ifndef OS_SYSTICKS_TO_MS
#define OS_SYSTICKS_TO_MS(n) (n)
#endif
//Retrieve 64-bit system time (not implemented)
#ifndef osGetSystemTime64
#define osGetSystemTime64() osGetSystemTime()
#endif
//Task prologue
#define osEnterTask()
//Task epilogue
#define osExitTask()
//Interrupt service routine prologue
#define osEnterIsr()
//Interrupt service routine epilogue
#define osExitIsr(flag)
//C++ guard
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Task function
**/
typedef VOID (*OsTaskFunction)(ULONG param);
/**
* @brief System time
**/
typedef uint32_t systime_t;
/**
* @brief Task identifier
**/
typedef TX_THREAD *OsTaskId;
/**
* @brief Task control block
**/
typedef TX_THREAD OsTaskTcb;
/**
* @brief Stack data type
**/
typedef uint32_t OsStackType;
/**
* @brief Event object
**/
typedef TX_EVENT_FLAGS_GROUP OsEvent;
/**
* @brief Semaphore object
**/
typedef TX_SEMAPHORE OsSemaphore;
/**
* @brief Mutex object
**/
typedef TX_MUTEX OsMutex;
/**
* @brief Task routine
**/
typedef void (*OsTaskCode)(void *param);
//Kernel management
void osInitKernel(void);
void osStartKernel(void);
//Task management
OsTaskId osCreateStaticTask(const char_t *name, OsTaskCode taskCode,
void *param, OsTaskTcb *tcb, OsStackType *stack, size_t stackSize,
int_t priority);
void osDeleteTask(OsTaskId taskId);
void osDelayTask(systime_t delay);
void osSwitchTask(void);
void osSuspendAllTasks(void);
void osResumeAllTasks(void);
//Event management
bool_t osCreateEvent(OsEvent *event);
void osDeleteEvent(OsEvent *event);
void osSetEvent(OsEvent *event);
void osResetEvent(OsEvent *event);
bool_t osWaitForEvent(OsEvent *event, systime_t timeout);
bool_t osSetEventFromIsr(OsEvent *event);
//Semaphore management
bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count);
void osDeleteSemaphore(OsSemaphore *semaphore);
bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout);
void osReleaseSemaphore(OsSemaphore *semaphore);
//Mutex management
bool_t osCreateMutex(OsMutex *mutex);
void osDeleteMutex(OsMutex *mutex);
void osAcquireMutex(OsMutex *mutex);
void osReleaseMutex(OsMutex *mutex);
//System time
systime_t osGetSystemTime(void);
//Memory management
void *osAllocMem(size_t size);
void osFreeMem(void *p);
//C++ guard
#ifdef __cplusplus
}
#endif
#endif