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                                            RXv1/IAR       */
29 /*                                                           6.1.11       */
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 /*  08-02-2021     William E. Lamie         Initial Version 6.1.8         */
51 /*  10-15-2021     William E. Lamie         Modified comment(s),          */
52 /*                                            resulting in version 6.1.9  */
53 /*  01-31-2022     William E. Lamie         Modified comment(s), removed  */
54 /*                                            system state macro, and     */
55 /*                                            added missing interrupt     */
56 /*                                            control defines,            */
57 /*                                            resulting in version 6.1.10 */
58 /*  04-25-2022     William E. Lamie         Modified comment(s),          */
59 /*                                            resulting in version 6.1.11 */
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
166 #define TX_THREAD_EXTENSION_3
167 
168 
169 /* Define the port extensions of the remaining ThreadX objects.  */
170 
171 #define TX_BLOCK_POOL_EXTENSION
172 #define TX_BYTE_POOL_EXTENSION
173 #define TX_EVENT_FLAGS_GROUP_EXTENSION
174 #define TX_MUTEX_EXTENSION
175 #define TX_QUEUE_EXTENSION
176 #define TX_SEMAPHORE_EXTENSION
177 #define TX_TIMER_EXTENSION
178 
179 
180 /* Define the user extension field of the thread control block.  Nothing
181    additional is needed for this port so it is defined as white space.  */
182 
183 #ifndef TX_THREAD_USER_EXTENSION
184 #define TX_THREAD_USER_EXTENSION
185 #endif
186 
187 
188 /* Define the macros for processing extensions in tx_thread_create, tx_thread_delete,
189    tx_thread_shell_entry, and tx_thread_terminate.  */
190 
191 
192 #define TX_THREAD_CREATE_EXTENSION(thread_ptr)
193 #define TX_THREAD_DELETE_EXTENSION(thread_ptr)
194 #define TX_THREAD_COMPLETED_EXTENSION(thread_ptr)
195 #define TX_THREAD_TERMINATED_EXTENSION(thread_ptr)
196 
197 
198 /* Define the ThreadX object creation extensions for the remaining objects.  */
199 
200 #define TX_BLOCK_POOL_CREATE_EXTENSION(pool_ptr)
201 #define TX_BYTE_POOL_CREATE_EXTENSION(pool_ptr)
202 #define TX_EVENT_FLAGS_GROUP_CREATE_EXTENSION(group_ptr)
203 #define TX_MUTEX_CREATE_EXTENSION(mutex_ptr)
204 #define TX_QUEUE_CREATE_EXTENSION(queue_ptr)
205 #define TX_SEMAPHORE_CREATE_EXTENSION(semaphore_ptr)
206 #define TX_TIMER_CREATE_EXTENSION(timer_ptr)
207 
208 
209 /* Define the ThreadX object deletion extensions for the remaining objects.  */
210 
211 #define TX_BLOCK_POOL_DELETE_EXTENSION(pool_ptr)
212 #define TX_BYTE_POOL_DELETE_EXTENSION(pool_ptr)
213 #define TX_EVENT_FLAGS_GROUP_DELETE_EXTENSION(group_ptr)
214 #define TX_MUTEX_DELETE_EXTENSION(mutex_ptr)
215 #define TX_QUEUE_DELETE_EXTENSION(queue_ptr)
216 #define TX_SEMAPHORE_DELETE_EXTENSION(semaphore_ptr)
217 #define TX_TIMER_DELETE_EXTENSION(timer_ptr)
218 
219 /* Define ThreadX interrupt lockout and restore macros for protection on
220    access of critical kernel information.  The restore interrupt macro must
221    restore the interrupt posture of the running thread prior to the value
222    present prior to the disable macro.  In most cases, the save area macro
223    is used to define a local function save area for the disable and restore
224    macros.  */
225 
226 #ifdef TX_DISABLE_INLINE
227 
228 UINT                                            _tx_thread_interrupt_disable(VOID);
229 VOID                                            _tx_thread_interrupt_restore(UINT previous_posture);
230 
231 #define TX_INTERRUPT_SAVE_AREA                  register UINT interrupt_save;
232 
233 #define TX_DISABLE                              interrupt_save = _tx_thread_interrupt_disable();
234 
235 #define TX_RESTORE                              _tx_thread_interrupt_restore(interrupt_save);
236 
237 #else
238 
239 #define TX_INTERRUPT_SAVE_AREA                  __istate_t interrupt_save;
240 #define TX_DISABLE                              {interrupt_save = __get_interrupt_state();__disable_interrupt();};
241 #define TX_RESTORE                              {__set_interrupt_state(interrupt_save);};
242 
243 #define _tx_thread_system_return                _tx_thread_system_return_inline
244 
_tx_thread_system_return_inline(void)245 static void _tx_thread_system_return_inline(void)
246 {
247     TX_INTERRUPT_SAVE_AREA
248 
249     TX_DISABLE
250 
251     *((volatile UCHAR *)(0x872E0u)) = 1u;
252 
253     TX_RESTORE
254 }
255 
256 #endif
257 
258 
259 /* Define the interrupt lockout macros for each ThreadX object.  */
260 
261 #define TX_BLOCK_POOL_DISABLE                   TX_DISABLE
262 #define TX_BYTE_POOL_DISABLE                    TX_DISABLE
263 #define TX_EVENT_FLAGS_GROUP_DISABLE            TX_DISABLE
264 #define TX_MUTEX_DISABLE                        TX_DISABLE
265 #define TX_QUEUE_DISABLE                        TX_DISABLE
266 #define TX_SEMAPHORE_DISABLE                    TX_DISABLE
267 
268 
269 /* Define the version ID of ThreadX.  This may be utilized by the application.  */
270 
271 #ifdef TX_THREAD_INIT
272 CHAR                            _tx_version_id[] =
273                                     "Copyright (c) Microsoft Corporation. All rights reserved.  *  ThreadX RXv1/IAR Version 6.3.0 *";
274 #else
275 extern  CHAR                    _tx_version_id[];
276 #endif
277 
278 
279 #endif
280 
281