Create start-up threads inside tx_application_define
Create your first ThreadX threads and objects inside tx_application_define, which tx_kernel_enter calls before the scheduler starts, on ThreadX 6.4.
In Eclipse ThreadX 6.4, main() does almost nothing. It calls tx_kernel_enter(), which initialises the kernel and then calls a function you must supply, tx_application_define(), to create the first threads and other objects. Only then does the scheduler start.
#include "tx_api.h"
#include <stdio.h>
static TX_THREAD blink_thread;
static UCHAR blink_stack[1024];
static void blink_entry(ULONG input)
{
while (1) {
printf("tick from input %lu\n", (unsigned long)input);
tx_thread_sleep(100);
}
}
void tx_application_define(void *first_unused_memory)
{
(void)first_unused_memory;
tx_thread_create(&blink_thread, "blink", blink_entry, 7,
blink_stack, sizeof(blink_stack),
10, 10, TX_NO_TIME_SLICE, TX_AUTO_START);
}
int main(void)
{
tx_kernel_enter();
return 0;
}tick from input 7
tick from input 7tx_kernel_enter() never returns, so the return is unreachable. The function runs in the initialisation context, before any thread exists, so it can create objects but must not call anything that blocks: no tx_thread_sleep(), no waiting tx_mutex_get(). The pointer argument is the first free RAM after the kernel's own use, a convenient place to carve a byte pool from; this example uses a static stack array instead, which keeps the memory visible in the map file.
Priority 10 here is both the priority and the preemption threshold, which disables the threshold feature. Lower numbers are more urgent in ThreadX, with 0 the highest. The ULONG argument is delivered to the entry function, which is how one function body can serve several threads. See the ThreadX services reference.