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