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

RIIC (ra8_i2c) controller self-test against the on-board U15. 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_i2c.h"
#include "ra8_isr.h"
#include "ra8_mpc.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  i2c_demo_const_t : uint32_t {
  k_i2c_demo_baud = 115200U ,
  k_i2c_demo_period_ms = 1000U ,
  k_i2c_demo_bus_hz = 100000U ,
  k_i2c_demo_iic_channel = 1U
}
 App-wide tunables. More...
enum  i2c_demo_byte_t : uint8_t { k_i2c_demo_probe_addr = 0x43U }
 Probe target – on-board PI4IOE5V6408 I/O port expander U15 at 7-bit address 0x43 (board UM section 4.3.4, p 24). More...

Functions

static void internal_panic_halt (void)
 Park forever after a fatal initialization failure.
static void internal_clocks_or_halt (void)
 Bring CGC + SysTick + MSTP up.
static void internal_setup_or_halt (void)
 Bring CGC + SysTick + console + IIC_B up.
void main (void)
 Application entry.

Variables

static const uint8_t s_i2c_demo_msg_ack [] = "i2c: scan 0x43 ack=1\r\n"
static const uint8_t s_i2c_demo_msg_nack [] = "i2c: scan 0x43 ack=0\r\n"
static const uint8_t s_i2c_demo_msg_err [] = "i2c: scan ERROR\r\n"

Detailed Description

RIIC (ra8_i2c) controller self-test against the on-board U15.

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

Standalone EVM-tier app that exercises the ra8_i2c (RIIC) controller driver (libs/ra8_hal/inc/ra8_i2c.h) against the on-board PI4IOE5V6408 I2C I/O port expander (U15) at 7-bit address 0x43 – the only I2C peripheral guaranteed to be populated on a bare EK-RA8D2 v1 (board UM section 4.3.4 "Switch Configuration", p 24). U15 sits on RIIC channel 1 (P512 SCL1 / P511 SDA1), per issue #46. The flow:

  1. ra8_cgc_init – bring CPUCLK0 up.
  2. ra8_board_uart_console_init – BSP SCI8 console (PD02 TXD / PD03 RXD) bring-up.
  3. ra8_board_io_expander_apply_project_sw4_defaults() – the board's validated U15 bring-up: bus-recover, P109/P311 pull-ups, P512/P511 SCL1/SDA1 route + NCODR, ra8_i2c_init(ch1) and a U15 write. A k_ra8_ok return means U15 ACKed.
  4. ra8_i2c_scan against 0x43 in a loop – the U15 expander ACKs every address-only probe, proving the bus and controller.
  5. LED1 toggles each scan; SCI8 prints "i2c: scan 0x43 ack=1\r\n" once a second so a host terminal sees the heartbeat. LED2 latches ON if the driver returns a hard error or U15 fails to ACK.

Hardware: bare EK-RA8D2 v1 only – U15 is on-board, no jumpers needed.

Since
0.1.0

Definition in file main.c.

Enumeration Type Documentation

◆ i2c_demo_byte_t

enum i2c_demo_byte_t : uint8_t

Probe target – on-board PI4IOE5V6408 I/O port expander U15 at 7-bit address 0x43 (board UM section 4.3.4, p 24).

This device is always populated on a bare EK-RA8D2 v1 and ACKs every address-only probe, so a successful scan proves both the bus and the controller are alive.

Enumerator
k_i2c_demo_probe_addr 

I2C demo probe address.

Definition at line 62 of file main.c.

◆ i2c_demo_const_t

enum i2c_demo_const_t : uint32_t

App-wide tunables.

Enumerator
k_i2c_demo_baud 

I2C demo baud.

k_i2c_demo_period_ms 

I2C demo period ms.

k_i2c_demo_bus_hz 

I2C demo bus Hz.

k_i2c_demo_iic_channel 

RIIC ch1 (P512 SCL1 / P511 SDA1) – U15 here, per #46.

Definition at line 50 of file main.c.

Function Documentation

◆ internal_clocks_or_halt()

void internal_clocks_or_halt ( void )
static

Bring CGC + SysTick + MSTP up.

Initializes the canonical clock tree, samples CPUCLK0, ungates required peripheral modules, and starts the millisecond timebase.

Precondition
IRQs masked or single-threaded init context.
Reset startup initialized static storage and the vector table.
Postcondition
On success CGC is live and SysTick is ticking.
Any failed dependency transfers to internal_panic_halt.
Note
Not thread-safe; it mutates global clock and module-stop state.
Since
0.1.0

Definition at line 108 of file main.c.

References internal_panic_halt(), k_ra8_clock_id_cpuclk0, k_ra8_ok, ra8_cgc_get_clock_hz(), ra8_cgc_init(), RA8_INTERNAL, ra8_mstp_init(), and ra8_time_init().

Referenced by internal_setup_or_halt().

◆ internal_panic_halt()

void internal_panic_halt ( void )
static

Park forever after a fatal initialization failure.

Repeatedly executes WFI so a debugger can inspect the failed bus or clock state without additional I2C traffic.

Precondition
Called only after a fatal error in boot.
The caller does not require recovery without reset.
Postcondition
CPU is parked; only a debugger or external reset wakes it.
No further I2C or console operation is requested.
Note
Not thread-safe; this is the terminal single-threaded path.
Since
0.1.0

Definition at line 88 of file main.c.

References RA8_INTERNAL.

◆ internal_setup_or_halt()

void internal_setup_or_halt ( void )
static

Bring CGC + SysTick + console + IIC_B up.

Panic-halts on any fail.

The BSP ra8_board_uart_console_init owns the SCI8 console (PD02 TXD / PD03 RXD pin routing + baud), so the app no longer hand-rolls the SCI bring-up.

Precondition
internal_clocks_or_halt may safely own global clock setup.
U15 is populated at its fixed EK-RA8D2 address.
Postcondition
On return, SCI8, RIIC1/U15, and both status LEDs are ready.
Any initialization failure has parked the core.
Note
Not thread-safe; it owns the demo's peripheral setup.
Since
0.1.0

Definition at line 140 of file main.c.

References internal_clocks_or_halt(), internal_panic_halt(), k_i2c_demo_baud, k_ra8_board_led1, k_ra8_board_led2, k_ra8_ok, ra8_board_io_expander_apply_project_sw4_defaults(), ra8_board_led_init(), ra8_board_uart_console_init(), and RA8_INTERNAL.

◆ main()

void main ( void )

Application entry.

The application entry point Reset_Handler hands control to.

Brings up CGC + IIC_B + console then probes.

Precondition
Reset_Handler has copied .data and zeroed .bss.
SystemInit has set VTOR, FPU, and priority grouping.
Postcondition
On clean entry the CPU stays in the scan + blink loop forever.
On any HAL hard error LED2 latches ON and the loop exits.
Since
0.1.0

Definition at line 173 of file main.c.

References internal_panic_halt(), internal_setup_or_halt(), k_i2c_demo_iic_channel, k_i2c_demo_period_ms, k_i2c_demo_probe_addr, k_ra8_board_led1, k_ra8_board_led2, k_ra8_ok, ra8_board_led_on(), ra8_board_led_toggle(), ra8_board_uart_console_write(), ra8_delay_ms(), ra8_i2c_scan(), ra8_isr_globals_enable(), s_i2c_demo_msg_ack, s_i2c_demo_msg_err, and s_i2c_demo_msg_nack.

Variable Documentation

◆ s_i2c_demo_msg_ack

const uint8_t s_i2c_demo_msg_ack[] = "i2c: scan 0x43 ack=1\r\n"
static

Definition at line 72 of file main.c.

Referenced by main().

◆ s_i2c_demo_msg_err

const uint8_t s_i2c_demo_msg_err[] = "i2c: scan ERROR\r\n"
static

Definition at line 74 of file main.c.

Referenced by main().

◆ s_i2c_demo_msg_nack

const uint8_t s_i2c_demo_msg_nack[] = "i2c: scan 0x43 ack=0\r\n"
static

Definition at line 73 of file main.c.

Referenced by main().