ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
1
35
36#include <stdint.h>
37
38#include "ra8_attributes.h"
39#include "ra8_board_ek_ra8d2.h"
40#include "ra8_boot_entry.h"
41#include "ra8_cgc.h"
42#include "ra8_err.h"
43#include "ra8_i2c.h"
44#include "ra8_isr.h"
45#include "ra8_mpc.h"
46#include "ra8_mstp.h"
47#include "ra8_time.h"
48
50typedef enum : uint32_t {
51 k_i2c_demo_baud = 115200U,
56
62typedef enum : uint8_t {
65
66/* SCI8 console (PD02 TXD / PD03 RXD) pin routing + baud are owned by the
67 * BSP via ra8_board_uart_console_init(). RIIC ch1 SCL1/SDA1 (P512/P511)
68 * routing + the P109/P311 pull-ups and NCODR are owned by
69 * ra8_board_io_expander_apply_project_sw4_defaults(), the same validated
70 * bring-up the board library uses for U15. */
71
72static const uint8_t s_i2c_demo_msg_ack[] = "i2c: scan 0x43 ack=1\r\n";
73static const uint8_t s_i2c_demo_msg_nack[] = "i2c: scan 0x43 ack=0\r\n";
74static const uint8_t s_i2c_demo_msg_err[] = "i2c: scan ERROR\r\n";
75
89{
90 while (1) {
91 __asm__ volatile("wfi");
92 }
93}
94
109{
110 uint32_t cpuclk0_hz = 0U;
111 if (ra8_cgc_init() != k_ra8_ok) {
113 }
116 }
117 if (ra8_mstp_init() != k_ra8_ok) {
119 }
120 if (ra8_time_init(cpuclk0_hz) != k_ra8_ok) {
122 }
123}
124
141{
143
146 }
147 /* Bring up RIIC ch1 + confirm U15 via the board's validated path
148 * (bus-recover + P109/P311 pull-ups + P512/P511 route + ra8_i2c_init +
149 * a U15 write). k_ra8_ok means U15 ACKed the project SW4 byte; the bus
150 * is then live for the ra8_i2c_scan loop below. */
153 }
156 }
159 }
160}
161
173void main(void)
174{
177
178 while (1) {
179 bool acked = false;
180 const ra8_err_t err =
182 const uint8_t* msg = s_i2c_demo_msg_err;
183 uint32_t msg_len = (uint32_t)(sizeof(s_i2c_demo_msg_err) - 1U);
184 if (err == k_ra8_ok) {
185 if (acked) {
186 msg = s_i2c_demo_msg_ack;
187 msg_len = (uint32_t)(sizeof(s_i2c_demo_msg_ack) - 1U);
188 } else {
190 msg_len = (uint32_t)(sizeof(s_i2c_demo_msg_nack) - 1U);
191 }
192 } else {
194 }
195 if (ra8_board_uart_console_write(msg, (size_t)msg_len) != k_ra8_ok) {
196 break;
197 }
199 break;
200 }
202 }
203
205}
void main(void)
Secure fallback main entry point.
Definition main.c:37
static void internal_setup_or_halt(void)
Bring up clocks, MSTP, delay timing, and the board console.
Definition main.c:211
static void internal_panic_halt(void)
Park the core after an unrecoverable ADC demo failure.
Definition main.c:123
static const uint8_t s_i2c_demo_msg_err[]
Definition main.c:74
static const uint8_t s_i2c_demo_msg_ack[]
Definition main.c:72
i2c_demo_byte_t
Probe target – on-board PI4IOE5V6408 I/O port expander U15 at 7-bit address 0x43 (board UM section 4....
Definition main.c:62
@ k_i2c_demo_probe_addr
I2C demo probe address.
Definition main.c:63
i2c_demo_const_t
App-wide tunables.
Definition main.c:50
@ k_i2c_demo_period_ms
I2C demo period ms.
Definition main.c:52
@ k_i2c_demo_iic_channel
RIIC ch1 (P512 SCL1 / P511 SDA1) – U15 here, per #46.
Definition main.c:54
@ k_i2c_demo_baud
I2C demo baud.
Definition main.c:51
@ k_i2c_demo_bus_hz
I2C demo bus Hz.
Definition main.c:53
static void internal_clocks_or_halt(void)
Bring CGC + SysTick + MSTP up.
Definition main.c:108
static const uint8_t s_i2c_demo_msg_nack[]
Definition main.c:73
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Board-support layer for the Renesas EK-RA8D2 v1 evaluation kit.
ra8_err_t ra8_board_led_toggle(ra8_board_led_id_t led)
Toggle led's output state.
ra8_err_t ra8_board_led_init(ra8_board_led_id_t led)
Configure led as a digital output, initial level low (off).
ra8_err_t ra8_board_led_on(ra8_board_led_id_t led)
Drive led HIGH (light it).
@ k_ra8_board_led2
LED2, GREEN, P303 (jumper E26).
@ k_ra8_board_led1
LED1, BLUE, P600 (jumper E27).
ra8_err_t ra8_board_io_expander_apply_project_sw4_defaults(void)
Program the U15 I/O expander to apply the project's SW4 layout.
ra8_err_t ra8_board_uart_console_write(const uint8_t *data, size_t len)
Polled blocking write to the J-Link OB VCOM console.
ra8_err_t ra8_board_uart_console_init(uint32_t baud)
Configure SCI8 + PD02/PD03 as the debug-console UART.
Boot entry points shared between a vector table and its startup code.
High-level Clock Generation Circuit driver.
ra8_err_t ra8_cgc_get_clock_hz(ra8_clock_id_t id, uint32_t *out_hz)
Query the current frequency of a clock-tree domain.
Definition ra8_cgc.c:132
@ k_ra8_clock_id_cpuclk0
Cortex-M85 CPUCLK0.
Definition ra8_cgc.h:70
ra8_err_t ra8_cgc_init(void)
Configure the clock tree to a safe default.
Definition ra8_cgc.c:727
Error Code Definitions for ra8-firmware.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
I2C Bus Interface (IIC) controller driver – polling mode.
ra8_err_t ra8_i2c_scan(uint8_t channel, uint8_t peripheral_7b, bool *out_acked)
Probe whether a 7-bit peripheral address ACKs.
Definition ra8_i2c.c:762
NVIC + ICU IELSR allocator.
void ra8_isr_globals_enable(void)
Globally enable maskable interrupts (PRIMASK = 0).
Definition ra8_isr.c:439
Multi-function Pin Controller (MPC) facade.
Ref-counted Module Stop Control wrapper for the RA8D2.
ra8_err_t ra8_mstp_init(void)
Re-establish the ra8_mstp ref-count table from current hardware state.
Definition ra8_mstp.c:291
SysTick-based tick counter, delay and timestamp helpers.
ra8_err_t ra8_time_init(uint32_t cpu_hz)
Initialise SysTick for a 1 kHz tick interrupt.
Definition ra8_time.c:59
void ra8_delay_ms(uint32_t ms)
Busy-wait for at least ms milliseconds.
Definition ra8_time.c:129