• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

example_build/11-Mar-2024-3,5582,152

inc/11-Mar-2024-412165

src/11-Mar-2024-3,7543,365

readme_threadx.txtD11-Mar-202413.7 KiB347260

readme_threadx.txt

1                Microsoft's Azure RTOS ThreadX SMP for Cortex-A5
2
3                              Using the GNU Tools
4
51.  Building the ThreadX run-time Library
6
7First make sure you are in the "example_build" directory. Also, make sure that
8you have setup your path and other environment variables necessary for the GNU
9development environment.
10
11At this point you may run the build_threadx.bat batch file. This will build the
12ThreadX run-time environment in the "example_build" directory.
13
14You should observe assembly and compilation of a series of ThreadX source
15files. At the end of the batch file, they are all combined into the
16run-time library file: tx.a. This file must be linked with your
17application in order to use ThreadX.
18
19
202.  Demonstration System
21
22The ThreadX demonstration is designed to execute under the ARM Cortex-A5x4 FVP.
23
24Building the demonstration is easy; simply execute the build_threadx_sample.bat
25batch file while inside the "example_build" directory.
26
27You should observe the compilation of sample_threadx.c (which is the demonstration
28application) and linking with TX.A. The resulting file DEMO is a binary file
29that can be downloaded and executed.
30
31
323.  System Initialization
33
34The entry point in ThreadX for the Cortex-A5 using GNU tools is at label
35Reset_Handler in startup.s. After the basic core initialization is complete,
36control will transfer to __main, which is where all static and global pre-set
37C variable initialization processing takes place.
38
39The ThreadX tx_initialize_low_level.s file is responsible for setting up
40various system data structures, the vector area, and a periodic timer interrupt
41source. By default, the vector area is defined to be located in the Init area,
42which is defined at the top of tx_initialize_low_level.s. This area is typically
43located at 0. In situations where this is impossible, the vectors at the beginning
44of the Init area should be copied to address 0.
45
46This is also where initialization of a periodic timer interrupt source
47should take place.
48
49In addition, _tx_initialize_low_level determines the first available
50address for use by the application, which is supplied as the sole input
51parameter to your application definition function, tx_application_define.
52
53
544.  Register Usage and Stack Frames
55
56The GNU compiler assumes that registers r0-r3 (a1-a4) and r12 (ip) are scratch
57registers for each function. All other registers used by a C function must
58be preserved by the function. ThreadX takes advantage of this in situations
59where a context switch happens as a result of making a ThreadX service call
60(which is itself a C function). In such cases, the saved context of a thread
61is only the non-scratch registers.
62
63The following defines the saved context stack frames for context switches
64that occur as a result of interrupt handling or from thread-level API calls.
65All suspended threads have one of these two types of stack frames. The top
66of the suspended thread's stack is pointed to by tx_thread_stack_ptr in the
67associated thread control block TX_THREAD.
68
69
70
71    Offset        Interrupted Stack Frame        Non-Interrupt Stack Frame
72
73     0x00                   1                           0
74     0x04                   CPSR                        CPSR
75     0x08                   r0  (a1)                    r4  (v1)
76     0x0C                   r1  (a2)                    r5  (v2)
77     0x10                   r2  (a3)                    r6  (v3)
78     0x14                   r3  (a4)                    r7  (v4)
79     0x18                   r4  (v1)                    r8  (v5)
80     0x1C                   r5  (v2)                    r9  (v6)
81     0x20                   r6  (v3)                    r10 (v7)
82     0x24                   r7  (v4)                    r11 (fp)
83     0x28                   r8  (v5)                    r14 (lr)
84     0x2C                   r9  (v6)
85     0x30                   r10 (v7)
86     0x34                   r11 (fp)
87     0x38                   r12 (ip)
88     0x3C                   r14 (lr)
89     0x40                   PC
90
91
925.  Improving Performance
93
94The distribution version of ThreadX is built without any compiler
95optimizations. This makes it easy to debug because you can trace or set
96breakpoints inside of ThreadX itself. Of course, this costs some
97performance. To make it run faster, you can change the build_threadx.bat file to
98remove the -g option and enable all compiler optimizations.
99
100In addition, you can eliminate the ThreadX basic API error checking by
101compiling your application code with the symbol TX_DISABLE_ERROR_CHECKING
102defined.
103
104
1056.  Interrupt Handling
106
107ThreadX provides complete and high-performance interrupt handling for Cortex-A5
108targets. There are a certain set of requirements that are defined in the
109following sub-sections:
110
111
1126.1  Vector Area
113
114The Cortex-A5 vectors start at address zero. The demonstration system startup
115Init area contains the vectors and is loaded at address zero. On actual
116hardware platforms, this area might have to be copied to address 0.
117
118
1196.2  IRQ ISRs
120
121ThreadX fully manages standard and vectored IRQ interrupts. ThreadX also supports nested
122IRQ interrupts. The following sub-sections define the IRQ capabilities.
123
124
1256.2.1 Standard IRQ ISRs
126
127The standard ARM IRQ mechanism has a single interrupt vector at address 0x18. This IRQ
128interrupt is managed by the __tx_irq_handler code in tx_initialize_low_level. The following
129is the default IRQ handler defined in tx_initialize_low_level.s:
130
131    EXPORT  __tx_irq_handler
132    EXPORT  __tx_irq_processing_return
133__tx_irq_handler
134;
135;    /* Jump to context save to save system context.  */
136    B       _tx_thread_context_save             ; Jump to the context save
137__tx_irq_processing_return
138;
139;    /* At this point execution is still in the IRQ mode. The CPSR, point of
140;       interrupt, and all C scratch registers are available for use. Note
141;       that IRQ interrupts are still disabled upon return from the context
142;       save function.  */
143;
144;    /* Application ISR call(s) go here!  */
145;
146;    /* Jump to context restore to restore system context.  */
147    B       _tx_thread_context_restore
148
149
1506.2.2 Vectored IRQ ISRs
151
152The vectored ARM IRQ mechanism has multiple interrupt vectors at addresses specified
153by the particular implementation. The following is an example IRQ handler defined in
154tx_initialize_low_level.s:
155
156    EXPORT  __tx_irq_example_handler
157__tx_irq_example_handler
158;
159;    /* Call context save to save system context.  */
160
161    STMDB   sp!, {r0-r3}                        ; Save some scratch registers
162    MRS     r0, SPSR                            ; Pickup saved SPSR
163    SUB     lr, lr, #4                          ; Adjust point of interrupt
164    STMDB   sp!, {r0, r10, r12, lr}             ; Store other scratch registers
165    BL      _tx_thread_vectored_context_save    ; Call the vectored IRQ context save
166;
167;    /* At this point execution is still in the IRQ mode. The CPSR, point of
168;       interrupt, and all C scratch registers are available for use. Note
169;       that IRQ interrupts are still disabled upon return from the context
170;       save function.  */
171;
172;    /* Application ISR call goes here!  */
173;
174;    /* Jump to context restore to restore system context.  */
175    B       _tx_thread_context_restore
176
177
1786.2.3  Nested IRQ Support
179
180By default, nested IRQ interrupt support is not enabled. To enable nested
181IRQ support, the entire library should be built with TX_ENABLE_IRQ_NESTING
182defined. With this defined, two new IRQ interrupt management services are
183available, namely _tx_thread_irq_nesting_start and _tx_thread_irq_nesting_end.
184These function should be called between the IRQ context save and restore
185calls.
186
187Execution between the calls to _tx_thread_irq_nesting_start and
188_tx_thread_irq_nesting_end is enabled for IRQ nesting. This is achieved
189by switching from IRQ mode to SYS mode and enabling IRQ interrupts.
190The SYS mode stack is used during the SYS mode operation, which was
191setup in tx_initialize_low_level.s. When nested IRQ interrupts are no longer required,
192calling the _tx_thread_irq_nesting_end service disables nesting by disabling
193IRQ interrupts and switching back to IRQ mode in preparation for the IRQ
194context restore service.
195
196The following is an example of enabling IRQ nested interrupts in a standard
197IRQ handler:
198
199    EXPORT  __tx_irq_handler
200    EXPORT  __tx_irq_processing_return
201__tx_irq_handler
202;
203;    /* Jump to context save to save system context.  */
204    B       _tx_thread_context_save
205__tx_irq_processing_return
206;
207;    /* Enable nested IRQ interrupts. NOTE:  Since this service returns
208;       with IRQ interrupts enabled, all IRQ interrupt sources must be
209;       cleared prior to calling this service.  */
210    BL      _tx_thread_irq_nesting_start
211;
212;    /* Application ISR call(s) go here!  */
213;
214;    /* Disable nested IRQ interrupts. The mode is switched back to
215;       IRQ mode and IRQ interrupts are disable upon return.  */
216    BL      _tx_thread_irq_nesting_end
217;
218;    /* Jump to context restore to restore system context.  */
219    B       _tx_thread_context_restore
220
221
2226.3  FIQ Interrupts
223
224By default, Cortex-A5 FIQ interrupts are left alone by ThreadX. Of course, this
225means that the application is fully responsible for enabling the FIQ interrupt
226and saving/restoring any registers used in the FIQ ISR processing. To globally
227enable FIQ interrupts, the application should enable FIQ interrupts at the
228beginning of each thread or before any threads are created in tx_application_define.
229In addition, the application must ensure that no ThreadX service calls are made
230from default FIQ ISRs, which is located in tx_initialize_low_level.s.
231
232
2336.3.1  Managed FIQ Interrupts
234
235Full ThreadX management of FIQ interrupts is provided if the ThreadX sources
236are built with the TX_ENABLE_FIQ_SUPPORT defined. If the library is built
237this way, the FIQ interrupt handlers are very similar to the IRQ interrupt
238handlers defined previously. The following is default FIQ handler
239defined in tx_initialize_low_level.s:
240
241
242    EXPORT  __tx_fiq_handler
243    EXPORT  __tx_fiq_processing_return
244__tx_fiq_handler
245;
246;    /* Jump to fiq context save to save system context.  */
247    B       _tx_thread_fiq_context_save
248__tx_fiq_processing_return:
249;
250;    /* At this point execution is still in the FIQ mode. The CPSR, point of
251;       interrupt, and all C scratch registers are available for use.  */
252;
253;    /* Application FIQ handlers can be called here!  */
254;
255;    /* Jump to fiq context restore to restore system context.  */
256    B       _tx_thread_fiq_context_restore
257
258
2596.3.1.1 Nested FIQ Support
260
261By default, nested FIQ interrupt support is not enabled. To enable nested
262FIQ support, the entire library should be built with TX_ENABLE_FIQ_NESTING
263defined. With this defined, two new FIQ interrupt management services are
264available, namely _tx_thread_fiq_nesting_start and _tx_thread_fiq_nesting_end.
265These function should be called between the FIQ context save and restore
266calls.
267
268Execution between the calls to _tx_thread_fiq_nesting_start and
269_tx_thread_fiq_nesting_end is enabled for FIQ nesting. This is achieved
270by switching from FIQ mode to SYS mode and enabling FIQ interrupts.
271The SYS mode stack is used during the SYS mode operation, which was
272setup in tx_initialize_low_level.s. When nested FIQ interrupts are no longer required,
273calling the _tx_thread_fiq_nesting_end service disables nesting by disabling
274FIQ interrupts and switching back to FIQ mode in preparation for the FIQ
275context restore service.
276
277The following is an example of enabling FIQ nested interrupts in the
278typical FIQ handler:
279
280
281    EXPORT  __tx_fiq_handler
282    EXPORT  __tx_fiq_processing_return
283__tx_fiq_handler
284;
285;    /* Jump to fiq context save to save system context.  */
286    B       _tx_thread_fiq_context_save
287__tx_fiq_processing_return
288;
289;    /* At this point execution is still in the FIQ mode. The CPSR, point of
290;       interrupt, and all C scratch registers are available for use.  */
291;
292;    /* Enable nested FIQ interrupts. NOTE:  Since this service returns
293;       with FIQ interrupts enabled, all FIQ interrupt sources must be
294;       cleared prior to calling this service.  */
295    BL      _tx_thread_fiq_nesting_start
296;
297;    /* Application FIQ handlers can be called here!  */
298;
299;    /* Disable nested FIQ interrupts. The mode is switched back to
300;       FIQ mode and FIQ interrupts are disable upon return.  */
301    BL      _tx_thread_fiq_nesting_end
302;
303;    /* Jump to fiq context restore to restore system context.  */
304    B       _tx_thread_fiq_context_restore
305
306
3077.  ThreadX Timer Interrupt
308
309ThreadX requires a periodic interrupt source to manage all time-slicing,
310thread sleeps, timeouts, and application timers. Without such a timer
311interrupt source, these services are not functional. However, all other
312ThreadX services are operational without a periodic timer source.
313
314To add the timer interrupt processing, simply make a call to
315_tx_timer_interrupt in the IRQ processing. An example of this can be
316found in the file tx_initialize_low_level.s in the Integrator sub-directories.
317
318
3198. VFP Support
320
321VFP support is optional, it can be enabled by building the ThreadX library
322assembly code with the following command-line option:
323
324-mfpu=neon -DTARGET_FPU_VFP
325
326Note that if ISRs need to use VFP registers, their contents much be saved
327before their use and restored after.
328
329
3309.  Revision History
331
332For generic code revision information, please refer to the readme_threadx_generic.txt
333file, which is included in your distribution. The following details the revision
334information associated with this specific port of ThreadX:
335
33604-02-2021  Release 6.1.6 changes:
337            tx_port.h                           Updated macro definition
338
33909-30-2020  Initial ThreadX 6.1 version for Cortex-A5 using GNU tools.
340
341
342Copyright(c) 1996-2020 Microsoft Corporation
343
344
345https://azure.com/rtos
346
347