|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
LSM6DSO 6-DoF IMU bring-up demo over IIC_B. More...
#include <stdint.h>#include "ra8_board_ek_ra8d2.h"#include "ra8_boot_entry.h"#include "ra8_cgc.h"#include "ra8_err.h"#include "ra8_i3c.h"#include "ra8_isr.h"#include "ra8_lsm6dso.h"#include "ra8_mstp.h"#include "ra8_port_utils.h"#include "ra8_time.h"Go to the source code of this file.
Data Structures | |
| struct | imu_demo_iic_ctx_t |
| Adapter context: holds channel + 7-bit address. More... | |
Enumerations | |
| enum | imu_demo_const_t : uint32_t { k_imu_decimal_base = 10U , k_imu_demo_baud = 115200U , k_imu_demo_period_ms = 250U , k_imu_demo_bus_hz = 100000U , k_imu_demo_iic_channel } |
| App-wide tunables. More... | |
| enum | imu_demo_str_cap_t : uint32_t { k_imu_demo_int_str_cap = 8U } |
| Result buffer for one decimal int16_t (max "-32768" = 6 bytes plus the trailing NUL). More... | |
| enum | imu_demo_iic_cap_t : uint32_t { k_imu_demo_iic_tx_cap = 16U } |
| Transport adapter: write N bytes starting at register reg. More... | |
Functions | |
| static void | imu_demo_panic_halt (void) |
| Park forever after a fatal error. | |
| static uint32_t | imu_demo_i32_to_dec (int32_t value, uint8_t *out) |
| Convert a signed 16-bit int into a decimal ASCII string. | |
| static ra8_err_t | imu_demo_iic_read (void *ctx, uint8_t reg, uint8_t *buf, uint32_t len) |
| Transport adapter: read N bytes starting at register reg. | |
| static ra8_err_t | imu_demo_iic_write (void *ctx, uint8_t reg, const uint8_t *buf, uint32_t len) |
| static void | imu_demo_clocks_or_halt (uint32_t *out_pclka_hz) |
Bring CGC + SysTick + MSTP up; return PCLKA via out_pclka_hz. | |
| static void | imu_demo_pfs_or_halt (void) |
| Route IIC channel-0 SCL/SDA via PFS. | |
| static void | imu_demo_setup_or_halt (void) |
| Bring CGC + SysTick + console + IIC_B up. | |
| static void | imu_demo_tx (const uint8_t *bytes, uint32_t len) |
| Emit one line of bytes via the BSP UART console (SCI8). | |
| static void | imu_demo_emit_kv (const uint8_t *label, uint32_t label_len, int32_t value) |
| Emit a labelled signed integer: "<label>=<n>". | |
| static void | imu_demo_check_who_am_i (ra8_lsm6dso_t *dev) |
| Verify the LSM6DSO is alive and is the expected silicon. | |
| static void | imu_demo_configure (ra8_lsm6dso_t *dev) |
| Apply the demo's fixed sensor configuration (+-2 g, +-250 dps, 104 Hz). | |
| static void | imu_demo_sample_and_emit (ra8_lsm6dso_t *dev) |
| Read one cycle of accel + gyro + temperature and emit the log line. | |
| void | main (void) |
| Application entry: bring up CGC + IIC_B + LSM6DSO, print samples. | |
Variables | |
| static const ra8_port_pin_t | k_imu_demo_pin_scl = (ra8_port_pin_t)k_ra8_board_mikrobus_i2c_scl |
| MikroBUS SDA/SCL routed through Arduino D14/D15 to SDA1/SCL1. | |
| static const ra8_port_pin_t | k_imu_demo_pin_sda = (ra8_port_pin_t)k_ra8_board_mikrobus_i2c_sda |
| static const uint8_t | k_imu_demo_banner_ok [] = "lsm6dso: who_am_i=0x6c\r\n" |
| Banner line scraped by hil.conf. | |
| static const uint8_t | k_imu_demo_banner_bad [] = "lsm6dso: who_am_i mismatch\r\n" |
| static const uint8_t | k_imu_demo_banner_nak [] = "lsm6dso: I2C NAK\r\n" |
| static const uint8_t | k_imu_demo_banner_err [] = "lsm6dso: read error\r\n" |
LSM6DSO 6-DoF IMU bring-up demo over IIC_B.
Stand-alone EK-RA8D2 application that exercises the libs/ra8_lsm6dso driver against a MikroE LSM6DSO 6-DoF IMU 12 Click sitting in the MikroBUS slot. Project wiring (see BSP comments at k_ra8_board_mikrobus_i2c_*):
Pins resolve through the BSP symbols k_ra8_board_mikrobus_i2c_sda / _scl; the underlying IIC_B controller is channel k_ra8_board_mikrobus_iic_b_channel (= 0 – the RA8D2 group exposes only one IIC_B controller).
Flow:
Definition in file main.c.
| enum imu_demo_const_t : uint32_t |
| enum imu_demo_iic_cap_t : uint32_t |
Transport adapter: write N bytes starting at register reg.
Stages [reg][buf[0..len-1]] on a small stack scratch and issues a single ra8_i3c_write. Capped at k_imu_demo_iic_tx_cap bytes payload because the LSM6DSO driver never writes more than eight bytes at once.
| [in] | ctx | Adapter context. |
| [in] | reg | First register address. |
| [in] | buf | Source buffer. |
| [in] | len | Byte count. |
| Enumerator | |
|---|---|
| k_imu_demo_iic_tx_cap | Imu demo iic TX cap. |
| enum imu_demo_str_cap_t : uint32_t |
|
static |
Verify the LSM6DSO is alive and is the expected silicon.
Reads WHO_AM_I and compares against k_lsm6dso_who_am_i_value. On any failure the function emits a banner, latches LED2, and parks via imu_demo_panic_halt – it never returns to the caller in that case.
| [in,out] | dev | Driver instance bound by ra8_lsm6dso_init. |
Definition at line 368 of file main.c.
References imu_demo_panic_halt(), imu_demo_tx(), k_imu_demo_banner_bad, k_imu_demo_banner_nak, k_imu_demo_banner_ok, k_lsm6dso_who_am_i_value, k_ra8_board_led2, k_ra8_ok, ra8_board_led_on(), and ra8_lsm6dso_who_am_i().
Referenced by main().
|
static |
Bring CGC + SysTick + MSTP up; return PCLKA via out_pclka_hz.
Definition at line 245 of file main.c.
References imu_demo_panic_halt(), k_ra8_clock_id_cpuclk0, k_ra8_clock_id_pclka, k_ra8_ok, ra8_cgc_get_clock_hz(), ra8_cgc_init(), ra8_mstp_init(), and ra8_time_init().
Referenced by imu_demo_setup_or_halt().
|
static |
Apply the demo's fixed sensor configuration (+-2 g, +-250 dps, 104 Hz).
Wraps the three configuration setters into a single panic-on-error gate. Halts the CPU and latches LED2 if any setter returns non-OK.
| [in,out] | dev | Driver instance bound by ra8_lsm6dso_init. |
Definition at line 403 of file main.c.
References imu_demo_panic_halt(), k_lsm6dso_g_fs_250dps, k_lsm6dso_odr_104hz, k_lsm6dso_xl_fs_2g, k_ra8_board_led2, k_ra8_ok, ra8_board_led_on(), ra8_lsm6dso_set_accel_range(), ra8_lsm6dso_set_gyro_range(), and ra8_lsm6dso_set_odr().
Referenced by main().
|
static |
Emit a labelled signed integer: "<label>=<n>".
| [in] | label | NUL-terminated label. |
| [in] | label_len | Length of the label. |
| [in] | value | Signed integer. |
Definition at line 335 of file main.c.
References imu_demo_i32_to_dec(), imu_demo_tx(), and k_imu_demo_int_str_cap.
Referenced by imu_demo_sample_and_emit().
|
static |
Convert a signed 16-bit int into a decimal ASCII string.
Avoids dragging in newlib's printf, which would push the firmware image past the smoke-test footprint budget. The buffer must be at least k_imu_demo_int_str_cap bytes.
| [in] | value | Integer to convert. |
| [out] | out | Destination buffer (must be >= 8 bytes). |
Definition at line 133 of file main.c.
References k_imu_decimal_base, and k_imu_demo_int_str_cap.
Referenced by imu_demo_emit_kv().
|
static |
Transport adapter: read N bytes starting at register reg.
Uses ra8_i3c_transfer which does the write-RESTART-read in one bus transaction – this is the I2C pattern the LSM6DSO needs to read an auto-incremented register block.
| [in] | ctx | Adapter context (cast to imu_demo_iic_ctx_t*). |
| [in] | reg | First register address. |
| [out] | buf | Destination buffer. |
| [in] | len | Byte count. |
Definition at line 192 of file main.c.
References imu_demo_iic_ctx_t::addr7, imu_demo_iic_ctx_t::channel, and ra8_i3c_transfer().
Referenced by main().
|
static |
Definition at line 218 of file main.c.
References imu_demo_iic_ctx_t::addr7, imu_demo_iic_ctx_t::channel, k_imu_demo_iic_tx_cap, k_ra8_err_invalid_arg, and ra8_i3c_write().
Referenced by main().
|
static |
Park forever after a fatal error.
Definition at line 95 of file main.c.
Referenced by imu_demo_check_who_am_i(), imu_demo_clocks_or_halt(), imu_demo_configure(), imu_demo_pfs_or_halt(), imu_demo_setup_or_halt(), and main().
|
static |
Route IIC channel-0 SCL/SDA via PFS.
Definition at line 273 of file main.c.
References imu_demo_panic_halt(), k_imu_demo_pin_scl, k_imu_demo_pin_sda, k_ra8_ok, k_ra8_psel_iic, and ra8_pfs_route_peripheral().
Referenced by imu_demo_setup_or_halt().
|
static |
Read one cycle of accel + gyro + temperature and emit the log line.
Performs three back-to-back driver reads and, on full success, prints the "lsm6dso: ax=.. ay=.. ..." log line scraped by the HIL harness. On any single read failure the error banner is printed and LED2 is latched ON for the rest of the run.
| [in,out] | dev | Driver instance bound by ra8_lsm6dso_init. |
Definition at line 439 of file main.c.
References imu_demo_emit_kv(), imu_demo_tx(), k_imu_demo_banner_err, k_ra8_board_led2, k_ra8_ok, ra8_board_led_on(), ra8_lsm6dso_read_accel(), ra8_lsm6dso_read_gyro(), ra8_lsm6dso_read_temp(), ra8_lsm6dso_xyz_t::x, ra8_lsm6dso_xyz_t::y, and ra8_lsm6dso_xyz_t::z.
Referenced by main().
|
static |
Bring CGC + SysTick + console + IIC_B up.
Panic-halts on any fail.
Definition at line 288 of file main.c.
References imu_demo_clocks_or_halt(), imu_demo_panic_halt(), imu_demo_pfs_or_halt(), k_imu_demo_baud, k_imu_demo_bus_hz, k_imu_demo_iic_channel, k_ra8_board_led1, k_ra8_board_led2, k_ra8_i3c_mode_i2c, k_ra8_ok, ra8_board_led_init(), ra8_board_uart_console_init(), and ra8_i3c_init().
Referenced by main().
|
static |
Emit one line of bytes via the BSP UART console (SCI8).
| [in] | bytes | Null-terminated byte array. |
| [in] | len | Byte count. |
Definition at line 321 of file main.c.
References ra8_board_uart_console_write().
Referenced by imu_demo_check_who_am_i(), imu_demo_emit_kv(), imu_demo_sample_and_emit(), and main().
| void main | ( | void | ) |
Application entry: bring up CGC + IIC_B + LSM6DSO, print samples.
The application entry point Reset_Handler hands control to.
Definition at line 487 of file main.c.
References imu_demo_check_who_am_i(), imu_demo_configure(), imu_demo_iic_read(), imu_demo_iic_write(), imu_demo_panic_halt(), imu_demo_sample_and_emit(), imu_demo_setup_or_halt(), imu_demo_tx(), k_imu_demo_banner_err, k_imu_demo_iic_channel, k_imu_demo_period_ms, k_lsm6dso_i2c_addr_sa0_high, k_ra8_board_led1, k_ra8_board_led2, k_ra8_ok, ra8_board_led_on(), ra8_board_led_toggle(), ra8_delay_ms(), ra8_isr_globals_enable(), and ra8_lsm6dso_init().
|
static |
Definition at line 83 of file main.c.
Referenced by imu_demo_check_who_am_i().
|
static |
Definition at line 85 of file main.c.
Referenced by imu_demo_sample_and_emit(), and main().
|
static |
Definition at line 84 of file main.c.
Referenced by imu_demo_check_who_am_i().
|
static |
Banner line scraped by hil.conf.
Definition at line 82 of file main.c.
Referenced by imu_demo_check_who_am_i().
|
static |
MikroBUS SDA/SCL routed through Arduino D14/D15 to SDA1/SCL1.
Definition at line 73 of file main.c.
Referenced by imu_demo_pfs_or_halt().
|
static |
Definition at line 74 of file main.c.
Referenced by imu_demo_pfs_or_halt().