Tx_Thread_Creation Application Description

This application provides an example of Azure RTOS ThreadX stack usage, it shows how to develop an application using the ThreadX thread management APIs. It demonstrates how to create and destroy multiple threads using Azure RTOS ThreadX APIs. In addition, it shows how to use preemption threshold between threads and change priorities on-fly. The main entry function tx_application_define() is then called by ThreadX during kernel start, at this stage, the application creates 3 threads with different priorities :

Once started, the MainThread is suspended waiting for the event flag. The ThreadOne starts to toggle the LED_GREEN each 500ms and ThreadTwo cannot as its priority is less than the ThreadOne threshold. After 5 seconds it sends an event THREAD_ONE_EVT to the MainThread.

After receiving the THREAD_ONE_EVT, the MainThread change the ThreadTwo priority to 8 and its preemption threshold to 8 to be more than the ThreadOne threshold then waits for an event.

Now, the ThreadTwo can preempt the ThreadOne and start toggling the LED_GREEN each 200ms for 5 seconds. Once done it send the THREAD_TWO_EVT to MainThread. Once ThreadTwo_Evt is received, the MainThread resets the ThreadTwo priority and preemption threshold to their original values (10, 10), ThreadOne is rescheduled and the above scenario is redone. After repeating the sequence above 3 times, the MainThread should destroy ThreadOne and ThreadTwo and toggles the LED_GREEN each 1 second for ever.

Expected success behavior

Error behaviors

On failure, an error message is printed to the serial port.

Assumptions if any

None

Known limitations

None

Notes

To optimize the application footprint, the following ThreadX configuration options should be enabled in the tx_user.h file:

#define TX_DISABLE_PREEMPTION_THRESHOLD

#define TX_DISABLE_NOTIFY_CALLBACKS

#define TX_DISABLE_REDUNDANT_CLEARING

#define TX_DISABLE_STACK_FILLING

#define TX_NOT_INTERRUPTABLE

#define TX_TIMER_PROCESS_IN_ISR

#define TX_DISABLE_ERROR_CHECKING

ThreadX usage hints

Keywords

RTOS, ThreadX, Threading, Event flags, Preemption threshold

Hardware and Software environment

How to use it ?

In order to make the program work, you must do the following :