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 ARC_HS/MetaWare */ 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 /* 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 /* 01-31-2022 Andres Mlinar Modified comments(s), */ 55 /* initialize interrupts right */ 56 /* before enabling the task */ 57 /* scheduler, */ 58 /* resulting in version 6.1.10 */ 59 /* */ 60 /**************************************************************************/ 61 62 #ifndef TX_PORT_H 63 #define TX_PORT_H 64 65 66 /* Remove volatile for ThreadX source on the ARC. This is because the ARC 67 compiler generates different non-cache r/w access when using volatile 68 that is different from the assembly language access of the same 69 global variables in ThreadX. */ 70 71 #ifdef TX_SOURCE_CODE 72 #define volatile 73 #else 74 #ifdef NX_SOURCE_CODE 75 #define volatile 76 #else 77 #ifdef FX_SOURCE_CODE 78 #define volatile 79 #else 80 #ifdef UX_SOURCE_CODE 81 #define volatile 82 #endif 83 #endif 84 #endif 85 #endif 86 87 88 /* Determine if the optional ThreadX user define file should be used. */ 89 90 #ifdef TX_INCLUDE_USER_DEFINE_FILE 91 92 93 /* Yes, include the user defines in tx_user.h. The defines in this file may 94 alternately be defined on the command line. */ 95 96 #include "tx_user.h" 97 #endif 98 99 100 /* Define compiler library include files. */ 101 102 #include <stdlib.h> 103 #include <string.h> 104 105 106 /* Define ThreadX basic types for this port. */ 107 108 #define VOID void 109 typedef char CHAR; 110 typedef unsigned char UCHAR; 111 typedef int INT; 112 typedef unsigned int UINT; 113 typedef long LONG; 114 typedef unsigned long ULONG; 115 typedef short SHORT; 116 typedef unsigned short USHORT; 117 118 119 /* Define the priority levels for ThreadX. Legal values range 120 from 32 to 1024 and MUST be evenly divisible by 32. */ 121 122 #ifndef TX_MAX_PRIORITIES 123 #define TX_MAX_PRIORITIES 32 124 #endif 125 126 127 /* Define the minimum stack for a ThreadX thread on this processor. If the size supplied during 128 thread creation is less than this value, the thread create call will return an error. */ 129 130 #ifndef TX_MINIMUM_STACK 131 #define TX_MINIMUM_STACK 800 /* Minimum stack size for this port */ 132 #endif 133 134 135 /* Define the system timer thread's default stack size and priority. These are only applicable 136 if TX_TIMER_PROCESS_IN_ISR is not defined. */ 137 138 #ifndef TX_TIMER_THREAD_STACK_SIZE 139 #define TX_TIMER_THREAD_STACK_SIZE 2048 /* Default timer thread stack size */ 140 #endif 141 142 #ifndef TX_TIMER_THREAD_PRIORITY 143 #define TX_TIMER_THREAD_PRIORITY 0 /* Default timer thread priority */ 144 #endif 145 146 147 /* Define various constants for the ThreadX ARC HS port. */ 148 149 #define TX_INT_ENABLE 0x0000001F /* Enable all interrupts */ 150 #define TX_INT_DISABLE_MASK 0x00000000 /* Disable all interrupts */ 151 152 153 /* Define the clock source for trace event entry time stamp. The following two item are port specific. 154 For example, if the time source is at the address 0x0a800024 and is 16-bits in size, the clock 155 source constants would be: 156 157 #define TX_TRACE_TIME_SOURCE *((ULONG *) 0x0a800024) 158 #define TX_TRACE_TIME_MASK 0x0000FFFFUL 159 160 */ 161 162 #ifndef TX_MISRA_ENABLE 163 #ifndef TX_TRACE_TIME_SOURCE 164 #define TX_TRACE_TIME_SOURCE ++_tx_trace_simulated_time 165 #endif 166 #else 167 ULONG _tx_misra_time_stamp_get(VOID); 168 #define TX_TRACE_TIME_SOURCE _tx_misra_time_stamp_get() 169 #endif 170 171 #ifndef TX_TRACE_TIME_MASK 172 #define TX_TRACE_TIME_MASK 0xFFFFFFFFUL 173 #endif 174 175 176 /* Define the port specific options for the _tx_build_options variable. This variable indicates 177 how the ThreadX library was built. */ 178 179 #define TX_PORT_SPECIFIC_BUILD_OPTIONS (0) 180 181 182 /* Define the in-line initialization constant so that modules with in-line 183 initialization capabilities can prevent their initialization from being 184 a function call. */ 185 186 #ifdef TX_MISRA_ENABLE 187 #define TX_DISABLE_INLINE 188 #else 189 #define TX_INLINE_INITIALIZATION 190 #endif 191 192 /* Define the ARC-specific initialization code that is expanded in the generic source. */ 193 194 void _tx_initialize_start_interrupts(void); 195 196 #define TX_PORT_SPECIFIC_PRE_SCHEDULER_INITIALIZATION _tx_initialize_start_interrupts(); 197 198 199 /* Determine whether or not stack checking is enabled. By default, ThreadX stack checking is 200 disabled. When the following is defined, ThreadX thread stack checking is enabled. If stack 201 checking is enabled (TX_ENABLE_STACK_CHECKING is defined), the TX_DISABLE_STACK_FILLING 202 define is negated, thereby forcing the stack fill which is necessary for the stack checking 203 logic. */ 204 205 #ifndef TX_MISRA_ENABLE 206 #ifdef TX_ENABLE_STACK_CHECKING 207 #undef TX_DISABLE_STACK_FILLING 208 #endif 209 #endif 210 211 212 /* Define the TX_THREAD control block extensions for this port. The main reason 213 for the multiple macros is so that backward compatibility can be maintained with 214 existing ThreadX kernel awareness modules. */ 215 216 #define TX_THREAD_EXTENSION_0 VOID *__mw_threadx_tls; \ 217 int __mw_errnum; \ 218 VOID (*__mw_thread_exit)(struct TX_THREAD_STRUCT *); 219 #define TX_THREAD_EXTENSION_1 220 #define TX_THREAD_EXTENSION_2 221 #define TX_THREAD_EXTENSION_3 222 223 224 /* Define the port extensions of the remaining ThreadX objects. */ 225 226 #define TX_BLOCK_POOL_EXTENSION 227 #define TX_BYTE_POOL_EXTENSION 228 #define TX_EVENT_FLAGS_GROUP_EXTENSION 229 #define TX_MUTEX_EXTENSION 230 #define TX_QUEUE_EXTENSION 231 #define TX_SEMAPHORE_EXTENSION 232 #define TX_TIMER_EXTENSION 233 234 235 /* Define the user extension field of the thread control block. Nothing 236 additional is needed for this port so it is defined as white space. */ 237 238 #ifndef TX_THREAD_USER_EXTENSION 239 #define TX_THREAD_USER_EXTENSION 240 #endif 241 242 243 /* Define the macros for processing extensions in tx_thread_create, tx_thread_delete, 244 tx_thread_shell_entry, and tx_thread_terminate. */ 245 246 #if __HIGHC__ 247 248 /* The MetaWare thread safe C/C++ runtime library needs space to 249 store thread specific information. In addition, a function pointer 250 is also supplied so that certain thread-specific resources may be 251 released upon thread termination and/or thread completion. */ 252 253 #define TX_THREAD_CREATE_EXTENSION(thread_ptr) \ 254 thread_ptr -> __mw_threadx_tls = 0; \ 255 thread_ptr -> __mw_errnum = 0; \ 256 thread_ptr -> __mw_thread_exit = TX_NULL; 257 #define TX_THREAD_DELETE_EXTENSION(thread_ptr) 258 #define TX_THREAD_COMPLETED_EXTENSION(thread_ptr) \ 259 if (thread_ptr -> __mw_thread_exit) \ 260 (thread_ptr -> __mw_thread_exit) (thread_ptr); 261 #define TX_THREAD_TERMINATED_EXTENSION(thread_ptr) \ 262 if (thread_ptr -> __mw_thread_exit) \ 263 (thread_ptr -> __mw_thread_exit) (thread_ptr); 264 265 #else 266 267 #define TX_THREAD_CREATE_EXTENSION(thread_ptr) 268 #define TX_THREAD_DELETE_EXTENSION(thread_ptr) 269 #define TX_THREAD_COMPLETED_EXTENSION(thread_ptr) 270 #define TX_THREAD_TERMINATED_EXTENSION(thread_ptr) 271 272 #endif 273 274 275 /* Define the ThreadX object creation extensions for the remaining objects. */ 276 277 #define TX_BLOCK_POOL_CREATE_EXTENSION(pool_ptr) 278 #define TX_BYTE_POOL_CREATE_EXTENSION(pool_ptr) 279 #define TX_EVENT_FLAGS_GROUP_CREATE_EXTENSION(group_ptr) 280 #define TX_MUTEX_CREATE_EXTENSION(mutex_ptr) 281 #define TX_QUEUE_CREATE_EXTENSION(queue_ptr) 282 #define TX_SEMAPHORE_CREATE_EXTENSION(semaphore_ptr) 283 #define TX_TIMER_CREATE_EXTENSION(timer_ptr) 284 285 286 /* Define the ThreadX object deletion extensions for the remaining objects. */ 287 288 #define TX_BLOCK_POOL_DELETE_EXTENSION(pool_ptr) 289 #define TX_BYTE_POOL_DELETE_EXTENSION(pool_ptr) 290 #define TX_EVENT_FLAGS_GROUP_DELETE_EXTENSION(group_ptr) 291 #define TX_MUTEX_DELETE_EXTENSION(mutex_ptr) 292 #define TX_QUEUE_DELETE_EXTENSION(queue_ptr) 293 #define TX_SEMAPHORE_DELETE_EXTENSION(semaphore_ptr) 294 #define TX_TIMER_DELETE_EXTENSION(timer_ptr) 295 296 297 /* Define ThreadX interrupt lockout and restore macros for protection on 298 access of critical kernel information. The restore interrupt macro must 299 restore the interrupt posture of the running thread prior to the value 300 present prior to the disable macro. In most cases, the save area macro 301 is used to define a local function save area for the disable and restore 302 macros. */ 303 304 305 #define TX_INTERRUPT_SAVE_AREA register UINT interrupt_save; 306 307 #define TX_DISABLE interrupt_save = _clri(); 308 #define TX_RESTORE _seti(interrupt_save); 309 310 311 /* Define the interrupt lockout macros for each ThreadX object. */ 312 313 #define TX_BLOCK_POOL_DISABLE TX_DISABLE 314 #define TX_BYTE_POOL_DISABLE TX_DISABLE 315 #define TX_EVENT_FLAGS_GROUP_DISABLE TX_DISABLE 316 #define TX_MUTEX_DISABLE TX_DISABLE 317 #define TX_QUEUE_DISABLE TX_DISABLE 318 #define TX_SEMAPHORE_DISABLE TX_DISABLE 319 320 321 /* Define ARC HS extension for assigning a hardware register bank to a thread. Note that this API can only be 322 called after a thread is created from initialization. It is assumed that interrupts are disabled and the 323 initialization code is running in hardware register bank 0. It is also assumed that the application provides 324 a vaild register bank number to the API. */ 325 326 #ifndef TX_SOURCE_CODE 327 #define tx_initialize_fast_interrupt_setup _tx_initialize_fast_interrupt_setup 328 #define tx_thread_register_bank_assign _tx_thread_register_bank_assign 329 #endif 330 331 VOID tx_initialize_fast_interrupt_setup(VOID *stack_ptr); 332 VOID tx_thread_register_bank_assign(VOID *thread_ptr, UINT register_bank); 333 334 335 /* Define the version ID of ThreadX. This may be utilized by the application. */ 336 337 #ifdef TX_THREAD_INIT 338 CHAR _tx_version_id[] = 339 "Copyright (c) Microsoft Corporation. All rights reserved. * ThreadX ARC_HS/MetaWare Version 6.3.0 *"; 340 #else 341 #ifdef TX_MISRA_ENABLE 342 extern CHAR _tx_version_id[100]; 343 #else 344 extern CHAR _tx_version_id[]; 345 #endif 346 #endif 347 348 349 #endif 350 351 352 353