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                                           ARM11/AC5       */
29 /*                                                            6.1.6       */
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 /*  04-02-2021     Bhupendra Naphade        Modified comment(s),updated   */
52 /*                                            macro definition,           */
53 /*                                            resulting in version 6.1.6  */
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 long                                    LONG;
87 typedef unsigned long                           ULONG;
88 typedef short                                   SHORT;
89 typedef unsigned short                          USHORT;
90 
91 
92 /* Define the priority levels for ThreadX.  Legal values range
93    from 32 to 1024 and MUST be evenly divisible by 32.  */
94 
95 #ifndef TX_MAX_PRIORITIES
96 #define TX_MAX_PRIORITIES                       32
97 #endif
98 
99 
100 /* Define the minimum stack for a ThreadX thread on this processor. If the size supplied during
101    thread creation is less than this value, the thread create call will return an error.  */
102 
103 #ifndef TX_MINIMUM_STACK
104 #define TX_MINIMUM_STACK                        200         /* Minimum stack size for this port  */
105 #endif
106 
107 
108 /* Define the system timer thread's default stack size and priority.  These are only applicable
109    if TX_TIMER_PROCESS_IN_ISR is not defined.  */
110 
111 #ifndef TX_TIMER_THREAD_STACK_SIZE
112 #define TX_TIMER_THREAD_STACK_SIZE              1024        /* Default timer thread stack size  */
113 #endif
114 
115 #ifndef TX_TIMER_THREAD_PRIORITY
116 #define TX_TIMER_THREAD_PRIORITY                0           /* Default timer thread priority    */
117 #endif
118 
119 
120 /* Define various constants for the ThreadX ARM port.  */
121 
122 #ifdef TX_ENABLE_FIQ_SUPPORT
123 #define TX_INT_DISABLE                          0xC0        /* Disable IRQ & FIQ interrupts     */
124 #else
125 #define TX_INT_DISABLE                          0x80        /* Disable IRQ interrupts           */
126 #endif
127 #define TX_INT_ENABLE                           0x00        /* Enable IRQ interrupts            */
128 
129 
130 /* Define the clock source for trace event entry time stamp. The following two item are port specific.
131    For example, if the time source is at the address 0x0a800024 and is 16-bits in size, the clock
132    source constants would be:
133 
134 #define TX_TRACE_TIME_SOURCE                    *((ULONG *) 0x0a800024)
135 #define TX_TRACE_TIME_MASK                      0x0000FFFFUL
136 
137 */
138 
139 #ifndef TX_TRACE_TIME_SOURCE
140 #define TX_TRACE_TIME_SOURCE                    ++_tx_trace_simulated_time
141 #endif
142 #ifndef TX_TRACE_TIME_MASK
143 #define TX_TRACE_TIME_MASK                      0xFFFFFFFFUL
144 #endif
145 
146 
147 /* Define the port specific options for the _tx_build_options variable. This variable indicates
148    how the ThreadX library was built.  */
149 
150 #ifdef TX_ENABLE_FIQ_SUPPORT
151 #define TX_FIQ_ENABLED                          1
152 #else
153 #define TX_FIQ_ENABLED                          0
154 #endif
155 
156 #ifdef TX_ENABLE_IRQ_NESTING
157 #define TX_IRQ_NESTING_ENABLED                  2
158 #else
159 #define TX_IRQ_NESTING_ENABLED                  0
160 #endif
161 
162 #ifdef TX_ENABLE_FIQ_NESTING
163 #define TX_FIQ_NESTING_ENABLED                  4
164 #else
165 #define TX_FIQ_NESTING_ENABLED                  0
166 #endif
167 
168 #define TX_PORT_SPECIFIC_BUILD_OPTIONS          TX_FIQ_ENABLED | TX_IRQ_NESTING_ENABLED | TX_FIQ_NESTING_ENABLED
169 
170 
171 /* Define the in-line initialization constant so that modules with in-line
172    initialization capabilities can prevent their initialization from being
173    a function call.  */
174 
175 #define TX_INLINE_INITIALIZATION
176 
177 
178 /* Determine whether or not stack checking is enabled. By default, ThreadX stack checking is
179    disabled. When the following is defined, ThreadX thread stack checking is enabled.  If stack
180    checking is enabled (TX_ENABLE_STACK_CHECKING is defined), the TX_DISABLE_STACK_FILLING
181    define is negated, thereby forcing the stack fill which is necessary for the stack checking
182    logic.  */
183 
184 #ifdef TX_ENABLE_STACK_CHECKING
185 #undef TX_DISABLE_STACK_FILLING
186 #endif
187 
188 
189 /* Define the TX_THREAD control block extensions for this port. The main reason
190    for the multiple macros is so that backward compatibility can be maintained with
191    existing ThreadX kernel awareness modules.  */
192 
193 #define TX_THREAD_EXTENSION_0
194 #define TX_THREAD_EXTENSION_1
195 #define TX_THREAD_EXTENSION_2
196 #define TX_THREAD_EXTENSION_3
197 
198 
199 /* Define the port extensions of the remaining ThreadX objects.  */
200 
201 #define TX_BLOCK_POOL_EXTENSION
202 #define TX_BYTE_POOL_EXTENSION
203 #define TX_EVENT_FLAGS_GROUP_EXTENSION
204 #define TX_MUTEX_EXTENSION
205 #define TX_QUEUE_EXTENSION
206 #define TX_SEMAPHORE_EXTENSION
207 #define TX_TIMER_EXTENSION
208 
209 
210 /* Define the user extension field of the thread control block.  Nothing
211    additional is needed for this port so it is defined as white space.  */
212 
213 #ifndef TX_THREAD_USER_EXTENSION
214 #define TX_THREAD_USER_EXTENSION
215 #endif
216 
217 
218 /* Define the macros for processing extensions in tx_thread_create, tx_thread_delete,
219    tx_thread_shell_entry, and tx_thread_terminate.  */
220 
221 
222 #define TX_THREAD_CREATE_EXTENSION(thread_ptr)
223 #define TX_THREAD_DELETE_EXTENSION(thread_ptr)
224 #define TX_THREAD_COMPLETED_EXTENSION(thread_ptr)
225 #define TX_THREAD_TERMINATED_EXTENSION(thread_ptr)
226 
227 
228 /* Define the ThreadX object creation extensions for the remaining objects.  */
229 
230 #define TX_BLOCK_POOL_CREATE_EXTENSION(pool_ptr)
231 #define TX_BYTE_POOL_CREATE_EXTENSION(pool_ptr)
232 #define TX_EVENT_FLAGS_GROUP_CREATE_EXTENSION(group_ptr)
233 #define TX_MUTEX_CREATE_EXTENSION(mutex_ptr)
234 #define TX_QUEUE_CREATE_EXTENSION(queue_ptr)
235 #define TX_SEMAPHORE_CREATE_EXTENSION(semaphore_ptr)
236 #define TX_TIMER_CREATE_EXTENSION(timer_ptr)
237 
238 
239 /* Define the ThreadX object deletion extensions for the remaining objects.  */
240 
241 #define TX_BLOCK_POOL_DELETE_EXTENSION(pool_ptr)
242 #define TX_BYTE_POOL_DELETE_EXTENSION(pool_ptr)
243 #define TX_EVENT_FLAGS_GROUP_DELETE_EXTENSION(group_ptr)
244 #define TX_MUTEX_DELETE_EXTENSION(mutex_ptr)
245 #define TX_QUEUE_DELETE_EXTENSION(queue_ptr)
246 #define TX_SEMAPHORE_DELETE_EXTENSION(semaphore_ptr)
247 #define TX_TIMER_DELETE_EXTENSION(timer_ptr)
248 
249 
250 /* Determine if the ARM architecture has the CLZ instruction. This is available on
251    architectures v5 and above. If available, redefine the macro for calculating the
252    lowest bit set.  */
253 
254 #ifndef __thumb
255 
256 #define TX_LOWEST_SET_BIT_CALCULATE(m, b)       m = m & ((ULONG) (-((LONG) m))); \
257                                                 b = (ULONG) __clz((unsigned int) m); \
258                                                 b = 31 - b;
259 #endif
260 
261 
262 /* Define ThreadX interrupt lockout and restore macros for protection on
263    access of critical kernel information.  The restore interrupt macro must
264    restore the interrupt posture of the running thread prior to the value
265    present prior to the disable macro.  In most cases, the save area macro
266    is used to define a local function save area for the disable and restore
267    macros.  */
268 
269 #ifndef __thumb
270 
271 #define TX_INTERRUPT_SAVE_AREA                  register UINT interrupt_save_disabled;
272 
273 #ifdef  TX_ENABLE_FIQ_SUPPORT
274 
275 /* IRQ and FIQ support.  */
276 
277 #define TX_DISABLE                              __memory_changed(), interrupt_save_disabled =  __disable_irq(); \
278                                                 __disable_fiq();
279 
280 #define TX_RESTORE                              if (!interrupt_save_disabled) \
281                                                 { \
282                                                     __enable_irq(); \
283                                                     __enable_fiq(); \
284                                                 }
285 
286 #else
287 
288 #define TX_DISABLE                              __memory_changed(), interrupt_save_disabled =  __disable_irq();
289 
290 #define TX_RESTORE                              if (!interrupt_save_disabled) \
291                                                 { \
292                                                     __enable_irq(); \
293                                                 }
294 #endif
295 
296 #else
297 
298 unsigned int   _tx_thread_interrupt_disable(void);
299 unsigned int   _tx_thread_interrupt_restore(UINT old_posture);
300 
301 
302 #define TX_INTERRUPT_SAVE_AREA                  UINT interrupt_save;
303 
304 #define TX_DISABLE                              interrupt_save =  _tx_thread_interrupt_disable();
305 #define TX_RESTORE                              _tx_thread_interrupt_restore(interrupt_save);
306 #endif
307 
308 
309 /* Define the interrupt lockout macros for each ThreadX object.  */
310 
311 #define TX_BLOCK_POOL_DISABLE                   TX_DISABLE
312 #define TX_BYTE_POOL_DISABLE                    TX_DISABLE
313 #define TX_EVENT_FLAGS_GROUP_DISABLE            TX_DISABLE
314 #define TX_MUTEX_DISABLE                        TX_DISABLE
315 #define TX_QUEUE_DISABLE                        TX_DISABLE
316 #define TX_SEMAPHORE_DISABLE                    TX_DISABLE
317 
318 
319 /* Define the version ID of ThreadX.  This may be utilized by the application.  */
320 
321 #ifdef TX_THREAD_INIT
322 CHAR                            _tx_version_id[] =
323                                     "Copyright (c) Microsoft Corporation. All rights reserved.  *  ThreadX ARM11/AC5 Version 6.3.0 *";
324 #else
325 extern  CHAR                    _tx_version_id[];
326 #endif
327 
328 
329 #endif
330 
331