1 /*************************************************************************** 2 * Copyright (c) 2024 Microsoft Corporation 3 * 4 * This program and the accompanying materials are made available under the 5 * terms of the MIT License which is available at 6 * https://opensource.org/licenses/MIT. 7 * 8 * SPDX-License-Identifier: MIT 9 **************************************************************************/ 10 11 12 /**************************************************************************/ 13 /**************************************************************************/ 14 /** */ 15 /** ThreadX Component */ 16 /** */ 17 /** Port Specific */ 18 /** */ 19 /**************************************************************************/ 20 /**************************************************************************/ 21 22 23 /**************************************************************************/ 24 /* */ 25 /* PORT SPECIFIC C INFORMATION RELEASE */ 26 /* */ 27 /* tx_port.h ARM9/AC5 */ 28 /* 6.1.6 */ 29 /* */ 30 /* AUTHOR */ 31 /* */ 32 /* William E. Lamie, Microsoft Corporation */ 33 /* */ 34 /* DESCRIPTION */ 35 /* */ 36 /* This file contains data type definitions that make the ThreadX */ 37 /* real-time kernel function identically on a variety of different */ 38 /* processor architectures. For example, the size or number of bits */ 39 /* in an "int" data type vary between microprocessor architectures and */ 40 /* even C compilers for the same microprocessor. ThreadX does not */ 41 /* directly use native C data types. Instead, ThreadX creates its */ 42 /* own special types that can be mapped to actual data types by this */ 43 /* file to guarantee consistency in the interface and functionality. */ 44 /* */ 45 /* RELEASE HISTORY */ 46 /* */ 47 /* DATE NAME DESCRIPTION */ 48 /* */ 49 /* 09-30-2020 William E. Lamie Initial Version 6.1 */ 50 /* 04-02-2021 Bhupendra Naphade Modified comment(s),updated */ 51 /* macro definition, */ 52 /* resulting in version 6.1.6 */ 53 /* */ 54 /**************************************************************************/ 55 56 #ifndef TX_PORT_H 57 #define TX_PORT_H 58 59 60 /* Determine if the optional ThreadX user define file should be used. */ 61 62 #ifdef TX_INCLUDE_USER_DEFINE_FILE 63 64 65 /* Yes, include the user defines in tx_user.h. The defines in this file may 66 alternately be defined on the command line. */ 67 68 #include "tx_user.h" 69 #endif 70 71 72 /* Define compiler library include files. */ 73 74 #include <stdlib.h> 75 #include <string.h> 76 77 78 /* Define ThreadX basic types for this port. */ 79 80 #define VOID void 81 typedef char CHAR; 82 typedef unsigned char UCHAR; 83 typedef int INT; 84 typedef unsigned int UINT; 85 typedef long LONG; 86 typedef unsigned long ULONG; 87 typedef short SHORT; 88 typedef unsigned short USHORT; 89 90 91 /* Define the priority levels for ThreadX. Legal values range 92 from 32 to 1024 and MUST be evenly divisible by 32. */ 93 94 #ifndef TX_MAX_PRIORITIES 95 #define TX_MAX_PRIORITIES 32 96 #endif 97 98 99 /* Define the minimum stack for a ThreadX thread on this processor. If the size supplied during 100 thread creation is less than this value, the thread create call will return an error. */ 101 102 #ifndef TX_MINIMUM_STACK 103 #define TX_MINIMUM_STACK 200 /* Minimum stack size for this port */ 104 #endif 105 106 107 /* Define the system timer thread's default stack size and priority. These are only applicable 108 if TX_TIMER_PROCESS_IN_ISR is not defined. */ 109 110 #ifndef TX_TIMER_THREAD_STACK_SIZE 111 #define TX_TIMER_THREAD_STACK_SIZE 1024 /* Default timer thread stack size */ 112 #endif 113 114 #ifndef TX_TIMER_THREAD_PRIORITY 115 #define TX_TIMER_THREAD_PRIORITY 0 /* Default timer thread priority */ 116 #endif 117 118 119 /* Define various constants for the ThreadX ARM port. */ 120 121 #ifdef TX_ENABLE_FIQ_SUPPORT 122 #define TX_INT_DISABLE 0xC0 /* Disable IRQ & FIQ interrupts */ 123 #else 124 #define TX_INT_DISABLE 0x80 /* Disable IRQ interrupts */ 125 #endif 126 #define TX_INT_ENABLE 0x00 /* Enable IRQ interrupts */ 127 128 129 /* Define the clock source for trace event entry time stamp. The following two item are port specific. 130 For example, if the time source is at the address 0x0a800024 and is 16-bits in size, the clock 131 source constants would be: 132 133 #define TX_TRACE_TIME_SOURCE *((ULONG *) 0x0a800024) 134 #define TX_TRACE_TIME_MASK 0x0000FFFFUL 135 136 */ 137 138 #ifndef TX_TRACE_TIME_SOURCE 139 #define TX_TRACE_TIME_SOURCE ++_tx_trace_simulated_time 140 #endif 141 #ifndef TX_TRACE_TIME_MASK 142 #define TX_TRACE_TIME_MASK 0xFFFFFFFFUL 143 #endif 144 145 146 /* Define the port specific options for the _tx_build_options variable. This variable indicates 147 how the ThreadX library was built. */ 148 149 #ifdef TX_ENABLE_FIQ_SUPPORT 150 #define TX_FIQ_ENABLED 1 151 #else 152 #define TX_FIQ_ENABLED 0 153 #endif 154 155 #ifdef TX_ENABLE_IRQ_NESTING 156 #define TX_IRQ_NESTING_ENABLED 2 157 #else 158 #define TX_IRQ_NESTING_ENABLED 0 159 #endif 160 161 #ifdef TX_ENABLE_FIQ_NESTING 162 #define TX_FIQ_NESTING_ENABLED 4 163 #else 164 #define TX_FIQ_NESTING_ENABLED 0 165 #endif 166 167 #define TX_PORT_SPECIFIC_BUILD_OPTIONS TX_FIQ_ENABLED | TX_IRQ_NESTING_ENABLED | TX_FIQ_NESTING_ENABLED 168 169 170 /* Define the in-line initialization constant so that modules with in-line 171 initialization capabilities can prevent their initialization from being 172 a function call. */ 173 174 #define TX_INLINE_INITIALIZATION 175 176 177 /* Determine whether or not stack checking is enabled. By default, ThreadX stack checking is 178 disabled. When the following is defined, ThreadX thread stack checking is enabled. If stack 179 checking is enabled (TX_ENABLE_STACK_CHECKING is defined), the TX_DISABLE_STACK_FILLING 180 define is negated, thereby forcing the stack fill which is necessary for the stack checking 181 logic. */ 182 183 #ifdef TX_ENABLE_STACK_CHECKING 184 #undef TX_DISABLE_STACK_FILLING 185 #endif 186 187 188 /* Define the TX_THREAD control block extensions for this port. The main reason 189 for the multiple macros is so that backward compatibility can be maintained with 190 existing ThreadX kernel awareness modules. */ 191 192 #define TX_THREAD_EXTENSION_0 193 #define TX_THREAD_EXTENSION_1 194 #define TX_THREAD_EXTENSION_2 195 #define TX_THREAD_EXTENSION_3 196 197 198 /* Define the port extensions of the remaining ThreadX objects. */ 199 200 #define TX_BLOCK_POOL_EXTENSION 201 #define TX_BYTE_POOL_EXTENSION 202 #define TX_EVENT_FLAGS_GROUP_EXTENSION 203 #define TX_MUTEX_EXTENSION 204 #define TX_QUEUE_EXTENSION 205 #define TX_SEMAPHORE_EXTENSION 206 #define TX_TIMER_EXTENSION 207 208 209 /* Define the user extension field of the thread control block. Nothing 210 additional is needed for this port so it is defined as white space. */ 211 212 #ifndef TX_THREAD_USER_EXTENSION 213 #define TX_THREAD_USER_EXTENSION 214 #endif 215 216 217 /* Define the macros for processing extensions in tx_thread_create, tx_thread_delete, 218 tx_thread_shell_entry, and tx_thread_terminate. */ 219 220 221 #define TX_THREAD_CREATE_EXTENSION(thread_ptr) 222 #define TX_THREAD_DELETE_EXTENSION(thread_ptr) 223 #define TX_THREAD_COMPLETED_EXTENSION(thread_ptr) 224 #define TX_THREAD_TERMINATED_EXTENSION(thread_ptr) 225 226 227 /* Define the ThreadX object creation extensions for the remaining objects. */ 228 229 #define TX_BLOCK_POOL_CREATE_EXTENSION(pool_ptr) 230 #define TX_BYTE_POOL_CREATE_EXTENSION(pool_ptr) 231 #define TX_EVENT_FLAGS_GROUP_CREATE_EXTENSION(group_ptr) 232 #define TX_MUTEX_CREATE_EXTENSION(mutex_ptr) 233 #define TX_QUEUE_CREATE_EXTENSION(queue_ptr) 234 #define TX_SEMAPHORE_CREATE_EXTENSION(semaphore_ptr) 235 #define TX_TIMER_CREATE_EXTENSION(timer_ptr) 236 237 238 /* Define the ThreadX object deletion extensions for the remaining objects. */ 239 240 #define TX_BLOCK_POOL_DELETE_EXTENSION(pool_ptr) 241 #define TX_BYTE_POOL_DELETE_EXTENSION(pool_ptr) 242 #define TX_EVENT_FLAGS_GROUP_DELETE_EXTENSION(group_ptr) 243 #define TX_MUTEX_DELETE_EXTENSION(mutex_ptr) 244 #define TX_QUEUE_DELETE_EXTENSION(queue_ptr) 245 #define TX_SEMAPHORE_DELETE_EXTENSION(semaphore_ptr) 246 #define TX_TIMER_DELETE_EXTENSION(timer_ptr) 247 248 249 /* Determine if the ARM architecture has the CLZ instruction. This is available on 250 architectures v5 and above. If available, redefine the macro for calculating the 251 lowest bit set. */ 252 253 #if __TARGET_ARCH_ARM > 4 254 255 #ifndef __thumb 256 257 #define TX_LOWEST_SET_BIT_CALCULATE(m, b) m = m & ((ULONG) (-((LONG) m))); \ 258 b = (ULONG) __clz((unsigned int) m); \ 259 b = 31 - b; 260 #endif 261 #endif 262 263 264 /* Define ThreadX interrupt lockout and restore macros for protection on 265 access of critical kernel information. The restore interrupt macro must 266 restore the interrupt posture of the running thread prior to the value 267 present prior to the disable macro. In most cases, the save area macro 268 is used to define a local function save area for the disable and restore 269 macros. */ 270 271 #ifndef __thumb 272 #define TX_INTERRUPT_SAVE_AREA register UINT interrupt_save_disabled; 273 274 #ifdef TX_ENABLE_FIQ_SUPPORT 275 276 /* IRQ and FIQ support. */ 277 278 #define TX_DISABLE __memory_changed(), interrupt_save_disabled = __disable_irq(); \ 279 __disable_fiq(); 280 281 #define TX_RESTORE if (!interrupt_save_disabled) \ 282 { \ 283 __enable_irq(); \ 284 __enable_fiq(); \ 285 } 286 287 #else 288 289 #define TX_DISABLE __memory_changed(), interrupt_save_disabled = __disable_irq(); 290 291 #define TX_RESTORE if (!interrupt_save_disabled) \ 292 { \ 293 __enable_irq(); \ 294 } 295 #endif 296 297 #else 298 299 unsigned int _tx_thread_interrupt_disable(void); 300 unsigned int _tx_thread_interrupt_restore(UINT old_posture); 301 302 303 #define TX_INTERRUPT_SAVE_AREA UINT interrupt_save; 304 305 #define TX_DISABLE interrupt_save = _tx_thread_interrupt_disable(); 306 #define TX_RESTORE _tx_thread_interrupt_restore(interrupt_save); 307 #endif 308 309 310 /* Define the interrupt lockout macros for each ThreadX object. */ 311 312 #define TX_BLOCK_POOL_DISABLE TX_DISABLE 313 #define TX_BYTE_POOL_DISABLE TX_DISABLE 314 #define TX_EVENT_FLAGS_GROUP_DISABLE TX_DISABLE 315 #define TX_MUTEX_DISABLE TX_DISABLE 316 #define TX_QUEUE_DISABLE TX_DISABLE 317 #define TX_SEMAPHORE_DISABLE TX_DISABLE 318 319 320 /* Define the version ID of ThreadX. This may be utilized by the application. */ 321 322 #ifdef TX_THREAD_INIT 323 CHAR _tx_version_id[] = 324 "Copyright (c) 2024 Microsoft Corporation. * ThreadX ARM9/AC5 Version 6.4.1 *"; 325 #else 326 extern CHAR _tx_version_id[]; 327 #endif 328 329 330 #endif 331 332