|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Clock Frequency Accuracy Measurement Circuit driver. More...
#include "ra8_cac.h"#include <stdint.h>#include "ra8_attributes.h"#include "ra8_cac_regs.h"#include "ra8_check.h"#include "ra8_err.h"#include "ra8_hw_err.h"#include "ra8_log.h"#include "ra8_mstp.h"Go to the source code of this file.
Data Structures | |
| struct | ra8_cac_state_t |
| Driver-wide runtime state. More... | |
Enumerations | |
| enum | ra8_cac_bit_t : uint8_t { k_ra8_cacr0_cfme = 0U , k_ra8_castr_ferrf = 0U , k_ra8_castr_mendf = 1U , k_ra8_castr_ovff = 2U } |
| enum | ra8_cac_misc_t : uint32_t { k_ra8_cac_castr_to_caicr_shift = 4U , k_ra8_cac_cfme_settle_iters = 1024U , k_ra8_cac_poll_limit = 200000U } |
| Miscellaneous shifts and bounded-spin budgets. More... | |
| enum | ra8_cac_bits_w43_t : uint8_t { k_ra8_cac_status_mask_all } |
| Combined CASTR status mask for FERRF | MENDF | OVFF. More... | |
Functions | |
| static void | internal_cac_wait_cfme (volatile r_cac_regs_t *reg, uint8_t expect) |
| Bounded busy-spin until CACR0 reads back expect. | |
| ra8_err_t | ra8_cac_init (uint16_t upper, uint16_t lower) |
| Programme CAC with upper + lower bounds on measured cycles. | |
| ra8_err_t | ra8_cac_measure (uint16_t *out_count) |
| Kick off a CAC measurement and wait for completion. | |
| ra8_err_t | ra8_cac_deinit (void) |
| Tear down the CAC (disable + MSTP release). | |
| ra8_err_t | ra8_cac_get_status (uint8_t *out_mask) |
| Read the CASTR flag bits. | |
| ra8_err_t | ra8_cac_clear_status (uint8_t mask) |
| Clear the CASTR flag bits via CAICR. | |
| ra8_err_t | ra8_cac_attach_handler (ra8_cac_event_fn_t fn, void *ctx) |
| Attach a callback for CAC events. | |
| void | ra8_cac_dispatch (void) |
| Dispatch CAC events – snapshot + fire callback. | |
| ra8_err_t | ra8_cac_enter_stop (void) |
| Put CAC into MSTP-gated stop. | |
| ra8_err_t | ra8_cac_exit_stop (void) |
| Exit MSTP-gated stop. | |
Variables | |
| static const char * | s_tag = "CAC" |
| static ra8_cac_state_t | s_cac_state |
Clock Frequency Accuracy Measurement Circuit driver.
driver for the CAC block. The CAC measures one clock source against another over a configurable time window and fires a measurement-end / overflow / frequency-error IRQ when the result is out of bounds. This driver exposes lifecycle, polled measurement, async event dispatch, and power transition. Every register write below carries a HUM Ch 10 citation.
Definition in file ra8_cac.c.
| enum ra8_cac_bit_t : uint8_t |
| enum ra8_cac_bits_w43_t : uint8_t |
| enum ra8_cac_misc_t : uint32_t |
Miscellaneous shifts and bounded-spin budgets.
FSP r_cac.c uses FSP_HARDWARE_REGISTER_WAIT(R_CAC->CACR0, x) to confirm that the start/stop write to CACR0 has propagated through the peripheral clock-domain crossing before the next access; we replace the unbounded wait with a bounded busy-spin (NASA Rule 2).
| Enumerator | |
|---|---|
| k_ra8_cac_castr_to_caicr_shift | CASTR -> CAICR. *CL clear-bit shift. |
| k_ra8_cac_cfme_settle_iters | Bounded settle on CACR0 write-back. |
| k_ra8_cac_poll_limit | Bounded MENDF poll budget. |
|
inlinestatic |
Bounded busy-spin until CACR0 reads back expect.
Mirrors FSP FSP_HARDWARE_REGISTER_WAIT(R_CAC->CACR0, expect) (HUM Ch 10.2.1 "CACR0" p 421 – CFME write must propagate before next CACR0 access). Returns regardless after k_ra8_cac_cfme_settle_iters to satisfy NASA Rule 2 (fixed loop bound).
| [in] | reg | CAC register block. |
| [in] | expect | Expected CACR0 value (0 = stopped, 1 = running). |
Definition at line 83 of file ra8_cac.c.
References r_cac_regs_t::CACR0, k_ra8_cac_cfme_settle_iters, and RA8_INTERNAL.
Referenced by ra8_cac_deinit(), ra8_cac_enter_stop(), ra8_cac_init(), and ra8_cac_measure().
|
nodiscard |
Attach a callback for CAC events.
Definition at line 205 of file ra8_cac.c.
References k_ra8_ok, and s_cac_state.
|
nodiscard |
Clear the CASTR flag bits via CAICR.
Definition at line 191 of file ra8_cac.c.
References r_cac_regs_t::CAICR, k_ra8_cac_castr_to_caicr_shift, k_ra8_cac_status_mask_all, k_ra8_ok, and ra8_cac().
|
nodiscard |
Tear down the CAC (disable + MSTP release).
Definition at line 169 of file ra8_cac.c.
References r_cac_regs_t::CACR0, r_cac_regs_t::CACR1, r_cac_regs_t::CACR2, r_cac_regs_t::CAICR, internal_cac_wait_cfme(), k_ra8_mstp_cac, ra8_cac(), ra8_mstp_disable(), and s_cac_state.
| void ra8_cac_dispatch | ( | void | ) |
Dispatch CAC events – snapshot + fire callback.
See the matching header declaration for the full contract; this site adds no behaviour beyond what the public API documents.
Definition at line 212 of file ra8_cac.c.
References r_cac_regs_t::CAICR, r_cac_regs_t::CASTR, k_ra8_cac_castr_to_caicr_shift, k_ra8_cac_status_mask_all, ra8_cac(), and s_cac_state.
|
nodiscard |
Put CAC into MSTP-gated stop.
Definition at line 227 of file ra8_cac.c.
References r_cac_regs_t::CACR0, internal_cac_wait_cfme(), k_ra8_mstp_cac, ra8_cac(), and ra8_mstp_disable().
|
nodiscard |
Exit MSTP-gated stop.
Definition at line 236 of file ra8_cac.c.
References k_ra8_mstp_cac, and ra8_mstp_enable().
|
nodiscard |
Read the CASTR flag bits.
Definition at line 184 of file ra8_cac.c.
References k_ra8_cac_status_mask_all, k_ra8_ok, ra8_cac(), RA8_CHECK_NULL_PTR, and s_tag.
Referenced by internal_sample().
|
nodiscard |
Programme CAC with upper + lower bounds on measured cycles.
| [in] | upper | Upper limit count. |
| [in] | lower | Lower limit count. |
Definition at line 99 of file ra8_cac.c.
References r_cac_regs_t::CACR0, r_cac_regs_t::CACR1, r_cac_regs_t::CACR2, r_cac_regs_t::CAICR, r_cac_regs_t::CALLVR, r_cac_regs_t::CAULVR, internal_cac_wait_cfme(), k_ra8_cac_castr_to_caicr_shift, k_ra8_cac_status_mask_all, k_ra8_mstp_cac, k_ra8_ok, ra8_cac(), ra8_log_info, ra8_mstp_enable(), RA8_RETURN_ON_ERROR, and s_tag.
Referenced by internal_configure().
|
nodiscard |
Kick off a CAC measurement and wait for completion.
| [out] | out_count | Counter value captured on completion. |
Definition at line 125 of file ra8_cac.c.
References r_cac_regs_t::CACNTBR, r_cac_regs_t::CACR0, r_cac_regs_t::CASTR, internal_cac_wait_cfme(), k_ra8_cac_poll_limit, k_ra8_cacr0_cfme, k_ra8_castr_mendf, k_ra8_err_hw_timeout, k_ra8_ok, ra8_cac(), RA8_CHECK_NULL_PTR, and s_tag.
Referenced by internal_sample().
|
static |
Definition at line 167 of file ra8_cac.c.
Referenced by ra8_cac_attach_handler(), ra8_cac_deinit(), and ra8_cac_dispatch().