1 Microsoft's Azure RTOS ThreadX for Renesas RXv2 2 3 Using the GNU Tools 4 5 61. Building the ThreadX run-time Library 7 8Please see the Samples repository on GitHub for the Azure RTOS demonstrations 9for the RXv2. 10 11 122. Demonstration System 13 14 15Please see the Samples repository on GitHub for the Azure RTOS demonstrations 16for the RXv2. 17 18 193. System Initialization 20 21The system entry point using the GNU tools is at the label _PowerON_Reset. 22 23The vector area is setup in the file tx_initialize_low_level.S. This file is also 24responsible for setting up various system data structures, interrupt vectors, and 25the periodic timer interrupt. This file is also an ideal place to add additional hardware 26initialization code. 27 28The ThreadX demonstration for the RXv2 utilizes CMT0 as a periodic timer interrupt 29source. The CMT0 interrupt is typically setup for 10ms periodic interrupts and the 30interrupt priority level is set to level 5 with the symbol CMT_RX_CFG_IPR in 31r_cmt_rx_config.h of Renesas CMT timer module(r_cmt_rx). You may change any of the timer 32parameters as needed. Increasing the timer interrupt frequency increases the overhead 33of the timer handling code on the system. 34 35In addition, _tx_initialize_low_level determines the first available address for use 36by the application, which is supplied as the sole input parameter to your application 37definition function, tx_application_define. The first available memory is determined 38by the location of the '_end' label the is defined in the linker script. 39'_end' should reference the first memory AFTER all other RAM 40sections in your linker control file. 41 42 434. Context Switch, Register Usage and Stack Frames 44 45The RXv2 port for ThreadX uses the first software interrupt, SWINT, i.e., interrupt #27, 46to perform context switch with the interrupt priority level 1. This ISR is thus reserved 47when using ThreadX and the SWINT should not be manipulated in any way by the application. 48The port will setup the interrupt within _tx_initialize_low_level and the compiler will 49automatically install the necessary interrupt vector. As such no additional initialization 50is necessary by the application. 51 52The following defines the saved context stack frame used by the ThreadX port. The 53state of the CPU registers at the time of a context switch is saved on the running 54thread's stack The top of the suspended thread's stack is pointed to by 55tx_thread_stack_ptr in the associated thread control block TX_THREAD. 56 57 Offset Interrupted Stack Frame 58 59 0x00 1 60 0x04 ACC0 61 0x08 ACC1 62 0x0C R6 63 0x10 R7 64 0x14 R8 65 0x18 R9 66 0x1C R10 67 0x20 R11 68 0x24 R12 69 0x28 R13 70 0x2C FPSW 71 0x30 R14 72 0x34 R15 73 0x38 R3 74 0x3C R4 75 0x40 R5 76 0x44 R1 77 0x48 R2 78 0x4C PC - return address 79 0x50 PSW 80 81Note: By default GNURX does not save the state of the accumulator registers ACC0 and ACC1 82when entering an ISR. This means that if the ISR uses any of the DSP instructions the 83content of those registers could be corrupted. Saving and restoring of the acummulators 84can be enabled by adding the -msave-acc-in-interrupts command line option. 85 86 875. Improving Performance 88 89The distribution version of ThreadX is built without any compiler optimizations. This 90makes it easy to debug because you can trace or set breakpoints inside of ThreadX itself. 91Of course, this costs some performance. To make ThreadX run faster, you can change the 92ThreadX Library project to disable debug information and enable the desired optimizations. 93 94In addition, you can eliminate the ThreadX basic API error checking by compiling your 95application code with the symbol TX_DISABLE_ERROR_CHECKING defined before tx_api.h 96is included. 97 98 996. Timer Processing 100 101Timer processign is performed by calling __tx_timer_interrupt(). This should usually be done 102from within the callback of a periodic timer with a period of 100Hz. In the sample projects 103a Renesas Fit CMT periodic timer module (r_cmt_rx) is used as the timer source. 104 105 1067. Interrupt Handling 107 108Interrupt handling is unaffected by the ThreadX port as such user interrupts can be 109written according to the toolchain's documentation. It is recommended not to use interrupt 110priority 1 as this is the priority of the context switch interrupt. However using interrupt 111priority 1 won't cause any negative side effects but doing so may slightly reduce 112performance. Please refer to the toolchain documentation for additional details on how to 113define interrupt service routines. 114 115 1168. Execution Profiling 117 118The RX port adds support for the Execution Profiling Kit (EPK). The EPK consists 119of the files tx_execution_profile.c and tx_execution_profile.h. See the documentation 120of the EPK for generic usage details. 121 122To add the EPK to your RXv2 release make the following modifications: 123 124* Enable the following define for both the Threadx library and the application 125TX_EXECUTION_PROFILE_ENABLE 126 127* Setup CMT1 as a free running 16 bit timer. 128 129* In tx_execution_profile.h, change following around line 52: 130 131#ifdef TX_EXECUTION_64BIT_TIME 132typedef unsigned long long EXECUTION_TIME; 133#define TX_EXECUTION_MAX_TIME_SOURCE 0xFFFFFFFFFFFFFFFF 134#else 135typedef unsigned long EXECUTION_TIME; 136#define TX_EXECUTION_MAX_TIME_SOURCE 0xFFFF 137#endif 138 139/* Define basic constants for the execution profile kit. */ 140 141#define TX_EXECUTION_TIME_SOURCE (EXECUTION_TIME) *((USHORT *) 0x8800A) 142 143Rebuild the Threadx library and the application. 144Refer to the EPK documentation how to interpret the results. 145 146 1479. Revision History 148 149For generic code revision information, please refer to the readme_threadx_generic.txt 150file, which is included in your distribution. The following details the revision 151information associated with this specific port of ThreadX: 152 15304-25-2022 Release 6.1.11 changes: 154 tx_thread_schedule.s Added low power support 155 15601-31-2022 Release 6.1.10 changes: 157 tx_port.h Added missing interrupt control defines 158 tx_timer_interrupt.s Added missing thread preemption logic 159 16010-15-2021 Release 6.1.9 changes: 161 tx_thread_context_restore.s Removed unnecessary stack type placement 162 tx_thread_schedule.s Removed unnecessary stack type checking 163 tx_thread_stack_build.s Removed unnecessary stack type placement 164 16506-02-2021 Release 6.1.7 changes: 166 tx_port.h Fix TX_RESTORE issue 167 readme_threadx.txt Updated instructions on how to use execution profile. 168 169 17004-02-2021 Release 6.1.6 changes: 171 tx_port.h Updated macro definition 172 17312-31-2020 Initial ThreadX release for the RXv2 using GNURX tools, version 6.1.3 174 175 176Copyright(c) 1996-2022 Microsoft Corporation 177 178 179https://azure.com/rtos 180 181