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
30
31#include <stdint.h>
32
33#include "ra8_board_ek_ra8d2.h"
34#include "ra8_boot_entry.h"
35#include "ra8_cgc.h"
36#include "ra8_crc.h"
37#include "ra8_crc_regs.h"
38#include "ra8_err.h"
39#include "ra8_isr.h"
40#include "ra8_time.h"
41
43typedef enum : uint32_t {
44 k_crc_demo_baud = 115200U,
47
49typedef enum : uint32_t {
50 k_crc_demo_sw_poly_rev = 0xEDB88320UL,
51 k_crc_demo_sw_init = 0xFFFFFFFFUL,
52 k_crc_demo_sw_xor_out = 0xFFFFFFFFUL,
56
66
69 0x00U,
70 0x11U,
71 0x22U,
72 0x33U,
73 0x44U,
74 0x55U,
75 0x66U,
76 0x77U,
77 0x88U,
78 0x99U,
79 0xAAU,
80 0xBBU,
81 0xCCU,
82 0xDDU,
83 0xEEU,
84 0xFFU,
85};
86
88static const uint8_t k_crc_demo_prefix[] = "crc: hw=";
89static const uint8_t k_crc_demo_sw_tag[] = " sw=";
90static const uint8_t k_crc_demo_ok_tag[] = " match=Y\r\n";
91static const uint8_t k_crc_demo_bad_tag[] = " match=N\r\n";
92
94static const uint8_t k_crc_demo_pass_msg[] = "crc: selftest PASS\r\n";
95
97static void crc_demo_panic_halt(void)
98{
99 while (1) {
100 __asm__ volatile("wfi");
101 }
102}
103
115static uint8_t crc_demo_nibble_to_hex(uint8_t nibble)
116{
117 uint8_t n = (uint8_t)(nibble & (uint8_t)k_crc_demo_nibble_mask);
118 if (n < (uint8_t)k_crc_demo_alpha_thresh) {
119 return (uint8_t)('0' + n);
120 }
121 return (uint8_t)('a' + (n - (uint8_t)k_crc_demo_alpha_thresh));
122}
123
135static void crc_demo_word_to_hex(uint32_t v, uint8_t* dst)
136{
137 for (uint8_t i = 0U; i < (uint8_t)k_crc_demo_hex_per_word; ++i) {
138 const uint8_t shift =
139 (uint8_t)(((uint8_t)k_crc_demo_hex_per_word - 1U - i) * (uint8_t)k_crc_demo_nibble_shift);
140 const uint8_t nibble = (uint8_t)((v >> shift) & (uint32_t)k_crc_demo_nibble_mask);
141 dst[i] = crc_demo_nibble_to_hex(nibble);
142 }
143}
144
170static uint32_t crc_demo_sw_crc32(const uint8_t* data, uint32_t len)
171{
172 uint32_t crc = (uint32_t)k_crc_demo_sw_init;
173 for (uint32_t i = 0U; i < len; ++i) {
174 crc ^= (uint32_t)data[i];
175 for (uint8_t b = 0U; b < (uint8_t)k_crc_demo_bits_per_byte; ++b) {
176 if ((crc & (uint32_t)k_crc_demo_lsb_mask) != 0U) {
177 crc = (crc >> 1) ^ (uint32_t)k_crc_demo_sw_poly_rev;
178 } else {
179 crc = (crc >> 1);
180 }
181 }
182 }
183 return crc ^ (uint32_t)k_crc_demo_sw_xor_out;
184}
185
187static void crc_demo_setup_or_halt(void)
188{
189 uint32_t cpuclk0_hz = 0U;
190
191 if (ra8_cgc_init() != k_ra8_ok) {
193 }
196 }
197 if (ra8_time_init(cpuclk0_hz) != k_ra8_ok) {
199 }
202 }
205 }
208 }
211 }
212}
213
233[[nodiscard]] static ra8_err_t crc_demo_one_iter(uint8_t* out_match)
234{
235 uint32_t hw = 0U;
238 return k_ra8_err_hw_error;
239 }
240 const uint32_t sw = crc_demo_sw_crc32(k_crc_demo_payload, (uint32_t)k_crc_demo_payload_len);
241
242 uint8_t hwhex[k_crc_demo_hex_per_word] = {};
243 uint8_t swhex[k_crc_demo_hex_per_word] = {};
244 crc_demo_word_to_hex(hw, hwhex);
245 crc_demo_word_to_hex(sw, swhex);
246
251 *out_match = (hw == sw) ? 1U : 0U;
252 if (*out_match != 0U) {
255 (size_t)(sizeof(k_crc_demo_pass_msg) - 1U));
256 return k_ra8_ok;
257 }
259 return k_ra8_ok;
260}
261
262void main(void)
263{
266
267 while (1) {
268 uint8_t match = 0U;
269 const ra8_err_t err = crc_demo_one_iter(&match);
270 if (err != k_ra8_ok) {
271 break;
272 }
273 if (match != 0U) {
275 } else {
277 }
279 }
281}
void main(void)
Secure fallback main entry point.
Definition main.c:37
static const uint8_t k_crc_demo_sw_tag[]
Definition main.c:89
static const uint8_t k_crc_demo_prefix[]
Output line tags.
Definition main.c:88
crc_demo_sw_const_t
Software CRC-32 polynomial + bit constants (reflected).
Definition main.c:49
@ k_crc_demo_byte_mask
CRC demo byte mask.
Definition main.c:53
@ k_crc_demo_sw_init
CRC demo sw init.
Definition main.c:51
@ k_crc_demo_sw_xor_out
CRC demo sw xor out.
Definition main.c:52
@ k_crc_demo_lsb_mask
CRC demo lsb mask.
Definition main.c:54
@ k_crc_demo_sw_poly_rev
CRC demo sw poly rev.
Definition main.c:50
crc_demo_config_t
Compile-time settings.
Definition main.c:43
@ k_crc_demo_baud
CRC demo baud.
Definition main.c:44
@ k_crc_demo_period_ms
CRC demo period ms.
Definition main.c:45
static void crc_demo_setup_or_halt(void)
Bring CGC + SysTick + SCI8 + LEDs + CRC unit up.
Definition main.c:187
static uint32_t crc_demo_sw_crc32(const uint8_t *data, uint32_t len)
Software reference CRC-32 (IEEE 802.3, reflected).
Definition main.c:170
static const uint8_t k_crc_demo_ok_tag[]
Definition main.c:90
static ra8_err_t crc_demo_one_iter(uint8_t *out_match)
One iteration: compute hw + sw CRC and emit the comparison line.
Definition main.c:233
static const uint8_t k_crc_demo_payload[k_crc_demo_payload_len]
Fixed 16-byte test payload.
Definition main.c:68
static void crc_demo_panic_halt(void)
Park the CPU forever after a fatal init failure.
Definition main.c:97
static void crc_demo_word_to_hex(uint32_t v, uint8_t *dst)
Render a 32-bit value as 8 ASCII hex chars (big-endian).
Definition main.c:135
static uint8_t crc_demo_nibble_to_hex(uint8_t nibble)
Convert the low nibble of n to its ASCII hex char.
Definition main.c:115
crc_demo_byte_t
Inner-loop bit count for the software CRC.
Definition main.c:58
@ k_crc_demo_bits_per_byte
CRC demo bits per byte.
Definition main.c:59
@ k_crc_demo_payload_len
CRC demo payload length.
Definition main.c:63
@ k_crc_demo_alpha_thresh
CRC demo alpha thresh.
Definition main.c:62
@ k_crc_demo_hex_per_word
CRC demo hex per word.
Definition main.c:64
@ k_crc_demo_nibble_shift
CRC demo nibble shift.
Definition main.c:61
@ k_crc_demo_nibble_mask
CRC demo nibble mask.
Definition main.c:60
static const uint8_t k_crc_demo_pass_msg[]
Self-test verdict emitted only on a hw==sw match (success-only).
Definition main.c:94
static const uint8_t k_crc_demo_bad_tag[]
Definition main.c:91
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).
@ k_ra8_board_led2
LED2, GREEN, P303 (jumper E26).
@ k_ra8_board_led1
LED1, BLUE, P600 (jumper E27).
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
CRC hardware calculator driver header.
ra8_err_t ra8_crc_init(ra8_crc_poly_t poly)
Configure the CRC block for a given polynomial.
Definition ra8_crc.c:158
ra8_err_t ra8_crc_compute(const uint8_t *data, uint32_t len, uint32_t *out_crc)
Compute a CRC over a byte buffer.
Definition ra8_crc.c:190
void ra8_crc_reset(void)
Clear the running CRC state.
Definition ra8_crc.c:180
CRC calculator register layout for the Renesas RA8D2.
@ k_ra8_crc_poly_32_ieee802_3
GPS=100 CRC-32 (IEEE 802.3).
Error Code Definitions for ra8-firmware.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
@ k_ra8_err_hw_error
Generic hardware fault detected (error flag set, fault interrupt).
Definition ra8_err.h:310
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
NVIC + ICU IELSR allocator.
void ra8_isr_globals_enable(void)
Globally enable maskable interrupts (PRIMASK = 0).
Definition ra8_isr.c:439
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