ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
main.c File Reference

Eclipse ThreadX bring-up HIL test on the EK-RA8D2. More...

#include <stdint.h>
#include "ra8_attributes.h"
#include "ra8_board_ek_ra8d2.h"
#include "ra8_boot_entry.h"
#include "ra8_cgc.h"
#include "ra8_err.h"
#include "ra8_isr.h"
#include "ra8_port_constants.h"
#include "ra8_port_utils.h"
#include "tx_api.h"
Include dependency graph for main.c:

Go to the source code of this file.

Enumerations

enum  blink_stack_t : uint16_t { k_blink_thread_stack_bytes = 1024U }
 Stack size, in bytes, for each user blink thread. More...
enum  blink_priority_t : uint8_t { k_blink_thread_priority = 4U }
 Thread priority for both blink threads. More...
enum  blink_period_t : uint16_t {
  k_blink_a_ticks = 500U ,
  k_blink_b_ticks = 1000U
}
 Sleep durations expressed in ThreadX ticks. More...

Functions

static void internal_thread_a_entry (ULONG thread_input)
 Thread A entry point: toggle LED1 every k_blink_a_ticks ms.
static void internal_thread_b_entry (ULONG thread_input)
 Thread B entry point: toggle LED2 every k_blink_b_ticks ms.
void tx_application_define (void *first_unused_memory)
 ThreadX application initialization callback.
void main (void)
 Application entry.

Variables

static uint8_t s_thread_a_stack [k_blink_thread_stack_bytes]
 Stack for thread A (LED1 blinker).
static uint8_t s_thread_b_stack [k_blink_thread_stack_bytes]
 Stack for thread B (LED2 blinker).
static TX_THREAD s_thread_a
 Thread A control block.
static TX_THREAD s_thread_b
 Thread B control block.
volatile uint32_t g_threadx_blink_tick = 0U
 HIL liveness counter – incremented by thread A on each LED-A toggle.

Detailed Description

Eclipse ThreadX bring-up HIL test on the EK-RA8D2.

Tag
[Ring 6 / APP] {World: S}

Two ThreadX threads, each blinking a different LED at a different rate, sharing the Cortex-M85 via cooperative-plus-preemptive scheduling. This is the canonical "is the RTOS alive?" demo and the first piece of code that exercises:

Like examples/blink_hal, this app deliberately skips ra8_cgc_init() – it runs on the boot-default MOCO (~8.4 MHz) so the SysTick reload programmed in tx_initialize_low_level.S stays accurate.

Threads
Name Priority Period LED
blink_a 4 1000 ms (1 Hz) LED1 P6_00
blink_b 4 2000 ms (0.5 Hz) LED2 P3_03

Both threads run at the same priority; ThreadX round-robins them on each tx_thread_sleep wake.

Since
0.1.0

Definition in file main.c.

Enumeration Type Documentation

◆ blink_period_t

enum blink_period_t : uint16_t

Sleep durations expressed in ThreadX ticks.

port/threadx/inc/tx_user.h pins the tick rate to 1000 Hz, so a tick is 1 ms. k_blink_a_ticks therefore lights LED1 at 1 Hz and k_blink_b_ticks lights LED2 at 0.5 Hz.

Enumerator
k_blink_a_ticks 

Blink a ticks.

k_blink_b_ticks 

Blink b ticks.

Definition at line 97 of file main.c.

◆ blink_priority_t

enum blink_priority_t : uint8_t

Thread priority for both blink threads.

Enumerator
k_blink_thread_priority 

Blink thread priority.

Definition at line 85 of file main.c.

◆ blink_stack_t

enum blink_stack_t : uint16_t

Stack size, in bytes, for each user blink thread.

1 KiB is comfortably above TX_MINIMUM_STACK (set to 512 in port/threadx/inc/tx_user.h) and accommodates the FPU + Helium register save area on a context switch. Static allocation keeps the demo compatible with NASA Power of 10 Rule 3 (no dynamic memory).

Enumerator
k_blink_thread_stack_bytes 

Blink thread stack bytes.

Definition at line 78 of file main.c.

Function Documentation

◆ internal_thread_a_entry()

void internal_thread_a_entry ( ULONG thread_input)
static

Thread A entry point: toggle LED1 every k_blink_a_ticks ms.

Drives the first board LED, advances the HIL liveness counter, and sleeps for the configured ThreadX interval on every iteration.

Parameters
[in]thread_inputUnused (ThreadX cookie).
Returns
None.
Precondition
ra8_gpio_output_init has succeeded for k_ra8_pin_led1.
ThreadX scheduler is running (tx_kernel_enter has dispatched a thread).
Postcondition
LED1 toggles on each loop iteration.
The thread blocks at tx_thread_sleep, yielding the CPU.
Note
Permanent single-instance worker; it never returns to ThreadX.
Since
0.1.0

Definition at line 179 of file main.c.

References g_threadx_blink_tick, k_blink_a_ticks, k_ra8_board_led1, ra8_board_led_toggle(), RA8_INTERNAL, and tx_thread_sleep.

Referenced by tx_application_define().

◆ internal_thread_b_entry()

void internal_thread_b_entry ( ULONG thread_input)
static

Thread B entry point: toggle LED2 every k_blink_b_ticks ms.

Independently drives the second board LED at its slower cadence and yields after every toggle so the scheduler can dispatch thread A.

Parameters
[in]thread_inputUnused (ThreadX cookie).
Returns
None.
Precondition
ra8_gpio_output_init has succeeded for k_ra8_pin_led2.
ThreadX scheduler is running.
Postcondition
LED2 toggles on each loop iteration.
Thread sleeps via tx_thread_sleep so the scheduler can pick A.
Note
Permanent single-instance worker; it never returns to ThreadX.
Since
0.1.0

Definition at line 208 of file main.c.

References k_blink_b_ticks, k_ra8_board_led2, ra8_board_led_toggle(), RA8_INTERNAL, and tx_thread_sleep.

Referenced by tx_application_define().

◆ main()

void main ( void )

Application entry.

The application entry point Reset_Handler hands control to.

Configures GPIO, then launches ThreadX.

Precondition
Reset_Handler has copied .data + zeroed .bss.
SystemInit has set VTOR, FPU, and priority grouping.
Postcondition
The two LED threads are running and SysTick is generating 1 ms ticks for the scheduler.
On any HAL init failure the function halts in __WFI.
Since
0.1.0

Definition at line 301 of file main.c.

References k_ra8_board_led1, k_ra8_board_led2, k_ra8_ok, ra8_board_led_init(), and ra8_cgc_init().

◆ tx_application_define()

void tx_application_define ( void * first_unused_memory)

ThreadX application initialization callback.

Parameters
[in]first_unused_memoryPointer to the first byte of free RAM after the kernel's internal allocations. Unused here – both threads use static stacks declared at file scope.
Precondition
Called from _tx_initialize_kernel_enter, before the scheduler starts. IRQs are masked at this point.
ra8_gpio_output_init has already configured LED1 + LED2 (done from main() before tx_kernel_enter()).
Postcondition
Thread A is created at priority k_blink_thread_priority and set to auto-start.
Thread B is created at the same priority.
Note
tx_thread_create returns TX_SUCCESS on a clean register – on failure we busy-loop here because there is no log channel up yet and the kernel is about to take over.

Definition at line 244 of file main.c.

References internal_thread_a_entry(), internal_thread_b_entry(), k_blink_thread_priority, k_blink_thread_stack_bytes, s_thread_a, s_thread_a_stack, s_thread_b, s_thread_b_stack, TX_AUTO_START, TX_NO_TIME_SLICE, TX_SUCCESS, and tx_thread_create.

Variable Documentation

◆ g_threadx_blink_tick

volatile uint32_t g_threadx_blink_tick = 0U

HIL liveness counter – incremented by thread A on each LED-A toggle.

Read externally by hil_jlink_memprobe.sh.

If ThreadX schedules thread A correctly, the counter advances at 1/k_blink_a_ticks Hz. The memprobe HIL mode asserts the counter has advanced over a sample window – catches "scheduler wedged" and "thread crashed before first iteration" failure modes that the plain HIL_MODE=alive check misses.

volatile keeps the increment alive under optimization; the global (non-static) keeps the symbol linker-visible without –gc-sections culling.

Note
Read externally by J-Link only; firmware never reads back.
Since
0.1.0

Definition at line 148 of file main.c.

Referenced by internal_thread_a_entry().

◆ s_thread_a

TX_THREAD s_thread_a
static

Thread A control block.

ThreadX zeroes it on tx_thread_create.

Definition at line 122 of file main.c.

Referenced by tx_application_define(), and wdt_sup_demo_spawn_workers().

◆ s_thread_a_stack

uint8_t s_thread_a_stack[k_blink_thread_stack_bytes]
static

Stack for thread A (LED1 blinker).

Note
32-bit aligned per ARMv8-M AAPCS.

Definition at line 112 of file main.c.

Referenced by tx_application_define(), and wdt_sup_demo_spawn_workers().

◆ s_thread_b

TX_THREAD s_thread_b
static

Thread B control block.

Definition at line 127 of file main.c.

Referenced by tx_application_define(), and wdt_sup_demo_spawn_workers().

◆ s_thread_b_stack

uint8_t s_thread_b_stack[k_blink_thread_stack_bytes]
static

Stack for thread B (LED2 blinker).

Definition at line 117 of file main.c.

Referenced by tx_application_define(), and wdt_sup_demo_spawn_workers().