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