1                  Microsoft's Azure RTOS ThreadX for Renesas RXv2
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 RXv2.
9
10
112.  Demonstration System
12
13Please see the Samples repository on GitHub for the Azure RTOS demonstrations
14for the RXv2
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 RXv2 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                   1
59     0x04                   ACC0
60     0x08                   ACC1
61     0x0C                   R6
62     0x10                   R7
63     0x14                   R8
64     0x18                   R9
65     0x1C                   R10
66     0x20                   R11
67     0x24                   R12
68     0x28                   R13
69     0x2C                   FPSW
70     0x30                   R14
71     0x34                   R15
72     0x38                   R3
73     0x3C                   R4
74     0x40                   R5
75     0x44                   R1
76     0x48                   R2
77     0x4C                   PC - return address
78     0x50                   PSW
79
80Note: By default ccrx does not save the state of the accumulator registers ACC0 and ACC1
81when entering an ISR. This means that if the ISR uses any of the DSP instructions the
82content of those registers could be corrupted. Saving and restoring of the acummulators
83can be enabled by adding the -save_acc command line option.
84
85
865.  Improving Performance
87
88The distribution version of ThreadX is built without any compiler
89optimizations.  This makes it easy to debug because you can trace or set
90breakpoints inside of ThreadX itself.  Of course, this costs some
91performance.  To make ThreadX run faster, you can change the ThreadX Library
92project to disable debug information and enable the desired optimizations.
93
94In addition, you can eliminate the ThreadX basic API error checking by
95compiling your application code with the symbol TX_DISABLE_ERROR_CHECKING
96defined before tx_api.h is 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
153For generic code revision information, please refer to the readme_threadx_generic.txt
154file, which is included in your distribution. The following details the revision
155information associated with this specific port of ThreadX:
156
15704-25-2022  Release 6.1.11 changes:
158            tx_thread_schedule.src              Added low power support
159
16001-31-2022  Release 6.1.10 changes:
161            tx_port.h                           Removed system state macro, and added
162                                                missing interrupt control defines
163            tx_timer_interrupt.src              Added missing thread preemption logic
164
16510-15-2021  Release 6.1.9 changes:
166            tx_thread_context_restore.src       Removed unnecessary stack type placement
167            tx_thread_schedule.src              Removed unnecessary stack type checking
168            tx_thread_stack_build.src           Removed unnecessary stack type placement
169
17006-02-2021  Release 6.1.7 changes:
171            readme_threadx.txt                  Updated instructions on how to use execution profile.
172
17304-02-2021  Release 6.1.6 changes:
174            tx_port.h                           Updated macro definition
175
17612-31-2020  Initial ThreadX release for the RXv2 using CC-RXX tools, version 6.1.3
177
178
179Copyright(c) 1996-2022 Microsoft Corporation
180
181
182https://azure.com/rtos
183
184
185
186www.expresslogic.com