Synergy Software Package User's Manual

Driver for the Clock Frequency Accuracy Measurement Circuit (CAC). More...

Data Structures

struct  cac_instance_ctrl_t
 

Functions

ssp_err_t R_CAC_Open (cac_ctrl_t *const p_api_ctrl, cac_cfg_t const *const p_cfg)
 Initialize the CAC peripheral. More...
 
ssp_err_t R_CAC_Close (cac_ctrl_t *const p_api_ctrl)
 Release any resources that were allocated by the Open() or any subsequent CAC operations. Implements r_cac_t::close. More...
 
ssp_err_t R_CAC_StopMeasurement (cac_ctrl_t *const p_api_ctrl)
 Stop the CAC measurement process. Implements r_cac_t::stopMeasurement. More...
 
ssp_err_t R_CAC_StartMeasurement (cac_ctrl_t *const p_api_ctrl)
 Start the CAC measurement process. Implements r_cac_t::startMeasurement. More...
 
ssp_err_t R_CAC_Reset (cac_ctrl_t *const p_api_ctrl)
 Resets the Overflow, Measurement End and Frequency Error interrupt flags. This will clear any of the CASTR status bits that have been set, but only if the CFME bit is off (Not measuring). Implements r_cac_t::reset. More...
 
ssp_err_t R_CAC_Read (cac_ctrl_t *const p_api_ctrl, uint8_t *const p_status, uint16_t *const p_counter)
 Read and return the CAC status and counter registers. Implements r_cac_t::read. More...
 
ssp_err_t R_CAC_VersionGet (ssp_version_t *const p_version)
 Get the API and code version information. More...
 

Detailed Description

Driver for the Clock Frequency Accuracy Measurement Circuit (CAC).

Summary

This module supports the CAC peripheral.

Function Documentation

◆ R_CAC_Close()

ssp_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. Implements r_cac_t::close.

Return values
SSP_SUCCESSSuccessful close.
SSP_ERR_ASSERTIONNULL provided for p_ctrl or p_cfg.
SSP_ERR_NOT_OPENR_CAC_Open() has not been successfully called.
// Example code
// Create a variable for the error
// Define a control block structure used in the API calls.
err = R_CAC_Close(&ctrl);

Eliminate warning if parameter checking is disabled.

Disable interrupts in the peripheral and NVIC

Disable interrupts in NVIC.

Disable the CAC ints.

Stop measuring.

Power down peripheral.

Return the hardware lock for the CAC.

◆ R_CAC_Open()

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

Initialize the CAC peripheral.

The Open function applies power to the CAC peripheral, checks/sets the interrupt priority, and configures the CAC based on the provided user configuration settings. If a user defined callback function has been provided in the configuration, then the CAC interrupt(s) will be enabled and the user callback function called accordingly. Implements r_cac_t::open.

Return values
SSP_SUCCESSCAC is available and available for measurement(s).
SSP_ERR_ASSERTIONNull Pointer.
SSP_ERR_INVALID_ARGUMENTOne or more configuration options are invalid.
SSP_ERR_HW_LOCKEDHardware lock for CAC peripheral is already taken.
SSP_ERR_INVALID_CAC_REF_CLOCKMeasured clock rate smaller than reference clock rate.
Returns
See Common Error Codes or functions called by this function for other possible return codes. This function calls:
Note
There is only a single CAC peripheral. It is not reentrant.
// Example code
// Create a variable for the error
// Define a control block structure used in the API calls.
// Define a configuration structure used in the API calls.
cac_cfg_t g_cac_example_cfg;
// Init the CGC and start the HOCO and LOCO clocks.
err = R_CGC_Init();
err = R_CGC_ClockStart(CGC_CLOCK_HOCO, &clock_config);
err = R_CGC_ClockStart(CGC_CLOCK_LOCO, &clock_config);
// Specify the parameters we are using
g_cac_example_cfg.callback = NULL,
g_cac_example_cfg.p_context = 0,
g_cac_example_cfg.p_extend = NULL,
g_cac_example_cfg.continuous_mode = false, // measurement does not continuously restart after completing.
g_cac_example_cfg.mei_interrupt_enabled = false; // Measurement complete interrupt disabled
g_cac_example_cfg.ovf_interrupt_enabled = false; // Overflow interrupt is disabled
g_cac_example_cfg.ferr_interrupt_enabled = false; // Frequency Error interrupt is disabled
g_cac_example_cfg.cac_ref_clock.digfilter = CAC_REF_DIGF_OFF; // No digital filter
g_cac_example_cfg.cac_ref_clock.edge = CAC_REF_EDGE_RISE; // Rising edge detect
g_cac_example_cfg.cac_meas_clock.clock = CAC_CLOCK_SOURCE_HOCO; // We want to measure HOCO (24 MHz)
g_cac_example_cfg.cac_meas_clock.divider = CAC_MEAS_DIV_1; // No divisor on the measurement clock
g_cac_example_cfg.cac_ref_clock.clock = CAC_CLOCK_SOURCE_LOCO; // Our reference clock will LOCO (32.768 kHz)
g_cac_example_cfg.cac_ref_clock.divider = CAC_REF_DIV_32; // Minimum divider is 32, so effective freq = 1024 Hz
err = R_CAC_Open(&ctrl, &g_cac_example_cfg);

g_cac_version is accessed by the ASSERT macro only and so compiler toolchain can issue a warning that they are not accessed. The code below eliminates this warning and also ensures these data structures are not optimised away.

Eliminate warning if parameter checking is disabled.

Take the hardware lock for the CAC.

Setup the interrupt vectors and priorities

Return the hardware lock for the CAC.

Apply power to the peripheral

Configure the CAC per the configuration.

Store the callback and context information

Mark driver as open by initializing it to "CAC" - its ASCII equivalent.

◆ R_CAC_Read()

ssp_err_t R_CAC_Read ( cac_ctrl_t *const  p_ctrl,
uint8_t *const  p_status,
uint16_t *const  p_counter 
)

Read and return the CAC status and counter registers. Implements r_cac_t::read.

Return values
SSP_SUCCESSCAC read successful.
SSP_ERR_ASSERTIONNULL provided for p_ctrl or p_cfg.
SSP_ERR_NOT_OPENR_CAC_Open() has not been successfully called.
// Example code
// Create a variable for the error and storage for the CAC count and status
uint8_t cac_status;
uint16_t cac_counter;
// Define a control block structure used in the API calls.
err = R_CAC_Read(&ctrl, &cac_status, &cac_counter);

Eliminate warning if parameter checking is disabled.

◆ R_CAC_Reset()

ssp_err_t R_CAC_Reset ( cac_ctrl_t *const  p_ctrl)

Resets the Overflow, Measurement End and Frequency Error interrupt flags. This will clear any of the CASTR status bits that have been set, but only if the CFME bit is off (Not measuring). Implements r_cac_t::reset.

Return values
SSP_SUCCESSCAC reset completed.
SSP_ERR_ASSERTIONNULL provided for p_ctrl or p_cfg.
SSP_ERR_NOT_OPENR_CAC_Open() has not been successfully called.
// Example code
// Create a variable for the error
// Define a control block structure used in the API calls.
cac_ctrl_t ctrl;
// Start the measurement process
err = R_CAC_Reset(&ctrl);

Eliminate warning if parameter checking is disabled.

Reset the CAC.

◆ R_CAC_StartMeasurement()

ssp_err_t R_CAC_StartMeasurement ( cac_ctrl_t *const  p_ctrl)

Start the CAC measurement process. Implements r_cac_t::startMeasurement.

Return values
SSP_SUCCESSCAC measurement started.
SSP_ERR_ASSERTIONNULL provided for p_ctrl or p_cfg.
SSP_ERR_NOT_OPENR_CAC_Open() has not been successfully called.
SSP_ERR_CLOCK_INACTIVEEither the provided Measurement or Reference clock is not running
Returns
See Common Error Codes or functions called by this function for other possible return codes. This function calls:
// Example code
// Create a variable for the error
// Define a control block structure used in the API calls.
cac_ctrl_t ctrl;
// Start the measurement process

Eliminate warnings if parameter checking is disabled.

Start measuring.

◆ R_CAC_StopMeasurement()

ssp_err_t R_CAC_StopMeasurement ( cac_ctrl_t *const  p_ctrl)

Stop the CAC measurement process. Implements r_cac_t::stopMeasurement.

Return values
SSP_SUCCESSCAC measuring has been stopped.
SSP_ERR_ASSERTIONNULL provided for p_ctrl or p_cfg.
SSP_ERR_NOT_OPENR_CAC_Open() has not been successfully called.
// Example code
// Create a variable for the error
// Define a control block structure used in the API calls.
cac_ctrl_t ctrl;
// Stop the measurement process
err = R_CAC_StopMeasurement(&ctrl);

Eliminate warning if parameter checking is disabled.

Stop measuring.

◆ R_CAC_VersionGet()

ssp_err_t R_CAC_VersionGet ( ssp_version_t *const  p_version)

Get the API and code version information.

Return values
SSP_SUCCESSVersion info returned.
Note
This function is reentrant.
// Example code
// Create a variable for the error
// Create a variable for the version information
ssp_version_t version;
// Get the current counter value
err = R_CAC_VersionGet(&version);