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                                            RXv2/IAR       */
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 /*  12-30-2020     William E. Lamie         Initial Version 6.1.3         */
51 /*  06-02-2021     William E. Lamie         Modified comments,            */
52 /*                                            resulting in version 6.1.7  */
53 /*  10-15-2021     William E. Lamie         Modified comment(s),          */
54 /*                                            resulting in version 6.1.9  */
55 /*  01-31-2022     William E. Lamie         Modified comment(s), removed  */
56 /*                                            system state macro, and     */
57 /*                                            added missing interrupt     */
58 /*                                            control defines,            */
59 /*                                            resulting in version 6.1.10 */
60 /*                                                                        */
61 /**************************************************************************/
62 
63 #ifndef TX_PORT_H
64 #define TX_PORT_H
65 
66 #include <string.h>
67 #include <intrinsics.h>
68 
69 /* Determine if the optional ThreadX user define file should be used.  */
70 
71 #ifdef TX_INCLUDE_USER_DEFINE_FILE
72 
73 
74 /* Yes, include the user defines in tx_user.h. The defines in this file may
75    alternately be defined on the command line.  */
76 
77 #include "tx_user.h"
78 #endif
79 
80 /* Define ThreadX basic types for this port.  */
81 
82 #define VOID                                    void
83 typedef char                                    CHAR;
84 typedef unsigned char                           UCHAR;
85 typedef int                                     INT;
86 typedef unsigned int                            UINT;
87 typedef long                                    LONG;
88 typedef unsigned long                           ULONG;
89 typedef short                                   SHORT;
90 typedef unsigned short                          USHORT;
91 
92 
93 /* Define interrupt control options.  */
94 
95 #define TX_INT_DISABLE                          0x00000000
96 #define TX_INT_ENABLE                           0x00010000
97 
98 
99 /* Define the priority levels for ThreadX.  Legal values range
100    from 32 to 1024 and MUST be evenly divisible by 32.  */
101 
102 #ifndef TX_MAX_PRIORITIES
103 #define TX_MAX_PRIORITIES                       32
104 #endif
105 
106 
107 /* Define the minimum stack for a ThreadX thread on this processor. If the size supplied during
108    thread creation is less than this value, the thread create call will return an error.  */
109 
110 #ifndef TX_MINIMUM_STACK
111 #define TX_MINIMUM_STACK                        256         /* Minimum stack size for this port  */
112 #endif
113 
114 
115 /* Define the system timer thread's default stack size and priority.  These are only applicable
116    if TX_TIMER_PROCESS_IN_ISR is not defined.  */
117 
118 #ifndef TX_TIMER_THREAD_STACK_SIZE
119 #define TX_TIMER_THREAD_STACK_SIZE              1024        /* Default timer thread stack size  */
120 #endif
121 
122 #ifndef TX_TIMER_THREAD_PRIORITY
123 #define TX_TIMER_THREAD_PRIORITY                0           /* Default timer thread priority    */
124 #endif
125 
126 
127 #ifndef TX_TRACE_TIME_SOURCE
128 #define TX_TRACE_TIME_SOURCE                    ++_tx_trace_simulated_time
129 #endif
130 #ifndef TX_TRACE_TIME_MASK
131 #define TX_TRACE_TIME_MASK                      0xFFFFFFFFUL
132 #endif
133 
134 
135 /* Define the port specific options for the _tx_build_options variable. This variable indicates
136    how the ThreadX library was built.  */
137 
138 #define TX_PORT_SPECIFIC_BUILD_OPTIONS          0
139 
140 
141 /* Define the in-line initialization constant so that modules with in-line
142    initialization capabilities can prevent their initialization from being
143    a function call.  */
144 
145 #define TX_INLINE_INITIALIZATION
146 
147 
148 /* Determine whether or not stack checking is enabled. By default, ThreadX stack checking is
149    disabled. When the following is defined, ThreadX thread stack checking is enabled.  If stack
150    checking is enabled (TX_ENABLE_STACK_CHECKING is defined), the TX_DISABLE_STACK_FILLING
151    define is negated, thereby forcing the stack fill which is necessary for the stack checking
152    logic.  */
153 
154 #ifdef TX_ENABLE_STACK_CHECKING
155 #undef TX_DISABLE_STACK_FILLING
156 #endif
157 
158 
159 /* Define the TX_THREAD control block extensions for this port. The main reason
160    for the multiple macros is so that backward compatibility can be maintained with
161    existing ThreadX kernel awareness modules.  */
162 
163 #define TX_THREAD_EXTENSION_0
164 #define TX_THREAD_EXTENSION_1
165 #define TX_THREAD_EXTENSION_2                   VOID    *tx_thread_module_instance_ptr;         \
166                                                 VOID    *tx_thread_module_entry_info_ptr;       \
167                                                 ULONG   tx_thread_module_current_user_mode;     \
168                                                 ULONG   tx_thread_module_user_mode;             \
169                                                 VOID    *tx_thread_module_kernel_stack_start;   \
170                                                 VOID    *tx_thread_module_kernel_stack_end;     \
171                                                 ULONG   tx_thread_module_kernel_stack_size;     \
172                                                 VOID    *tx_thread_module_stack_ptr;            \
173                                                 VOID    *tx_thread_module_stack_start;          \
174                                                 VOID    *tx_thread_module_stack_end;            \
175                                                 ULONG   tx_thread_module_stack_size;            \
176                                                 VOID    *tx_thread_module_reserved;             \
177                                                 VOID    *tx_thread_iar_tls_pointer;
178 #define TX_THREAD_EXTENSION_3
179 
180 
181 /* Define the port extensions of the remaining ThreadX objects.  */
182 
183 #define TX_BLOCK_POOL_EXTENSION
184 #define TX_BYTE_POOL_EXTENSION
185 #define TX_MUTEX_EXTENSION
186 #define TX_EVENT_FLAGS_GROUP_EXTENSION          VOID    *tx_event_flags_group_module_instance; \
187                                                 VOID   (*tx_event_flags_group_set_module_notify)(struct TX_EVENT_FLAGS_GROUP_STRUCT *group_ptr);
188 
189 #define TX_QUEUE_EXTENSION                      VOID    *tx_queue_module_instance; \
190                                                 VOID   (*tx_queue_send_module_notify)(struct TX_QUEUE_STRUCT *queue_ptr);
191 
192 #define TX_SEMAPHORE_EXTENSION                  VOID    *tx_semaphore_module_instance; \
193                                                 VOID   (*tx_semaphore_put_module_notify)(struct TX_SEMAPHORE_STRUCT *semaphore_ptr);
194 
195 #define TX_TIMER_EXTENSION                      VOID    *tx_timer_module_instance; \
196                                                 VOID   (*tx_timer_module_expiration_function)(ULONG id);
197 
198 
199 /* Define the user extension field of the thread control block.  Nothing
200    additional is needed for this port so it is defined as white space.  */
201 
202 #ifndef TX_THREAD_USER_EXTENSION
203 #define TX_THREAD_USER_EXTENSION
204 #endif
205 
206 
207 /* Define the macros for processing extensions in tx_thread_create, tx_thread_delete,
208    tx_thread_shell_entry, and tx_thread_terminate.  */
209 
210 
211 #define TX_THREAD_CREATE_EXTENSION(thread_ptr)
212 #define TX_THREAD_DELETE_EXTENSION(thread_ptr)
213 #define TX_THREAD_COMPLETED_EXTENSION(thread_ptr)
214 #define TX_THREAD_TERMINATED_EXTENSION(thread_ptr)
215 
216 
217 /* Define the ThreadX object creation extensions for the remaining objects.  */
218 
219 #define TX_BLOCK_POOL_CREATE_EXTENSION(pool_ptr)
220 #define TX_BYTE_POOL_CREATE_EXTENSION(pool_ptr)
221 #define TX_EVENT_FLAGS_GROUP_CREATE_EXTENSION(group_ptr)
222 #define TX_MUTEX_CREATE_EXTENSION(mutex_ptr)
223 #define TX_QUEUE_CREATE_EXTENSION(queue_ptr)
224 #define TX_SEMAPHORE_CREATE_EXTENSION(semaphore_ptr)
225 #define TX_TIMER_CREATE_EXTENSION(timer_ptr)
226 
227 
228 /* Define the ThreadX object deletion extensions for the remaining objects.  */
229 
230 #define TX_BLOCK_POOL_DELETE_EXTENSION(pool_ptr)
231 #define TX_BYTE_POOL_DELETE_EXTENSION(pool_ptr)
232 #define TX_EVENT_FLAGS_GROUP_DELETE_EXTENSION(group_ptr)
233 #define TX_MUTEX_DELETE_EXTENSION(mutex_ptr)
234 #define TX_QUEUE_DELETE_EXTENSION(queue_ptr)
235 #define TX_SEMAPHORE_DELETE_EXTENSION(semaphore_ptr)
236 #define TX_TIMER_DELETE_EXTENSION(timer_ptr)
237 
238 /* Define ThreadX interrupt lockout and restore macros for protection on
239    access of critical kernel information.  The restore interrupt macro must
240    restore the interrupt posture of the running thread prior to the value
241    present prior to the disable macro.  In most cases, the save area macro
242    is used to define a local function save area for the disable and restore
243    macros.  */
244 
245 #ifdef TX_DISABLE_INLINE
246 
247 UINT                                            _tx_thread_interrupt_disable(VOID);
248 VOID                                            _tx_thread_interrupt_restore(UINT previous_posture);
249 
250 #define TX_INTERRUPT_SAVE_AREA                  register UINT interrupt_save;
251 
252 #define TX_DISABLE                              interrupt_save = _tx_thread_interrupt_disable();
253 
254 #define TX_RESTORE                              _tx_thread_interrupt_restore(interrupt_save);
255 
256 #else
257 
258 #define TX_INTERRUPT_SAVE_AREA                  __istate_t interrupt_save;
259 #define TX_DISABLE                              {interrupt_save = __get_interrupt_state();__disable_interrupt();};
260 #define TX_RESTORE                              {__set_interrupt_state(interrupt_save);};
261 
262 #define _tx_thread_system_return                _tx_thread_system_return_inline
263 
_tx_thread_system_return_inline(void)264 static void _tx_thread_system_return_inline(void)
265 {
266     TX_INTERRUPT_SAVE_AREA
267 
268     TX_DISABLE
269 
270     *((volatile UCHAR *)(0x872E0u)) = 1u;
271 
272     TX_RESTORE
273 }
274 
275 #endif
276 
277 /* Define the interrupt lockout macros for each ThreadX object.  */
278 
279 #define TX_BLOCK_POOL_DISABLE                   TX_DISABLE
280 #define TX_BYTE_POOL_DISABLE                    TX_DISABLE
281 #define TX_EVENT_FLAGS_GROUP_DISABLE            TX_DISABLE
282 #define TX_MUTEX_DISABLE                        TX_DISABLE
283 #define TX_QUEUE_DISABLE                        TX_DISABLE
284 #define TX_SEMAPHORE_DISABLE                    TX_DISABLE
285 
286 
287 /* Define the version ID of ThreadX.  This may be utilized by the application.  */
288 
289 #ifdef TX_THREAD_INIT
290 CHAR                            _tx_version_id[] =
291                                     "Copyright (c) Microsoft Corporation. All rights reserved.  *  ThreadX RXv2/IAR Version 6.3.0 *";
292 #else
293 extern  CHAR                    _tx_version_id[];
294 #endif
295 
296 
297 #endif
298 
299