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
33
34#include <stdint.h>
35
36#include "ra8_attributes.h"
37#include "ra8_board_ek_ra8d2.h"
38#include "ra8_boot_entry.h"
39#include "ra8_cgc.h"
40#include "ra8_err.h"
41#include "ra8_isr.h"
42#include "ra8_lpm.h"
43#include "ra8_lpm_regs.h"
44#include "ra8_time.h"
45
47typedef enum : uint32_t {
48 k_lpm_demo_baud = 115200U,
51
59
61static const uint8_t s_lpm_demo_prefix[] = "lpm: wake_count=";
62static const uint8_t s_lpm_demo_eol[] = "\r\n";
63
65static uint32_t s_wake_count;
66
81{
82 while (1) {
83 __asm__ volatile("wfi");
84 }
85}
86
105RA8_INTERNAL static uint8_t internal_lpm_demo_nibble_to_hex(uint8_t nibble)
106{
107 uint8_t n = (uint8_t)(nibble & (uint8_t)k_lpm_demo_nibble_mask);
108 if (n < (uint8_t)k_lpm_demo_alpha_thresh) {
109 return (uint8_t)('0' + n);
110 }
111 return (uint8_t)('a' + (n - (uint8_t)k_lpm_demo_alpha_thresh));
112}
113
130RA8_INTERNAL static void internal_lpm_demo_word_to_hex(uint32_t v, uint8_t* dst)
131{
132 for (uint8_t i = 0U; i < (uint8_t)k_lpm_demo_hex_per_word; ++i) {
133 const uint8_t shift =
134 (uint8_t)(((uint8_t)k_lpm_demo_hex_per_word - 1U - i) * (uint8_t)k_lpm_demo_nibble_shift);
135 const uint8_t nibble = (uint8_t)((v >> shift) & (uint32_t)k_lpm_demo_nibble_mask);
136 dst[i] = internal_lpm_demo_nibble_to_hex(nibble);
137 }
138}
139
154{
155 uint32_t cpuclk0_hz = 0U;
156
157 if (ra8_cgc_init() != k_ra8_ok) {
159 }
162 }
163 if (ra8_time_init(cpuclk0_hz) != k_ra8_ok) {
165 }
168 }
171 }
172
173 /* LPM block uses the cold-reset defaults: OPE=1, IOKEEP=0, no
174 * fast-return / SS2LP options. ra8_lpm_init takes care of the
175 * PRC1 unlock + SBYCR / DPSBYCR / SSCR1 programming for us. */
176 const ra8_lpm_config_t lpm_cfg = {
177 .io_port_keep = false,
178 .opa_bus_keep = true,
179 .sscr_fast_return = false,
180 .dcdc_softstart = k_ra8_lpm_dcssmode_128us,
181 .sscr_low_power = k_ra8_lpm_ss2lp_default,
182 };
183 if (ra8_lpm_init(&lpm_cfg) != k_ra8_ok) {
185 }
186}
187
214{
215 /* Sleep mode -- WFI returns on the next SysTick IRQ ~1 ms later. */
217 return k_ra8_err_hw_error;
218 }
219 /* Continue idling until ~100 ms have accumulated. */
221 s_wake_count++;
222
223 uint8_t hex[k_lpm_demo_hex_per_word] = {};
225
228 (void)ra8_board_uart_console_write(s_lpm_demo_eol, (size_t)(sizeof(s_lpm_demo_eol) - 1U));
229 return k_ra8_ok;
230}
231
232void main(void)
233{
236
237 while (1) {
239 break;
240 }
242 }
244}
void main(void)
Secure fallback main entry point.
Definition main.c:37
static void internal_lpm_demo_setup_or_halt(void)
Bring CGC, SysTick, SCI8, LED1, and the LPM block up.
Definition main.c:153
lpm_demo_config_t
Compile-time settings.
Definition main.c:47
@ k_lpm_demo_baud
Lpm demo baud.
Definition main.c:48
@ k_lpm_demo_period_ms
Lpm demo period ms.
Definition main.c:49
static const uint8_t s_lpm_demo_prefix[]
Output line tags.
Definition main.c:61
static uint8_t internal_lpm_demo_nibble_to_hex(uint8_t nibble)
Convert the low nibble of a byte to an ASCII hex character.
Definition main.c:105
static uint32_t s_wake_count
Cumulative wake count incremented after every sleep+wake cycle.
Definition main.c:65
static void internal_lpm_demo_panic_halt(void)
Park the processor after a fatal setup or sleep-cycle failure.
Definition main.c:80
static ra8_err_t internal_lpm_demo_one_wake(void)
Sleep + wake + emit one wake-count line.
Definition main.c:213
lpm_demo_byte_t
Single-byte constants.
Definition main.c:53
@ k_lpm_demo_alpha_thresh
Lpm demo alpha thresh.
Definition main.c:56
@ k_lpm_demo_nibble_shift
Lpm demo nibble shift.
Definition main.c:55
@ k_lpm_demo_hex_per_word
Lpm demo hex per word.
Definition main.c:57
@ k_lpm_demo_nibble_mask
Lpm demo nibble mask.
Definition main.c:54
static const uint8_t s_lpm_demo_eol[]
Definition main.c:62
static void internal_lpm_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:130
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).
@ 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
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
Low Power Mode (LPM) HAL driver – public API.
ra8_err_t ra8_lpm_init(const ra8_lpm_config_t *cfg)
Initialise the LPM block from a config descriptor.
Definition ra8_lpm.c:358
ra8_err_t ra8_lpm_enter_sleep(ra8_sleep_mode_t mode)
Programme LPSCR for mode and enter the requested sleep.
Definition ra8_lpm.c:735
Low Power Mode (LPM) register layout for the Renesas RA8D2.
@ k_ra8_lpm_ss2lp_default
SS2LP_0 – default mode.
@ k_ra8_sleep_mode_sleep
CPU sleep, peripherals run.
@ k_ra8_lpm_dcssmode_128us
128 us soft-start (cold-reset default).
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
Configuration descriptor for ra8_lpm_init.
Definition ra8_lpm.h:96