S32 SDK
clock_S32K1xx.c File Reference
#include "device_registers.h"
#include "sim_hw_access.h"
#include "scg_hw_access.h"
#include "pcc_hw_access.h"
#include "pmc_hw_access.h"
#include "smc_hw_access.h"
#include "clock_manager.h"
#include <stddef.h>

Go to the source code of this file.

Macros

#define SCG_SPLL_MULT_BASE   16U
 
#define SCG_SPLL_PREDIV_BASE   1U
 
#define SCG_SPLL_REF_MIN   8000000U
 
#define SCG_SPLL_REF_MAX   32000000U
 
#define LPO_128K_FREQUENCY   128000UL
 
#define LPO_32K_FREQUENCY   32000UL
 
#define LPO_1K_FREQUENCY   1000UL
 
#define HIGH_SPEED_RUNNING_MODE   (1UL << 7U)
 
#define RUN_SPEED_RUNNING_MODE   (1UL << 0U)
 
#define VLPR_SPEED_RUNNING_MODE   (1UL << 2U)
 

Enumerations

enum  scg_system_clock_type_t { SCG_SYSTEM_CLOCK_CORE, SCG_SYSTEM_CLOCK_BUS, SCG_SYSTEM_CLOCK_SLOW, SCG_SYSTEM_CLOCK_MAX }
 SCG system clock type. Implements scg_system_clock_type_t_Class. More...
 
enum  scg_async_clock_type_t { SCG_ASYNC_CLOCK_DIV1 = 0U, SCG_ASYNC_CLOCK_DIV2 = 1U, SCG_ASYNC_CLOCK_MAX = 2U }
 SCG asynchronous clock type. Implements scg_async_clock_type_t_Class. More...
 
enum  scg_system_clock_mode_t {
  SCG_SYSTEM_CLOCK_MODE_CURRENT = 0U, SCG_SYSTEM_CLOCK_MODE_RUN = 1U, SCG_SYSTEM_CLOCK_MODE_VLPR = 2U, SCG_SYSTEM_CLOCK_MODE_HSRUN = 3U,
  SCG_SYSTEM_CLOCK_MODE_NONE
}
 SCG system clock modes. Implements scg_system_clock_mode_t_Class. More...
 

Functions

static status_t CLOCK_SYS_GetScgClockFreq (clock_names_t clockName, uint32_t *frequency)
 
static status_t CLOCK_SYS_GetSimClockFreq (clock_names_t clockName, uint32_t *frequency)
 
static status_t CLOCK_SYS_GetPccClockFreq (clock_names_t clockName, uint32_t *frequency)
 
static uint32_t CLOCK_SYS_GetPeripheralClock (clock_names_t clockName, scg_async_clock_type_t divider)
 
static scg_system_clock_mode_t CLOCK_SYS_GetCurrentRunMode (void)
 
static status_t CLOCK_SYS_TransitionSystemClock (const scg_system_clock_config_t *to_clk)
 
static uint32_t CLOCK_SYS_GetSimClkOutFreq (void)
 
static uint32_t CLOCK_SYS_GetScgClkOutFreq (void)
 
static uint32_t CLOCK_SYS_GetSimRtcClkFreq (void)
 
static status_t CLOCK_SYS_ConfigureTemporarySystemClock (void)
 
static status_t CLOCK_SYS_ConfigureModulesFromScg (const scg_config_t *scgConfig)
 
static status_t CLOCK_SYS_ConfigureSIRC (bool enable, const scg_sirc_config_t *sircConfig)
 
static status_t CLOCK_SYS_ConfigureFIRC (bool enable, const scg_firc_config_t *fircConfig)
 
static status_t CLOCK_SYS_ConfigureSOSC (bool enable, const scg_sosc_config_t *soscConfig)
 
static status_t CLOCK_SYS_ConfigureSPLL (bool enable, const scg_spll_config_t *spllConfig)
 
static uint32_t CLOCK_SYS_GetSystemClockFreq (scg_system_clock_type_t type)
 
static status_t CLOCK_SYS_SetSystemClockConfig (scg_system_clock_mode_t mode, scg_system_clock_config_t const *config)
 
static uint32_t CLOCK_SYS_GetSysAsyncFreq (clock_names_t clockSource, scg_async_clock_type_t type)
 
static uint32_t CLOCK_SYS_GetSircFreq (void)
 
static uint32_t CLOCK_SYS_GetFircFreq (void)
 
static uint32_t CLOCK_SYS_GetSysOscFreq (void)
 
static uint32_t CLOCK_SYS_GetSysPllFreq (void)
 
static uint32_t CLOCK_SYS_GetLpoFreq (void)
 
static status_t CLOCK_SYS_TransitionToTmpSysClk (scg_system_clock_src_t currentSysClkSrc)
 
static void CLOCK_SYS_GetCurrentSysClkConfig (scg_system_clock_config_t *sysClockConfig)
 
status_t CLOCK_SYS_SetConfiguration (clock_manager_user_config_t const *config)
 Set system clock configuration. More...
 
status_t CLOCK_SYS_SetScgConfiguration (const scg_config_t *scgConfig)
 Configures SCG module. More...
 
void CLOCK_SYS_SetPccConfiguration (const pcc_config_t *peripheralClockConfig)
 Configures PCC module. More...
 
void CLOCK_SYS_SetSimConfiguration (const sim_clock_config_t *simClockConfig)
 Configures SIM module. More...
 
void CLOCK_SYS_SetPmcConfiguration (const pmc_config_t *pmcConfig)
 Configures PMC module. More...
 
status_t CLOCK_SYS_GetFreq (clock_names_t clockName, uint32_t *frequency)
 Gets the clock frequency for a specific clock name. More...
 
void CLOCK_DRV_EnablePeripheralClock (clock_names_t clockName, const periph_clk_config_t *periphClkConfig)
 Enables peripheral clock. More...
 
void CLOCK_DRV_DisablePeripheralClock (clock_names_t clockName)
 Disables peripheral clock. More...
 
status_t CLOCK_DRV_SetSystemClock (const pwr_modes_t *mode, const sys_clk_config_t *sysClkConfig)
 Configures the system clocks. More...
 
status_t CLOCK_DRV_SetSirc (bool enable, const sirc_config_t *sircConfig)
 This function enables or disables SIRC clock source. More...
 
status_t CLOCK_DRV_SetFirc (bool enable, const firc_config_t *fircConfig)
 This function enables or disables FIRC clock source. More...
 
status_t CLOCK_DRV_SetSosc (bool enable, const sosc_config_t *soscConfig)
 This function enables or disables SOSC clock source. More...
 
status_t CLOCK_DRV_SetSpll (bool enable, const spll_config_t *spllConfig)
 This function enables or disables SPLL clock source. More...
 
status_t CLOCK_DRV_SetLpo (bool enable)
 This function enables or disables LPO clock source. More...
 

Variables

uint32_t g_TClkFreq [NUMBER_OF_TCLK_INPUTS]
 
uint32_t g_RtcClkInFreq
 
uint32_t g_xtal0ClkFreq
 
const uint16_t clockNameMappings [] = PCC_CLOCK_NAME_MAPPINGS
 Clock name mappings Constant array storing the mappings between clock names and peripheral clock control indexes. If there is no peripheral clock control index for a clock name, then the corresponding value is PCC_INVALID_INDEX. More...
 
const uint8_t peripheralFeaturesList [] = PERIPHERAL_FEATURES
 Peripheral features list Constant array storing the mappings between clock names of the peripherals and feature lists. More...
 

Macro Definition Documentation

#define HIGH_SPEED_RUNNING_MODE   (1UL << 7U)

Definition at line 117 of file clock_S32K1xx.c.

#define LPO_128K_FREQUENCY   128000UL

Definition at line 102 of file clock_S32K1xx.c.

#define LPO_1K_FREQUENCY   1000UL

Definition at line 112 of file clock_S32K1xx.c.

#define LPO_32K_FREQUENCY   32000UL

Definition at line 107 of file clock_S32K1xx.c.

#define RUN_SPEED_RUNNING_MODE   (1UL << 0U)

Definition at line 118 of file clock_S32K1xx.c.

#define SCG_SPLL_MULT_BASE   16U

Definition at line 79 of file clock_S32K1xx.c.

#define SCG_SPLL_PREDIV_BASE   1U

Definition at line 85 of file clock_S32K1xx.c.

#define SCG_SPLL_REF_MAX   32000000U

Definition at line 97 of file clock_S32K1xx.c.

#define SCG_SPLL_REF_MIN   8000000U

Definition at line 91 of file clock_S32K1xx.c.

#define VLPR_SPEED_RUNNING_MODE   (1UL << 2U)

Definition at line 119 of file clock_S32K1xx.c.

Enumeration Type Documentation

SCG asynchronous clock type. Implements scg_async_clock_type_t_Class.

Enumerator
SCG_ASYNC_CLOCK_DIV1 

Clock divider 1

SCG_ASYNC_CLOCK_DIV2 

Clock divider 2

SCG_ASYNC_CLOCK_MAX 

Max value.

Definition at line 149 of file clock_S32K1xx.c.

SCG system clock modes. Implements scg_system_clock_mode_t_Class.

Enumerator
SCG_SYSTEM_CLOCK_MODE_CURRENT 

Current mode.

SCG_SYSTEM_CLOCK_MODE_RUN 

Run mode.

SCG_SYSTEM_CLOCK_MODE_VLPR 

Very Low Power Run mode.

SCG_SYSTEM_CLOCK_MODE_HSRUN 

High Speed Run mode.

SCG_SYSTEM_CLOCK_MODE_NONE 

MAX value.

Definition at line 160 of file clock_S32K1xx.c.

SCG system clock type. Implements scg_system_clock_type_t_Class.

Enumerator
SCG_SYSTEM_CLOCK_CORE 

Core clock.

SCG_SYSTEM_CLOCK_BUS 

BUS clock.

SCG_SYSTEM_CLOCK_SLOW 

System slow clock.

SCG_SYSTEM_CLOCK_MAX 

Max value.

Definition at line 137 of file clock_S32K1xx.c.

Function Documentation

void CLOCK_DRV_DisablePeripheralClock ( clock_names_t  clockName)

Disables peripheral clock.

This function disables a peripheral clock.

Parameters
[in]clockNameClock name of the configured peripheral clock

Definition at line 2124 of file clock_S32K1xx.c.

void CLOCK_DRV_EnablePeripheralClock ( clock_names_t  clockName,
const periph_clk_config_t periphClkConfig 
)

Enables peripheral clock.

This function enables a peripheral clock according to the configuration. If no configuration is provided (periphClkConfig is null), then a default one is used

Parameters
[in]clockNameClock name of the configured peripheral clock
[in]periphClkConfigPointer to the configuration structure.

Definition at line 2045 of file clock_S32K1xx.c.

status_t CLOCK_DRV_SetFirc ( bool  enable,
const firc_config_t fircConfig 
)

This function enables or disables FIRC clock source.

When FIRC is enabled, the clock source is configured based on the provided configuration. All values from the previous configuration of FIRC clock are overwritten. If no configuration is provided, then a default one is used. When FIRC is disabled, no configuration is required.

Parameters
[in]enableEnables or disables the clock source.
[in]fircConfigPointer to the configuration structure, this parameter is unused when FIRC is disabled and is optional when FIRC is enabled.
Returns
Status of module initialization

Definition at line 2372 of file clock_S32K1xx.c.

status_t CLOCK_DRV_SetLpo ( bool  enable)

This function enables or disables LPO clock source.

Parameters
[in]enabledEnable command.
Returns
Status of module initialization

Definition at line 2627 of file clock_S32K1xx.c.

status_t CLOCK_DRV_SetSirc ( bool  enable,
const sirc_config_t sircConfig 
)

This function enables or disables SIRC clock source.

When SIRC is enabled, the clock source is configured based on the provided configuration. All values from the previous configuration of SIRC clock are overwritten. If no configuration is provided, then a default one is used. When SIRC is disabled, no configuration is required.

Parameters
[in]enableEnables or disables the clock source.
[in]sircConfigPointer to the configuration structure, this parameter is unused when SIRC is disabled and is optional when SIRC is enabled.
Returns
Status of module initialization

Definition at line 2286 of file clock_S32K1xx.c.

status_t CLOCK_DRV_SetSosc ( bool  enable,
const sosc_config_t soscConfig 
)

This function enables or disables SOSC clock source.

When SOSC is enabled, the clock source is configured based on the provided configuration. All values from the previous configuration of SOSC clock are overwritten. If no configuration is provided, then a default one is used. When SOSC is disabled, no configuration is required.

Parameters
[in]enableEnables or disables the clock source.
[in]soscConfigPointer to the configuration structure, this parameter is unused when SOSC is disabled and is optional when SOSC is enabled.
Returns
Status of module initialization

Definition at line 2459 of file clock_S32K1xx.c.

status_t CLOCK_DRV_SetSpll ( bool  enable,
const spll_config_t spllConfig 
)

This function enables or disables SPLL clock source.

When SPLL is enabled, the clock source is configured based on the provided configuration. All values from the previous configuration of SPLL clock are overwritten. If no configuration is provided, then a default one is used. When SPLL is disabled, no configuration is required.

Parameters
[in]enableEnables or disables the clock source.
[in]spllConfigPointer to the configuration structure, this parameter is unused when SPLL is disabled and is optional when SPLL is enabled.
Returns
Status of module initialization

Definition at line 2551 of file clock_S32K1xx.c.

status_t CLOCK_DRV_SetSystemClock ( const pwr_modes_t mode,
const sys_clk_config_t sysClkConfig 
)

Configures the system clocks.

This function configures the system clocks (core, bus and flash clocks) in the specified power mode. If no power mode is specified (null parameter) then it is the current power mode.

Parameters
[in]modePointer to power mode for which the configured system clocks apply
[in]sysClkConfigPointer to the system clocks configuration structure.

Definition at line 2171 of file clock_S32K1xx.c.

static status_t CLOCK_SYS_ConfigureFIRC ( bool  enable,
const scg_firc_config_t fircConfig 
)
static

Definition at line 1149 of file clock_S32K1xx.c.

static status_t CLOCK_SYS_ConfigureModulesFromScg ( const scg_config_t scgConfig)
static

Definition at line 1465 of file clock_S32K1xx.c.

static status_t CLOCK_SYS_ConfigureSIRC ( bool  enable,
const scg_sirc_config_t sircConfig 
)
static

Definition at line 1076 of file clock_S32K1xx.c.

static status_t CLOCK_SYS_ConfigureSOSC ( bool  enable,
const scg_sosc_config_t soscConfig 
)
static

Definition at line 1223 of file clock_S32K1xx.c.

static status_t CLOCK_SYS_ConfigureSPLL ( bool  enable,
const scg_spll_config_t spllConfig 
)
static

Definition at line 1325 of file clock_S32K1xx.c.

static status_t CLOCK_SYS_ConfigureTemporarySystemClock ( void  )
static

Definition at line 1428 of file clock_S32K1xx.c.

static scg_system_clock_mode_t CLOCK_SYS_GetCurrentRunMode ( void  )
static

Definition at line 876 of file clock_S32K1xx.c.

static void CLOCK_SYS_GetCurrentSysClkConfig ( scg_system_clock_config_t sysClockConfig)
static

Definition at line 2018 of file clock_S32K1xx.c.

static uint32_t CLOCK_SYS_GetFircFreq ( void  )
static

Definition at line 1877 of file clock_S32K1xx.c.

static uint32_t CLOCK_SYS_GetLpoFreq ( void  )
static

Definition at line 1931 of file clock_S32K1xx.c.

static status_t CLOCK_SYS_GetPccClockFreq ( clock_names_t  clockName,
uint32_t *  frequency 
)
static

Definition at line 709 of file clock_S32K1xx.c.

static uint32_t CLOCK_SYS_GetPeripheralClock ( clock_names_t  clockName,
scg_async_clock_type_t  divider 
)
static

Definition at line 831 of file clock_S32K1xx.c.

static uint32_t CLOCK_SYS_GetScgClkOutFreq ( void  )
static

Definition at line 1010 of file clock_S32K1xx.c.

static status_t CLOCK_SYS_GetScgClockFreq ( clock_names_t  clockName,
uint32_t *  frequency 
)
static

Definition at line 451 of file clock_S32K1xx.c.

static uint32_t CLOCK_SYS_GetSimClkOutFreq ( void  )
static

Definition at line 956 of file clock_S32K1xx.c.

static status_t CLOCK_SYS_GetSimClockFreq ( clock_names_t  clockName,
uint32_t *  frequency 
)
static

Definition at line 535 of file clock_S32K1xx.c.

static uint32_t CLOCK_SYS_GetSimRtcClkFreq ( void  )
static

Definition at line 1044 of file clock_S32K1xx.c.

static uint32_t CLOCK_SYS_GetSircFreq ( void  )
static

Definition at line 1857 of file clock_S32K1xx.c.

static uint32_t CLOCK_SYS_GetSysAsyncFreq ( clock_names_t  clockSource,
scg_async_clock_type_t  type 
)
static

Definition at line 1731 of file clock_S32K1xx.c.

static uint32_t CLOCK_SYS_GetSysOscFreq ( void  )
static

Definition at line 1838 of file clock_S32K1xx.c.

static uint32_t CLOCK_SYS_GetSysPllFreq ( void  )
static

Definition at line 1901 of file clock_S32K1xx.c.

static uint32_t CLOCK_SYS_GetSystemClockFreq ( scg_system_clock_type_t  type)
static

Definition at line 1590 of file clock_S32K1xx.c.

void CLOCK_SYS_SetPccConfiguration ( const pcc_config_t peripheralClockConfig)

Configures PCC module.

This function configures the PCC module according to the configuration.

Parameters
[in]peripheralClockConfigPointer to the configuration structure.

Definition at line 334 of file clock_S32K1xx.c.

void CLOCK_SYS_SetPmcConfiguration ( const pmc_config_t pmcConfig)

Configures PMC module.

This function configures the PMC module according to the configuration.

Parameters
[in]pmcConfigPointer to the configuration structure.

Definition at line 430 of file clock_S32K1xx.c.

status_t CLOCK_SYS_SetScgConfiguration ( const scg_config_t scgConfig)

Configures SCG module.

This function configures the SCG module according to the configuration.

Parameters
[in]scgConfigPointer to the configuration structure.
Returns
Status of module initialization

Definition at line 274 of file clock_S32K1xx.c.

void CLOCK_SYS_SetSimConfiguration ( const sim_clock_config_t simClockConfig)

Configures SIM module.

This function configures the SIM module according to the configuration.

Parameters
[in]simClockConfigPointer to the configuration structure.

Definition at line 365 of file clock_S32K1xx.c.

static status_t CLOCK_SYS_SetSystemClockConfig ( scg_system_clock_mode_t  mode,
scg_system_clock_config_t const *  config 
)
static

< Run mode.

< Very Low Power Run mode.

< High Speed Run mode.

< Run mode.

< Very Low Power Run mode.

< High Speed Run mode.

Definition at line 1641 of file clock_S32K1xx.c.

static status_t CLOCK_SYS_TransitionSystemClock ( const scg_system_clock_config_t to_clk)
static

Definition at line 909 of file clock_S32K1xx.c.

static status_t CLOCK_SYS_TransitionToTmpSysClk ( scg_system_clock_src_t  currentSysClkSrc)
static

Definition at line 1962 of file clock_S32K1xx.c.

Variable Documentation

const uint16_t clockNameMappings[] = PCC_CLOCK_NAME_MAPPINGS

Clock name mappings Constant array storing the mappings between clock names and peripheral clock control indexes. If there is no peripheral clock control index for a clock name, then the corresponding value is PCC_INVALID_INDEX.

Definition at line 126 of file clock_S32K1xx.c.