ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_cgc.c
Go to the documentation of this file.
1
51
52#include "ra8_cgc.h"
53
54#include <stdint.h>
55
56#include "ra8_attributes.h"
57#include "ra8_cgc_internal.h"
58#include "ra8_cgc_regs.h"
59#include "ra8_check.h"
60#include "ra8_err.h"
61#include "ra8_hw_err.h"
62#include "ra8_log.h"
63#include "ra8_mrms_regs.h"
64#include "ra8_mstp.h"
65#include "ra8_mstp_regs.h"
67#include "ra8_sram.h"
68#include "ra8_system_regs.h"
69#include "ra8_time_constants.h"
70
71static const char* s_tag = "CGC";
72
77typedef enum : uint8_t {
80
107
131
133{
134 if (out_hz == nullptr) {
135 return k_ra8_err_null_ptr;
136 }
137 const uint8_t idx = (uint8_t)id;
138 if (idx >= (uint8_t)(sizeof(s_clock_hz) / sizeof(s_clock_hz[0]))) {
140 }
141 *out_hz = s_clock_hz[idx];
142 return k_ra8_ok;
143}
144
145/* =============================================================================
146 * Local-only typed-enum vocabulary
147 * =============================================================================
148 */
149
161
171typedef enum : uint8_t {
174
179typedef enum : uint8_t {
182
187typedef enum : uint8_t {
191
205
214typedef enum : uint8_t {
216 k_ra8_scickcr_cksreq = (1U << 6U),
217 k_ra8_scickcr_cksrdy = (1U << 7U),
219
229typedef enum : uint8_t {
232
234{
235 /* HUM Ch 9.2.21 "OSCSF : Oscillation Stabilization Flag Register" p 344 */
236 volatile const uint8_t* const oscsf = ra8_sys_oscsf();
237 /* On host tests the bounded wait consults the ra8_fake_mmio seam: it
238 * succeeds on the first poll unless a test arms a fault, so the real
239 * poll/timeout legs run everywhere (T1-01, no off-target short-circuit). */
240 return ra8_hw_wait_flag_set8(oscsf, (uint8_t)(1U << bit), (uint32_t)k_ra8_cgc_osc_spin_limit);
241}
242
244{
245 /* HUM Ch 9.2.21 "OSCSF : Oscillation Stabilization Flag Register" p 344 */
246 volatile const uint8_t* const oscsf = ra8_sys_oscsf();
247 return ra8_hw_wait_flag_clear8(oscsf, (uint8_t)(1U << bit), (uint32_t)k_ra8_cgc_pll_spin_limit);
248}
249
270{
271 /* HUM Ch 59.4.3 "Frequency Change Procedure" p 3548 */
272 /* Cross-reference: FSP bsp_clocks.c. */
273 volatile uint32_t* const mrcpfb = ra8_mrms_mrcpfb();
274 *mrcpfb = k_ra8_mrcpfb_disable;
275 for (uint8_t i = 0U; i < k_ra8_pfb_flush_dummy_reads; i++) {
276 (void)*mrcpfb;
277 }
278}
279
304{
305 /* HUM Ch 11.2.43 "VSCR : Voltage Scaling Control Register" p 477 */
306 /* Cross-reference: FSP bsp_clocks.c. */
307 volatile uint32_t* const vscr = ra8_sys_vscr();
308 *vscr = k_ra8_vscr_bit_vscm;
309
310 return ra8_hw_wait_flag_clear32(vscr,
311 (uint32_t)k_ra8_vscr_bit_vscmtsf,
312 (uint32_t)k_ra8_cgc_vscr_spin_limit);
313}
314
338{
339 /* HUM Ch 9.2.8 "PLLCR : PLL Control Register" p 333 */
340 /* Cross-reference: FSP bsp_clocks.c. */
342 /* HUM Ch 9.2.21 "OSCSF : Oscillation Stabilization Flag Register" p 344 */
343 /* Cross-reference: FSP bsp_clocks.c. */
345}
346
375{
376 /* PLLMUL is encoded as (integer*4 + quarters) shifted by 6, which
377 * simultaneously fills PLLMULNF[7:6] and PLLMUL[16:8]. */
378 const uint32_t mul_quarters =
381
382 const uint32_t pllccr =
386
387 const uint16_t pllccr2 = (uint16_t)(((uint16_t)k_ra8_plodiv_div5 << k_ra8_pllccr2_shift_plodivr) |
390
391 /* HUM Ch 9.2.6 "PLLCCR : PLL Clock Control Register" p 331 */
392 /* Cross-reference: FSP bsp_clocks.c. */
393 *ra8_sys_pllccr() = pllccr;
394 /* HUM Ch 9.2.7 "PLLCCR2 : PLL Clock Control Register 2" p 332 */
395 /* Cross-reference: FSP bsp_clocks.c. */
396 *ra8_sys_pllccr2() = pllccr2;
397
398 /* HUM Ch 9.2.8 "PLLCR : PLL Control Register" p 333 */
399 /* Cross-reference: FSP bsp_clocks.c. */
401 /* HUM Ch 9.2.21 "OSCSF : Oscillation Stabilization Flag Register" p 344 */
402 /* Cross-reference: FSP bsp_clocks.c. */
404}
405
437internal_wait_mrm_freq(volatile uint32_t* reg, uint32_t key, uint32_t freq_mhz)
438{
439 for (uint32_t i = 0U; i < k_ra8_cgc_mrm_spin_limit; i++) {
440#if defined(RA8_OFF_TARGET) && defined(UNIT_TEST)
441 /* Host MMIO fault seam: the loop-exit decision comes from
442 * ra8_fake_mmio_wait_eval (satisfied on the first poll unless a test
443 * arms a fault) because plain host RAM cannot strip the key byte
444 * on readback the way the silicon latch does. */
445 if (ra8_fake_mmio_wait_eval(reg, i, (*reg == freq_mhz))) {
446 return k_ra8_ok;
447 }
448#else
449 if (*reg == freq_mhz) {
450 return k_ra8_ok;
451 }
452#endif
453 *reg = key | freq_mhz;
454 }
456}
457
484RA8_INTERNAL static ra8_err_t internal_set_mrm_wait_states(uint32_t mriclk_hz, uint32_t mrpclk_hz)
485{
486 const uint32_t mri_mhz = (mriclk_hz <= k_ra8_cgc_mr_min_hz)
487 ? 0U
488 : ((mriclk_hz + k_ra8_cgc_hz_per_mhz - 1U) / k_ra8_cgc_hz_per_mhz);
489 const uint32_t mre_mhz = (mrpclk_hz <= k_ra8_cgc_mr_min_hz)
490 ? 0U
491 : ((mrpclk_hz + k_ra8_cgc_hz_per_mhz - 1U) / k_ra8_cgc_hz_per_mhz);
492
493 /* HUM Ch 59.5.2 "MRCFREQ : Code MRAM Frequency Notifications Register" p 3551 */
494 /* Cross-reference: FSP bsp_clocks.c. */
496 if (err != k_ra8_ok) {
497 return err;
498 }
499 /* HUM Ch 59.5.3 "MREFREQ : Extra MRAM Frequency Notifications Register" p 3552 */
500 /* Cross-reference: FSP bsp_clocks.c. */
502 return err;
503}
504
528{
529 /* HUM Ch 9.2.6 "SCKDIVCR : System Clock Division Control Register"
530 * / FSP bsp_clocks.c */
531 const uint32_t sckdivcr = ((uint32_t)k_ra8_clock_div_8 << k_ra8_sckdivcr_fck_shift) |
539 *ra8_sys_sckdivcr() = sckdivcr;
540
541 /* HUM Ch 9.2.7 "SCKDIVCR2 : System Clock Division Control Register 2"
542 * / FSP bsp_clocks.c */
543 const uint16_t sckdivcr2 =
544 (uint16_t)(((uint16_t)k_ra8_clock_div_4 << k_ra8_sckdivcr2_mriclk_shift) |
548 *ra8_sys_sckdivcr2() = sckdivcr2;
549}
550
571{
572 const uint32_t mri_mhz = *ra8_mrms_mrcfreq();
573 if (mri_mhz >= k_ra8_mrcpfb_threshold_mhz) {
574 /* HUM Ch 59.5.1 "MRCPFB : Code MRAM Prefetch Buffer Enable Register" p 3551 */
575 /* Cross-reference: FSP bsp_clocks.c. */
577 }
578}
579
607{
608 volatile uint8_t* const ckcr = ra8_sys_scickcr();
609 volatile uint8_t* const divcr = ra8_sys_scickdivcr();
610
611 /* HUM Ch 9.2.54 "SCICKCR : SCI Clock Control Register" p 368 */
612 /* step 1 */
613 *ckcr = (uint8_t)(*ckcr | k_ra8_scickcr_cksreq);
614 const ra8_err_t req_err =
616 if (req_err != k_ra8_ok) {
617 return req_err;
618 }
619 /* HUM Ch 9.2.49 "SCICKDIVCR : SCI Clock Division Control Register" p 365 */
620 /* step 2 */
621 *divcr = k_ra8_scickdivcr_div4;
623 /* Step 3: clear CKSREQ to start the new clock. */
625 return ra8_hw_wait_flag_clear8(ckcr,
626 (uint8_t)k_ra8_scickcr_cksrdy,
627 (uint32_t)k_ra8_cgc_scik_spin_limit);
628}
629
653{
654 /* HUM Ch 9.2.27 "MOSCWTCR : Main Clock Oscillator Wait Control Register" p 349 */
656
657 /* HUM Ch 9.2.13 "MOSCCR : Main Clock Oscillator Control Register" p 338 */
658 volatile uint8_t* const moscr =
659 (volatile uint8_t*)((uintptr_t)k_ra8_system_base_addr + (uintptr_t)k_ra8_sys_off_moscr);
660 *moscr = (uint8_t)(*moscr & (uint8_t)~k_ra8_moscr_mostp_mask);
661
663}
664
689{
691 if (err == k_ra8_ok) {
693 }
694 if (err == k_ra8_ok) {
695 err = internal_stop_pll1();
696 }
697 if (err == k_ra8_ok) {
699 }
700 if (err == k_ra8_ok) {
701 /* Step 6: MRMS wait-state latches must come BEFORE the SCKSCR
702 * switch -- the new MRICLK and MRPCLK rates kick in the moment
703 * SCKDIVCR2 is committed. */
705 }
706 if (err == k_ra8_ok) {
707 /* Step 7: the SRAM wait state, for exactly the same reason and in
708 * exactly the same window as step 6. HUM Ch 58.3.7 "Wait State"
709 * p 3540 is unambiguous -- above half the maximum ICLK, "when the
710 * wait is not inserted, the operation is not guaranteed" -- and
711 * SRAMWTSC.WTEN resets to 0 while this sequence takes ICLK to
712 * k_ra8_iclk_hz, its maximum. Programming it after the SCKSCR
713 * switch would leave a window in which .data, .bss and the stack
714 * are read at full speed with no wait; the ONE fault it is known
715 * to produce is a single dropped bit in a value read back out of
716 * SRAM, so that window has to be empty, not short (tracker #524). */
718 }
719 if (err == k_ra8_ok) {
721 /* HUM Ch 9.2.5 "SCKSCR : System Clock Source Control Register" p 330 */
723 }
724 return err;
725}
726
728{
729 ra8_log_info(s_tag, "cgc_init -> XTAL -> PLL1 (1 GHz)");
730
731 /* Step 1 happens outside the PRCR window: MRMS isn't a protected block. */
733
734 ra8_err_t err = k_ra8_ok;
736 {
738 }
739
740 if (err != k_ra8_ok) {
741 ra8_log_error_val(s_tag, "cgc_init failed", (uint32_t)err);
742 return err;
743 }
744
745 /* Step 10 happens after SCKSCR is on PLL1 -- MRMS isn't protected. */
747
748 /* Step 11 needs PRCR unlocked again. */
750 {
751 err = internal_route_sciclk();
752 }
753 if (err != k_ra8_ok) {
754 ra8_log_error_val(s_tag, "sciclk route failed", (uint32_t)err);
755 return err;
756 }
757
759 ra8_log_info(s_tag, "system clock = PLL1, CPUCLK0 = 1 GHz");
760 return k_ra8_ok;
761}
762
764{
765 volatile uint8_t* const hococr = ra8_sys_hococr();
766 *hococr = (uint8_t)((uint8_t)*hococr & (uint8_t)~(1U << k_ra8_hococr_hcstp));
767
769 if (err != k_ra8_ok) {
770 return err;
771 }
772
774 {
776 }
777
778 ra8_log_info(s_tag, "switched to HOCO");
779 return k_ra8_ok;
780}
781
782/* =============================================================================
783 * Runtime reconfigure + stop detection
784 * =============================================================================
785 */
786
797
804static void* s_ostd_ctx = nullptr;
805
812static bool s_ostd_enabled = false;
813
815{
816 if (new_cpuclk_hz == 0U) {
818 }
819 ra8_log_info_val(s_tag, "switch pll1 target", new_cpuclk_hz);
820
821 /* Step 1: temporarily fall back to MOCO so the CPU is not clocked
822 * from PLL1 while we reprogramme it. */
824 {
826 }
827
828 /* Step 2: stop + restart PLL1 with the existing field encodings.
829 * For now we only support the FSP-quickstart values; a future
830 * change can compute PLLCCR / PLLCCR2 from `new_cpuclk_hz`. */
831 ra8_err_t pll_err = k_ra8_ok;
833 {
834 pll_err = internal_stop_pll1();
835 if (pll_err == k_ra8_ok) {
837 }
838 if (pll_err != k_ra8_ok) {
839 ra8_log_error_val(s_tag, "pll1 retune failed", (uint32_t)pll_err);
840 /* fall through: leave SCKSCR on MOCO so the CPU keeps running. */
841 }
842 }
843
844 /* Step 3: switch SCKSCR back to PLL1 if the lock succeeded, then
845 * republish the clock tree. */
847 {
848 if (pll_err == k_ra8_ok) {
850 }
851 }
853 s_clock_hz[k_ra8_clock_id_cpuclk0] = new_cpuclk_hz;
854 return k_ra8_ok;
855}
856
858{
859 if (handler == nullptr) {
860 return k_ra8_err_null_ptr;
861 }
862 s_ostd_handler = handler;
863 s_ostd_ctx = ctx;
864 s_ostd_enabled = true;
865 /* HUM Ch 9.2.23 "OSTDCR : Oscillation Stop Detection Control Register", p 346
866 * -- target programming deferred until the first real NMI wiring
867 * lands. On host (fake) the enable-flag is tracked
868 * purely in software and the test helper fires the stored
869 * callback directly. */
870 ra8_log_info(s_tag, "stop detection armed");
871 return k_ra8_ok;
872}
873
875{
876 s_ostd_handler = nullptr;
877 s_ostd_ctx = nullptr;
878 s_ostd_enabled = false;
879 ra8_log_info(s_tag, "stop detection disarmed");
880 return k_ra8_ok;
881}
882
884{
885 if (!s_ostd_enabled) {
886 return;
887 }
889 void* const ctx = s_ostd_ctx;
890 if (cb != nullptr) {
891 cb(ctx);
892 }
893}
static const char * s_tag
Logging / check tag.
Definition ra8_app.c:17
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.
Definition ra8_cgc.c:132
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.
Definition ra8_cgc.c:484
ra8_cgc_clock_count_t
Sentinel for the size of the published frequency table.
Definition ra8_cgc.c:77
@ k_ra8_cgc_clock_count
Number of tracked clock-tree domains.
Definition ra8_cgc.c:78
void ra8_cgc_fake_trigger_stop_detection(void)
Test helper: invoke the registered OSTD callback.
Definition ra8_cgc.c:883
ra8_cgc_pll_mul_t
PLL multiplier vocabulary for the EK-RA8D2 quickstart target.
Definition ra8_cgc.c:201
@ k_ra8_cgc_pllmul_quarters
Fractional quarter-steps.
Definition ra8_cgc.c:203
@ k_ra8_cgc_pllmul_int_default
Integer multiplier x250.
Definition ra8_cgc.c:202
static ra8_err_t internal_start_main_osc(void)
Start the main crystal oscillator and wait for stabilisation.
Definition ra8_cgc.c:652
ra8_cgc_scickdivcr_t
Discrete values written to the 8-bit SCICKDIVCR register.
Definition ra8_cgc.c:229
@ k_ra8_scickdivcr_div4
SCICLK divider code for /4.
Definition ra8_cgc.c:230
ra8_err_t ra8_cgc_disable_stop_detection(void)
Disable oscillation-stop detection.
Definition ra8_cgc.c:874
ra8_err_t ra8_cgc_use_hoco(void)
Switch the system clock source to HOCO (20 MHz).
Definition ra8_cgc.c:763
static ra8_err_t internal_route_sciclk(void)
Step 11: route SCICLK = PLL1R / 4 per HUM 9.2.54.
Definition ra8_cgc.c:606
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.
Definition ra8_cgc.c:437
static ra8_err_t internal_stop_pll1(void)
Step 3: stop PLL1 and wait for the PLLSF flag to clear.
Definition ra8_cgc.c:337
ra8_pllcr_val_t
Discrete values written to the 8-bit PLLCR register.
Definition ra8_cgc.c:187
@ k_ra8_pllcr_run
Clear PLLSTP -> run PLL.
Definition ra8_cgc.c:188
@ k_ra8_pllcr_stop
Set PLLSTP -> stop PLL.
Definition ra8_cgc.c:189
static uint32_t s_clock_hz[k_ra8_cgc_clock_count]
Most-recently programmed frequency for each clock-tree domain.
Definition ra8_cgc.c:95
ra8_pllcr_bit_t
Bit positions in PLLCR (PLL stop control).
Definition ra8_cgc.c:179
@ k_ra8_pllcr_bit_pllstp
PLLCR.PLLSTP: 1 stops PLL, 0 runs PLL.
Definition ra8_cgc.c:180
ra8_err_t priv_ra8_cgc_wait_oscsf_clear(uint8_t bit)
Bounded poll on a single OSCSF flag becoming clear.
Definition ra8_cgc.c:243
ra8_cgc_dummy_count_t
How many dummy reads to issue when flushing the MRAM PFB.
Definition ra8_cgc.c:171
@ k_ra8_pfb_flush_dummy_reads
Dummy-read count after MRCPFB clear.
Definition ra8_cgc.c:172
static ra8_err_t internal_set_vscr_not_high_v(void)
Step 2: drop core to not-high-voltage range before lifting PLL.
Definition ra8_cgc.c:303
ra8_err_t priv_ra8_cgc_wait_oscsf_set(uint8_t bit)
Bounded poll on a single OSCSF flag becoming set.
Definition ra8_cgc.c:233
ra8_err_t ra8_cgc_enable_stop_detection(ra8_cgc_ostd_fn_t handler, void *ctx)
Enable oscillation-stop detection on the main crystal.
Definition ra8_cgc.c:857
static ra8_err_t internal_cgc_init_protected(void)
PRCR-protected core of ra8_cgc_init – runs steps 2..8.
Definition ra8_cgc.c:688
static void * s_ostd_ctx
Stored context passed to s_ostd_handler.
Definition ra8_cgc.c:804
static void internal_clear_pfb(void)
Step 1: clear the MRAM prefetch buffer before any clock change.
Definition ra8_cgc.c:269
static void internal_publish_clocks(void)
Internal helper.
Definition ra8_cgc.c:118
static void internal_program_dividers(void)
Step 8: programme SCKDIVCR + SCKDIVCR2 for the FSP-quickstart tree.
Definition ra8_cgc.c:527
ra8_err_t ra8_cgc_init(void)
Configure the clock tree to a safe default.
Definition ra8_cgc.c:727
static void internal_set_pfb(void)
Step 10: re-enable the MRAM prefetch buffer if MRICLK >= 100 MHz.
Definition ra8_cgc.c:570
ra8_cgc_scickcr_bit_t
Bit positions inside SCICKCR (SCICLK clock-source control).
Definition ra8_cgc.c:214
@ k_ra8_scickcr_sel_pll1r
CKSEL = 0x08 selects PLL1R.
Definition ra8_cgc.c:215
@ k_ra8_scickcr_cksrdy
CKSRDY – switch acknowledged.
Definition ra8_cgc.c:217
@ k_ra8_scickcr_cksreq
CKSREQ – request switch.
Definition ra8_cgc.c:216
static ra8_err_t internal_program_and_start_pll1(void)
Steps 4 + 5: programme PLLCCR / PLLCCR2 then start PLL1.
Definition ra8_cgc.c:374
static ra8_cgc_ostd_fn_t s_ostd_handler
Registered oscillation-stop-detection callback.
Definition ra8_cgc.c:796
ra8_cgc_spin_t
Bounded polling limits for oscillator / PLL / wait-state spins.
Definition ra8_cgc.c:154
@ k_ra8_cgc_vscr_spin_limit
VSCMTSF wait budget.
Definition ra8_cgc.c:158
@ k_ra8_cgc_pll_spin_limit
PLL stop / start wait budget.
Definition ra8_cgc.c:156
@ k_ra8_cgc_scik_spin_limit
SCICKCR.CKSRDY wait budget.
Definition ra8_cgc.c:159
@ k_ra8_cgc_osc_spin_limit
Generic OSCSF wait budget.
Definition ra8_cgc.c:155
@ k_ra8_cgc_mrm_spin_limit
MRCFREQ / MREFREQ wait.
Definition ra8_cgc.c:157
ra8_err_t ra8_cgc_switch_pll1_target(uint32_t new_cpuclk_hz)
Retune PLL1 to a new CPUCLK0 target without a full deinit.
Definition ra8_cgc.c:814
static bool s_ostd_enabled
true while the stop-detection path is armed.
Definition ra8_cgc.c:812
High-level Clock Generation Circuit driver.
ra8_clock_id_t
Identifiers for the clock-tree frequencies queryable at runtime.
Definition ra8_cgc.h:69
@ k_ra8_clock_id_pclkc
PCLKC.
Definition ra8_cgc.h:75
@ k_ra8_clock_id_fclk
Flash/MRAM interface clock.
Definition ra8_cgc.h:78
@ k_ra8_clock_id_cpuclk1
Cortex-M33 CPUCLK1.
Definition ra8_cgc.h:71
@ k_ra8_clock_id_pclkd
PCLKD.
Definition ra8_cgc.h:76
@ k_ra8_clock_id_pclkb
PCLKB.
Definition ra8_cgc.h:74
@ k_ra8_clock_id_pclke
PCLKE.
Definition ra8_cgc.h:77
@ k_ra8_clock_id_cpuclk0
Cortex-M85 CPUCLK0.
Definition ra8_cgc.h:70
@ k_ra8_clock_id_mriclk
MRAM bus clock.
Definition ra8_cgc.h:79
@ k_ra8_clock_id_pclka
PCLKA.
Definition ra8_cgc.h:73
@ k_ra8_clock_id_iclk
System ICLK.
Definition ra8_cgc.h:72
void(* ra8_cgc_ostd_fn_t)(void *ctx)
Oscillation-stop-detection callback.
Definition ra8_cgc.h:114
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.
Definition ra8_err.h:152
@ k_ra8_err_hw_timeout
Hardware timed out waiting for a flag or handshake.
Definition ra8_err.h:304
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
@ k_ra8_err_null_ptr
Pointer was NULL where a valid pointer was required.
Definition ra8_err.h:478
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
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.
Definition ra8_hw_err.h:262
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.
Definition ra8_hw_err.h:219
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.
Definition ra8_hw_err.h:351
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_info_val(tag, message, value)
RA8 log info val.
Definition ra8_log.h:366
#define ra8_log_error_val(tag, message, value)
RA8 log error val.
Definition ra8_log.h:337
#define ra8_log_info(tag, message)
RA8 log info.
Definition ra8_log.h:364
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.
Definition ra8_sram.c:661
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.