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

Non-Secure main entry point: launches ThreadX and demo worker threads. More...

#include <stdint.h>
#include <string.h>
#include "ra8_err.h"
#include "ra8_nsc.h"
#include "tx_api.h"
Include dependency graph for ns_main.c:

Go to the source code of this file.

Typedefs

typedef void(* ns_exc_handler_t) (void)

Enumerations

enum  ns_scb_addr_t : uintptr_t { k_ns_scb_vtor_addr = 0xE000ED08U }
 Address of NS VTOR register. More...
enum  ns_thread_stack_t : uint32_t {
  k_ns_ui_thread_stack_size = 2048U ,
  k_ns_work_thread_stack_size = 2048U
}
 Stack sizes for Non-Secure ThreadX threads. More...
enum  ns_log_cadence_t : uint32_t {
  k_ns_ui_heartbeat_iters = 50U ,
  k_ns_work_heartbeat_iters = 10U
}
 Heartbeat-log cadence per thread (iterations between log lines). More...
enum  ns_thread_cadence_t : uint16_t {
  k_ns_ui_sleep_ticks = 20U ,
  k_ns_work_sleep_ticks = 100U
}
 Per-thread sleep cadence, in ThreadX ticks. More...

Functions

void PendSV_Handler (void)
void _tx_timer_interrupt (void)
static void ns_systick_handler (void)
 SysTick exception handler for the Non-Secure ThreadX OS.
static void ns_panic_halt (void)
 Park the CPU in an idle loop if a fatal startup error occurs.
static void ui_thread_entry (ULONG thread_input)
 UI thread entry: logs periodically to simulate UI rendering loops.
static void work_thread_entry (ULONG thread_input)
 Worker thread entry: simulates background sensors/storage processing.
void tx_application_define (void *first_unused_memory)
 Setup ThreadX threads and resources.
void ns_reset_handler (void)
 Non-Secure Reset handler: entered via Secure-to-NS transition.
static void ns_nmi_halt (void)

Variables

uint32_t g_ra8_ls_ns_bss_start
uint32_t g_ra8_ls_ns_bss_end
uint32_t g_ra8_ls_ns_stack_top
uint32_t g_ra8_ls_ns_run_start
static TX_THREAD s_ui_thread
static TX_THREAD s_work_thread
static uint8_t s_ui_thread_stack [k_ns_ui_thread_stack_size]
static uint8_t s_work_thread_stack [k_ns_work_thread_stack_size]
volatile uint32_t g_ra8_threadx_systick_ready
 0 until _tx_initialize_low_level has armed ThreadX's SysTick + timer state; 1 afterwards.
const ns_exc_handler_t g_ra8_ns_vector_table [16]

Detailed Description

Non-Secure main entry point: launches ThreadX and demo worker threads.

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

This file is executed after the Secure world bootloader configures the SAU and jumps to ns_reset_handler. It operates entirely in Non-Secure state, leveraging ThreadX for multitasking and calling Secure services via NSC veneers.

Since
0.1.0

Definition in file ns_main.c.

Typedef Documentation

◆ ns_exc_handler_t

typedef void(* ns_exc_handler_t) (void)

Definition at line 221 of file ns_main.c.

Enumeration Type Documentation

◆ ns_log_cadence_t

enum ns_log_cadence_t : uint32_t

Heartbeat-log cadence per thread (iterations between log lines).

Since
0.1.0
Enumerator
k_ns_ui_heartbeat_iters 

UI heartbeat log cadence.

k_ns_work_heartbeat_iters 

Worker heartbeat log cadence.

Definition at line 58 of file ns_main.c.

◆ ns_scb_addr_t

enum ns_scb_addr_t : uintptr_t

Address of NS VTOR register.

Enumerator
k_ns_scb_vtor_addr 

Ns scb vtor address.

Definition at line 33 of file ns_main.c.

◆ ns_thread_cadence_t

enum ns_thread_cadence_t : uint16_t

Per-thread sleep cadence, in ThreadX ticks.

The UI thread runs the more responsive of the two so screen refreshes stay ahead of the background worker's batch work.

Invariant
Both values are non-zero: a zero sleep would spin the scheduler.
See also
ui_thread_entry
work_thread_entry
Enumerator
k_ns_ui_sleep_ticks 

UI thread sleep between refreshes.

k_ns_work_sleep_ticks 

Worker thread sleep between batches.

Definition at line 97 of file ns_main.c.

◆ ns_thread_stack_t

enum ns_thread_stack_t : uint32_t

Stack sizes for Non-Secure ThreadX threads.

Since
0.1.0
Enumerator
k_ns_ui_thread_stack_size 

Stack size for UI thread.

k_ns_work_thread_stack_size 

Stack size for Worker thread.

Definition at line 42 of file ns_main.c.

Function Documentation

◆ _tx_timer_interrupt()

void _tx_timer_interrupt ( void )
extern

◆ ns_nmi_halt()

void ns_nmi_halt ( void )
static

Definition at line 223 of file ns_main.c.

◆ ns_panic_halt()

void ns_panic_halt ( void )
static

Park the CPU in an idle loop if a fatal startup error occurs.

Definition at line 81 of file ns_main.c.

Referenced by ns_reset_handler().

◆ ns_reset_handler()

void ns_reset_handler ( void )

Non-Secure Reset handler: entered via Secure-to-NS transition.

Slot 1 of the NS vector table and the NS image's linker entry symbol; the Secure boot BLXNS-es here. No header declares it because the only callers are the hardware vector fetch and the linker – the prototype below satisfies -Wmissing-prototypes for this externally-linked boot symbol.

Precondition
The Secure boot copied/armed the NS image and programmed VTOR_NS.
Executes in NS Thread mode with MSP_NS from vector slot 0.
Postcondition
.bss is zeroed; ThreadX never returns.
Interrupt state is whatever tx_kernel_enter establishes.
Note
Not thread-safe; single-threaded NS boot only.
Since
0.1.0

Definition at line 191 of file ns_main.c.

References g_ra8_ls_ns_bss_end, g_ra8_ls_ns_bss_start, g_ra8_ls_ns_run_start, k_ns_scb_vtor_addr, k_ra8_ok, ns_panic_halt(), ra8_nsc_log_emit(), and ra8_nsc_periph_init().

◆ ns_systick_handler()

void ns_systick_handler ( void )
static

SysTick exception handler for the Non-Secure ThreadX OS.

Definition at line 71 of file ns_main.c.

References _tx_timer_interrupt(), and g_ra8_threadx_systick_ready.

◆ PendSV_Handler()

void PendSV_Handler ( void )
extern

◆ tx_application_define()

void tx_application_define ( void * first_unused_memory)

◆ ui_thread_entry()

void ui_thread_entry ( ULONG thread_input)
static

UI thread entry: logs periodically to simulate UI rendering loops.

Definition at line 105 of file ns_main.c.

References k_ns_ui_heartbeat_iters, k_ns_ui_sleep_ticks, ra8_nsc_log_emit(), and tx_thread_sleep.

Referenced by tx_application_define().

◆ work_thread_entry()

void work_thread_entry ( ULONG thread_input)
static

Worker thread entry: simulates background sensors/storage processing.

Definition at line 123 of file ns_main.c.

References k_ns_work_heartbeat_iters, k_ns_work_sleep_ticks, ra8_nsc_log_emit(), and tx_thread_sleep.

Referenced by tx_application_define().

Variable Documentation

◆ g_ra8_ls_ns_bss_end

uint32_t g_ra8_ls_ns_bss_end
extern

◆ g_ra8_ls_ns_bss_start

uint32_t g_ra8_ls_ns_bss_start
extern

◆ g_ra8_ls_ns_run_start

uint32_t g_ra8_ls_ns_run_start
extern

◆ g_ra8_ls_ns_stack_top

uint32_t g_ra8_ls_ns_stack_top
extern

◆ g_ra8_ns_vector_table

const ns_exc_handler_t g_ra8_ns_vector_table[16]
Initial value:
= {
0,
0,
0,
0,
}
uint32_t g_ra8_ls_ns_stack_top
void ns_reset_handler(void)
Definition ns_main.c:384
static void ns_nmi_halt(void)
NMI / fault halt vector for the NS table.
Definition ns_main.c:352
void(* ns_exc_handler_t)(void)
Function-pointer type for entries in the NS vector table.
Definition ns_main.c:337
static void ns_systick_handler(void)
NS SysTick handler – drives the ThreadX 1 ms time base.
Definition ns_main.c:316
void PendSV_Handler(void)

Definition at line 230 of file ns_main.c.

◆ g_ra8_threadx_systick_ready

volatile uint32_t g_ra8_threadx_systick_ready
extern

0 until _tx_initialize_low_level has armed ThreadX's SysTick + timer state; 1 afterwards.

Set by the kernel once tx_initialize_low_level has run.

Read by the shared SysTick handler in libs/ra8_core/src/ra8_time.c.

Note
Single-writer (assembly, once); multi-reader (every SysTick).
Since
0.1.0

Definition at line 58 of file tx_systick_ready.c.

◆ s_ui_thread

TX_THREAD s_ui_thread
static

Definition at line 47 of file ns_main.c.

Referenced by tx_application_define().

◆ s_ui_thread_stack

uint8_t s_ui_thread_stack[k_ns_ui_thread_stack_size]
static

Definition at line 50 of file ns_main.c.

Referenced by tx_application_define().

◆ s_work_thread

TX_THREAD s_work_thread
static

Definition at line 48 of file ns_main.c.

Referenced by tx_application_define().

◆ s_work_thread_stack

uint8_t s_work_thread_stack[k_ns_work_thread_stack_size]
static

Definition at line 51 of file ns_main.c.

Referenced by tx_application_define().