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

SMBus 3.2 protocol-layer demo + HIL over IIC_B (#128). More...

#include <stddef.h>
#include <stdint.h>
#include "ra8_board_ek_ra8d2.h"
#include "ra8_boot_entry.h"
#include "ra8_cgc.h"
#include "ra8_err.h"
#include "ra8_i2c_bus_ops.h"
#include "ra8_i3c.h"
#include "ra8_io_i2c_bus.h"
#include "ra8_io_i2c_bus_i3c_compat.h"
#include "ra8_isr.h"
#include "ra8_mstp.h"
#include "ra8_port_utils.h"
#include "ra8_smbus.h"
#include "ra8_time.h"
Include dependency graph for main.c:

Go to the source code of this file.

Enumerations

enum  sd_consts_t : uint32_t {
  k_sd_uart_baud = 115200U ,
  k_sd_bus_hz = 100000U ,
  k_sd_iic_chan = (uint32_t)k_ra8_board_mikrobus_iic_b_channel ,
  k_sd_lsm_addr = 0x6BU ,
  k_sd_reg_whoami = 0x0FU ,
  k_sd_whoami_val = 0x6CU ,
  k_sd_hex_shift = 4U ,
  k_sd_hex_mask = 0x0FU ,
  k_sd_dec_ten = 10U
}
 Console / bus / device knobs (no magic numbers). More...

Functions

static void sd_print (const uint8_t *msg, uint32_t len)
 Emit a byte run on the SCI8 console.
static void sd_panic_halt (const uint8_t *msg, uint32_t len)
 Print the fail banner and trap (ra8_emulator halts on the BKPT).
static void sd_print_hex8 (uint8_t value)
 Print one byte as two upper-case hex digits.
static ra8_err_t sd_pins_init (void)
 Route the MikroBUS IIC SCL/SDA via PFS.
static void sd_setup_or_halt (uint32_t *out_pclka_hz)
 Bring up clocks/MSTP/time + the SCI8 console; halt on failure.
static void sd_read_whoami_or_halt (uint8_t *out_a, uint8_t *out_b)
 Read WHO_AM_I two ways over SMBus; halt on any failure.
void main (void)
 App entry: bring up SMBus, read WHO_AM_I two ways, print the banner.

Variables

static const ra8_port_pin_t k_sd_pin_scl = (ra8_port_pin_t)k_ra8_board_mikrobus_i2c_scl
 MikroBUS SCL routed through the Pmod1 I2C side (SCL1).
static const ra8_port_pin_t k_sd_pin_sda = (ra8_port_pin_t)k_ra8_board_mikrobus_i2c_sda
 MikroBUS SDA routed through the Pmod1 I2C side (SDA1).
static ra8_io_i2c_bus_t s_sd_bus
 Bound I2C bus handle the SMBus layer's injected seam points at.
static const uint8_t k_msg_boot [] = "smbus-demo: boot\r\n"
static const uint8_t k_msg_fail [] = "smbus-demo: FAIL init\r\n"
static const uint8_t k_msg_open [] = "smbus: FAIL open\r\n"
static const uint8_t k_msg_nak [] = "smbus: NAK (no LSM6DSO)\r\n"
static const uint8_t k_msg_bad [] = "smbus: mismatch\r\n"
static const uint8_t k_msg_pre [] = "smbus: whoami="
static const uint8_t k_msg_mid [] = " sendrecv="
static const uint8_t k_msg_ok [] = " PASS\r\n"

Detailed Description

SMBus 3.2 protocol-layer demo + HIL over IIC_B (#128).

ra8_smbus is the SMBus 3.2 protocol layer on top of the IIC_B (I3C-in- I2C-mode) controller – it frames Send Byte / Receive Byte / Read Byte Data / ... transactions and delegates the raw byte movement to ra8_i3c. It had no example and no CI gate. This app is that gate: it drives real SMBus byte transactions against an I2C register-file device and checks the decoded bytes.

The target is the ST LSM6DSO 6-DoF IMU (MikroBUS / IMU 12 Click on the Pmod1 I2C side, 7-bit address 0x6B) – a plain register-indexed I2C device, so it answers the SMBus byte protocols natively (SMBus is electrically I2C). Two independent reads of the WHO_AM_I register (0x0F, fixed 0x6C) exercise three protocol shapes:

  • Read Byte Data: write [0x0F], RESTART, read [0x6C].
  • Send Byte + Receive Byte: send [0x0F] (sets the device register pointer), then a separate read returns [0x6C]. PEC is left disabled (the IMU is not an SMBus PEC device), so the frames are plain I2C. The console banner is:

smbus: whoami=6C sendrecv=6C PASS

Under ra8_emulator the modelled LSM6DSO answers on the modelled IIC_B bus, so the banner is deterministic; on the bench it needs the IMU 12 Click fitted (same prerequisite as imu_lsm6dso_demo).

[Ring 7 / App] {World: NS}

Since
0.1.0

Definition in file main.c.

Enumeration Type Documentation

◆ sd_consts_t

enum sd_consts_t : uint32_t

Console / bus / device knobs (no magic numbers).

Enumerator
k_sd_uart_baud 

Console baud.

k_sd_bus_hz 

IIC_B standard-mode bit rate.

k_sd_iic_chan 

0.

k_sd_lsm_addr 

LSM6DSO 7-bit address (SA0 high).

k_sd_reg_whoami 

WHO_AM_I register index.

k_sd_whoami_val 

Expected WHO_AM_I value.

k_sd_hex_shift 

Nibble shift for hex printing.

k_sd_hex_mask 

Low-nibble mask.

k_sd_dec_ten 

Hex digit / decimal split.

Definition at line 56 of file main.c.

Function Documentation

◆ main()

void main ( void )

App entry: bring up SMBus, read WHO_AM_I two ways, 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 whoami PASS banner is emitted; the CPU then loops in WFI.
Since
0.1.0

Definition at line 194 of file main.c.

References k_msg_boot, k_msg_mid, k_msg_ok, k_msg_open, k_msg_pre, k_ra8_i3c_mode_i2c, k_ra8_ok, k_sd_bus_hz, k_sd_iic_chan, ra8_i3c_init(), ra8_io_i2c_bus_as_ops(), ra8_io_i2c_bus_bind_i3c_compat(), ra8_isr_globals_enable(), ra8_smbus_init(), s_sd_bus, sd_panic_halt(), sd_print(), sd_print_hex8(), sd_read_whoami_or_halt(), and sd_setup_or_halt().

◆ sd_panic_halt()

void sd_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 103 of file main.c.

References sd_print().

Referenced by main(), sd_read_whoami_or_halt(), and sd_setup_or_halt().

◆ sd_pins_init()

ra8_err_t sd_pins_init ( void )
staticnodiscard

Route the MikroBUS IIC SCL/SDA via PFS.

Definition at line 124 of file main.c.

References k_ra8_err_hw_init_failed, k_ra8_ok, k_ra8_psel_iic, k_sd_pin_scl, k_sd_pin_sda, and ra8_pfs_route_peripheral().

Referenced by sd_setup_or_halt().

◆ sd_print()

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

Emit a byte run on the SCI8 console.

Definition at line 97 of file main.c.

References ra8_board_uart_console_write().

Referenced by main(), sd_panic_halt(), and sd_print_hex8().

◆ sd_print_hex8()

void sd_print_hex8 ( uint8_t value)
static

Print one byte as two upper-case hex digits.

Definition at line 113 of file main.c.

References k_sd_dec_ten, k_sd_hex_mask, k_sd_hex_shift, and sd_print().

Referenced by main().

◆ sd_read_whoami_or_halt()

void sd_read_whoami_or_halt ( uint8_t * out_a,
uint8_t * out_b )
static

Read WHO_AM_I two ways over SMBus; halt on any failure.

(1) Read Byte Data(0x0F) -> a, (2) Send Byte(0x0F) then Receive Byte -> b. Both must equal 0x6C. A NAK (no IMU fitted) prints the NAK banner; a wrong value prints the mismatch banner; either halts on a BKPT before the PASS line so the gate is exact.

Parameters
[out]out_aReceives the Read-Byte-Data WHO_AM_I.
[out]out_bReceives the Send-Byte + Receive-Byte WHO_AM_I.

Definition at line 166 of file main.c.

References k_msg_bad, k_msg_nak, k_ra8_ok, k_sd_lsm_addr, k_sd_reg_whoami, k_sd_whoami_val, ra8_smbus_read_byte_data(), ra8_smbus_receive_byte(), ra8_smbus_send_byte(), and sd_panic_halt().

Referenced by main().

◆ sd_setup_or_halt()

void sd_setup_or_halt ( uint32_t * out_pclka_hz)
static

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

Definition at line 133 of file main.c.

References k_msg_fail, k_ra8_clock_id_cpuclk0, k_ra8_clock_id_pclka, k_ra8_ok, k_sd_uart_baud, ra8_board_uart_console_init(), ra8_cgc_get_clock_hz(), ra8_cgc_init(), ra8_mstp_init(), ra8_time_init(), sd_panic_halt(), and sd_pins_init().

Referenced by main().

Variable Documentation

◆ k_msg_bad

const uint8_t k_msg_bad[] = "smbus: mismatch\r\n"
static

Definition at line 91 of file main.c.

Referenced by sd_read_whoami_or_halt().

◆ k_msg_boot

const uint8_t k_msg_boot[] = "smbus-demo: boot\r\n"
static

Definition at line 87 of file main.c.

◆ k_msg_fail

const uint8_t k_msg_fail[] = "smbus-demo: FAIL init\r\n"
static

Definition at line 88 of file main.c.

◆ k_msg_mid

const uint8_t k_msg_mid[] = " sendrecv="
static

Definition at line 93 of file main.c.

Referenced by main().

◆ k_msg_nak

const uint8_t k_msg_nak[] = "smbus: NAK (no LSM6DSO)\r\n"
static

Definition at line 90 of file main.c.

◆ k_msg_ok

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

Definition at line 94 of file main.c.

◆ k_msg_open

const uint8_t k_msg_open[] = "smbus: FAIL open\r\n"
static

Definition at line 89 of file main.c.

◆ k_msg_pre

const uint8_t k_msg_pre[] = "smbus: whoami="
static

Definition at line 92 of file main.c.

◆ k_sd_pin_scl

MikroBUS SCL routed through the Pmod1 I2C side (SCL1).

Definition at line 70 of file main.c.

Referenced by sd_pins_init().

◆ k_sd_pin_sda

MikroBUS SDA routed through the Pmod1 I2C side (SDA1).

Definition at line 72 of file main.c.

Referenced by sd_pins_init().

◆ s_sd_bus

ra8_io_i2c_bus_t s_sd_bus
static

Bound I2C bus handle the SMBus layer's injected seam points at.

File-scope because the seam's ctx references it for the whole run.

Note
Written once during bring-up, then read-only.
Warning
Do not rebind while the SMBus layer is initialised.
Since
0.1.0

Definition at line 85 of file main.c.

Referenced by main().