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 ARMv7-A */ 28 /* 6.1.12 */ 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 /* 04-25-2022 Zhen Kong Updated comments, */ 54 /* resulting in version 6.1.11 */ 55 /* 07-29-2022 Scott Larson Updated comments, removed */ 56 /* unneeded temp variable, */ 57 /* resulting in version 6.1.12 */ 58 /* */ 59 /**************************************************************************/ 60 61 #ifndef TX_PORT_H 62 #define TX_PORT_H 63 64 65 /* Determine if the optional ThreadX user define file should be used. */ 66 67 #ifdef TX_INCLUDE_USER_DEFINE_FILE 68 69 70 /* Yes, include the user defines in tx_user.h. The defines in this file may 71 alternately be defined on the command line. */ 72 73 #include "tx_user.h" 74 #endif 75 76 77 /* Define compiler library include files. */ 78 79 #include <stdlib.h> 80 #include <string.h> 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_TRACE_TIME_SOURCE 144 #define TX_TRACE_TIME_SOURCE ++_tx_trace_simulated_time 145 #endif 146 #ifndef TX_TRACE_TIME_MASK 147 #define TX_TRACE_TIME_MASK 0xFFFFFFFFUL 148 #endif 149 150 151 /* Define the port specific options for the _tx_build_options variable. This variable indicates 152 how the ThreadX library was built. */ 153 154 #ifdef TX_ENABLE_FIQ_SUPPORT 155 #define TX_FIQ_ENABLED 1 156 #else 157 #define TX_FIQ_ENABLED 0 158 #endif 159 160 #ifdef TX_ENABLE_IRQ_NESTING 161 #define TX_IRQ_NESTING_ENABLED 2 162 #else 163 #define TX_IRQ_NESTING_ENABLED 0 164 #endif 165 166 #ifdef TX_ENABLE_FIQ_NESTING 167 #define TX_FIQ_NESTING_ENABLED 4 168 #else 169 #define TX_FIQ_NESTING_ENABLED 0 170 #endif 171 172 #define TX_PORT_SPECIFIC_BUILD_OPTIONS TX_FIQ_ENABLED | TX_IRQ_NESTING_ENABLED | TX_FIQ_NESTING_ENABLED 173 174 175 /* Define the in-line initialization constant so that modules with in-line 176 initialization capabilities can prevent their initialization from being 177 a function call. */ 178 179 #define TX_INLINE_INITIALIZATION 180 181 182 /* Determine whether or not stack checking is enabled. By default, ThreadX stack checking is 183 disabled. When the following is defined, ThreadX thread stack checking is enabled. If stack 184 checking is enabled (TX_ENABLE_STACK_CHECKING is defined), the TX_DISABLE_STACK_FILLING 185 define is negated, thereby forcing the stack fill which is necessary for the stack checking 186 logic. */ 187 188 #ifdef TX_ENABLE_STACK_CHECKING 189 #undef TX_DISABLE_STACK_FILLING 190 #endif 191 192 193 /* Define the TX_THREAD control block extensions for this port. The main reason 194 for the multiple macros is so that backward compatibility can be maintained with 195 existing ThreadX kernel awareness modules. */ 196 197 #define TX_THREAD_EXTENSION_0 198 #define TX_THREAD_EXTENSION_1 199 #define TX_THREAD_EXTENSION_2 ULONG tx_thread_vfp_enable; 200 #define TX_THREAD_EXTENSION_3 201 202 203 /* Define the port extensions of the remaining ThreadX objects. */ 204 205 #define TX_BLOCK_POOL_EXTENSION 206 #define TX_BYTE_POOL_EXTENSION 207 #define TX_EVENT_FLAGS_GROUP_EXTENSION 208 #define TX_MUTEX_EXTENSION 209 #define TX_QUEUE_EXTENSION 210 #define TX_SEMAPHORE_EXTENSION 211 #define TX_TIMER_EXTENSION 212 213 214 /* Define the user extension field of the thread control block. Nothing 215 additional is needed for this port so it is defined as white space. */ 216 217 #ifndef TX_THREAD_USER_EXTENSION 218 #define TX_THREAD_USER_EXTENSION 219 #endif 220 221 222 /* Define the macros for processing extensions in tx_thread_create, tx_thread_delete, 223 tx_thread_shell_entry, and tx_thread_terminate. */ 224 225 226 #define TX_THREAD_CREATE_EXTENSION(thread_ptr) 227 #define TX_THREAD_DELETE_EXTENSION(thread_ptr) 228 #define TX_THREAD_COMPLETED_EXTENSION(thread_ptr) 229 #define TX_THREAD_TERMINATED_EXTENSION(thread_ptr) 230 231 232 /* Define the ThreadX object creation extensions for the remaining objects. */ 233 234 #define TX_BLOCK_POOL_CREATE_EXTENSION(pool_ptr) 235 #define TX_BYTE_POOL_CREATE_EXTENSION(pool_ptr) 236 #define TX_EVENT_FLAGS_GROUP_CREATE_EXTENSION(group_ptr) 237 #define TX_MUTEX_CREATE_EXTENSION(mutex_ptr) 238 #define TX_QUEUE_CREATE_EXTENSION(queue_ptr) 239 #define TX_SEMAPHORE_CREATE_EXTENSION(semaphore_ptr) 240 #define TX_TIMER_CREATE_EXTENSION(timer_ptr) 241 242 243 /* Define the ThreadX object deletion extensions for the remaining objects. */ 244 245 #define TX_BLOCK_POOL_DELETE_EXTENSION(pool_ptr) 246 #define TX_BYTE_POOL_DELETE_EXTENSION(pool_ptr) 247 #define TX_EVENT_FLAGS_GROUP_DELETE_EXTENSION(group_ptr) 248 #define TX_MUTEX_DELETE_EXTENSION(mutex_ptr) 249 #define TX_QUEUE_DELETE_EXTENSION(queue_ptr) 250 #define TX_SEMAPHORE_DELETE_EXTENSION(semaphore_ptr) 251 #define TX_TIMER_DELETE_EXTENSION(timer_ptr) 252 253 254 /* Determine if the ARM architecture has the CLZ instruction. This is available on 255 architectures v5 and above. If available, redefine the macro for calculating the 256 lowest bit set. */ 257 258 #if __TARGET_ARCH_ARM > 4 259 260 #ifndef __thumb__ 261 262 #define TX_LOWEST_SET_BIT_CALCULATE(m, b) m = m & ((ULONG) (-((LONG) m))); \ 263 asm volatile (" CLZ %0,%1 ": "=r" (b) : "r" (m) ); \ 264 b = 31 - b; 265 #endif 266 #endif 267 268 269 /* Define ThreadX interrupt lockout and restore macros for protection on 270 access of critical kernel information. The restore interrupt macro must 271 restore the interrupt posture of the running thread prior to the value 272 present prior to the disable macro. In most cases, the save area macro 273 is used to define a local function save area for the disable and restore 274 macros. */ 275 276 #ifdef __thumb__ 277 278 unsigned int _tx_thread_interrupt_disable(void); 279 unsigned int _tx_thread_interrupt_restore(UINT old_posture); 280 281 282 #define TX_INTERRUPT_SAVE_AREA UINT interrupt_save; 283 284 #define TX_DISABLE interrupt_save = _tx_thread_interrupt_disable(); 285 #define TX_RESTORE _tx_thread_interrupt_restore(interrupt_save); 286 287 #else 288 289 #define TX_INTERRUPT_SAVE_AREA UINT interrupt_save; 290 291 #ifdef TX_ENABLE_FIQ_SUPPORT 292 #define TX_DISABLE asm volatile (" MRS %0,CPSR; CPSID if ": "=r" (interrupt_save) ); 293 #else 294 #define TX_DISABLE asm volatile (" MRS %0,CPSR; CPSID i ": "=r" (interrupt_save) ); 295 #endif 296 297 #define TX_RESTORE asm volatile (" MSR CPSR_c,%0 "::"r" (interrupt_save) ); 298 299 #endif 300 301 302 /* Define VFP extension for the ARMv7-A. Each is assumed to be called in the context of the executing 303 thread. */ 304 305 void tx_thread_vfp_enable(void); 306 void tx_thread_vfp_disable(void); 307 308 309 /* Define the interrupt lockout macros for each ThreadX object. */ 310 311 #define TX_BLOCK_POOL_DISABLE TX_DISABLE 312 #define TX_BYTE_POOL_DISABLE TX_DISABLE 313 #define TX_EVENT_FLAGS_GROUP_DISABLE TX_DISABLE 314 #define TX_MUTEX_DISABLE TX_DISABLE 315 #define TX_QUEUE_DISABLE TX_DISABLE 316 #define TX_SEMAPHORE_DISABLE TX_DISABLE 317 318 319 /* Define the version ID of ThreadX. This may be utilized by the application. */ 320 321 #ifdef TX_THREAD_INIT 322 CHAR _tx_version_id[] = 323 "Copyright (c) 2024 Microsoft Corporation. * ThreadX ARMv7-A Version 6.4.1 *"; 324 #else 325 extern CHAR _tx_version_id[]; 326 #endif 327 328 329 #endif 330 331