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
- Supports clock frequency-measurement and monitoring based on a reference signal input
- Reference can be either an externally supplied clock source or an internal clock source
- An interrupt request may optionally be generated by a completed measurement, a detected frequency error, or a counter overflow.
- A digital filter is available for an externally supplied reference clock, and dividers are available for both internally supplied measurement and reference clocks.
- Edge-detection options for the reference clock are configurable as rising, falling, or both.
Configuration
Build Time Configurations for r_cac
The following build time configurations are defined in fsp_cfg/r_cac_cfg.h:
Configuration | Options | Default | Description |
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.
Configuration | Options | Default | Description |
Name | Name must be a valid C symbol | g_cac0 | Module name. |
Reference clock divider |
| 32 | Reference clock divider. |
Reference clock source | MCU Specific Options | | Reference 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 | Reference clock edge detection. |
Measurement clock divider |
| 1 | Measurement clock divider. |
Measurement clock source | MCU Specific Options | | Measurement clock source. |
Upper Limit Threshold | Value must be a non-negative integer, between 0 to 65535 | 0 | Top end of allowable range for measurement completion. |
Lower Limit Threshold | Value must be a non-negative integer, between 0 to 65535 | 0 | Bottom end of allowable range for measurement completion. |
Frequency Error Interrupt Priority | MCU Specific Options | | CAC frequency error interrupt priority. |
Measurement End Interrupt Priority | MCU Specific Options | | CAC measurement end interrupt priority. |
Overflow Interrupt Priority | MCU Specific Options | | CAC overflow interrupt priority. |
Callback | Name must be a valid C symbol | NULL | Function name for callback |
Clock Configuration
The CAC measurement clock source can be configured as the following:
- MAIN_OSC
- SUBCLOCK
- HOCO
- MOCO
- LOCO
- PCLKB
- IWDT
The CAC reference clock source can be configured as the following:
- MAIN_OSC
- SUBCLOCK
- HOCO
- MOCO
- LOCO
- PCLKB
- IWDT
- 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;
assert(FSP_SUCCESS == err);
while (0 == g_callback_complete)
{
}
uint32_t value;
}
{
{
g_callback_complete = 1U;
}
}
◆ cac_instance_ctrl_t
struct cac_instance_ctrl_t |
CAC instance control block. DO NOT INITIALIZE.
◆ R_CAC_Open()
The Open function configures the CAC based on the provided user configuration settings.
- Return values
-
FSP_SUCCESS | CAC is available and available for measurement(s). |
FSP_ERR_ASSERTION | An argument is invalid. |
FSP_ERR_ALREADY_OPEN | The CAC has already been opened. |
- Note
- There is only a single CAC peripheral.
◆ R_CAC_StartMeasurement()
Start the CAC measurement process.
- Return values
-
FSP_SUCCESS | CAC measurement started. |
FSP_ERR_ASSERTION | NULL provided for p_instance_ctrl or p_cfg. |
FSP_ERR_NOT_OPEN | R_CAC_Open() has not been successfully called. |
◆ R_CAC_StopMeasurement()
Stop the CAC measurement process.
- Return values
-
FSP_SUCCESS | CAC measuring has been stopped. |
FSP_ERR_ASSERTION | NULL provided for p_instance_ctrl or p_cfg. |
FSP_ERR_NOT_OPEN | R_CAC_Open() has not been successfully called. |
◆ R_CAC_Read()
Read and return the CAC status and counter registers.
- Return values
-
FSP_SUCCESS | CAC read successful. |
FSP_ERR_ASSERTION | An argument is NULL. |
FSP_ERR_NOT_OPEN | R_CAC_Open() has not been successfully called. |
◆ R_CAC_CallbackSet()
Updates the user callback with the option to provide memory for the callback argument structure. Implements cac_api_t::callbackSet.
- Return values
-
FSP_SUCCESS | Callback updated successfully. |
FSP_ERR_ASSERTION | A required pointer is NULL. |
FSP_ERR_NOT_OPEN | The control block has not been opened. |
FSP_ERR_NO_CALLBACK_MEMORY | p_callback is non-secure and p_callback_memory is either secure or NULL. |
◆ R_CAC_Close()
Release any resources that were allocated by the Open() or any subsequent CAC operations.
- Return values
-
FSP_SUCCESS | Successful close. |
FSP_ERR_ASSERTION | NULL provided for p_instance_ctrl or p_cfg. |
FSP_ERR_NOT_OPEN | R_CAC_Open() has not been successfully called. |