71static const char*
s_tag =
"CGC";
77typedef enum : uint8_t {
134 if (out_hz ==
nullptr) {
137 const uint8_t idx = (uint8_t)
id;
154typedef enum : uint32_t {
171typedef enum : uint8_t {
179typedef enum : uint8_t {
187typedef enum : uint8_t {
201typedef enum : uint16_t {
214typedef enum : uint8_t {
229typedef enum : uint8_t {
378 const uint32_t mul_quarters =
382 const uint32_t pllccr =
440#if defined(RA8_OFF_TARGET) && defined(UNIT_TEST)
445 if (ra8_fake_mmio_wait_eval(reg, i, (*reg == freq_mhz))) {
449 if (*reg == freq_mhz) {
453 *reg = key | freq_mhz;
543 const uint16_t sckdivcr2 =
658 volatile uint8_t*
const moscr =
816 if (new_cpuclk_hz == 0U) {
859 if (handler ==
nullptr) {
static const char * s_tag
Logging / check tag.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
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.
static ra8_err_t internal_set_mrm_wait_states(uint32_t mriclk_hz, uint32_t mrpclk_hz)
Step 6: programme MRMS wait-state frequency latches.
ra8_cgc_clock_count_t
Sentinel for the size of the published frequency table.
@ k_ra8_cgc_clock_count
Number of tracked clock-tree domains.
void ra8_cgc_fake_trigger_stop_detection(void)
Test helper: invoke the registered OSTD callback.
ra8_cgc_pll_mul_t
PLL multiplier vocabulary for the EK-RA8D2 quickstart target.
@ k_ra8_cgc_pllmul_quarters
Fractional quarter-steps.
@ k_ra8_cgc_pllmul_int_default
Integer multiplier x250.
static ra8_err_t internal_start_main_osc(void)
Start the main crystal oscillator and wait for stabilisation.
ra8_cgc_scickdivcr_t
Discrete values written to the 8-bit SCICKDIVCR register.
@ k_ra8_scickdivcr_div4
SCICLK divider code for /4.
ra8_err_t ra8_cgc_disable_stop_detection(void)
Disable oscillation-stop detection.
ra8_err_t ra8_cgc_use_hoco(void)
Switch the system clock source to HOCO (20 MHz).
static ra8_err_t internal_route_sciclk(void)
Step 11: route SCICLK = PLL1R / 4 per HUM 9.2.54.
static ra8_err_t internal_wait_mrm_freq(volatile uint32_t *reg, uint32_t key, uint32_t freq_mhz)
Bounded write-and-readback poll on MRCFREQ or MREFREQ.
static ra8_err_t internal_stop_pll1(void)
Step 3: stop PLL1 and wait for the PLLSF flag to clear.
ra8_pllcr_val_t
Discrete values written to the 8-bit PLLCR register.
@ k_ra8_pllcr_run
Clear PLLSTP -> run PLL.
@ k_ra8_pllcr_stop
Set PLLSTP -> stop PLL.
static uint32_t s_clock_hz[k_ra8_cgc_clock_count]
Most-recently programmed frequency for each clock-tree domain.
ra8_pllcr_bit_t
Bit positions in PLLCR (PLL stop control).
@ k_ra8_pllcr_bit_pllstp
PLLCR.PLLSTP: 1 stops PLL, 0 runs PLL.
ra8_err_t priv_ra8_cgc_wait_oscsf_clear(uint8_t bit)
Bounded poll on a single OSCSF flag becoming clear.
ra8_cgc_dummy_count_t
How many dummy reads to issue when flushing the MRAM PFB.
@ k_ra8_pfb_flush_dummy_reads
Dummy-read count after MRCPFB clear.
static ra8_err_t internal_set_vscr_not_high_v(void)
Step 2: drop core to not-high-voltage range before lifting PLL.
ra8_err_t priv_ra8_cgc_wait_oscsf_set(uint8_t bit)
Bounded poll on a single OSCSF flag becoming set.
ra8_err_t ra8_cgc_enable_stop_detection(ra8_cgc_ostd_fn_t handler, void *ctx)
Enable oscillation-stop detection on the main crystal.
static ra8_err_t internal_cgc_init_protected(void)
PRCR-protected core of ra8_cgc_init – runs steps 2..8.
static void * s_ostd_ctx
Stored context passed to s_ostd_handler.
static void internal_clear_pfb(void)
Step 1: clear the MRAM prefetch buffer before any clock change.
static void internal_publish_clocks(void)
Internal helper.
static void internal_program_dividers(void)
Step 8: programme SCKDIVCR + SCKDIVCR2 for the FSP-quickstart tree.
ra8_err_t ra8_cgc_init(void)
Configure the clock tree to a safe default.
static void internal_set_pfb(void)
Step 10: re-enable the MRAM prefetch buffer if MRICLK >= 100 MHz.
ra8_cgc_scickcr_bit_t
Bit positions inside SCICKCR (SCICLK clock-source control).
@ k_ra8_scickcr_sel_pll1r
CKSEL = 0x08 selects PLL1R.
@ k_ra8_scickcr_cksrdy
CKSRDY – switch acknowledged.
@ k_ra8_scickcr_cksreq
CKSREQ – request switch.
static ra8_err_t internal_program_and_start_pll1(void)
Steps 4 + 5: programme PLLCCR / PLLCCR2 then start PLL1.
static ra8_cgc_ostd_fn_t s_ostd_handler
Registered oscillation-stop-detection callback.
ra8_cgc_spin_t
Bounded polling limits for oscillator / PLL / wait-state spins.
@ k_ra8_cgc_vscr_spin_limit
VSCMTSF wait budget.
@ k_ra8_cgc_pll_spin_limit
PLL stop / start wait budget.
@ k_ra8_cgc_scik_spin_limit
SCICKCR.CKSRDY wait budget.
@ k_ra8_cgc_osc_spin_limit
Generic OSCSF wait budget.
@ k_ra8_cgc_mrm_spin_limit
MRCFREQ / MREFREQ wait.
ra8_err_t ra8_cgc_switch_pll1_target(uint32_t new_cpuclk_hz)
Retune PLL1 to a new CPUCLK0 target without a full deinit.
static bool s_ostd_enabled
true while the stop-detection path is armed.
High-level Clock Generation Circuit driver.
ra8_clock_id_t
Identifiers for the clock-tree frequencies queryable at runtime.
@ k_ra8_clock_id_pclkc
PCLKC.
@ k_ra8_clock_id_fclk
Flash/MRAM interface clock.
@ k_ra8_clock_id_cpuclk1
Cortex-M33 CPUCLK1.
@ k_ra8_clock_id_pclkd
PCLKD.
@ k_ra8_clock_id_pclkb
PCLKB.
@ k_ra8_clock_id_pclke
PCLKE.
@ k_ra8_clock_id_cpuclk0
Cortex-M85 CPUCLK0.
@ k_ra8_clock_id_mriclk
MRAM bus clock.
@ k_ra8_clock_id_pclka
PCLKA.
@ k_ra8_clock_id_iclk
System ICLK.
void(* ra8_cgc_ostd_fn_t)(void *ctx)
Oscillation-stop-detection callback.
Cross-TU sharing for the split Clock Generation Circuit driver.
@ k_ra8_cgc_hz_per_mhz
Hz per MHz.
@ k_ra8_cgc_quarters_per_unit
PLL multiplier 0.25 step.
@ k_ra8_cgc_mr_min_hz
Below this, MR*FREQ field = 0.
Clock Generation Circuit (CGC) field layouts for the Renesas RA8D2.
@ k_ra8_clock_div_1
Divide by 1.
@ k_ra8_clock_div_8
Divide by 8.
@ k_ra8_clock_div_4
Divide by 4.
@ k_ra8_clock_div_16
Divide by 16.
@ k_ra8_sckdivcr_pckd_shift
PCLKD divider nibble @ [3:0].
@ k_ra8_sckdivcr_pcke_shift
PCLKE divider nibble @ [23:20].
@ k_ra8_sckdivcr_pcka_shift
PCLKA divider nibble @ [15:12].
@ k_ra8_sckdivcr_ick_shift
ICLK divider nibble @ [27:24].
@ k_ra8_sckdivcr_bck_shift
BCLK divider nibble @ [19:16].
@ k_ra8_sckdivcr_fck_shift
FCLK divider nibble @ [31:28].
@ k_ra8_sckdivcr_pckb_shift
PCLKB divider nibble @ [11:8].
@ k_ra8_sckdivcr_pckc_shift
PCLKC divider nibble @ [7:4].
@ k_ra8_pllccr_mask_quarters
11-bit (mul*4) field.
@ k_ra8_pllccr_mask_plidiv
PLIDIV 2-bit field.
@ k_ra8_moscwtcr_2_to_16_cycles
RA8 moscwtcr 2 to 16 cycles.
@ k_ra8_plidiv_div3
PLL input divide by 3.
@ k_ra8_plodiv_div2
PLL output divide by 2.
@ k_ra8_plodiv_div5
PLL output divide by 5.
@ k_ra8_plodiv_div6
PLL output divide by 6.
@ k_ra8_pllccr2_shift_plodivp
PLODIVP field starts at bit 0.
@ k_ra8_pllccr2_shift_plodivr
PLODIVR field starts at bit 8.
@ k_ra8_pllccr2_shift_plodivq
PLODIVQ field starts at bit 4.
@ k_ra8_sckdivcr2_cpuclk0_shift
CPUCLK0 (M85) divider @ [3:0].
@ k_ra8_sckdivcr2_mriclk_shift
MRAM bus clk divider @ [15:12].
@ k_ra8_sckdivcr2_cpuclk1_shift
CPUCLK1 (M33) divider @ [7:4].
@ k_ra8_sckdivcr2_npuclk_shift
NPUCLK divider @ [11:8].
@ k_ra8_pllccr_shift_quarters
(mul * 4) goes here.
@ k_ra8_pllccr_shift_plsrcsel
PLSRCSEL field is bit 4.
@ k_ra8_plsrcsel_main
Main-oscillator input (default on EK board).
@ k_ra8_hococr_hcstp
HCSTP: 0 operating, 1 stopped.
@ k_ra8_cksel_hoco
High-speed on-chip oscillator.
@ k_ra8_cksel_moco
Middle-speed on-chip osc.
@ k_ra8_cksel_pll1
PLL1 output.
Validation and Error-Checking Macros for ra8-firmware.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_err_hw_timeout
Hardware timed out waiting for a flag or handshake.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_null_ptr
Pointer was NULL where a valid pointer was required.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Bounded wait-flag primitives for RA8D2 HAL drivers.
static ra8_err_t ra8_hw_wait_flag_clear8(volatile const uint8_t *reg, uint8_t mask, uint32_t budget)
Spin until (*reg & mask) == 0 or budget runs out.
static ra8_err_t ra8_hw_wait_flag_set8(volatile const uint8_t *reg, uint8_t mask, uint32_t budget)
Spin until (*reg & mask) != 0 or budget runs out.
static ra8_err_t ra8_hw_wait_flag_clear32(volatile const uint32_t *reg, uint32_t mask, uint32_t budget)
Spin until (*reg & mask) == 0 or budget runs out.
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_info_val(tag, message, value)
RA8 log info val.
#define ra8_log_error_val(tag, message, value)
RA8 log error val.
#define ra8_log_info(tag, message)
RA8 log info.
MRAM Memory System (MRMS) wait-state register layout for the RA8D2.
static volatile uint32_t * ra8_mrms_mrefreq(void)
Get pointer to the 32-bit MREFREQ register (MRPCLK frequency).
static volatile uint32_t * ra8_mrms_mrcpfb(void)
Get pointer to the 32-bit MRCPFB register.
@ k_ra8_mrcpfb_threshold_mhz
Minimum MRICLK MHz to enable PFB.
@ k_ra8_mrcfreq_key
MRCFREQ unlock key, upper byte = 0x1E.
@ k_ra8_mrefreq_key
MREFREQ unlock key, upper byte = 0xE1.
@ k_ra8_mrcpfb_disable
Prefetch buffer off.
@ k_ra8_mrcpfb_enable
Prefetch buffer on.
static volatile uint32_t * ra8_mrms_mrcfreq(void)
Get pointer to the 32-bit MRCFREQ register (MRICLK frequency).
Ref-counted Module Stop Control wrapper for the RA8D2.
Module Stop Control (MSTP) register layout for the Renesas RA8D2.
Scoped PRCR unlock helper.
#define RA8_PROTECTED_WRITE(unlock_val)
Scoped PRCR unlock block.
SRAM (with ECC) HAL driver public API.
ra8_err_t ra8_sram_set_wait_state_for_clock(uint32_t iclk_hz, uint32_t iclk_max_hz)
Derive SRAMWTSC.WTEN from an ICLK frequency and program it.
System Control (SYSC) register layout for the Renesas RA8D2.
static volatile uint8_t * ra8_sys_scickcr(void)
Get pointer to the 8-bit SCICKCR register (SCICLK source select).
@ k_ra8_prcr_unlock_cgc
RA8 prcr unlock cgc.
@ k_ra8_sys_off_moscr
MOSCCR (8-bit).
static volatile uint8_t * ra8_sys_pllcr(void)
Get pointer to the 8-bit PLLCR register (PLL enable/stop).
static volatile uint32_t * ra8_sys_vscr(void)
Get pointer to the 32-bit VSCR register (voltage scaling control).
@ k_ra8_oscsf_bit_pll1sf
PLL1 stabilisation flag.
@ k_ra8_oscsf_bit_moscsf
Main oscillator stab flag.
@ k_ra8_oscsf_bit_hocosf
HOCO stabilisation flag.
static volatile uint8_t * ra8_sys_hococr(void)
Get pointer to the 8-bit HOCOCR register.
static volatile uint8_t * ra8_sys_moscwtcr(void)
Get pointer to the 8-bit MOSCWTCR register.
static volatile uint16_t * ra8_sys_sckdivcr2(void)
Get pointer to the 16-bit SCKDIVCR2 register.
static volatile uint16_t * ra8_sys_pllccr2(void)
Get pointer to the 16-bit PLLCCR2 register (PLL1 output dividers).
static volatile uint8_t * ra8_sys_oscsf(void)
Get pointer to the 8-bit OSCSF (oscillation stabilisation) register.
@ k_ra8_system_base_addr
R_SYSTEM.
static volatile uint8_t * ra8_sys_sckscr(void)
Get pointer to the 8-bit SCKSCR register.
static volatile uint32_t * ra8_sys_sckdivcr(void)
Get pointer to the 32-bit SCKDIVCR register.
static volatile uint32_t * ra8_sys_pllccr(void)
Get pointer to the 32-bit PLLCCR register.
static volatile uint8_t * ra8_sys_scickdivcr(void)
Get pointer to the 8-bit SCICKDIVCR register (SCICLK divider).
@ k_ra8_vscr_bit_vscm
VSCM bit mask (write 1 = not-high-V).
@ k_ra8_vscr_bit_vscmtsf
VSCMTSF transition-in-flight mask.
@ k_ra8_moscr_mostp_mask
MOSTP – 0 starts XTAL, 1 stops it.
Named Time Unit Constants for Delay / Timeout / Tick Math.
@ k_ra8_mriclk_hz
MRICLK = PLL1P/4 = 250 MHz (MRAM I/F).
@ k_ra8_pclka_hz
PCLKA = PLL1P/8 = 125 MHz.
@ k_ra8_cpuclk1_hz
CPUCLK1 = PLL1P/4 = 250 MHz.
@ k_ra8_cpuclk0_hz
CPUCLK0 = PLL1P/1 = 1 GHz.
@ k_ra8_pclkb_hz
PCLKB = PLL1P/16 = 62.5 MHz.
@ k_ra8_moco_hz
Middle-speed on-chip oscillator.
@ k_ra8_fclk_hz
FCK (MRPCLK) = PLL1P/8 = 125 MHz.
@ k_ra8_pclkd_hz
PCLKD = PLL1P/4 = 250 MHz.
@ k_ra8_pclke_hz
PCLKE = PLL1P/4 = 250 MHz.
@ k_ra8_pclkc_hz
PCLKC = PLL1P/8 = 125 MHz.
@ k_ra8_iclk_hz
ICLK = PLL1P/4 = 250 MHz.
@ k_ra8_iclk_max_hz
Highest ICLK the part is rated for.