1 /**************************************************************************/
2 /* */
3 /* Copyright (c) Microsoft Corporation. All rights reserved. */
4 /* */
5 /* This software is licensed under the Microsoft Software License */
6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */
7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
8 /* and in the root directory of this software. */
9 /* */
10 /**************************************************************************/
11
12
13 /**************************************************************************/
14 /**************************************************************************/
15 /** */
16 /** ThreadX Component */
17 /** */
18 /** Port Specific */
19 /** */
20 /**************************************************************************/
21 /**************************************************************************/
22
23
24 /**************************************************************************/
25 /* */
26 /* PORT SPECIFIC C INFORMATION RELEASE */
27 /* */
28 /* tx_port.h ARMv8-A */
29 /* 6.1.10 */
30 /* */
31 /* AUTHOR */
32 /* */
33 /* William E. Lamie, Microsoft Corporation */
34 /* */
35 /* DESCRIPTION */
36 /* */
37 /* This file contains data type definitions that make the ThreadX */
38 /* real-time kernel function identically on a variety of different */
39 /* processor architectures. For example, the size or number of bits */
40 /* in an "int" data type vary between microprocessor architectures and */
41 /* even C compilers for the same microprocessor. ThreadX does not */
42 /* directly use native C data types. Instead, ThreadX creates its */
43 /* own special types that can be mapped to actual data types by this */
44 /* file to guarantee consistency in the interface and functionality. */
45 /* */
46 /* RELEASE HISTORY */
47 /* */
48 /* DATE NAME DESCRIPTION */
49 /* */
50 /* 09-30-2020 William E. Lamie Initial Version 6.1 */
51 /* 01-31-2022 Bhupendra Naphade Modified comment(s),updated */
52 /* macro definition, */
53 /* resulting in version 6.1.10 */
54 /* */
55 /**************************************************************************/
56
57 #ifndef TX_PORT_H
58 #define TX_PORT_H
59
60
61 /* Determine if the optional ThreadX user define file should be used. */
62
63 #ifdef TX_INCLUDE_USER_DEFINE_FILE
64
65
66 /* Yes, include the user defines in tx_user.h. The defines in this file may
67 alternately be defined on the command line. */
68
69 #include "tx_user.h"
70 #endif
71
72
73 /* Define compiler library include files. */
74
75 #include <stdlib.h>
76 #include <string.h>
77
78
79 /* Define ThreadX basic types for this port. */
80
81 #define VOID void
82 typedef char CHAR;
83 typedef unsigned char UCHAR;
84 typedef int INT;
85 typedef unsigned int UINT;
86 typedef int LONG;
87 typedef unsigned int ULONG;
88 typedef unsigned long long ULONG64;
89 typedef short SHORT;
90 typedef unsigned short USHORT;
91 #define ULONG64_DEFINED
92
93 /* Override the alignment type to use 64-bit alignment and storage for pointers. */
94
95 #define ALIGN_TYPE_DEFINED
96 typedef unsigned long long ALIGN_TYPE;
97
98
99 /* Override the free block marker for byte pools to be a 64-bit constant. */
100
101 #define TX_BYTE_BLOCK_FREE ((ALIGN_TYPE) 0xFFFFEEEEFFFFEEEE)
102
103
104 /* Define the priority levels for ThreadX. Legal values range
105 from 32 to 1024 and MUST be evenly divisible by 32. */
106
107 #ifndef TX_MAX_PRIORITIES
108 #define TX_MAX_PRIORITIES 32
109 #endif
110
111
112 /* Define the minimum stack for a ThreadX thread on this processor. If the size supplied during
113 thread creation is less than this value, the thread create call will return an error. */
114
115 #ifndef TX_MINIMUM_STACK
116 #define TX_MINIMUM_STACK 200 /* Minimum stack size for this port */
117 #endif
118
119
120 /* Define the system timer thread's default stack size and priority. These are only applicable
121 if TX_TIMER_PROCESS_IN_ISR is not defined. */
122
123 #ifndef TX_TIMER_THREAD_STACK_SIZE
124 #define TX_TIMER_THREAD_STACK_SIZE 4096 /* Default timer thread stack size */
125 #endif
126
127 #ifndef TX_TIMER_THREAD_PRIORITY
128 #define TX_TIMER_THREAD_PRIORITY 0 /* Default timer thread priority */
129 #endif
130
131
132 /* Define various constants for the ThreadX ARM port. */
133
134 #define TX_INT_DISABLE 0xC0 /* Disable IRQ & FIQ interrupts */
135 #define TX_INT_ENABLE 0x00 /* Enable IRQ & FIQ interrupts */
136
137
138 /* Define the clock source for trace event entry time stamp. The following two item are port specific.
139 For example, if the time source is at the address 0x0a800024 and is 16-bits in size, the clock
140 source constants would be:
141
142 #define TX_TRACE_TIME_SOURCE *((ULONG *) 0x0a800024)
143 #define TX_TRACE_TIME_MASK 0x0000FFFFUL
144
145 */
146
147 #ifndef TX_MISRA_ENABLE
148 #ifndef TX_TRACE_TIME_SOURCE
149 #define TX_TRACE_TIME_SOURCE _tx_thread_smp_time_get()
150 #endif
151 #else
152 #ifndef TX_TRACE_TIME_SOURCE
153 ULONG _tx_misra_time_stamp_get(VOID);
154 #define TX_TRACE_TIME_SOURCE _tx_misra_time_stamp_get()
155 #endif
156 #endif
157 #ifndef TX_TRACE_TIME_MASK
158 #define TX_TRACE_TIME_MASK 0xFFFFFFFFUL
159 #endif
160
161
162 /* Define the port specific options for the _tx_build_options variable. This variable indicates
163 how the ThreadX library was built. */
164
165 #ifdef TX_ENABLE_FIQ_SUPPORT
166 #define TX_FIQ_ENABLED 1
167 #else
168 #define TX_FIQ_ENABLED 0
169 #endif
170
171 #ifdef TX_ENABLE_IRQ_NESTING
172 #define TX_IRQ_NESTING_ENABLED 2
173 #else
174 #define TX_IRQ_NESTING_ENABLED 0
175 #endif
176
177 #ifdef TX_ENABLE_FIQ_NESTING
178 #define TX_FIQ_NESTING_ENABLED 4
179 #else
180 #define TX_FIQ_NESTING_ENABLED 0
181 #endif
182
183 #define TX_PORT_SPECIFIC_BUILD_OPTIONS (TX_FIQ_ENABLED | TX_IRQ_NESTING_ENABLED | TX_FIQ_NESTING_ENABLED)
184
185
186 /* Define the in-line initialization constant so that modules with in-line
187 initialization capabilities can prevent their initialization from being
188 a function call. */
189
190 #ifdef TX_MISRA_ENABLE
191 #define TX_DISABLE_INLINE
192 #else
193 #define TX_INLINE_INITIALIZATION
194 #endif
195
196
197 /* Determine whether or not stack checking is enabled. By default, ThreadX stack checking is
198 disabled. When the following is defined, ThreadX thread stack checking is enabled. If stack
199 checking is enabled (TX_ENABLE_STACK_CHECKING is defined), the TX_DISABLE_STACK_FILLING
200 define is negated, thereby forcing the stack fill which is necessary for the stack checking
201 logic. */
202
203 #ifndef TX_MISRA_ENABLE
204 #ifdef TX_ENABLE_STACK_CHECKING
205 #undef TX_DISABLE_STACK_FILLING
206 #endif
207 #endif
208
209
210 /* Define the TX_THREAD control block extensions for this port. The main reason
211 for the multiple macros is so that backward compatibility can be maintained with
212 existing ThreadX kernel awareness modules. */
213
214 #define TX_THREAD_EXTENSION_0
215 #define TX_THREAD_EXTENSION_1
216 #define TX_THREAD_EXTENSION_2 ULONG tx_thread_fp_enable;
217 #define TX_THREAD_EXTENSION_3
218
219
220 /* Define the port extensions of the remaining ThreadX objects. */
221
222 #define TX_BLOCK_POOL_EXTENSION
223 #define TX_BYTE_POOL_EXTENSION
224 #define TX_EVENT_FLAGS_GROUP_EXTENSION
225 #define TX_MUTEX_EXTENSION
226 #define TX_QUEUE_EXTENSION
227 #define TX_SEMAPHORE_EXTENSION
228 #define TX_TIMER_EXTENSION
229
230
231 /* Define the user extension field of the thread control block. Nothing
232 additional is needed for this port so it is defined as white space. */
233
234 #ifndef TX_THREAD_USER_EXTENSION
235 #define TX_THREAD_USER_EXTENSION
236 #endif
237
238
239 /* Define the macros for processing extensions in tx_thread_create, tx_thread_delete,
240 tx_thread_shell_entry, and tx_thread_terminate. */
241
242
243 #define TX_THREAD_CREATE_EXTENSION(thread_ptr)
244 #define TX_THREAD_DELETE_EXTENSION(thread_ptr)
245 #define TX_THREAD_COMPLETED_EXTENSION(thread_ptr)
246 #define TX_THREAD_TERMINATED_EXTENSION(thread_ptr)
247
248
249 /* Define the ThreadX object creation extensions for the remaining objects. */
250
251 #define TX_BLOCK_POOL_CREATE_EXTENSION(pool_ptr)
252 #define TX_BYTE_POOL_CREATE_EXTENSION(pool_ptr)
253 #define TX_EVENT_FLAGS_GROUP_CREATE_EXTENSION(group_ptr)
254 #define TX_MUTEX_CREATE_EXTENSION(mutex_ptr)
255 #define TX_QUEUE_CREATE_EXTENSION(queue_ptr)
256 #define TX_SEMAPHORE_CREATE_EXTENSION(semaphore_ptr)
257 #define TX_TIMER_CREATE_EXTENSION(timer_ptr)
258
259
260 /* Define the ThreadX object deletion extensions for the remaining objects. */
261
262 #define TX_BLOCK_POOL_DELETE_EXTENSION(pool_ptr)
263 #define TX_BYTE_POOL_DELETE_EXTENSION(pool_ptr)
264 #define TX_EVENT_FLAGS_GROUP_DELETE_EXTENSION(group_ptr)
265 #define TX_MUTEX_DELETE_EXTENSION(mutex_ptr)
266 #define TX_QUEUE_DELETE_EXTENSION(queue_ptr)
267 #define TX_SEMAPHORE_DELETE_EXTENSION(semaphore_ptr)
268 #define TX_TIMER_DELETE_EXTENSION(timer_ptr)
269
270
271 /* Determine if the ARM architecture has the CLZ instruction. This is available on
272 architectures v5 and above. If available, redefine the macro for calculating the
273 lowest bit set. */
274
275 #ifndef TX_DISABLE_INLINE
276
277 #define TX_LOWEST_SET_BIT_CALCULATE(m, b) b = (UINT) __builtin_ctz((unsigned int) m);
278
279 #endif
280
281
282 /* Define the internal timer extension to also hold the thread pointer such that _tx_thread_timeout
283 can figure out what thread timeout to process. */
284
285 #define TX_TIMER_INTERNAL_EXTENSION VOID *tx_timer_internal_thread_timeout_ptr;
286
287
288 /* Define the thread timeout setup logic in _tx_thread_create. */
289
290 #define TX_THREAD_CREATE_TIMEOUT_SETUP(t) (t) -> tx_thread_timer.tx_timer_internal_timeout_function = &(_tx_thread_timeout); \
291 (t) -> tx_thread_timer.tx_timer_internal_timeout_param = 0; \
292 (t) -> tx_thread_timer.tx_timer_internal_thread_timeout_ptr = (VOID *) (t);
293
294
295 /* Define the thread timeout pointer setup in _tx_thread_timeout. */
296
297 #define TX_THREAD_TIMEOUT_POINTER_SETUP(t) (t) = (TX_THREAD *) _tx_timer_expired_timer_ptr -> tx_timer_internal_thread_timeout_ptr;
298
299
300 /* Define ThreadX interrupt lockout and restore macros for protection on
301 access of critical kernel information. The restore interrupt macro must
302 restore the interrupt posture of the running thread prior to the value
303 present prior to the disable macro. In most cases, the save area macro
304 is used to define a local function save area for the disable and restore
305 macros. */
306
307 #ifndef TX_DISABLE_INLINE
308
309 /* Define macros, with in-line assembly for performance. */
310
__disable_interrupts(void)311 __attribute__( ( always_inline ) ) static inline unsigned int __disable_interrupts(void)
312 {
313
314 unsigned long long daif_value;
315
316 __asm__ volatile (" MRS %0, DAIF ": "=r" (daif_value) );
317 __asm__ volatile (" MSR DAIFSet, 0x3" : : : "memory" );
318 return((unsigned int) daif_value);
319 }
320
__restore_interrupts(unsigned int daif_value)321 __attribute__( ( always_inline ) ) static inline void __restore_interrupts(unsigned int daif_value)
322 {
323
324 unsigned long long temp;
325
326 temp = (unsigned long long) daif_value;
327 __asm__ volatile (" MSR DAIF,%0": : "r" (temp): "memory" );
328 }
329
330
331 #define TX_INTERRUPT_SAVE_AREA UINT interrupt_save;
332 #define TX_DISABLE interrupt_save = __disable_interrupts();
333 #define TX_RESTORE __restore_interrupts(interrupt_save);
334
335 #else
336
337 unsigned int _tx_thread_interrupt_disable(void);
338 unsigned int _tx_thread_interrupt_restore(UINT old_posture);
339
340
341 #define TX_INTERRUPT_SAVE_AREA UINT interrupt_save;
342
343 #define TX_DISABLE interrupt_save = _tx_thread_interrupt_disable();
344 #define TX_RESTORE _tx_thread_interrupt_restore(interrupt_save);
345 #endif
346
347
348 /* Define the interrupt lockout macros for each ThreadX object. */
349
350 #define TX_BLOCK_POOL_DISABLE TX_DISABLE
351 #define TX_BYTE_POOL_DISABLE TX_DISABLE
352 #define TX_EVENT_FLAGS_GROUP_DISABLE TX_DISABLE
353 #define TX_MUTEX_DISABLE TX_DISABLE
354 #define TX_QUEUE_DISABLE TX_DISABLE
355 #define TX_SEMAPHORE_DISABLE TX_DISABLE
356
357
358 /* Define FP extension for ARMv8. Each is assumed to be called in the context of the executing thread. */
359
360 #ifndef TX_SOURCE_CODE
361 #define tx_thread_fp_enable _tx_thread_fp_enable
362 #define tx_thread_fp_disable _tx_thread_fp_disable
363 #endif
364
365 VOID tx_thread_fp_enable(VOID);
366 VOID tx_thread_fp_disable(VOID);
367
368
369 /* Define the version ID of ThreadX. This may be utilized by the application. */
370
371 #ifdef TX_THREAD_INIT
372 CHAR _tx_version_id[] =
373 "Copyright (c) Microsoft Corporation. All rights reserved. * ThreadX ARMv8-A Version 6.3.0 *";
374 #else
375 extern CHAR _tx_version_id[];
376 #endif
377
378
379 #endif
380