![]() |
MCUXpresso SDK API Reference Manual
Rev. 0
NXP Semiconductors
|
The MCUXpresso SDK provides APIs for MCUXpresso SDK devices' clock operation.
The clock driver supports:
Files | |
file | fsl_clock.h |
Data Structures | |
struct | sim_clock_config_t |
SIM configuration structure for clock setting. More... | |
struct | osc_config_t |
OSC Initialization Configuration Structure. More... | |
struct | ics_config_t |
ICS configuration structure. More... | |
Macros | |
#define | ICS_CONFIG_CHECK_PARAM 0U |
Configures whether to check a parameter in a function. More... | |
#define | FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL 0 |
Configure whether driver controls clock. More... | |
#define | UART_CLOCKS |
Clock ip name array for UART. More... | |
#define | ADC_CLOCKS |
Clock ip name array for ADC16. More... | |
#define | IRQ_CLOCKS |
Clock ip name array for IRQ. More... | |
#define | KBI_CLOCKS |
Clock ip name array for KBI. More... | |
#define | SPI_CLOCKS |
Clock ip name array for SPI. More... | |
#define | I2C_CLOCKS |
Clock ip name array for I2C. More... | |
#define | FTM_CLOCKS |
Clock ip name array for FTM. More... | |
#define | ACMP_CLOCKS |
Clock ip name array for CMP. More... | |
#define | CRC_CLOCKS |
Clock ip name array for CRC. More... | |
#define | PWT_CLOCKS |
Clock ip name array for PWT. More... | |
#define | PIT_CLOCKS |
Clock ip name array for PIT. More... | |
#define | RTC_CLOCKS |
Clock ip name array for RTC. More... | |
#define | MSCAN_CLOCKS |
Clock ip name array for MSCAN. More... | |
#define | LPO_CLK_FREQ 1000U |
LPO clock frequency. | |
Functions | |
static void | CLOCK_EnableClock (clock_ip_name_t name) |
Enable the clock for specific IP. More... | |
static void | CLOCK_DisableClock (clock_ip_name_t name) |
Disable the clock for specific IP. More... | |
static void | CLOCK_SetOutDiv (uint32_t outdiv1, uint32_t outdiv2, uint32_t outdiv3) |
clock divider More... | |
uint32_t | CLOCK_GetFreq (clock_name_t clockName) |
Gets the clock frequency for a specific clock name. More... | |
uint32_t | CLOCK_GetCoreSysClkFreq (void) |
Get the core clock or system clock frequency. More... | |
uint32_t | CLOCK_GetBusClkFreq (void) |
Get the bus clock frequency. More... | |
uint32_t | CLOCK_GetFlashClkFreq (void) |
Get the flash clock frequency. More... | |
uint32_t | CLOCK_GetOsc0ErClkFreq (void) |
Get the OSC0 external reference clock frequency (OSC0ERCLK). More... | |
void | CLOCK_SetSimConfig (sim_clock_config_t const *config) |
Set the clock configure in SIM module. More... | |
static void | CLOCK_SetSimSafeDivs (void) |
Set the system clock dividers in SIM to safe value. More... | |
Variables | |
volatile uint32_t | g_xtal0Freq |
External XTAL0 (OSC0) clock frequency. More... | |
Driver version | |
#define | FSL_CLOCK_DRIVER_VERSION (MAKE_VERSION(2, 2, 1)) |
CLOCK driver version 2.2.1. More... | |
ICS frequency functions. | |
uint32_t | CLOCK_GetICSOutClkFreq (void) |
Gets the ICS output clock (ICSOUTCLK) frequency. More... | |
uint32_t | CLOCK_GetFllFreq (void) |
Gets the ICS FLL clock (ICSFLLCLK) frequency. More... | |
uint32_t | CLOCK_GetInternalRefClkFreq (void) |
Gets the ICS internal reference clock (ICSIRCLK) frequency. More... | |
uint32_t | CLOCK_GetICSFixedFreqClkFreq (void) |
Gets the ICS fixed frequency clock (ICSFFCLK) frequency. More... | |
uint32_t | CLOCK_GetTimerClkFreq (void) |
Gets the Timer(FTM/PWT) clock frequency. More... | |
ICS clock configuration. | |
static void | CLOCK_SetLowPowerEnable (bool enable) |
Enables or disables the ICS low power. More... | |
static void | CLOCK_SetInternalRefClkConfig (uint8_t enableMode) |
Configures the Internal Reference clock (ICSIRCLK). More... | |
static void | CLOCK_SetFllExtRefDiv (uint8_t rdiv) |
Set the FLL external reference clock divider value. More... | |
ICS clock lock monitor functions. | |
static void | CLOCK_SetOsc0MonitorMode (bool enable) |
Sets the OSC0 clock monitor mode. More... | |
OSC configuration | |
void | CLOCK_InitOsc0 (osc_config_t const *config) |
Initializes the OSC0. More... | |
void | CLOCK_DeinitOsc0 (void) |
Deinitializes the OSC0. More... | |
External clock frequency | |
static void | CLOCK_SetXtal0Freq (uint32_t freq) |
Sets the XTAL0 frequency based on board settings. More... | |
static void | CLOCK_SetOsc0Enable (uint8_t enable) |
Sets the OSC enable. More... | |
ICS mode functions. | |
ics_mode_t | CLOCK_GetMode (void) |
Gets the current ICS mode. More... | |
status_t | CLOCK_SetFeiMode (uint8_t bDiv) |
Sets the ICS to FEI mode. More... | |
status_t | CLOCK_SetFeeMode (uint8_t bDiv, uint8_t rDiv) |
Sets the ICS to FEE mode. More... | |
status_t | CLOCK_SetFbiMode (uint8_t bDiv) |
Sets the ICS to FBI mode. More... | |
status_t | CLOCK_SetFbeMode (uint8_t bDiv, uint8_t rDiv) |
Sets the ICS to FBE mode. More... | |
status_t | CLOCK_SetBilpMode (uint8_t bDiv) |
Sets the ICS to BILP mode. More... | |
status_t | CLOCK_SetBelpMode (uint8_t bDiv) |
Sets the ICS to BELP mode. More... | |
status_t | CLOCK_BootToFeiMode (uint8_t bDiv) |
Sets the ICS to FEI mode during system boot up. More... | |
status_t | CLOCK_BootToFeeMode (uint8_t bDiv, uint8_t rDiv) |
Sets the ICS to FEE mode during system bootup. More... | |
status_t | CLOCK_BootToBilpMode (uint8_t bDiv) |
Sets the ICS to BILP mode during system boot up. More... | |
status_t | CLOCK_BootToBelpMode (uint8_t bDiv) |
Sets the ICS to BELP mode during system boot up. More... | |
status_t | CLOCK_SetIcsConfig (ics_config_t const *config) |
Sets the ICS to a target mode. More... | |
struct sim_clock_config_t |
Data Fields | |
uint8_t | outDiv1 |
OUTDIV1. | |
uint8_t | outDiv2 |
OUTDIV2. | |
uint8_t | outDiv3 |
OUTDIV3. | |
uint8_t | busClkPrescaler |
A option prescaler for bus clock. | |
struct osc_config_t |
Defines the configuration data structure to initialize the OSC. When porting to a new board, set the following members according to the board setting:
Data Fields | |
uint32_t | freq |
External clock frequency. More... | |
uint8_t | workMode |
OSC work mode setting. More... | |
uint8_t | enableMode |
Configuration for OSCERCLK. More... | |
uint32_t osc_config_t::freq |
uint8_t osc_config_t::workMode |
uint8_t osc_config_t::enableMode |
struct ics_config_t |
When porting to a new board, set the following members according to the board setting:
Data Fields | |
ics_mode_t | icsMode |
ICS mode. More... | |
uint8_t | irClkEnableMode |
ICSIRCLK enable mode. More... | |
uint8_t | rDiv |
Divider for external reference clock, ICS_C1[RDIV]. More... | |
uint8_t | bDiv |
Divider for ICS output clock ICS_C2[BDIV]. More... | |
ics_mode_t ics_config_t::icsMode |
uint8_t ics_config_t::irClkEnableMode |
uint8_t ics_config_t::rDiv |
uint8_t ics_config_t::bDiv |
#define ICS_CONFIG_CHECK_PARAM 0U |
Some ICS settings must be changed with conditions, for example:
ICS functions check the parameter and ICS status before setting, if not allowed to change, the functions return error. The parameter checking increases code size, if code size is a critical requirement, change ICS_CONFIG_CHECK_PARAM to 0 to disable parameter checking.
#define FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL 0 |
When set to 0, peripheral drivers will enable clock in initialize function and disable clock in de-initialize function. When set to 1, peripheral driver will not control the clock, application could control the clock out of the driver.
#define FSL_CLOCK_DRIVER_VERSION (MAKE_VERSION(2, 2, 1)) |
#define UART_CLOCKS |
#define ADC_CLOCKS |
#define IRQ_CLOCKS |
#define KBI_CLOCKS |
#define SPI_CLOCKS |
#define I2C_CLOCKS |
#define FTM_CLOCKS |
#define ACMP_CLOCKS |
#define CRC_CLOCKS |
#define PWT_CLOCKS |
#define PIT_CLOCKS |
#define RTC_CLOCKS |
#define MSCAN_CLOCKS |
enum clock_name_t |
enum clock_ip_name_t |
enum _osc_work_mode |
enum _osc_enable_mode |
enum ics_fll_src_t |
enum ics_clkout_src_t |
enum _ics_status |
enum ics_mode_t |
|
inlinestatic |
name | Which clock to enable, see clock_ip_name_t. |
|
inlinestatic |
name | Which clock to disable, see clock_ip_name_t. |
|
inlinestatic |
Set the SIM_CLKDIV[OUTDIV1], SIM_CLKDIV[OUTDIV2], SIM_CLKDIV[OUTDIV3]. Carefully configure the OUTDIV1 and OUTDIV2 to avoid bus clock frequency higher than 24MHZ.
outdiv1 | Clock 1 output divider value. |
outdiv2 | Clock 2 output divider value. |
outdiv3 | Clock 3 output divider value. |
uint32_t CLOCK_GetFreq | ( | clock_name_t | clockName | ) |
This function checks the current clock configurations and then calculates the clock frequency for a specific clock name defined in clock_name_t. The ICS must be properly configured before using this function.
clockName | Clock names defined in clock_name_t |
uint32_t CLOCK_GetCoreSysClkFreq | ( | void | ) |
uint32_t CLOCK_GetBusClkFreq | ( | void | ) |
uint32_t CLOCK_GetFlashClkFreq | ( | void | ) |
uint32_t CLOCK_GetOsc0ErClkFreq | ( | void | ) |
void CLOCK_SetSimConfig | ( | sim_clock_config_t const * | config | ) |
This function sets system layer clock settings in SIM module.
config | Pointer to the configure structure. |
|
inlinestatic |
The system level clocks (core clock, bus clock, and flash clock) must be in allowed ranges. During ICS clock mode switch, the ICS output clock changes then the system level clocks may be out of range. This function could be used before ICS mode change, to make sure system level clocks are in allowed range.
uint32_t CLOCK_GetICSOutClkFreq | ( | void | ) |
This function gets the ICS output clock frequency in Hz based on the current ICS register value.
uint32_t CLOCK_GetFllFreq | ( | void | ) |
This function gets the ICS FLL clock frequency in Hz based on the current ICS register value. The FLL is enabled in FEI/FBI/FEE/FBE mode and disabled in low power state in other modes.
uint32_t CLOCK_GetInternalRefClkFreq | ( | void | ) |
This function gets the ICS internal reference clock frequency in Hz based on the current ICS register value.
uint32_t CLOCK_GetICSFixedFreqClkFreq | ( | void | ) |
This function gets the ICS fixed frequency clock frequency in Hz based on the current ICS register value.
uint32_t CLOCK_GetTimerClkFreq | ( | void | ) |
This function gets the Timer clock frequency in Hz based on the current ICSOUTCLK.
|
inlinestatic |
Enabling the ICS low power disables the PLL and FLL in bypass modes. In other words, in FBE and PBE modes, enabling low power sets the ICS to BELP mode. In FBI and PBI modes, enabling low power sets the ICS to BILP mode. When disabling the ICS low power, the PLL or FLL are enabled based on ICS settings.
enable | True to enable ICS low power, false to disable ICS low power. |
|
inlinestatic |
This function sets the ICSIRCLK base on parameters. This function also sets whether the ICSIRCLK
is enabled in stop mode.
enableMode | ICSIRCLK enable mode, OR'ed value of _ics_irclk_enable_mode. |
|
inlinestatic |
Sets the FLL external reference clock divider value, the register ICS_C1[RDIV]. Resulting frequency must be in the range 31.25KHZ to 39.0625KHZ.
rdiv | The FLL external reference clock divider value, ICS_C1[RDIV]. |
|
inlinestatic |
This function sets the OSC0 clock monitor mode.
enable | true to enable clock monitor, false to disable clock monitor. |
void CLOCK_InitOsc0 | ( | osc_config_t const * | config | ) |
This function initializes the OSC0 according to the board configuration.
config | Pointer to the OSC0 configuration structure. |
void CLOCK_DeinitOsc0 | ( | void | ) |
This function deinitializes the OSC0.
|
inlinestatic |
freq | The XTAL0/EXTAL0 input clock frequency in Hz. |
|
inlinestatic |
enable | osc enable mode. |
ics_mode_t CLOCK_GetMode | ( | void | ) |
This function checks the ICS registers and determines the current ICS mode.
status_t CLOCK_SetFeiMode | ( | uint8_t | bDiv | ) |
This function sets the ICS to FEI mode. If setting to FEI mode fails from the current mode, this function returns an error.
bDiv | bus clock divider |
kStatus_ICS_ModeUnreachable | Could not switch to the target mode. |
kStatus_Success | Switched to the target mode successfully. |
status_t CLOCK_SetFeeMode | ( | uint8_t | bDiv, |
uint8_t | rDiv | ||
) |
This function sets the ICS to FEE mode. If setting to FEE mode fails from the current mode, this function returns an error.
bDiv | bus clock divider |
rDiv | FLL reference clock divider setting, RDIV. |
kStatus_ICS_ModeUnreachable | Could not switch to the target mode. |
kStatus_Success | Switched to the target mode successfully. |
status_t CLOCK_SetFbiMode | ( | uint8_t | bDiv | ) |
This function sets the ICS to FBI mode. If setting to FBI mode fails from the current mode, this function returns an error.
bDiv | bus clock divider |
kStatus_ICS_ModeUnreachable | Could not switch to the target mode. |
kStatus_Success | Switched to the target mode successfully. |
status_t CLOCK_SetFbeMode | ( | uint8_t | bDiv, |
uint8_t | rDiv | ||
) |
This function sets the ICS to FBE mode. If setting to FBE mode fails from the current mode, this function returns an error.
bDiv | bus clock divider |
rDiv | FLL reference clock divider setting, RDIV. |
kStatus_ICS_ModeUnreachable | Could not switch to the target mode. |
kStatus_Success | Switched to the target mode successfully. |
status_t CLOCK_SetBilpMode | ( | uint8_t | bDiv | ) |
This function sets the ICS to BILP mode. If setting to BILP mode fails from the current mode, this function returns an error.
bDiv | bus clock divider |
kStatus_ICS_ModeUnreachable | Could not switch to the target mode. |
kStatus_Success | Switched to the target mode successfully. |
status_t CLOCK_SetBelpMode | ( | uint8_t | bDiv | ) |
This function sets the ICS to BELP mode. If setting to BELP mode fails from the current mode, this function returns an error.
bDiv | bus clock divider |
kStatus_ICS_ModeUnreachable | Could not switch to the target mode. |
kStatus_Success | Switched to the target mode successfully. |
status_t CLOCK_BootToFeiMode | ( | uint8_t | bDiv | ) |
This function sets the ICS to FEI mode from the reset mode. It can also be used to set up ICS during system boot up.
bDiv | bus clock divider. |
kStatus_ICS_ModeUnreachable | Could not switch to the target mode. |
kStatus_Success | Switched to the target mode successfully. |
status_t CLOCK_BootToFeeMode | ( | uint8_t | bDiv, |
uint8_t | rDiv | ||
) |
This function sets ICS to FEE mode from the reset mode. It can also be used to set up the ICS during system boot up.
bDiv | bus clock divider. |
rDiv | FLL reference clock divider setting, RDIV. |
kStatus_ICS_ModeUnreachable | Could not switch to the target mode. |
kStatus_Success | Switched to the target mode successfully. |
status_t CLOCK_BootToBilpMode | ( | uint8_t | bDiv | ) |
This function sets the ICS to BILP mode from the reset mode. It can also be used to set up the ICS during system boot up.
bDiv | bus clock divider. |
kStatus_ICS_SourceUsed | Could not change ICSIRCLK setting. |
kStatus_Success | Switched to the target mode successfully. |
status_t CLOCK_BootToBelpMode | ( | uint8_t | bDiv | ) |
This function sets the ICS to BELP mode from the reset mode. It can also be used to set up the ICS during system boot up.
bDiv | bus clock divider. |
kStatus_ICS_ModeUnreachable | Could not switch to the target mode. |
kStatus_Success | Switched to the target mode successfully. |
status_t CLOCK_SetIcsConfig | ( | ics_config_t const * | config | ) |
This function sets ICS to a target mode defined by the configuration structure. If switching to the target mode fails, this function chooses the correct path.
config | Pointer to the target ICS mode configuration structure. |
volatile uint32_t g_xtal0Freq |
The XTAL0/EXTAL0 (OSC0) clock frequency in Hz. When the clock is set up, use the function CLOCK_SetXtal0Freq to set the value in the clock driver. For example, if XTAL0 is 8 MHz:
This is important for the multicore platforms where only one core needs to set up the OSC0 using the CLOCK_InitOsc0. All other cores need to call the CLOCK_SetXtal0Freq to get a valid clock frequency.