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/IAR       */
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 #include <intrinsics.h>
78 #ifdef  TX_ENABLE_IAR_LIBRARY_SUPPORT
79 #include <yvals.h>
80 #endif
81 
82 
83 /* Define ThreadX basic types for this port.  */
84 
85 #define VOID                                    void
86 typedef char                                    CHAR;
87 typedef unsigned char                           UCHAR;
88 typedef int                                     INT;
89 typedef unsigned int                            UINT;
90 typedef long                                    LONG;
91 typedef unsigned long                           ULONG;
92 typedef short                                   SHORT;
93 typedef unsigned short                          USHORT;
94 
95 
96 /* Define the priority levels for ThreadX.  Legal values range
97    from 32 to 1024 and MUST be evenly divisible by 32.  */
98 
99 #ifndef TX_MAX_PRIORITIES
100 #define TX_MAX_PRIORITIES                       32
101 #endif
102 
103 
104 /* Define the minimum stack for a ThreadX thread on this processor. If the size supplied during
105    thread creation is less than this value, the thread create call will return an error.  */
106 
107 #ifndef TX_MINIMUM_STACK
108 #define TX_MINIMUM_STACK                        200         /* Minimum stack size for this port  */
109 #endif
110 
111 
112 /* Define the system timer thread's default stack size and priority.  These are only applicable
113    if TX_TIMER_PROCESS_IN_ISR is not defined.  */
114 
115 #ifndef TX_TIMER_THREAD_STACK_SIZE
116 #define TX_TIMER_THREAD_STACK_SIZE              1024        /* Default timer thread stack size  */
117 #endif
118 
119 #ifndef TX_TIMER_THREAD_PRIORITY
120 #define TX_TIMER_THREAD_PRIORITY                0           /* Default timer thread priority    */
121 #endif
122 
123 
124 /* Define various constants for the ThreadX ARM port.  */
125 
126 #ifdef TX_ENABLE_FIQ_SUPPORT
127 #define TX_INT_DISABLE                          0xC0        /* Disable IRQ & FIQ interrupts     */
128 #else
129 #define TX_INT_DISABLE                          0x80        /* Disable IRQ interrupts           */
130 #endif
131 #define TX_INT_ENABLE                           0x00        /* Enable IRQ interrupts            */
132 
133 
134 /* Define the clock source for trace event entry time stamp. The following two item are port specific.
135    For example, if the time source is at the address 0x0a800024 and is 16-bits in size, the clock
136    source constants would be:
137 
138 #define TX_TRACE_TIME_SOURCE                    *((ULONG *) 0x0a800024)
139 #define TX_TRACE_TIME_MASK                      0x0000FFFFUL
140 
141 */
142 
143 #ifndef TX_MISRA_ENABLE
144 #ifndef TX_TRACE_TIME_SOURCE
145 #define TX_TRACE_TIME_SOURCE                    ++_tx_trace_simulated_time
146 #endif
147 #else
148 ULONG   _tx_misra_time_stamp_get(VOID);
149 #define TX_TRACE_TIME_SOURCE                    _tx_misra_time_stamp_get()
150 #endif
151 
152 #ifndef TX_TRACE_TIME_MASK
153 #define TX_TRACE_TIME_MASK                      0xFFFFFFFFUL
154 #endif
155 
156 
157 /* Define the port specific options for the _tx_build_options variable. This variable indicates
158    how the ThreadX library was built.  */
159 
160 #ifdef TX_ENABLE_FIQ_SUPPORT
161 #define TX_FIQ_ENABLED                          1
162 #else
163 #define TX_FIQ_ENABLED                          0
164 #endif
165 
166 #ifdef TX_ENABLE_IRQ_NESTING
167 #define TX_IRQ_NESTING_ENABLED                  2
168 #else
169 #define TX_IRQ_NESTING_ENABLED                  0
170 #endif
171 
172 #ifdef TX_ENABLE_FIQ_NESTING
173 #define TX_FIQ_NESTING_ENABLED                  4
174 #else
175 #define TX_FIQ_NESTING_ENABLED                  0
176 #endif
177 
178 #define TX_PORT_SPECIFIC_BUILD_OPTIONS          (TX_FIQ_ENABLED | TX_IRQ_NESTING_ENABLED | TX_FIQ_NESTING_ENABLED)
179 
180 
181 /* Define the in-line initialization constant so that modules with in-line
182    initialization capabilities can prevent their initialization from being
183    a function call.  */
184 
185 #ifdef TX_MISRA_ENABLE
186 #define TX_DISABLE_INLINE
187 #else
188 #define TX_INLINE_INITIALIZATION
189 #endif
190 
191 
192 /* Determine whether or not stack checking is enabled. By default, ThreadX stack checking is
193    disabled. When the following is defined, ThreadX thread stack checking is enabled.  If stack
194    checking is enabled (TX_ENABLE_STACK_CHECKING is defined), the TX_DISABLE_STACK_FILLING
195    define is negated, thereby forcing the stack fill which is necessary for the stack checking
196    logic.  */
197 
198 #ifndef TX_MISRA_ENABLE
199 #ifdef TX_ENABLE_STACK_CHECKING
200 #undef TX_DISABLE_STACK_FILLING
201 #endif
202 #endif
203 
204 
205 /* Define the TX_THREAD control block extensions for this port. The main reason
206    for the multiple macros is so that backward compatibility can be maintained with
207    existing ThreadX kernel awareness modules.  */
208 
209 #define TX_THREAD_EXTENSION_0
210 #define TX_THREAD_EXTENSION_1
211 #ifdef  TX_ENABLE_IAR_LIBRARY_SUPPORT
212 #define TX_THREAD_EXTENSION_2           VOID    *tx_thread_iar_tls_pointer;
213 #else
214 #define TX_THREAD_EXTENSION_2
215 #endif
216 #define TX_THREAD_EXTENSION_3
217 
218 
219 /* Define the port extensions of the remaining ThreadX objects.  */
220 
221 #define TX_BLOCK_POOL_EXTENSION
222 #define TX_BYTE_POOL_EXTENSION
223 #define TX_EVENT_FLAGS_GROUP_EXTENSION
224 #define TX_MUTEX_EXTENSION
225 #define TX_QUEUE_EXTENSION
226 #define TX_SEMAPHORE_EXTENSION
227 #define TX_TIMER_EXTENSION
228 
229 
230 /* Define the user extension field of the thread control block.  Nothing
231    additional is needed for this port so it is defined as white space.  */
232 
233 #ifndef TX_THREAD_USER_EXTENSION
234 #define TX_THREAD_USER_EXTENSION
235 #endif
236 
237 
238 /* Define the macros for processing extensions in tx_thread_create, tx_thread_delete,
239    tx_thread_shell_entry, and tx_thread_terminate.  */
240 
241 
242 #ifdef  TX_ENABLE_IAR_LIBRARY_SUPPORT
243 #if (__VER__ < 8000000)
244 #define TX_THREAD_CREATE_EXTENSION(thread_ptr)                      thread_ptr -> tx_thread_iar_tls_pointer =  __iar_dlib_perthread_allocate();
245 #define TX_THREAD_DELETE_EXTENSION(thread_ptr)                      __iar_dlib_perthread_deallocate(thread_ptr -> tx_thread_iar_tls_pointer); \
246                                                                     thread_ptr -> tx_thread_iar_tls_pointer =  TX_NULL;
247 #define TX_PORT_SPECIFIC_PRE_SCHEDULER_INITIALIZATION               __iar_dlib_perthread_access(0);
248 #else
249 void    *_tx_iar_create_per_thread_tls_area(void);
250 void    _tx_iar_destroy_per_thread_tls_area(void *tls_ptr);
251 void    __iar_Initlocks(void);
252 
253 #define TX_THREAD_CREATE_EXTENSION(thread_ptr)                      thread_ptr -> tx_thread_iar_tls_pointer =  _tx_iar_create_per_thread_tls_area();
254 #define TX_THREAD_DELETE_EXTENSION(thread_ptr)                      do {_tx_iar_destroy_per_thread_tls_area(thread_ptr -> tx_thread_iar_tls_pointer); \
255                                                                         thread_ptr -> tx_thread_iar_tls_pointer =  TX_NULL; } while(0);
256 #define TX_PORT_SPECIFIC_PRE_SCHEDULER_INITIALIZATION               do {__iar_Initlocks();} while(0);
257 #endif
258 #else
259 #define TX_THREAD_CREATE_EXTENSION(thread_ptr)
260 #define TX_THREAD_DELETE_EXTENSION(thread_ptr)
261 #endif
262 #define TX_THREAD_COMPLETED_EXTENSION(thread_ptr)
263 #define TX_THREAD_TERMINATED_EXTENSION(thread_ptr)
264 
265 
266 /* Define the ThreadX object creation extensions for the remaining objects.  */
267 
268 #define TX_BLOCK_POOL_CREATE_EXTENSION(pool_ptr)
269 #define TX_BYTE_POOL_CREATE_EXTENSION(pool_ptr)
270 #define TX_EVENT_FLAGS_GROUP_CREATE_EXTENSION(group_ptr)
271 #define TX_MUTEX_CREATE_EXTENSION(mutex_ptr)
272 #define TX_QUEUE_CREATE_EXTENSION(queue_ptr)
273 #define TX_SEMAPHORE_CREATE_EXTENSION(semaphore_ptr)
274 #define TX_TIMER_CREATE_EXTENSION(timer_ptr)
275 
276 
277 /* Define the ThreadX object deletion extensions for the remaining objects.  */
278 
279 #define TX_BLOCK_POOL_DELETE_EXTENSION(pool_ptr)
280 #define TX_BYTE_POOL_DELETE_EXTENSION(pool_ptr)
281 #define TX_EVENT_FLAGS_GROUP_DELETE_EXTENSION(group_ptr)
282 #define TX_MUTEX_DELETE_EXTENSION(mutex_ptr)
283 #define TX_QUEUE_DELETE_EXTENSION(queue_ptr)
284 #define TX_SEMAPHORE_DELETE_EXTENSION(semaphore_ptr)
285 #define TX_TIMER_DELETE_EXTENSION(timer_ptr)
286 
287 
288 /* Determine if the ARM architecture has the CLZ instruction. This is available on
289    architectures v5 and above. If available, redefine the macro for calculating the
290    lowest bit set.  */
291 
292 #ifndef TX_DISABLE_INLINE
293 
294 #if __CORE__ > __ARM4TM__
295 
296 #if __CPU_MODE__ == 2
297 
298 #define TX_LOWEST_SET_BIT_CALCULATE(m, b)       m = m & ((ULONG) (-((LONG) m))); \
299                                                 b = (UINT) __CLZ(m); \
300                                                 b = 31 - b;
301 #endif
302 #endif
303 #endif
304 
305 
306 /* Define ThreadX interrupt lockout and restore macros for protection on
307    access of critical kernel information.  The restore interrupt macro must
308    restore the interrupt posture of the running thread prior to the value
309    present prior to the disable macro.  In most cases, the save area macro
310    is used to define a local function save area for the disable and restore
311    macros.  */
312 
313 
314 /* First, check and see what mode the file is being compiled in. The IAR compiler
315    defines __CPU_MODE__ to 1, if the Thumb mode is present, and 2 if ARM 32-bit mode
316    is present.  If ARM 32-bit mode is present, the fast CPSR manipulation macros
317    are available. Otherwise, if Thumb mode is present, we must use function calls.  */
318 
319 #ifdef TX_DISABLE_INLINE
320 
321 UINT  _tx_thread_interrupt_disable(void);
322 void  _tx_thread_interrupt_restore(UINT old_posture);
323 
324 
325 #define TX_INTERRUPT_SAVE_AREA      UINT  interrupt_save;
326 
327 #define TX_DISABLE                  interrupt_save =  _tx_thread_interrupt_disable();
328 #define TX_RESTORE                  _tx_thread_interrupt_restore(interrupt_save);
329 
330 #else
331 #if __CPU_MODE__ == 2
332 
333 #if (__VER__ < 8002000)
334 __intrinsic unsigned long __get_CPSR();
335 __intrinsic void          __set_CPSR( unsigned long );
336 #endif
337 
338 
339 #if (__VER__ < 8002000)
340 #define TX_INTERRUPT_SAVE_AREA      ULONG interrupt_save;
341 #else
342 #define TX_INTERRUPT_SAVE_AREA      UINT interrupt_save;
343 #endif
344 
345 #define TX_DISABLE                  interrupt_save =  __get_CPSR(); \
346                                     __set_CPSR(interrupt_save | TX_INT_DISABLE);
347 #define TX_RESTORE                  __set_CPSR(interrupt_save);
348 
349 #else
350 
351 UINT  _tx_thread_interrupt_disable(void);
352 void  _tx_thread_interrupt_restore(UINT old_posture);
353 
354 
355 #define TX_INTERRUPT_SAVE_AREA      UINT  interrupt_save;
356 
357 #define TX_DISABLE                  interrupt_save =  _tx_thread_interrupt_disable();
358 #define TX_RESTORE                  _tx_thread_interrupt_restore(interrupt_save);
359 
360 #endif
361 #endif
362 
363 
364 /* Define the interrupt lockout macros for each ThreadX object.  */
365 
366 #define TX_BLOCK_POOL_DISABLE                   TX_DISABLE
367 #define TX_BYTE_POOL_DISABLE                    TX_DISABLE
368 #define TX_EVENT_FLAGS_GROUP_DISABLE            TX_DISABLE
369 #define TX_MUTEX_DISABLE                        TX_DISABLE
370 #define TX_QUEUE_DISABLE                        TX_DISABLE
371 #define TX_SEMAPHORE_DISABLE                    TX_DISABLE
372 
373 
374 /* Define the version ID of ThreadX.  This may be utilized by the application.  */
375 
376 #ifdef TX_THREAD_INIT
377 CHAR                            _tx_version_id[] =
378                                     "Copyright (c) Microsoft Corporation. All rights reserved.  *  ThreadX ARM11/IAR Version 6.3.0 *";
379 #else
380 #ifdef TX_MISRA_ENABLE
381 extern  CHAR                    _tx_version_id[100];
382 #else
383 extern  CHAR                    _tx_version_id[];
384 #endif
385 #endif
386 
387 
388 #endif
389 
390 
391 
392