ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_cgc_internal.h File Reference

Cross-TU sharing for the split Clock Generation Circuit driver. More...

#include <stdint.h>
#include "ra8_attributes.h"
#include "ra8_err.h"
Include dependency graph for ra8_cgc_internal.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  ra8_cgc_byte_const_t : uint32_t {
  k_ra8_cgc_quarters_per_unit = 4UL ,
  k_ra8_cgc_hz_per_mhz = 1000000UL ,
  k_ra8_cgc_mr_min_hz = 1UL
}
 Bit-width / Hz-conversion constants used across the CGC driver. More...

Functions

ra8_err_t priv_ra8_cgc_wait_oscsf_set (uint8_t bit)
 Bounded poll on a single OSCSF flag becoming set.
ra8_err_t priv_ra8_cgc_wait_oscsf_clear (uint8_t bit)
 Bounded poll on a single OSCSF flag becoming clear.
ra8_err_t priv_ra8_cgc_ensure_hoco_running_for_usb_ck (void)
 Ensure HOCO is running so a USBCKCR/USB60CKCR/ESWCKCR SREQ->SRDY handshake can drain.

Detailed Description

Cross-TU sharing for the split Clock Generation Circuit driver.

The CGC driver is split across several translation units that all live in libs/ra8_hal/src/:

  • ra8_cgc.c – core clock-tree bring-up (PLL1, SCKDIVCR, MRMS wait states, SCICLK) plus runtime reconfigure and oscillation-stop detection.
  • ra8_cgc_usb.c – PLL2 bring-up and the USB-FS / USB-HS clock paths.
  • ra8_cgc_eswclk.c – the Ethernet-switch (ESWCLK / ESWPHYCLK) path.

Any symbol referenced by more than one of those units is declared here so there is exactly one definition and no implicit cross-TU reference. The bounded OSCSF poll helpers and the HOCO-restart helper live in this seam because the USB and ESW paths reuse the same hardware handshakes the core bring-up established. The shared k_ra8_cgc_quarters_per_unit PLL-multiplier scale factor is the only member of ra8_cgc_byte_const_t referenced from more than one unit, so the whole enum block lives here.

This header is internal to the CGC driver – it is NOT a public API and must not be included outside libs/ra8_hal/src/ra8_cgc*.c.

Tag ring/world:
Ring 1 (HAL), World S (secure-callable). Same ring/world as the parent ra8_cgc.c.
Since
0.1.0

Definition in file ra8_cgc_internal.h.

Enumeration Type Documentation

◆ ra8_cgc_byte_const_t

enum ra8_cgc_byte_const_t : uint32_t

Bit-width / Hz-conversion constants used across the CGC driver.

k_ra8_cgc_quarters_per_unit is referenced by both the core PLL1 path (ra8_cgc.c) and the PLL2 path (ra8_cgc_usb.c), so the whole block lives in this shared seam. The two Hz-conversion members are used only by the MRMS wait-state stage in ra8_cgc.c, but they ride along so the multiplier scale factor keeps its documented neighbours.

Since
0.1.0
Enumerator
k_ra8_cgc_quarters_per_unit 

PLL multiplier 0.25 step.

k_ra8_cgc_hz_per_mhz 

Hz per MHz.

k_ra8_cgc_mr_min_hz 

Below this, MR*FREQ field = 0.

Definition at line 56 of file ra8_cgc_internal.h.

Function Documentation

◆ priv_ra8_cgc_ensure_hoco_running_for_usb_ck()

ra8_err_t priv_ra8_cgc_ensure_hoco_running_for_usb_ck ( void )

Ensure HOCO is running so a USBCKCR/USB60CKCR/ESWCKCR SREQ->SRDY handshake can drain.

USBCKCR / USB60CKCR / ESWCKCR all share HOCO as their reset-default source. The SREQ -> SRDY synchronizer chain crosses from ICLK into the CURRENT clock source's domain (HOCO at boot). If HOCO is stopped (HCSTP = 1) the handshake never completes. ra8_cgc_init leaves HOCO stopped because it switches SCKSCR to PLL1, so this helper restarts HOCO under a PRCR-CGC unlock window (HOCOCR IS PRCR-protected; writes outside the window are silently dropped) and then waits OSCSF.HOCOSF outside the PRCR window (read-only). Defined in ra8_cgc_usb.c and reused by ra8_cgc_eswclk.c.

Returns
ra8_err_t error code.
Return values
k_ra8_okHOCO running, OSCSF.HOCOSF asserted.
k_ra8_err_hw_timeoutHOCOSF never asserted.
Precondition
Caller is single-threaded init context.
PRCR is currently locked (helper takes its own window).
Postcondition
On k_ra8_ok HOCO is running.
PRCR is re-locked.
Note
Not thread-safe.
Since
0.1.0

Definition at line 564 of file ra8_cgc_usb.c.

References k_ra8_hococr_hcstp, k_ra8_oscsf_bit_hocosf, k_ra8_prcr_unlock_cgc, priv_ra8_cgc_wait_oscsf_set(), RA8_PROTECTED_WRITE, and ra8_sys_hococr().

Referenced by ra8_cgc_eswclk_init(), and ra8_cgc_usbhs_pll_enable().

◆ priv_ra8_cgc_wait_oscsf_clear()

ra8_err_t priv_ra8_cgc_wait_oscsf_clear ( uint8_t bit)

Bounded poll on a single OSCSF flag becoming clear.

Shared between the core PLL1 bring-up (ra8_cgc.c) and the PLL2 path (ra8_cgc_usb.c). Spins up to k_ra8_cgc_pll_spin_limit iterations.

Parameters
[in]bitOSCSF bit number to wait on.
Returns
ra8_err_t error code.
Return values
k_ra8_okFlag observed clear.
k_ra8_err_hw_timeoutSpin limit exhausted.
Precondition
The associated oscillator / PLL has just been stopped.
Caller is single-threaded init context.
Postcondition
On k_ra8_ok return, the polled bit reads as 0.
Iteration count is bounded.
Note
Not thread-safe.
Since
0.1.0

Definition at line 243 of file ra8_cgc.c.

References k_ra8_cgc_pll_spin_limit, ra8_hw_wait_flag_clear8(), and ra8_sys_oscsf().

Referenced by internal_pll2_program_protected(), and internal_stop_pll1().

◆ priv_ra8_cgc_wait_oscsf_set()

ra8_err_t priv_ra8_cgc_wait_oscsf_set ( uint8_t bit)

Bounded poll on a single OSCSF flag becoming set.

Shared between the core PLL1 bring-up (ra8_cgc.c) and the PLL2 / USB paths (ra8_cgc_usb.c). Spins up to k_ra8_cgc_osc_spin_limit iterations.

Parameters
[in]bitOSCSF bit number to wait on (e.g. k_ra8_oscsf_bit_pll1sf).
Returns
ra8_err_t error code.
Return values
k_ra8_okFlag observed set.
k_ra8_err_hw_timeoutSpin limit exhausted.
Precondition
The associated oscillator / PLL has been started.
Caller is single-threaded init context.
Postcondition
On k_ra8_ok return, the polled bit reads as 1.
Iteration count is bounded.
Note
Not thread-safe.
Since
0.1.0

Definition at line 233 of file ra8_cgc.c.

References k_ra8_cgc_osc_spin_limit, ra8_hw_wait_flag_set8(), and ra8_sys_oscsf().

Referenced by internal_pll2_program_protected(), internal_program_and_start_pll1(), internal_start_main_osc(), priv_ra8_cgc_ensure_hoco_running_for_usb_ck(), ra8_cgc_usbfs_clock_enable(), ra8_cgc_usbhs_pll_enable(), and ra8_cgc_use_hoco().