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

Headless on-silicon self-test gate for the JTAG boundary-scan TAP bookkeeping driver ra8_bscan (#138). More...

#include <stddef.h>
#include <stdint.h>
#include "ra8_board_ek_ra8d2.h"
#include "ra8_boot_entry.h"
#include "ra8_bscan.h"
#include "ra8_bscan_regs.h"
#include "ra8_cgc.h"
#include "ra8_err.h"
#include "ra8_isr.h"
#include "ra8_mstp.h"
#include "ra8_time.h"
Include dependency graph for main.c:

Go to the source code of this file.

Enumerations

enum  bs_consts_t : uint32_t {
  k_bs_uart_baud = 115200U ,
  k_bs_reserved_op = 0x02U ,
  k_bs_clear_none = 0x00U ,
  k_bs_bad_mask = 0x01U ,
  k_bs_checks_total = 17U ,
  k_bs_hex_nibbles = 8U ,
  k_bs_nibble_bits = 4U ,
  k_bs_nibble_mask = 0x0FU ,
  k_bs_dec_ten = 10U
}
 Console / self-check knobs (no magic numbers). More...

Functions

static void bs_print (const uint8_t *msg, uint32_t len)
 Emit a byte run on the SCI8 console.
static void bs_panic_halt (const uint8_t *msg, uint32_t len)
 Print the fail banner and trap (ra8_emulator halts on the BKPT).
static void bs_require (bool ok)
 Self-check assertion: halt on the FAIL-check banner if ok is false.
static void bs_print_hex (uint32_t value)
 Print a 32-bit value as 8 upper-case hex digits.
static void bs_print_uint (uint32_t value)
 Print a small unsigned integer in decimal.
static uint32_t bs_run_checks (uint32_t *out_idcode)
 Run the full ra8_bscan CPU-side contract; halt on any failure.
static void bs_setup_or_halt (void)
 Bring up clocks/MSTP/time + the SCI8 console; halt on failure.
void main (void)
 App entry: run the bscan self-check, print the banner.

Variables

static const uint8_t k_msg_boot [] = "bscan-selftest: boot\r\n"
static const uint8_t k_msg_fail [] = "bscan-selftest: FAIL init\r\n"
static const uint8_t k_msg_chk [] = "bscan-selftest: FAIL check\r\n"
static const uint8_t k_msg_pre [] = "bscan: idcode="
static const uint8_t k_msg_mid [] = " checks="
static const uint8_t k_msg_ok [] = " PASS\r\n"

Detailed Description

Headless on-silicon self-test gate for the JTAG boundary-scan TAP bookkeeping driver ra8_bscan (#138).

The RA8D2 boundary-scan TAP (HUM Ch 50, p 3257-3262) is driven by an external IEEE-1149.1 manufacturing-test fixture over the four JTAG pins while RES is held low; its four registers (JTIR/JTIDR/JTBPR/JTBSR) are not CPU-reachable. So the actual scan chain cannot be exercised from firmware – that validation is inherently external-tool-driven.

What firmware can validate is its own contribution to boundary scan: the ra8_bscan bookkeeping object (HUM-sourced IDCODE constant, opcode validation, lifecycle). This app runs that contract end-to-end as a power-on self-test – no panel / SD / touch / JTAG fixture needed – and prints a deterministic banner on the SCI8 J-Link OB console:

bscan: idcode=085DA447 checks=17 PASS

The IDCODE is the chip's hardwired device ID (0x085D_A447, HUM Ch 50.2.2 p 3258) that the external fixture should scan out over TDO; asserting it here is the firmware's authoritative cross-check. Every sub-check (positive and negative API paths) must pass or the app halts on a FAIL banner before reaching the PASS line, so the gate is exact. The banner is identical on host, ra8_emulator, and silicon.

[Ring 7 / App] {World: NS}

Since
0.1.0

Definition in file main.c.

Enumeration Type Documentation

◆ bs_consts_t

enum bs_consts_t : uint32_t

Console / self-check knobs (no magic numbers).

Enumerator
k_bs_uart_baud 

Console baud.

k_bs_reserved_op 

A reserved JTIR opcode (HUM 50.2.1).

k_bs_clear_none 

Legal clear mask (the only one).

k_bs_bad_mask 

Illegal non-zero clear mask.

k_bs_checks_total 

Count of self-checks below.

k_bs_hex_nibbles 

Hex digits in a 32-bit value.

k_bs_nibble_bits 

Bits per hex nibble.

k_bs_nibble_mask 

Low-nibble mask.

k_bs_dec_ten 

Hex digit / decimal split.

Definition at line 50 of file main.c.

Function Documentation

◆ bs_panic_halt()

void bs_panic_halt ( const uint8_t * msg,
uint32_t len )
static

Print the fail banner and trap (ra8_emulator halts on the BKPT).

Definition at line 76 of file main.c.

References bs_print().

Referenced by bs_require(), and bs_setup_or_halt().

◆ bs_print()

void bs_print ( const uint8_t * msg,
uint32_t len )
static

Emit a byte run on the SCI8 console.

Definition at line 70 of file main.c.

References ra8_board_uart_console_write().

Referenced by bs_panic_halt(), bs_print_hex(), bs_print_uint(), and main().

◆ bs_print_hex()

void bs_print_hex ( uint32_t value)
static

Print a 32-bit value as 8 upper-case hex digits.

Definition at line 94 of file main.c.

References bs_print(), k_bs_dec_ten, k_bs_hex_nibbles, k_bs_nibble_bits, and k_bs_nibble_mask.

Referenced by main().

◆ bs_print_uint()

void bs_print_uint ( uint32_t value)
static

Print a small unsigned integer in decimal.

Definition at line 106 of file main.c.

References bs_print(), and k_bs_dec_ten.

Referenced by main().

◆ bs_require()

void bs_require ( bool ok)
static

Self-check assertion: halt on the FAIL-check banner if ok is false.

Definition at line 86 of file main.c.

References bs_panic_halt(), and k_msg_chk.

Referenced by bs_run_checks().

◆ bs_run_checks()

uint32_t bs_run_checks ( uint32_t * out_idcode)
static

Run the full ra8_bscan CPU-side contract; halt on any failure.

Exercises every public entry point on both its positive and negative paths: the IDCODE constant cross-check (the firmware's boundary-scan contribution), opcode validation, the clear-mask guard, and the NULL guards. Returns the chip device ID for the banner.

Parameters
[out]out_idcodeReceives the JTIDR device ID read back.
Returns
The number of checks performed (== k_bs_checks_total).

Definition at line 136 of file main.c.

References bs_require(), ra8_bscan_status_t::expected_idcode, ra8_bscan_status_t::initialized, k_bs_bad_mask, k_bs_checks_total, k_bs_clear_none, k_bs_reserved_op, k_ra8_bscan_instr_bypass, k_ra8_bscan_instr_idcode, k_ra8_bscan_jtidr_reset, k_ra8_err_invalid_arg, k_ra8_err_null_ptr, k_ra8_ok, ra8_bscan_status_t::last_instruction, ra8_bscan_clear_status(), ra8_bscan_get_idcode(), ra8_bscan_get_status(), ra8_bscan_init(), and ra8_bscan_set_instruction().

Referenced by main().

◆ bs_setup_or_halt()

void bs_setup_or_halt ( void )
static

Bring up clocks/MSTP/time + the SCI8 console; halt on failure.

Definition at line 165 of file main.c.

References bs_panic_halt(), k_bs_uart_baud, k_msg_fail, k_ra8_clock_id_cpuclk0, k_ra8_ok, ra8_board_uart_console_init(), ra8_cgc_get_clock_hz(), ra8_cgc_init(), ra8_mstp_init(), and ra8_time_init().

Referenced by main().

◆ main()

void main ( void )

App entry: run the bscan self-check, print the banner.

The application entry point Reset_Handler hands control to.

Precondition
Reset_Handler copied .data and zeroed .bss.
SystemInit set VTOR / FPU / priority grouping.
Postcondition
The IDCODE/checks PASS banner is emitted; the CPU then loops in WFI.
Since
0.1.0

Definition at line 190 of file main.c.

References bs_print(), bs_print_hex(), bs_print_uint(), bs_run_checks(), bs_setup_or_halt(), k_msg_boot, k_msg_mid, k_msg_ok, k_msg_pre, and ra8_isr_globals_enable().

Variable Documentation

◆ k_msg_boot

const uint8_t k_msg_boot[] = "bscan-selftest: boot\r\n"
static

Definition at line 62 of file main.c.

◆ k_msg_chk

const uint8_t k_msg_chk[] = "bscan-selftest: FAIL check\r\n"
static

Definition at line 64 of file main.c.

Referenced by bs_require().

◆ k_msg_fail

const uint8_t k_msg_fail[] = "bscan-selftest: FAIL init\r\n"
static

Definition at line 63 of file main.c.

◆ k_msg_mid

const uint8_t k_msg_mid[] = " checks="
static

Definition at line 66 of file main.c.

◆ k_msg_ok

const uint8_t k_msg_ok[] = " PASS\r\n"
static

Definition at line 67 of file main.c.

◆ k_msg_pre

const uint8_t k_msg_pre[] = "bscan: idcode="
static

Definition at line 65 of file main.c.