readme_threadx.txt
1 Microsoft's Azure RTOS ThreadX SMP for Cortex-A9
2
3 Thumb & 32-bit Mode
4
5 Using the ARM Compiler 5 & DS
6
7
81. Import the ThreadX Projects
9
10In order to build the ThreadX SMP library and the ThreadX SMP demonstration, first import
11the 'tx' and 'sample_threadx' projects (located in the "example_build" directory)
12into your DS workspace.
13
14Note: the projects were made using DS-5, so DS will prompt you to migrate the projects.
15This is expected, so please do so.
16
17
182. Building the ThreadX SMP run-time Library
19
20Building the ThreadX SMP library is easy; simply select the Eclipse project file
21"tx" and then select the build button. You should now observe the compilation
22and assembly of the ThreadX SMP library. This project build produces the ThreadX SMP
23library file tx.a.
24
25
263. Demonstration System
27
28The ThreadX SMP demonstration is designed to execute under the DS debugger on the
29VE_Cortex-A9x4 Bare Metal simulator.
30
31Building the demonstration is easy; simply open the workspace file, select the
32sample_threadx project, and select the build button. Next, expand the demo ThreadX
33project folder in the Project Explorer window, right-click on the 'Cortex-A9x4_tx.launch'
34file, click 'Debug As', and then click 'Cortex-A9x4_tx' from the submenu. This will cause the
35debugger to load the sample_threadx.axf ELF file and run to main. You are now ready
36to execute the ThreadX demonstration.
37
38
394. System Initialization
40
41The entry point in ThreadX SMP for the Cortex-A9 using ARM tools is at label
42"ENTRY". This is defined within the ARM compiler's startup code. In addition,
43this is where all static and global pre-set C variable initialization processing
44takes place.
45
46The ThreadX SMP tx_initialize_low_level.s file is responsible for determining the
47first available RAM address for use by the application, which is supplied as the
48sole input parameter to your application definition function, tx_application_define.
49
50
515. Register Usage and Stack Frames
52
53The ARM compiler assumes that registers r0-r3 (a1-a4) and r12 (ip) are scratch
54registers for each function. All other registers used by a C function must
55be preserved by the function. ThreadX takes advantage of this in situations
56where a context switch happens as a result of making a ThreadX service call
57(which is itself a C function). In such cases, the saved context of a thread
58is only the non-scratch registers.
59
60The following defines the saved context stack frames for context switches
61that occur as a result of interrupt handling or from thread-level API calls.
62All suspended threads have one of these two types of stack frames. The top
63of the suspended thread's stack is pointed to by tx_thread_stack_ptr in the
64associated thread control block TX_THREAD.
65
66
67
68 Offset Interrupted Stack Frame Non-Interrupt Stack Frame
69
70 0x00 1 0
71 0x04 CPSR CPSR
72 0x08 r0 (a1) r4 (v1)
73 0x0C r1 (a2) r5 (v2)
74 0x10 r2 (a3) r6 (v3)
75 0x14 r3 (a4) r7 (v4)
76 0x18 r4 (v1) r8 (v5)
77 0x1C r5 (v2) r9 (v6)
78 0x20 r6 (v3) r10 (v7)
79 0x24 r7 (v4) r11 (fp)
80 0x28 r8 (v5) r14 (lr)
81 0x2C r9 (v6)
82 0x30 r10 (v7)
83 0x34 r11 (fp)
84 0x38 r12 (ip)
85 0x3C r14 (lr)
86 0x40 PC
87
88
896. Improving Performance
90
91The distribution version of ThreadX is built without any compiler
92optimizations. This makes it easy to debug because you can trace or set
93breakpoints inside of ThreadX itself. Of course, this costs some
94performance. To make it run faster, you can change the build_threadx.bat file to
95remove the -g option and enable all compiler optimizations.
96
97In addition, you can eliminate the ThreadX basic API error checking by
98compiling your application code with the symbol TX_DISABLE_ERROR_CHECKING
99defined.
100
101
1027. Interrupt Handling
103
104ThreadX provides complete and high-performance interrupt handling for Cortex-A9
105targets. There are a certain set of requirements that are defined in the
106following sub-sections:
107
108
1097.1 Vector Area
110
111The Cortex-A9 vectors start at address zero. The demonstration system startup
112Init area contains the vectors and is loaded at address zero. On actual
113hardware platforms, this area might have to be copied to address 0.
114
115
1168.2 IRQ ISRs
117
118ThreadX fully manages standard and vectored IRQ interrupts. ThreadX also supports nested
119IRQ interrupts. The following sub-sections define the IRQ capabilities.
120
121
1227.2.1 Standard IRQ ISRs
123
124The standard ARM IRQ mechanism has a single interrupt vector at address 0x18. This IRQ
125interrupt is managed by the __tx_irq_handler code in startup.s. The following
126is the default IRQ handler defined in startup.s:
127
128 EXPORT IRQ_Handler
129 EXPORT __tx_irq_processing_return
130IRQ_Handler PROC
131;
132; /* Jump to context save to save system context. */
133 B _tx_thread_context_save ; Jump to the context save
134__tx_irq_processing_return
135;
136; /* At this point execution is still in the IRQ mode. The CPSR, point of
137; interrupt, and all C scratch registers are available for use. Note
138; that IRQ interrupts are still disabled upon return from the context
139; save function. */
140;
141; /* Application ISR call(s) go here! */
142;
143; /* Jump to context restore to restore system context. */
144 B _tx_thread_context_restore
145
146
1477.3 FIQ Interrupts
148
149By default, Cortex-A9 FIQ interrupts are left alone by ThreadX. Of course, this
150means that the application is fully responsible for enabling the FIQ interrupt
151and saving/restoring any registers used in the FIQ ISR processing. To globally
152enable FIQ interrupts, the application should enable FIQ interrupts at the
153beginning of each thread or before any threads are created in tx_application_define.
154In addition, the application must ensure that no ThreadX service calls are made
155from default FIQ ISRs, which is located in tx_initialize_low_level.s.
156
157
1587.3.1 Managed FIQ Interrupts
159
160Full ThreadX management of FIQ interrupts is provided if the ThreadX sources
161are built with the TX_ENABLE_FIQ_SUPPORT defined. If the library is built
162this way, the FIQ interrupt handlers are very similar to the IRQ interrupt
163handlers defined previously. The following is default FIQ handler
164defined in tx_initialize_low_level.s:
165
166
167 EXPORT __tx_fiq_handler
168 EXPORT __tx_fiq_processing_return
169__tx_fiq_handler
170;
171; /* Jump to fiq context save to save system context. */
172 B _tx_thread_fiq_context_save
173__tx_fiq_processing_return:
174;
175; /* At this point execution is still in the FIQ mode. The CPSR, point of
176; interrupt, and all C scratch registers are available for use. */
177;
178; /* Application FIQ handlers can be called here! */
179;
180; /* Jump to fiq context restore to restore system context. */
181 B _tx_thread_fiq_context_restore
182
183
1848. ThreadX Timer Interrupt
185
186ThreadX requires a periodic interrupt source to manage all time-slicing,
187thread sleeps, timeouts, and application timers. Without such a timer
188interrupt source, these services are not functional. However, all other
189ThreadX services are operational without a periodic timer source.
190
191To add the timer interrupt processing, simply make a call to
192_tx_timer_interrupt in the IRQ processing. An example of this can be
193found in the file tx_initialize_low_level.s in the Integrator sub-directories.
194
195
1969. Thumb/Cortex-A9 Mixed Mode
197
198By default, ThreadX is setup for running in Cortex-A9 32-bit mode. This is
199also true for the demonstration system. It is possible to build any
200ThreadX file and/or the application in Thumb mode. If any Thumb code
201is used the entire ThreadX source- both C and assembly - should be built
202with the "-apcs /interwork" option.
203
204
20510. VFP Support
206
207By default, VFP support is disabled for each thread. If saving the context of the VFP registers
208is needed, the following API call must be made from the context of the application thread - before
209the VFP usage:
210
211void tx_thread_vfp_enable(void);
212
213After this API is called in the application, VFP registers will be saved/restored for this thread if it
214is preempted via an interrupt. All other suspension of the this thread will not require the VFP registers
215to be saved/restored.
216
217To disable VFP register context saving, simply call the following API:
218
219void tx_thread_vfp_disable(void);
220
221
22211. Revision History
223
224For generic code revision information, please refer to the readme_threadx_generic.txt
225file, which is included in your distribution. The following details the revision
226information associated with this specific port of ThreadX:
227
22804-02-2021 Release 6.1.6 changes:
229 tx_port.h Updated macro definition
230
23109-30-2020 Initial ThreadX 6.1 version for Cortex-A9 using AC5 tools.
232
233
234Copyright(c) 1996-2020 Microsoft Corporation
235
236
237https://azure.com/rtos
238
239