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                                       SMP/ARC_HS/MetaWare */
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 /* Remove volatile for ThreadX source on the ARC. This is because the ARC
62    compiler generates different non-cache r/w access when using volatile
63    that is different from the assembly language access of the same
64    global variables in ThreadX.  */
65 
66 #ifdef TX_SOURCE_CODE
67 #define volatile
68 #else
69 #ifdef NX_SOURCE_CODE
70 #define volatile
71 #else
72 #ifdef FX_SOURCE_CODE
73 #define volatile
74 #else
75 #ifdef UX_SOURCE_CODE
76 #define volatile
77 #endif
78 #endif
79 #endif
80 #endif
81 
82 /************* Define ThreadX SMP constants.  *************/
83 
84 /* Define the ThreadX SMP maximum number of cores.  */
85 
86 #ifndef TX_THREAD_SMP_MAX_CORES
87 #define TX_THREAD_SMP_MAX_CORES                 2
88 #endif
89 
90 
91 /* Define the ThreadX SMP core mask. */
92 
93 #ifndef TX_THREAD_SMP_CORE_MASK
94 #define TX_THREAD_SMP_CORE_MASK                 0x3            /* Where bit 0 represents Core 0, bit 1 represents Core 1, etc.  */
95 #endif
96 
97 
98 /* Define INLINE_DECLARE to whitespace for MetaWare compiler.  */
99 
100 #define INLINE_DECLARE
101 
102 
103 /* Define dynamic number of cores option.  When commented out, the number of cores is static.  */
104 
105 /* #define TX_THREAD_SMP_DYNAMIC_CORE_MAX  */
106 
107 
108 /* Define ThreadX SMP initialization macro.  */
109 
110 #define TX_PORT_SPECIFIC_PRE_INITIALIZATION
111 
112 
113 /* Define ThreadX SMP pre-scheduler initialization.  */
114 
115 #define TX_PORT_SPECIFIC_PRE_SCHEDULER_INITIALIZATION
116 
117 
118 /* Enable the inter-core interrupt logic.  */
119 
120 #define TX_THREAD_SMP_INTER_CORE_INTERRUPT
121 
122 
123 /* Determine if there is customer-specific wakeup logic needed.  */
124 
125 #ifdef TX_THREAD_SMP_WAKEUP_LOGIC
126 
127 /* Include customer-specific wakeup code.  */
128 
129 #include "tx_thread_smp_core_wakeup.h"
130 #else
131 
132 #ifdef TX_THREAD_SMP_DEFAULT_WAKEUP_LOGIC
133 
134 /* Default wakeup code.  */
135 #define TX_THREAD_SMP_WAKEUP_LOGIC
136 #define TX_THREAD_SMP_WAKEUP(i)                _tx_thread_smp_core_preempt(i)
137 #endif
138 #endif
139 
140 
141 /* Ensure that the in-line resume/suspend define is not allowed.  */
142 
143 #ifdef TX_INLINE_THREAD_RESUME_SUSPEND
144 #undef TX_INLINE_THREAD_RESUME_SUSPEND
145 #endif
146 
147 /************* End ThreadX SMP constants.  *************/
148 
149 
150 /* Determine if the optional ThreadX user define file should be used.  */
151 
152 #ifdef TX_INCLUDE_USER_DEFINE_FILE
153 
154 
155 /* Yes, include the user defines in tx_user.h. The defines in this file may
156    alternately be defined on the command line.  */
157 
158 #include "tx_user.h"
159 #endif
160 
161 
162 /* Define compiler library include files.  */
163 
164 #include <stdlib.h>
165 #include <string.h>
166 
167 
168 /* Define ThreadX basic types for this port.  */
169 
170 #define VOID                                    void
171 typedef char                                    CHAR;
172 typedef unsigned char                           UCHAR;
173 typedef int                                     INT;
174 typedef unsigned int                            UINT;
175 typedef long                                    LONG;
176 typedef unsigned long                           ULONG;
177 typedef short                                   SHORT;
178 typedef unsigned short                          USHORT;
179 
180 
181 /* Define the priority levels for ThreadX.  Legal values range
182    from 32 to 1024 and MUST be evenly divisible by 32.  */
183 
184 #ifndef TX_MAX_PRIORITIES
185 #define TX_MAX_PRIORITIES                       32
186 #endif
187 
188 
189 /* Define the minimum stack for a ThreadX thread on this processor. If the size supplied during
190    thread creation is less than this value, the thread create call will return an error.  */
191 
192 #ifndef TX_MINIMUM_STACK
193 #define TX_MINIMUM_STACK                        800         /* Minimum stack size for this port  */
194 #endif
195 
196 
197 /* Define the system timer thread's default stack size and priority.  These are only applicable
198    if TX_TIMER_PROCESS_IN_ISR is not defined.  */
199 
200 #ifndef TX_TIMER_THREAD_STACK_SIZE
201 #define TX_TIMER_THREAD_STACK_SIZE              2048        /* Default timer thread stack size  */
202 #endif
203 
204 #ifndef TX_TIMER_THREAD_PRIORITY
205 #define TX_TIMER_THREAD_PRIORITY                0           /* Default timer thread priority    */
206 #endif
207 
208 
209 /* Define various constants for the ThreadX ARC HS port.  */
210 
211 #define TX_INT_ENABLE                           0x0000001F  /* Enable all interrupts            */
212 #define TX_INT_DISABLE_MASK                     0x00000000  /* Disable all interrupts           */
213 
214 
215 /* Define the clock source for trace event entry time stamp. The following two item are port specific.
216    For example, if the time source is at the address 0x0a800024 and is 16-bits in size, the clock
217    source constants would be:
218 
219 #define TX_TRACE_TIME_SOURCE                    *((ULONG *) 0x0a800024)
220 #define TX_TRACE_TIME_MASK                      0x0000FFFFUL
221 
222 */
223 
224 #ifndef TX_MISRA_ENABLE
225 #ifndef TX_TRACE_TIME_SOURCE
226 #define TX_TRACE_TIME_SOURCE                                _tx_thread_smp_time_get()
227 #endif
228 #else
229 #ifndef TX_TRACE_TIME_SOURCE
230 ULONG   _tx_misra_time_stamp_get(VOID);
231 #define TX_TRACE_TIME_SOURCE                                _tx_misra_time_stamp_get()
232 #endif
233 #endif
234 #ifndef TX_TRACE_TIME_MASK
235 #define TX_TRACE_TIME_MASK                                  0xFFFFFFFFUL
236 #endif
237 
238 
239 /* Define the port specific options for the _tx_build_options variable. This variable indicates
240    how the ThreadX library was built.  */
241 
242 #define TX_PORT_SPECIFIC_BUILD_OPTIONS          (0)
243 
244 
245 /* Define the in-line initialization constant so that modules with in-line
246    initialization capabilities can prevent their initialization from being
247    a function call.  */
248 
249 #ifdef TX_MISRA_ENABLE
250 #define TX_DISABLE_INLINE
251 #else
252 #define TX_INLINE_INITIALIZATION
253 #endif
254 
255 
256 /* Determine whether or not stack checking is enabled. By default, ThreadX stack checking is
257    disabled. When the following is defined, ThreadX thread stack checking is enabled.  If stack
258    checking is enabled (TX_ENABLE_STACK_CHECKING is defined), the TX_DISABLE_STACK_FILLING
259    define is negated, thereby forcing the stack fill which is necessary for the stack checking
260    logic.  */
261 
262 #ifndef TX_MISRA_ENABLE
263 #ifdef TX_ENABLE_STACK_CHECKING
264 #undef TX_DISABLE_STACK_FILLING
265 #endif
266 #endif
267 
268 
269 /* Define the TX_THREAD control block extensions for this port. The main reason
270    for the multiple macros is so that backward compatibility can be maintained with
271    existing ThreadX kernel awareness modules.  */
272 
273 #define TX_THREAD_EXTENSION_0       VOID        *__mw_threadx_tls; \
274                                     int         __mw_errnum; \
275                                     VOID        (*__mw_thread_exit)(struct TX_THREAD_STRUCT *);
276 #define TX_THREAD_EXTENSION_1
277 #define TX_THREAD_EXTENSION_2
278 #define TX_THREAD_EXTENSION_3
279 
280 
281 /* Define the port extensions of the remaining ThreadX objects.  */
282 
283 #define TX_BLOCK_POOL_EXTENSION
284 #define TX_BYTE_POOL_EXTENSION
285 #define TX_EVENT_FLAGS_GROUP_EXTENSION
286 #define TX_MUTEX_EXTENSION
287 #define TX_QUEUE_EXTENSION
288 #define TX_SEMAPHORE_EXTENSION
289 #define TX_TIMER_EXTENSION
290 
291 
292 /* Define the user extension field of the thread control block.  Nothing
293    additional is needed for this port so it is defined as white space.  */
294 
295 #ifndef TX_THREAD_USER_EXTENSION
296 #define TX_THREAD_USER_EXTENSION
297 #endif
298 
299 
300 /* Define the macros for processing extensions in tx_thread_create, tx_thread_delete,
301    tx_thread_shell_entry, and tx_thread_terminate.  */
302 
303 #if __HIGHC__
304 
305 /* The MetaWare thread safe C/C++ runtime library needs space to
306    store thread specific information.  In addition, a function pointer
307    is also supplied so that certain thread-specific resources may be
308    released upon thread termination and/or thread completion.  */
309 
310 #define TX_THREAD_CREATE_EXTENSION(thread_ptr)          \
311                                                         thread_ptr -> __mw_threadx_tls = 0; \
312                                                         thread_ptr -> __mw_errnum = 0; \
313                                                         thread_ptr -> __mw_thread_exit =  TX_NULL;
314 #define TX_THREAD_DELETE_EXTENSION(thread_ptr)
315 #define TX_THREAD_COMPLETED_EXTENSION(thread_ptr)       \
316                                                         if (thread_ptr -> __mw_thread_exit) \
317                                                             (thread_ptr -> __mw_thread_exit) (thread_ptr);
318 #define TX_THREAD_TERMINATED_EXTENSION(thread_ptr)      \
319                                                         if (thread_ptr -> __mw_thread_exit) \
320                                                             (thread_ptr -> __mw_thread_exit) (thread_ptr);
321 
322 #else
323 
324 #define TX_THREAD_CREATE_EXTENSION(thread_ptr)
325 #define TX_THREAD_DELETE_EXTENSION(thread_ptr)
326 #define TX_THREAD_COMPLETED_EXTENSION(thread_ptr)
327 #define TX_THREAD_TERMINATED_EXTENSION(thread_ptr)
328 
329 #endif
330 
331 
332 /* Define the ThreadX object creation extensions for the remaining objects.  */
333 
334 #define TX_BLOCK_POOL_CREATE_EXTENSION(pool_ptr)
335 #define TX_BYTE_POOL_CREATE_EXTENSION(pool_ptr)
336 #define TX_EVENT_FLAGS_GROUP_CREATE_EXTENSION(group_ptr)
337 #define TX_MUTEX_CREATE_EXTENSION(mutex_ptr)
338 #define TX_QUEUE_CREATE_EXTENSION(queue_ptr)
339 #define TX_SEMAPHORE_CREATE_EXTENSION(semaphore_ptr)
340 #define TX_TIMER_CREATE_EXTENSION(timer_ptr)
341 
342 
343 /* Define the ThreadX object deletion extensions for the remaining objects.  */
344 
345 #define TX_BLOCK_POOL_DELETE_EXTENSION(pool_ptr)
346 #define TX_BYTE_POOL_DELETE_EXTENSION(pool_ptr)
347 #define TX_EVENT_FLAGS_GROUP_DELETE_EXTENSION(group_ptr)
348 #define TX_MUTEX_DELETE_EXTENSION(mutex_ptr)
349 #define TX_QUEUE_DELETE_EXTENSION(queue_ptr)
350 #define TX_SEMAPHORE_DELETE_EXTENSION(semaphore_ptr)
351 #define TX_TIMER_DELETE_EXTENSION(timer_ptr)
352 
353 
354 /************* Define ThreadX SMP data types and function prototypes.  *************/
355 
356 struct TX_THREAD_STRUCT;
357 
358 
359 /* Define the ThreadX SMP protection structure.   */
360 
361 typedef struct TX_THREAD_SMP_PROTECT_STRUCT
362 {
363     ULONG           tx_thread_smp_protect_in_force;
364     struct TX_THREAD_STRUCT *
365                     tx_thread_smp_protect_thread;
366     ULONG           tx_thread_smp_protect_core;
367     ULONG           tx_thread_smp_protect_count;
368 
369     /* Implementation specific information follows.  */
370 
371     ULONG           tx_thread_smp_protect_get_caller;
372     ULONG           tx_thread_smp_protect_status32;
373     ULONG           tx_thread_smp_protect_release_caller;
374 } TX_THREAD_SMP_PROTECT;
375 
376 
377 /* Define ThreadX interrupt lockout and restore macros for protection on
378    access of critical kernel information.  The restore interrupt macro must
379    restore the interrupt posture of the running thread prior to the value
380    present prior to the disable macro.  In most cases, the save area macro
381    is used to define a local function save area for the disable and restore
382    macros.  */
383 
384 #define TX_INTERRUPT_SAVE_AREA                  UINT interrupt_save;
385 
386 #define TX_DISABLE                              interrupt_save =  _tx_thread_smp_protect();
387 #define TX_RESTORE                              _tx_thread_smp_unprotect(interrupt_save);
388 
389 
390 /************* End ThreadX SMP data type and function prototype definitions.  *************/
391 
392 
393 /* Define the interrupt lockout macros for each ThreadX object.  */
394 
395 #define TX_BLOCK_POOL_DISABLE                   TX_DISABLE
396 #define TX_BYTE_POOL_DISABLE                    TX_DISABLE
397 #define TX_EVENT_FLAGS_GROUP_DISABLE            TX_DISABLE
398 #define TX_MUTEX_DISABLE                        TX_DISABLE
399 #define TX_QUEUE_DISABLE                        TX_DISABLE
400 #define TX_SEMAPHORE_DISABLE                    TX_DISABLE
401 
402 
403 /* Define the version ID of ThreadX.  This may be utilized by the application.  */
404 
405 #ifdef TX_THREAD_INIT
406 CHAR                            _tx_version_id[] =
407                                     "Copyright (c) Microsoft Corporation. All rights reserved.  *  ThreadX SMP/ARC_HS/MetaWare Version 6.2.1 *";
408 #else
409 extern  CHAR                    _tx_version_id[];
410 #endif
411 
412 
413 #endif
414 
415 
416 
417 
418 
419