RA Flexible Software Package Documentation  Release v5.6.0

 
Clock Accuracy Circuit (r_cac)

Functions

fsp_err_t R_CAC_Open (cac_ctrl_t *const p_ctrl, cac_cfg_t const *const p_cfg)
 
fsp_err_t R_CAC_StartMeasurement (cac_ctrl_t *const p_ctrl)
 
fsp_err_t R_CAC_StopMeasurement (cac_ctrl_t *const p_ctrl)
 
fsp_err_t R_CAC_Read (cac_ctrl_t *const p_ctrl, uint32_t *const p_counter)
 
fsp_err_t R_CAC_CallbackSet (cac_ctrl_t *const p_ctrl, void(*p_callback)(cac_callback_args_t *), void const *const p_context, cac_callback_args_t *const p_callback_memory)
 
fsp_err_t R_CAC_Close (cac_ctrl_t *const p_ctrl)
 

Detailed Description

Driver for the CAC peripheral on RA MCUs. This module implements the CAC Interface.

Overview

The interface for the clock frequency accuracy measurement circuit (CAC) peripheral is used to check a system clock frequency with a reference clock signal by counting the number of measurement clock edges that occur between two edges of the reference clock.

Features

Configuration

Build Time Configurations for r_cac

The following build time configurations are defined in fsp_cfg/r_cac_cfg.h:

ConfigurationOptionsDefaultDescription
Parameter Checking
  • Default (BSP)
  • Enabled
  • Disabled
Default (BSP) If selected code for parameter checking is included in the build.

Configurations for Monitoring > Clock Accuracy Circuit (r_cac)

This module can be added to the Stacks tab via New Stack > Monitoring > Clock Accuracy Circuit (r_cac). Non-secure callable guard functions can be generated for this module by right clicking the module in the RA Configuration tool and checking the "Non-secure Callable" box.

ConfigurationOptionsDefaultDescription
NameName must be a valid C symbolg_cac0 Module name.
Reference clock divider
  • 32
  • 128
  • 1024
  • 8192
32 Reference clock divider.
Reference clock sourceMCU Specific OptionsReference clock source.
Reference clock digital filter
  • Disabled
  • Sampling clock=Measuring freq
  • Sampling clock=Measuring freq/4
  • Sampling clock=Measuring freq/16
Disabled Reference clock digital filter.
Reference clock edge detect
  • Rising
  • Falling
  • Both
Rising Reference clock edge detection.
Measurement clock divider
  • 1
  • 4
  • 8
  • 32
1 Measurement clock divider.
Measurement clock sourceMCU Specific OptionsMeasurement clock source.
Upper Limit ThresholdValue must be a non-negative integer, between 0 to 655350 Top end of allowable range for measurement completion.
Lower Limit ThresholdValue must be a non-negative integer, between 0 to 655350 Bottom end of allowable range for measurement completion.
Frequency Error Interrupt PriorityMCU Specific OptionsCAC frequency error interrupt priority.
Measurement End Interrupt PriorityMCU Specific OptionsCAC measurement end interrupt priority.
Overflow Interrupt PriorityMCU Specific OptionsCAC overflow interrupt priority.
CallbackName must be a valid C symbolNULL Function name for callback

Clock Configuration

The CAC measurement clock source can be configured as the following:

  1. MAIN_OSC
  2. SUBCLOCK
  3. HOCO
  4. MOCO
  5. LOCO
  6. PCLKB
  7. IWDT

The CAC reference clock source can be configured as the following:

  1. MAIN_OSC
  2. SUBCLOCK
  3. HOCO
  4. MOCO
  5. LOCO
  6. PCLKB
  7. IWDT
  8. External Clock Source (CACREF)

Pin Configuration

The CACREF pin can be configured to provide the reference clock for CAC measurements.

Usage Notes

Measurement Accuracy

The clock measurement result may be off by up to one pulse depending on the phase difference between the edge detection circuit, digital filter, and CACREF pin signal, if applicable.

Frequency Error Interrupt

The frequency error interrupt is only triggered at the end of a CAC measurement. This means that there will be a measurement complete interrupt in addition to the frequency error interrupt.

Examples

Basic Example

This is a basic example of minimal use of the CAC in an application.

volatile uint32_t g_callback_complete;
void cac_basic_example ()
{
g_callback_complete = 0;
fsp_err_t err = R_CAC_Open(&g_cac_ctrl, &g_cac_cfg);
/* Handle any errors. This function should be defined by the user. */
assert(FSP_SUCCESS == err);
(void) R_CAC_StartMeasurement(&g_cac_ctrl);
/* Wait for measurement to complete. */
while (0 == g_callback_complete)
{
}
uint32_t value;
/* Read the CAC measurement. */
(void) R_CAC_Read(&g_cac_ctrl, &value);
}
/* Called when measurement is completed. */
static void r_cac_callback (cac_callback_args_t * p_args)
{
{
g_callback_complete = 1U;
}
}

Data Structures

struct  cac_instance_ctrl_t
 

Data Structure Documentation

◆ cac_instance_ctrl_t

struct cac_instance_ctrl_t

CAC instance control block. DO NOT INITIALIZE.

Function Documentation

◆ R_CAC_Open()

fsp_err_t R_CAC_Open ( cac_ctrl_t *const  p_ctrl,
cac_cfg_t const *const  p_cfg 
)

The Open function configures the CAC based on the provided user configuration settings.

Return values
FSP_SUCCESSCAC is available and available for measurement(s).
FSP_ERR_ASSERTIONAn argument is invalid.
FSP_ERR_ALREADY_OPENThe CAC has already been opened.
Note
There is only a single CAC peripheral.

◆ R_CAC_StartMeasurement()

fsp_err_t R_CAC_StartMeasurement ( cac_ctrl_t *const  p_ctrl)

Start the CAC measurement process.

Return values
FSP_SUCCESSCAC measurement started.
FSP_ERR_ASSERTIONNULL provided for p_instance_ctrl or p_cfg.
FSP_ERR_NOT_OPENR_CAC_Open() has not been successfully called.

◆ R_CAC_StopMeasurement()

fsp_err_t R_CAC_StopMeasurement ( cac_ctrl_t *const  p_ctrl)

Stop the CAC measurement process.

Return values
FSP_SUCCESSCAC measuring has been stopped.
FSP_ERR_ASSERTIONNULL provided for p_instance_ctrl or p_cfg.
FSP_ERR_NOT_OPENR_CAC_Open() has not been successfully called.

◆ R_CAC_Read()

fsp_err_t R_CAC_Read ( cac_ctrl_t *const  p_ctrl,
uint32_t *const  p_counter 
)

Read and return the CAC status and counter registers.

Return values
FSP_SUCCESSCAC read successful.
FSP_ERR_ASSERTIONAn argument is NULL.
FSP_ERR_NOT_OPENR_CAC_Open() has not been successfully called.

◆ R_CAC_CallbackSet()

fsp_err_t R_CAC_CallbackSet ( cac_ctrl_t *const  p_ctrl,
void(*)(cac_callback_args_t *)  p_callback,
void const *const  p_context,
cac_callback_args_t *const  p_callback_memory 
)

Updates the user callback with the option to provide memory for the callback argument structure. Implements cac_api_t::callbackSet.

Return values
FSP_SUCCESSCallback updated successfully.
FSP_ERR_ASSERTIONA required pointer is NULL.
FSP_ERR_NOT_OPENThe control block has not been opened.
FSP_ERR_NO_CALLBACK_MEMORYp_callback is non-secure and p_callback_memory is either secure or NULL.

◆ R_CAC_Close()

fsp_err_t R_CAC_Close ( cac_ctrl_t *const  p_ctrl)

Release any resources that were allocated by the Open() or any subsequent CAC operations.

Return values
FSP_SUCCESSSuccessful close.
FSP_ERR_ASSERTIONNULL provided for p_instance_ctrl or p_cfg.
FSP_ERR_NOT_OPENR_CAC_Open() has not been successfully called.