RA Flexible Software Package Documentation
Release v5.7.0
|
|
Driver for the CGC peripheral on RA MCUs. This module implements the CGC Interface.
The CGC module supports runtime modifications of clock settings. Key features include the following:
The RA microcontrollers have up to seven internal clocks. Not all internal clocks exist on all MCUs. Each clock domain has its own divider that can be updated in R_CGC_SystemClockSet(). The dividers are subject to constraints described in the footnote of the table "Specifications of the Clock Generation Circuit for the internal clocks" in the hardware manual.
The internal clocks include:
Configuration | Options | Default | Description |
---|---|---|---|
Parameter Checking |
| Default (BSP) | If selected code for parameter checking is included in the build. |
Configuration | Options | Default | Description |
---|---|---|---|
Sub Clock Oscillation Stop Detection Settings | |||
Enable sub clock oscillator stop detection via the SOSC_STOP interrupt |
| Disabled | Oscillation Stop Detection for Sub Clock enabled. |
Sub Clock Oscillation Stop Detection Time | Manual Entry | 0 | These bits specify the oscillation stop detection time. It is detected that oscillation has stopped when oscillation has been stopped for (A-2) to (A+1) clock cycles, where A refers to the time specified by these bits. Oscillation stop detection time = Low-speed on-chip oscillator clock (LOCO) cycle x ((value of OSDCCMP) + 1). |
Sub Clock Oscillation Stop Detection Interrupt Priority | MCU Specific Options | [Optional] Select the interrupt priority for the Sub Clock Oscillation Stop Detection interrupt. | |
Main Oscillation Stop Detection Settings | |||
Enable main clock oscillator stop detection via the MOSC_STOP interrupt |
| Disabled | Oscillation Stop Detection for Main Clock enabled. |
Main Oscillation Stop Detection Time | Manual Entry | 0 | These bits specify the oscillation stop detection time. It is detected that oscillation has stopped when oscillation has been stopped for (A - 2) to (A + 1) clock cycles, where A refers to the time specified by these bits. Oscillation stop detection time = High speed on-chip oscillator clock (HOCO) cycle x ((value of OSDCCMP) + 1). |
Main Oscillation Stop Detection Interrupt Priority | MCU Specific Options | [Optional] Select the interrupt priority for the Main Oscillation Stop Detection interrupt. | |
Oscillator Stop Detection Settings | |||
Clock Switch Enable for Oscillation Stop Detected of SDADCCLK |
| Disabled | The OSTDCSE bit specifies the source clock of the 24-bit Sigma-delta A/D Converter Clock switched to HOCO when oscillation stop detected. |
Name | Name must be a valid C symbol | g_cgc0 | Module name. |
Enable main oscillator stop detection via the NMI interrupt |
| Enabled | Oscillation Stop Detection for System Clock enabled. |
Oscillation Stop Detection Callback | Name must be a valid C symbol | NULL | A user callback function must be provided if oscillation stop detection for System Clock/Main Oscillation/Sub Clock Oscillation is used. If this callback function is provided, it is called from the NMI handler if the main oscillator stops. |
This module is used to configure the system clocks. There are no module specific clock configurations required to use it.
The CGC module controls the output of the CLOCKOUT signal.
If an external oscillator is used the XTAL and EXTAL pins must be configured accordingly. When running from an on chip oscillator there is no requirement for the main clock external oscillator. In this case, the XTAL and EXTAL pins can be set to a different function in the RA Configuration editor.
The functionality of the subclock external oscillator pins XCIN and XCOUT is fixed.
CGC driver supports following oscillation stop detection function.
The CGC driver uses the NMI for oscillation stop detection of the main oscillator after R_CGC_OscStopDetectEnable is called. The NMI is enabled by default. No special configuration is required. When the NMI is triggered, the callback function registered during R_CGC_Open() is called.
A main clock oscillation stop detection interrupt (MOSTD_STOP) is generated when the Oscillation Stop Detection for Main Clock is enabled. The main oscillation stop detection interrupt is a maskable interrupt. When the MOSTD_STOP is triggered, the callback function registered during R_CGC_Open() is called.
A sub clock oscillation stop detection interrupt (SOSC_STOP) is generated when the Oscillation Stop Detection for Sub Clock is enabled. The sub clock oscillation stop detection interrupt is a maskable interrupt. When the SOSC_STOP is triggered, the callback function registered during R_CGC_Open() is called.
When Clock Switch Enable for Oscillation Stop Detected is set.
If the Subclock Populated property is set to Populated on the BSP configuration tab, then the subclock is started in the BSP startup routine. Otherwise, it is stopped in the BSP startup routine. Starting and stopping the subclock at runtime is not recommended since the stabilization requirements typically negate the negligible power savings.
The application is responsible for ensuring required clocks are started and stable before accessing MCU peripheral registers.
Changing the subclock state during R_CGC_ClocksCfg() is not supported.
If "Use Low Voltage Mode" is enabled in the BSP MCU specific properties (not available on all MCUs), the MCU is always in low voltage mode and no other power modes are considered. The following conditions must be met for the MCU to run in low voltage mode:
If "Use Low Voltage Mode" is not enabled, the MCU applies the lowest power mode by searching through the following list in order and applying the first power mode that is supported under the current conditions:
Refer to the section "Function for Lower Operating Power Consumption" in the "Low Power Modes" chapter of the hardware manual for MCU specific information about operating power control modes.
When low voltage mode is not used, the following functions adjust the operating power control mode to ensure it remains within the hardware specification and to ensure the MCU is running at the optimal operating power control mode:
No action is required by the user of these APIs. This section is provided for informational purposes only.
This is a basic example of minimal use of the CGC in an application.
This example demonstrates switching to a new source clock and stopping the previous source clock in a single function call using R_CGC_ClocksCfg().
This example demonstrates registering a callback for oscillation stop detection of the main oscillator.
Data Structures | |
struct | cgc_instance_ctrl_t |
struct cgc_instance_ctrl_t |
CGC private control block. DO NOT MODIFY. Initialization occurs when R_CGC_Open() is called.
Data Fields | |
void const * | p_context |
void const* cgc_instance_ctrl_t::p_context |
Placeholder for user data. Passed to the user callback in cgc_callback_args_t.
fsp_err_t R_CGC_Open | ( | cgc_ctrl_t *const | p_ctrl, |
cgc_cfg_t const *const | p_cfg | ||
) |
Initialize the CGC API. Implements cgc_api_t::open.
Example:
FSP_SUCCESS | CGC successfully initialized. |
FSP_ERR_ASSERTION | Invalid input argument. |
FSP_ERR_ALREADY_OPEN | Module is already open. |
fsp_err_t R_CGC_ClocksCfg | ( | cgc_ctrl_t *const | p_ctrl, |
cgc_clocks_cfg_t const *const | p_clock_cfg | ||
) |
Reconfigures all main system clocks. This API can be used for any of the following purposes:
If the requested system clock source has a stabilization flag, this function blocks waiting for the stabilization flag of the requested system clock source to be set. If the requested system clock source was just started and it has no stabilization flag, this function blocks for the stabilization time required by the requested system clock source according to the Electrical Characteristics section of the hardware manual. If the requested system clock source has no stabilization flag and it is already running, it is assumed to be stable and this function will not block. If the requested system clock is the subclock, the subclock must be stable prior to calling this function.
The internal dividers (cgc_clocks_cfg_t::divider_cfg) are subject to constraints described in footnotes of the hardware manual table detailing specifications for the clock generation circuit for the internal clocks for the MCU. For example:
Do not attempt to stop the requested clock source or the source of a PLL if the PLL will be running after this operation completes.
Implements cgc_api_t::clocksCfg.
Example:
FSP_SUCCESS | Clock configuration applied successfully. |
FSP_ERR_ASSERTION | Invalid input argument. |
FSP_ERR_NOT_OPEN | Module is not open. |
FSP_ERR_IN_USE | Attempt to stop the current system clock or the PLL source clock. |
FSP_ERR_CLOCK_ACTIVE | PLL configuration cannot be changed while PLL is running. |
FSP_ERR_OSC_STOP_DET_ENABLED | PLL multiplier must be less than 20 if oscillation stop detect is enabled and the input frequency is less than 12.5 MHz. |
FSP_ERR_NOT_STABILIZED | PLL clock source is not stable. |
FSP_ERR_PLL_SRC_INACTIVE | PLL clock source is not running. |
FSP_ERR_INVALID_STATE | The subclock must be running before activating HOCO with FLL. |
fsp_err_t R_CGC_ClockStart | ( | cgc_ctrl_t *const | p_ctrl, |
cgc_clock_t | clock_source, | ||
cgc_pll_cfg_t const *const | p_pll_cfg | ||
) |
Start the specified clock if it is not currently active. The PLL configuration cannot be changed while the PLL is running. Implements cgc_api_t::clockStart.
The PLL source clock must be operating and stable prior to starting the PLL.
Example:
FSP_SUCCESS | Clock initialized successfully. |
FSP_ERR_ASSERTION | Invalid input argument. |
FSP_ERR_NOT_OPEN | Module is not open. |
FSP_ERR_NOT_STABILIZED | The clock source is not stabilized after being turned off or PLL clock source is not stable. |
FSP_ERR_PLL_SRC_INACTIVE | PLL clock source is not running. |
FSP_ERR_CLOCK_ACTIVE | PLL configuration cannot be changed while PLL is running. |
FSP_ERR_OSC_STOP_DET_ENABLED | PLL multiplier must be less than 20 if oscillation stop detect is enabled and the input frequency is less than 12.5 MHz. |
FSP_ERR_INVALID_STATE | The subclock must be running before activating HOCO with FLL. |
fsp_err_t R_CGC_ClockStop | ( | cgc_ctrl_t *const | p_ctrl, |
cgc_clock_t | clock_source | ||
) |
Stop the specified clock if it is active. Implements cgc_api_t::clockStop.
Do not attempt to stop the current system clock source. Do not attempt to stop the source clock of a PLL if the PLL is running.
FSP_SUCCESS | Clock stopped successfully. |
FSP_ERR_ASSERTION | Invalid input argument. |
FSP_ERR_NOT_OPEN | Module is not open. |
FSP_ERR_IN_USE | Attempt to stop the current system clock or the PLL source clock. |
FSP_ERR_OSC_STOP_DET_ENABLED | Attempt to stop MOCO when Oscillation stop is enabled. |
FSP_ERR_NOT_STABILIZED | Clock not stabilized after starting. |
fsp_err_t R_CGC_SystemClockSet | ( | cgc_ctrl_t *const | p_ctrl, |
cgc_clock_t | clock_source, | ||
cgc_divider_cfg_t const *const | p_divider_cfg | ||
) |
Set the specified clock as the system clock and configure the internal dividers for ICLK, PCLKA, PCLKB, PCLKC, PCLKD, BCLK, and FCLK. Implements cgc_api_t::systemClockSet.
The requested clock source must be running and stable prior to calling this function. The internal dividers are subject to constraints described in the hardware manual table "Specifications of the Clock Generation Circuit for the internal clocks".
The internal dividers (p_divider_cfg) are subject to constraints described in footnotes of the hardware manual table detailing specifications for the clock generation circuit for the internal clocks for the MCU. For example:
This function also updates the RAM and ROM wait states, the operating power control mode, and the SystemCoreClock CMSIS global variable.
Example:
FSP_SUCCESS | Operation performed successfully. |
FSP_ERR_ASSERTION | Invalid input argument. |
FSP_ERR_NOT_OPEN | Module is not open. |
FSP_ERR_CLOCK_INACTIVE | The specified clock source is inactive. |
FSP_ERR_NOT_STABILIZED | The clock source has not stabilized |
fsp_err_t R_CGC_SystemClockGet | ( | cgc_ctrl_t *const | p_ctrl, |
cgc_clock_t *const | p_clock_source, | ||
cgc_divider_cfg_t *const | p_divider_cfg | ||
) |
Return the current system clock source and configuration. Implements cgc_api_t::systemClockGet.
FSP_SUCCESS | Parameters returned successfully. |
FSP_ERR_ASSERTION | Invalid input argument. |
FSP_ERR_NOT_OPEN | Module is not open. |
fsp_err_t R_CGC_ClockCheck | ( | cgc_ctrl_t *const | p_ctrl, |
cgc_clock_t | clock_source | ||
) |
Check the specified clock for stability. Implements cgc_api_t::clockCheck.
FSP_SUCCESS | Clock is running and stable. |
FSP_ERR_ASSERTION | Invalid input argument. |
FSP_ERR_NOT_OPEN | Module is not open. |
FSP_ERR_NOT_STABILIZED | Clock not stabilized. |
FSP_ERR_CLOCK_INACTIVE | Clock not turned on. |
fsp_err_t R_CGC_OscStopDetectEnable | ( | cgc_ctrl_t *const | p_ctrl | ) |
Enable the oscillation stop detection for the main clock. Implements cgc_api_t::oscStopDetectEnable.
The MCU will automatically switch the system clock to MOCO when a stop is detected if Main Clock is the system clock. If the system clock is the PLL, then the clock source will not be changed and the PLL free running frequency will be the system clock frequency.
Example:
FSP_SUCCESS | Operation performed successfully. |
FSP_ERR_ASSERTION | Invalid input argument. |
FSP_ERR_NOT_OPEN | Module is not open. |
FSP_ERR_LOW_VOLTAGE_MODE | Settings not allowed in low voltage mode. |
FSP_ERR_UNSUPPORTED | Function not supported. |
fsp_err_t R_CGC_OscStopDetectDisable | ( | cgc_ctrl_t *const | p_ctrl | ) |
Disable the oscillation stop detection for the main clock. Implements cgc_api_t::oscStopDetectDisable.
Example:
FSP_SUCCESS | Operation performed successfully. |
FSP_ERR_ASSERTION | Invalid input argument. |
FSP_ERR_NOT_OPEN | Module is not open. |
FSP_ERR_OSC_STOP_DETECTED | The Oscillation stop detect status flag is set. Under this condition it is not possible to disable the Oscillation stop detection function. |
FSP_ERR_UNSUPPORTED | Function not supported. |
fsp_err_t R_CGC_OscStopStatusClear | ( | cgc_ctrl_t *const | p_ctrl | ) |
Clear the Oscillation Stop Detection Status register. This register is not cleared automatically if the stopped clock is restarted. Implements cgc_api_t::oscStopStatusClear.
After clearing the status, oscillation stop detection is no longer enabled.
This register cannot be cleared while the main oscillator is the system clock or the PLL source clock.
Example:
FSP_SUCCESS | Operation performed successfully. |
FSP_ERR_ASSERTION | Invalid input argument. |
FSP_ERR_NOT_OPEN | Module is not open. |
FSP_ERR_CLOCK_INACTIVE | Main oscillator must be running to clear the oscillation stop detection flag. |
FSP_ERR_OSC_STOP_CLOCK_ACTIVE | The Oscillation Detect Status flag cannot be cleared if the Main Osc or PLL is set as the system clock. Change the system clock before attempting to clear this bit. |
FSP_ERR_INVALID_HW_CONDITION | Oscillation stop status was not cleared. Check preconditions and try again. |
FSP_ERR_UNSUPPORTED | Function not supported. |
fsp_err_t R_CGC_CallbackSet | ( | cgc_ctrl_t *const | p_api_ctrl, |
void(*)(cgc_callback_args_t *) | p_callback, | ||
void const *const | p_context, | ||
cgc_callback_args_t *const | p_callback_memory | ||
) |
Updates the user callback and has option of providing memory for callback structure. Implements cgc_api_t::callbackSet
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. |
FSP_ERR_UNSUPPORTED | Function not supported. |
fsp_err_t R_CGC_Close | ( | cgc_ctrl_t *const | p_ctrl | ) |
Closes the CGC module. Implements cgc_api_t::close.
FSP_SUCCESS | The module is successfully closed. |
FSP_ERR_ASSERTION | Invalid input argument. |
FSP_ERR_NOT_OPEN | Module is not open. |