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

..--

example_build/11-Mar-2024-3,5542,148

inc/11-Mar-2024-407164

src/11-Mar-2024-3,7563,367

readme_threadx.txtD11-Mar-20249.5 KiB242168

readme_threadx.txt

1                Microsoft's Azure RTOS ThreadX SMP for Cortex-A9
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-A9x4 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-A9 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-A9
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-A9 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.3  FIQ Interrupts
151
152By default, Cortex-A9 FIQ interrupts are left alone by ThreadX. Of course, this
153means that the application is fully responsible for enabling the FIQ interrupt
154and saving/restoring any registers used in the FIQ ISR processing. To globally
155enable FIQ interrupts, the application should enable FIQ interrupts at the
156beginning of each thread or before any threads are created in tx_application_define.
157In addition, the application must ensure that no ThreadX service calls are made
158from default FIQ ISRs, which is located in tx_initialize_low_level.s.
159
160
1616.3.1  Managed FIQ Interrupts
162
163Full ThreadX management of FIQ interrupts is provided if the ThreadX sources
164are built with the TX_ENABLE_FIQ_SUPPORT defined. If the library is built
165this way, the FIQ interrupt handlers are very similar to the IRQ interrupt
166handlers defined previously. The following is default FIQ handler
167defined in tx_initialize_low_level.s:
168
169
170    EXPORT  __tx_fiq_handler
171    EXPORT  __tx_fiq_processing_return
172__tx_fiq_handler
173;
174;    /* Jump to fiq context save to save system context.  */
175    B       _tx_thread_fiq_context_save
176__tx_fiq_processing_return:
177;
178;    /* At this point execution is still in the FIQ mode. The CPSR, point of
179;       interrupt, and all C scratch registers are available for use.  */
180;
181;    /* Application FIQ handlers can be called here!  */
182;
183;    /* Jump to fiq context restore to restore system context.  */
184    B       _tx_thread_fiq_context_restore
185
186
1877.  ThreadX Timer Interrupt
188
189ThreadX requires a periodic interrupt source to manage all time-slicing,
190thread sleeps, timeouts, and application timers. Without such a timer
191interrupt source, these services are not functional. However, all other
192ThreadX services are operational without a periodic timer source.
193
194To add the timer interrupt processing, simply make a call to
195_tx_timer_interrupt in the IRQ processing. An example of this can be
196found in the file tx_initialize_low_level.s in the Integrator sub-directories.
197
198
1998.  Thumb/Cortex-A9 Mixed Mode
200
201By default, ThreadX is setup for running in Cortex-A9 32-bit mode. This is
202also true for the demonstration system. It is possible to build any
203ThreadX file and/or the application in Thumb mode. If any Thumb code
204is used the entire ThreadX source- both C and assembly - should be built
205with the "-apcs /interwork" option.
206
207
2089. VFP Support
209
210By default, VFP support is disabled for each thread. If saving the context of the VFP registers
211is needed, the following API call must be made from the context of the application thread - before
212the VFP usage:
213
214void    tx_thread_vfp_enable(void);
215
216After this API is called in the application, VFP registers will be saved/restored for this thread if it
217is preempted via an interrupt. All other suspension of the this thread will not require the VFP registers
218to be saved/restored.
219
220To disable VFP register context saving, simply call the following API:
221
222void    tx_thread_vfp_disable(void);
223
224
22510.  Revision History
226
227For generic code revision information, please refer to the readme_threadx_generic.txt
228file, which is included in your distribution. The following details the revision
229information associated with this specific port of ThreadX:
230
23104-02-2021  Release 6.1.6 changes:
232            tx_port.h                           Updated macro definition
233
23409-30-2020  Initial ThreadX 6.1 version for Cortex-A9 using GNU tools.
235
236
237Copyright(c) 1996-2020 Microsoft Corporation
238
239
240https://azure.com/rtos
241
242