1 Introduction
Azure RTOS is an embedded development suite including a small but powerful operating system that provides reliable, ultra-fast performance for resource-constrained devices.
Azure RTOS include 5 components. In project, it is compiled as 5 libs
2 Basic Threadx Structure
Below picture shows the initialization process of Azure RTOS.
2.1 main function
In main function, we can set up the processor, initialize the board. For most applications, the main function simply calls tx_kernel_enter, which is the entry into threadx.
2.2 tx_kernel_enter
This function is the first ThreadX function called during initialization. It is important to note that this routine never returns. The processing of this function is relatively simple. It calls several ThreadX initialization functions, calls the application define function, and then invokes the scheduler.
2.3 Application Definition Function
The tx_application_define function defines all of the initial application threads, queues, semaphores, mutexes, event flags, memory pools, and timers. It is also possible to create and delete system resources from threads during the normal operation of the application. However, all initial application resources are defined here.
When tx_application_define returns, control is transferred to the thread scheduling loop. This marks the end of initialization.
2.4 your thread entry
Every thread is just an infinite loop, that is what your code mainly about.
2.5 important files
tx_api.h : C header file containing all system equates, data structures, and service prototypes. All application files that use ThreadX api should include this header file.
tx_port.h : C header files containing all development-tool and target specific data definitions and structures.
3 Build a ThreadX application
There are four steps required to build a ThreadX application.
4 Simple demo
#include "tx_api.h"
unsigned long my_thread_counter = 0;
TX_THREAD my_thread;
main( )
{
/* Enter the ThreadX kernel. */
tx_kernel_enter( );
}
void tx_application_define(void *first_unused_memory)
{
/* Create my_thread! */
tx_thread_create(&my_thread, "My Thread",
my_thread_entry, 0x1234, first_unused_memory, 1024,
3, 3, TX_NO_TIME_SLICE, TX_AUTO_START);
}
void my_thread_entry(ULONG thread_input)
{
/* Enter into a forever loop. */
while(1)
{
/* Increment thread counter. */
my_thread_counter++;
/* Sleep for 1 tick. */
tx_thread_sleep(1);
}
}
5 Debug with TAD
The Thread Aware Debugging (TAD) tool is a useful and powerful instrument to debug the Azure RTOS application. With MCUXpresso IDE 11.4.1, we can show the Azure RTOS ThreasX TAD views. We take the evkmimxrt1060_threadx_demo as example.
Theads view shows the threads in a table, we can see the priority, state, stack usage for each thread.
Message Queues view shows the message queues in a table
Semaphores view shows the semaphores in a table
Suspended means the threads that are suspended and waiting for access to current resource.
Mutexes View shows the information about mutexes used inside the application
Event flags view shows the event flags in a table. Suspended : threads that are suspended and waiting for access to current resource.
Reference doc:
https://docs.microsoft.com/en-us/azure/rtos/