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 CANFD heartbeat / RX-logger demo for RA8D2. More...

#include <stdint.h>
#include "ra8_attributes.h"
#include "ra8_board_ek_ra8d2.h"
#include "ra8_boot_entry.h"
#include "ra8_canfd.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  canfd_marker_t : uint8_t {
  k_canfd_marker_0 = 0xA5U ,
  k_canfd_marker_1 = 0x5AU ,
  k_canfd_marker_2 = 0x12U ,
  k_canfd_marker_3 = 0x34U ,
  k_canfd_marker_4 = 0x56U ,
  k_canfd_marker_5 = 0x78U ,
  k_canfd_marker_6 = 0x9AU
}
 Stack size, in bytes, for each CANFD demo thread. More...
enum  canfd_stack_t : uint16_t { k_canfd_thread_stack_bytes = 1024U }
enum  canfd_priority_t : uint8_t { k_canfd_thread_priority = 4U }
 Thread priorities. More...
enum  canfd_period_t : uint16_t {
  k_canfd_heartbeat_ticks = 500U ,
  k_canfd_rx_poll_ticks = 50U ,
  k_canfd_heartbeat_id = 0x123U ,
  k_canfd_heartbeat_dlc = 8U
}
 Period and identifier values used by the heartbeat thread. More...
enum  canfd_link_t : uint32_t {
  k_canfd_demo_channel = 0U ,
  k_canfd_demo_bitrate = 500000U
}
 CAN-FD channel + bit-rate constants shared by both threads. More...

Functions

static void internal_thread_tx_entry (ULONG thread_input)
 Heartbeat TX thread: send a CAN-FD frame each period.
static void internal_thread_rx_entry (ULONG thread_input)
 RX polling thread: drain the loopback-mirrored frame.
void tx_application_define (void *first_unused_memory)
 ThreadX application init – creates the TX and RX threads.
void main (void)
 Application entry: GPIO bring-up then ThreadX dispatch.

Variables

static uint8_t s_thread_tx_stack [k_canfd_thread_stack_bytes]
static uint8_t s_thread_rx_stack [k_canfd_thread_stack_bytes]
static TX_THREAD s_thread_tx
static TX_THREAD s_thread_rx
volatile uint32_t g_threadx_canfd_match = 0U
 HIL success counter – one increment per successful CAN-FD transmit (TX thread) or per accepted RX frame (RX thread).
volatile uint32_t g_threadx_canfd_mismatch = 0U
 HIL failure counter – one increment per TX or RX error.

Detailed Description

Eclipse ThreadX CANFD heartbeat / RX-logger demo for RA8D2.

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

Two ThreadX threads cooperate over the EK-RA8D2's CANFD0 channel:

  • canfd_tx periodically transmits an 8-byte heartbeat frame at standard ID k_canfd_heartbeat_id once per k_canfd_heartbeat_ms.
  • canfd_rx polls the channel and toggles LED2 for each accepted frame – a visual "we received something" beacon.

The demo exists to prove the ra8_canfd HAL driver wires up cleanly under ThreadX – it is intentionally minimal and does not try to be a full CAN stack. Both threads use static stacks so the binary stays compatible with NASA Power of 10 Rule 3 (no dynamic allocation).

Threads
Name Priority Period
canfd_tx 4 500 ms
canfd_rx 4 50 ms (poll loop)
Since
0.1.0

Definition in file main.c.

Enumeration Type Documentation

◆ canfd_link_t

enum canfd_link_t : uint32_t

CAN-FD channel + bit-rate constants shared by both threads.

Enumerator
k_canfd_demo_channel 

CANFD0 (only channel on this board).

k_canfd_demo_bitrate 

500 kbit/s nominal + data rate.

Definition at line 92 of file main.c.

◆ canfd_marker_t

enum canfd_marker_t : uint8_t

Stack size, in bytes, for each CANFD demo thread.

Enumerator
k_canfd_marker_0 

CANFD marker 0.

k_canfd_marker_1 

CANFD marker 1.

k_canfd_marker_2 

CANFD marker 2.

k_canfd_marker_3 

CANFD marker 3.

k_canfd_marker_4 

CANFD marker 4.

k_canfd_marker_5 

CANFD marker 5.

k_canfd_marker_6 

CANFD marker 6.

Definition at line 58 of file main.c.

◆ canfd_period_t

enum canfd_period_t : uint16_t

Period and identifier values used by the heartbeat thread.

Enumerator
k_canfd_heartbeat_ticks 

500 ms in 1 kHz ticks.

k_canfd_rx_poll_ticks 

50 ms RX poll cadence.

k_canfd_heartbeat_id 

11-bit CAN identifier.

k_canfd_heartbeat_dlc 

Data length code (bytes).

Definition at line 82 of file main.c.

◆ canfd_priority_t

enum canfd_priority_t : uint8_t

Thread priorities.

Enumerator
k_canfd_thread_priority 

CANFD thread priority.

Definition at line 75 of file main.c.

◆ canfd_stack_t

enum canfd_stack_t : uint16_t
Enumerator
k_canfd_thread_stack_bytes 

CANFD thread stack bytes.

Definition at line 68 of file main.c.

Function Documentation

◆ internal_thread_rx_entry()

void internal_thread_rx_entry ( ULONG thread_input)
static

RX polling thread: drain the loopback-mirrored frame.

Polls ra8_canfd_receive each k_canfd_rx_poll_ticks. On a hit (k_ra8_ok), toggles LED2 and bumps g_threadx_canfd_match. No-data returns are expected between TX bursts and never increment either counter; only genuine HW errors advance the mismatch counter.

Parameters
[in]thread_inputThreadX cookie – unused.
Returns
None.
Precondition
ThreadX scheduler is running.
LED2 has been configured as an output.
Postcondition
LED2 toggles after every accepted RX frame.
g_threadx_canfd_match advances after every accepted RX frame.
g_threadx_canfd_mismatch advances on every receive error.
Note
Not thread-safe; only this thread calls ra8_canfd_receive on this channel.
Since
0.1.0

Definition at line 215 of file main.c.

References g_threadx_canfd_match, g_threadx_canfd_mismatch, k_canfd_demo_channel, k_canfd_rx_poll_ticks, k_ra8_board_led2, k_ra8_err_no_data, k_ra8_ok, ra8_board_led_toggle(), ra8_canfd_receive(), RA8_INTERNAL, and tx_thread_sleep.

Referenced by tx_application_define().

◆ internal_thread_tx_entry()

void internal_thread_tx_entry ( ULONG thread_input)
static

Heartbeat TX thread: send a CAN-FD frame each period.

Builds an 8-byte frame at k_canfd_heartbeat_id and calls ra8_canfd_transmit. The chip is in internal-loopback mode (set in tx_application_define) so the frame appears on the RX FIFO for internal_thread_rx_entry to consume.

Parameters
[in]thread_inputThreadX cookie – unused.
Returns
None.
Precondition
ThreadX scheduler is running.
LED1 has been configured as an output.
Postcondition
LED1 toggles after every successful transmit.
g_threadx_canfd_match advances after every successful transmit.
g_threadx_canfd_mismatch advances on every TX failure.
Note
Not thread-safe; only this thread calls ra8_canfd_transmit on this channel.
Since
0.1.0

Definition at line 160 of file main.c.

References g_threadx_canfd_match, g_threadx_canfd_mismatch, k_canfd_demo_channel, k_canfd_heartbeat_dlc, k_canfd_heartbeat_id, k_canfd_heartbeat_ticks, k_canfd_marker_0, k_canfd_marker_1, k_canfd_marker_2, k_canfd_marker_3, k_canfd_marker_4, k_canfd_marker_5, k_canfd_marker_6, k_ra8_board_led1, k_ra8_ok, ra8_board_led_toggle(), ra8_canfd_transmit(), RA8_INTERNAL, and tx_thread_sleep.

Referenced by tx_application_define().

◆ main()

void main ( void )

Application entry: GPIO bring-up then ThreadX dispatch.

The application entry point Reset_Handler hands control to.

Precondition
Reset_Handler completed .data/.bss init.
SystemInit set VTOR + FPU.
Postcondition
Two CANFD demo threads are running.

Definition at line 290 of file main.c.

References k_canfd_demo_bitrate, k_canfd_demo_channel, k_ra8_board_led1, k_ra8_board_led2, k_ra8_ctms_self_test_1, k_ra8_ok, ra8_board_led_init(), ra8_canfd_init(), ra8_canfd_set_bitrate(), ra8_canfd_set_test_mode(), ra8_cgc_init(), and ra8_isr_globals_enable().

◆ tx_application_define()

void tx_application_define ( void * first_unused_memory)

ThreadX application init – creates the TX and RX threads.

Parameters
[in]first_unused_memoryUnused (we use static stacks).
Precondition
Called from _tx_initialize_kernel_enter before the scheduler starts; IRQs are masked.
Postcondition
Both threads are created auto-start at the same priority.

Definition at line 241 of file main.c.

References internal_thread_rx_entry(), internal_thread_tx_entry(), k_canfd_thread_priority, k_canfd_thread_stack_bytes, s_thread_rx, s_thread_rx_stack, s_thread_tx, s_thread_tx_stack, TX_AUTO_START, TX_NO_TIME_SLICE, TX_SUCCESS, and tx_thread_create.

Variable Documentation

◆ g_threadx_canfd_match

volatile uint32_t g_threadx_canfd_match = 0U

HIL success counter – one increment per successful CAN-FD transmit (TX thread) or per accepted RX frame (RX thread).

Read externally by scripts/hil/jlink_memprobe.sh via SWD. The probe asserts this counter advances by >= HIL_PROBE_MIN_ADVANCE over the sample window, proving real CAN-FD frames are flowing on the internal-loopback path under ThreadX.

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

Definition at line 121 of file main.c.

Referenced by internal_thread_rx_entry(), and internal_thread_tx_entry().

◆ g_threadx_canfd_mismatch

volatile uint32_t g_threadx_canfd_mismatch = 0U

HIL failure counter – one increment per TX or RX error.

Read externally as HIL_PROBE_FAILURE_SYMBOL. Any non-zero reading means a CAN-FD primitive returned non-ok; the gate fails the run.

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

Definition at line 134 of file main.c.

Referenced by internal_thread_rx_entry(), and internal_thread_tx_entry().

◆ s_thread_rx

TX_THREAD s_thread_rx
static

Definition at line 105 of file main.c.

Referenced by tx_application_define().

◆ s_thread_rx_stack

uint8_t s_thread_rx_stack[k_canfd_thread_stack_bytes]
static

Definition at line 103 of file main.c.

Referenced by tx_application_define().

◆ s_thread_tx

TX_THREAD s_thread_tx
static

Definition at line 104 of file main.c.

Referenced by tx_application_define().

◆ s_thread_tx_stack

uint8_t s_thread_tx_stack[k_canfd_thread_stack_bytes]
static

Definition at line 102 of file main.c.

Referenced by tx_application_define().