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

Clock Accuracy Check driver. More...

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

Go to the source code of this file.

Typedefs

typedef void(* ra8_cac_event_fn_t) (void *ctx, uint8_t status_mask)
 CAC event callback.

Enumerations

enum  ra8_cac_status_mask_t : uint8_t {
  k_ra8_cac_status_none = 0x00U ,
  k_ra8_cac_status_ferrf = 0x01U ,
  k_ra8_cac_status_mendf = 0x02U ,
  k_ra8_cac_status_ovff = 0x04U
}
 CASTR status-flag bit masks (HUM Ch 10.2.5 "CASTR" p 424). More...

Functions

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.

Detailed Description

Clock Accuracy Check driver.

Declares configuration and status access for hardware clock-accuracy measurement against caller-supplied cycle limits.

Definition in file ra8_cac.h.

Typedef Documentation

◆ ra8_cac_event_fn_t

typedef void(* ra8_cac_event_fn_t) (void *ctx, uint8_t status_mask)

CAC event callback.

Definition at line 68 of file ra8_cac.h.

Enumeration Type Documentation

◆ ra8_cac_status_mask_t

enum ra8_cac_status_mask_t : uint8_t

CASTR status-flag bit masks (HUM Ch 10.2.5 "CASTR" p 424).

CASTR layout (cross-verified against FSP R_CAC_Type.CASTR_b and CMSIS R_CAC_CASTR_*_Pos in R7KA8D2KF_core0.h):

  • bit 0 = FERRF (Frequency Error Flag)
  • bit 1 = MENDF (Measurement End Flag)
  • bit 2 = OVFF (Counter Overflow Flag)

To clear a flag, write 1 to the matching *CL bit in CAICR shifted up by k_ra8_cac_castr_to_caicr_shift (= 4): FERRFCL=bit4, MENDFCL=bit5, OVFFCL=bit6 (HUM Ch 10.2.4 "CAICR" p 423).

Enumerator
k_ra8_cac_status_none 

RA8 cac status none.

k_ra8_cac_status_ferrf 

Frequency error (CASTR bit 0).

k_ra8_cac_status_mendf 

Measurement end (CASTR bit 1).

k_ra8_cac_status_ovff 

Counter overflow (CASTR bit 2).

Definition at line 57 of file ra8_cac.h.

Function Documentation

◆ ra8_cac_attach_handler()

ra8_err_t ra8_cac_attach_handler ( ra8_cac_event_fn_t fn,
void * ctx )
nodiscard

Attach a callback for CAC events.

Since
0.1.0

Definition at line 205 of file ra8_cac.c.

References k_ra8_ok, and s_cac_state.

◆ ra8_cac_clear_status()

ra8_err_t ra8_cac_clear_status ( uint8_t mask)
nodiscard

Clear the CASTR flag bits via CAICR.

Since
0.1.0

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().

◆ ra8_cac_deinit()

ra8_err_t ra8_cac_deinit ( void )
nodiscard

Tear down the CAC (disable + MSTP release).

Since
0.1.0

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.

◆ ra8_cac_dispatch()

void ra8_cac_dispatch ( void )

Dispatch CAC events – snapshot + fire callback.

Since
0.1.0

See the matching header declaration for the full contract; this site adds no behaviour beyond what the public API documents.

Precondition
Driver state has been initialized by the matching *_init.
Caller has validated all pointer parameters.
Postcondition
Side effects are limited to those documented in the header.
No global state is modified on the error path.
Note
Thread safety: see the header declaration.

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.

◆ ra8_cac_enter_stop()

ra8_err_t ra8_cac_enter_stop ( void )
nodiscard

Put CAC into MSTP-gated stop.

Since
0.1.0

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().

◆ ra8_cac_exit_stop()

ra8_err_t ra8_cac_exit_stop ( void )
nodiscard

Exit MSTP-gated stop.

Since
0.1.0

Definition at line 236 of file ra8_cac.c.

References k_ra8_mstp_cac, and ra8_mstp_enable().

◆ ra8_cac_get_status()

ra8_err_t ra8_cac_get_status ( uint8_t * out_mask)
nodiscard

Read the CASTR flag bits.

Since
0.1.0

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().

◆ ra8_cac_init()

ra8_err_t ra8_cac_init ( uint16_t upper,
uint16_t lower )
nodiscard

Programme CAC with upper + lower bounds on measured cycles.

Parameters
[in]upperUpper limit count.
[in]lowerLower limit count.
Returns
k_ra8_ok on success.
Since
0.1.0

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().

◆ ra8_cac_measure()

ra8_err_t ra8_cac_measure ( uint16_t * out_count)
nodiscard

Kick off a CAC measurement and wait for completion.

Parameters
[out]out_countCounter value captured on completion.
Returns
k_ra8_ok if the measurement completed inside the window, k_ra8_err_hw_timeout if CAC did not finish.
Since
0.1.0

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().