rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions | Variables
clock_config.c File Reference

Functions

static void CLOCK_CONFIG_FircSafeConfig (const scg_firc_config_t *fircConfig)
 
static bool ke1xf_clock_is_external (kinetis_clock_type_e ct)
 
static bool ke1xf_clock_is_high_speed (kinetis_clock_type_e ct)
 
static void setClockConfig (kinetis_clock_type_e ct)
 
void ke1xf_clock_init (kinetis_clock_type_e ct)
 This function executes the configuration of clocks.
 
kinetis_clock_type_e ke1xf_clock_get_current_type (void)
 

Variables

static kinetis_clock_type_e clockType = kinetis_clock_default_firc
 
const scg_sys_clk_config_t g_sysClkConfig_BOARD_BootClockRUN_HS
 
const scg_sys_clk_config_t g_sysClkConfig_BOARD_BootClockRUN
 
const scg_sosc_config_t g_scgSysOscConfig_BOARD_BootClockRUN
 
const scg_sirc_config_t g_scgSircConfig_BOARD_BootClockRUN
 
const scg_firc_config_t g_scgFircConfig_EXT_BOARD_BootClockRUN
 
const scg_spll_config_t g_scgSysPllConfig_EXT_BOARD_BootClockRUN
 
const scg_firc_config_t g_scgFircConfig_INT_BOARD_BootClockRUN
 
const scg_spll_config_t g_scgSysPllConfig_INT_BOARD_BootClockRUN
 

Function Documentation

◆ CLOCK_CONFIG_FircSafeConfig()

static void CLOCK_CONFIG_FircSafeConfig ( const scg_firc_config_t fircConfig)
static

Definition at line 103 of file clock_config.c.

103 {
104 scg_sys_clk_config_t curConfig;
105 const scg_sirc_config_t scgSircConfig = {
107 .div1 = kSCG_AsyncClkDisable,
108 .div2 = kSCG_AsyncClkDivBy2,
109 .range = kSCG_SircRangeHigh
110 };
111 scg_sys_clk_config_t sysClkSafeConfigSource = {
112 .divSlow = kSCG_SysClkDivBy4, /* Slow clock divider */
113 .divBus = kSCG_SysClkDivBy1, /* Bus clock divider */
114 .divCore = kSCG_SysClkDivBy1, /* Core clock divider */
115 .src = kSCG_SysClkSrcSirc /* System clock source */
116 };
117 /* Init Sirc. */
118 CLOCK_InitSirc(&scgSircConfig);
119 /* Change to use SIRC as system clock source to prepare to change FIRCCFG register. */
120 CLOCK_SetRunModeSysClkConfig(&sysClkSafeConfigSource);
121 /* Wait for clock source switch finished. */
122 do {
123 CLOCK_GetCurSysClkConfig(&curConfig);
124 } while (curConfig.src != sysClkSafeConfigSource.src);
125
126 /* Init Firc. */
127 CLOCK_InitFirc(fircConfig);
128 /* Change back to use FIRC as system clock source in order to configure SIRC if needed. */
129 sysClkSafeConfigSource.src = kSCG_SysClkSrcFirc;
130 CLOCK_SetRunModeSysClkConfig(&sysClkSafeConfigSource);
131 /* Wait for clock source switch finished. */
132 do {
133 CLOCK_GetCurSysClkConfig(&curConfig);
134 } while (curConfig.src != sysClkSafeConfigSource.src);
135}
static void CLOCK_SetRunModeSysClkConfig(const scg_sys_clk_config_t *config)
Sets the system clock configuration for RUN mode.
Definition fsl_clock.h:795
static void CLOCK_GetCurSysClkConfig(scg_sys_clk_config_t *config)
Gets the system clock configuration in the current power mode.
Definition fsl_clock.h:823
status_t CLOCK_InitSirc(const scg_sirc_config_t *config)
Initializes the SCG slow IRC clock.
Definition fsl_clock.c:558
status_t CLOCK_InitFirc(const scg_firc_config_t *config)
Initializes the SCG fast IRC clock.
Definition fsl_clock.c:690
uint32_t enableMode
Definition fsl_clock.h:493
@ kSCG_AsyncClkDivBy2
Definition fsl_clock.h:420
@ kSCG_AsyncClkDisable
Definition fsl_clock.h:418
@ kSCG_SircRangeHigh
Definition fsl_clock.h:477
@ kSCG_SircEnable
Definition fsl_clock.h:483
@ kSCG_SysClkDivBy4
Definition fsl_clock.h:362
@ kSCG_SysClkDivBy1
Definition fsl_clock.h:359
@ kSCG_SysClkSrcFirc
Definition fsl_clock.h:350
@ kSCG_SysClkSrcSirc
Definition fsl_clock.h:349
SCG slow IRC clock configuration.
Definition fsl_clock.h:492
SCG system clock configuration.
Definition fsl_clock.h:381

Referenced by ke1xf_clock_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ke1xf_clock_get_current_type()

kinetis_clock_type_e ke1xf_clock_get_current_type ( void  )

Definition at line 249 of file clock_config.c.

249 {
250 return clockType;
251}
static kinetis_clock_type_e clockType

Referenced by flashUnlock().

Here is the caller graph for this function:

◆ ke1xf_clock_init()

void ke1xf_clock_init ( kinetis_clock_type_e  ct)

This function executes the configuration of clocks.

Definition at line 168 of file clock_config.c.

168 {
169 // Init External Osc.
170 if (ke1xf_clock_is_external(ct)) {
171 // Init SOSC according to board configuration.
173 // Set the XTAL0 frequency based on board settings.
175 }
176 // Init FIRC.
179 }
180
182 // Set HSRUN power mode.
186 }
187 } else {
188 // If we've already started and want to change the mode, then we have to lower the frequency first:
189 // [RTFM: "Before exiting HSRUN mode, clock frequencies should be reduced back down to those acceptable in RUN mode."]
191 setClockConfig(ct);
192 }
193
196 }
197 }
198
199 // Now the mode is "officially" changed!
200 clockType = ct;
201
202 // Init SIRC.
203 //CLOCK_InitSirc(&g_scgSircConfig_BOARD_BootClockRUN);
204
205 // Init SysPll.
207
208 // Set SCG to SPLL mode.
209 setClockConfig(ct);
210
211 /* Set SystemCoreClock variable. */
212 //SystemCoreClock = KINETIS_PLL_FREQ;
213
214 /* Set PCC ADC0 selection */
216 /* Set PCC ADC1 selection */
218 /* Set PCC ADC2 selection */
220 /* Set PCC LPSPI0 selection */
222 /* Set PCC LPSPI1 selection */
224 /* Set PCC LPUART0 selection */
226 /* Set PCC LPUART1 selection */
228 /* Set PCC LPTMR0 selection */
230 /* Set PCC LPIT0 selection */
232 /* Set PCC FTM0 selection */
234 /* Set PCC FTM1 selection */
236 /* Set PCC FTM2 selection */
238 /* Set PCC FTM3 selection */
240
241#if 0
243 // try to restore the UART if the frequency has been changed
244 LPUART_SetBaudRate(LPUART0, CLOCK_SYS_GetUartFreq(UART0_IDX), KINETIS_UART_FREQUENCY);
245 }
246#endif
247}
const scg_spll_config_t g_scgSysPllConfig_EXT_BOARD_BootClockRUN
const scg_firc_config_t g_scgFircConfig_EXT_BOARD_BootClockRUN
static void setClockConfig(kinetis_clock_type_e ct)
const scg_sosc_config_t g_scgSysOscConfig_BOARD_BootClockRUN
const scg_firc_config_t g_scgFircConfig_INT_BOARD_BootClockRUN
static void CLOCK_CONFIG_FircSafeConfig(const scg_firc_config_t *fircConfig)
static bool ke1xf_clock_is_high_speed(kinetis_clock_type_e ct)
const scg_spll_config_t g_scgSysPllConfig_INT_BOARD_BootClockRUN
static bool ke1xf_clock_is_external(kinetis_clock_type_e ct)
@ kinetis_clock_default_firc
static void CLOCK_SetXtal0Freq(uint32_t freq)
Sets the XTAL0 frequency based on board settings.
Definition fsl_clock.h:1347
static void CLOCK_SetIpSrc(clock_ip_name_t name, clock_ip_src_t src)
Set the clock source for specific IP module.
Definition fsl_clock.h:684
status_t CLOCK_InitSysPll(const scg_spll_config_t *config)
Initializes the SCG system PLL.
Definition fsl_clock.c:984
status_t CLOCK_InitSysOsc(const scg_sosc_config_t *config)
Initializes the SCG system OSC.
Definition fsl_clock.c:397
@ kCLOCK_Lptmr0
Definition fsl_clock.h:293
@ kCLOCK_Adc1
Definition fsl_clock.h:278
@ kCLOCK_Ftm3
Definition fsl_clock.h:277
@ kCLOCK_Adc2
Definition fsl_clock.h:290
@ kCLOCK_Lpuart1
Definition fsl_clock.h:306
@ kCLOCK_Adc0
Definition fsl_clock.h:289
@ kCLOCK_Lpspi1
Definition fsl_clock.h:280
@ kCLOCK_Lpuart0
Definition fsl_clock.h:305
@ kCLOCK_Lpit0
Definition fsl_clock.h:285
@ kCLOCK_Ftm1
Definition fsl_clock.h:287
@ kCLOCK_Lpspi0
Definition fsl_clock.h:279
@ kCLOCK_Ftm2
Definition fsl_clock.h:288
@ kCLOCK_Ftm0
Definition fsl_clock.h:286
@ kCLOCK_IpSrcSysPllAsync
Definition fsl_clock.h:259
status_t LPUART_SetBaudRate(LPUART_Type *base, uint32_t baudRate_Bps, uint32_t srcClock_Hz)
Sets the LPUART instance baudrate.
Definition fsl_lpuart.c:564
static void SMC_SetPowerModeProtection(SMC_Type *base, uint8_t allowedModes)
Configures all power mode protection settings.
Definition fsl_smc.h:260
static smc_power_state_t SMC_GetPowerModeState(SMC_Type *base)
Gets the current power mode status.
Definition fsl_smc.h:279
status_t SMC_SetPowerModeRun(SMC_Type *base)
Configures the system to RUN power mode.
Definition fsl_smc.c:147
status_t SMC_SetPowerModeHsrun(SMC_Type *base)
Configures the system to HSRUN power mode.
Definition fsl_smc.c:167
@ kSMC_AllowPowerModeAll
Definition fsl_smc.h:42
@ kSMC_PowerStateRun
Definition fsl_smc.h:65
@ kSMC_PowerStateHsrun
Definition fsl_smc.h:77

Referenced by __late_init(), flashLock(), and flashUnlock().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ke1xf_clock_is_external()

static bool ke1xf_clock_is_external ( kinetis_clock_type_e  ct)
static

Definition at line 137 of file clock_config.c.

137 {
138 return (ct == kinetis_clock_ext_osc_hs);
139}
@ kinetis_clock_ext_osc_hs

Referenced by ke1xf_clock_init().

Here is the caller graph for this function:

◆ ke1xf_clock_is_high_speed()

static bool ke1xf_clock_is_high_speed ( kinetis_clock_type_e  ct)
static

Definition at line 141 of file clock_config.c.

141 {
143}
@ kinetis_clock_int_osc_hs

Referenced by ke1xf_clock_init(), and setClockConfig().

Here is the caller graph for this function:

◆ setClockConfig()

static void setClockConfig ( kinetis_clock_type_e  ct)
static

Definition at line 145 of file clock_config.c.

145 {
146 scg_sys_clk_config_t curConfig;
147
148 // set a new config
149 const scg_sys_clk_config_t *sysClkConfig = ke1xf_clock_is_high_speed(ct) ?
151
152 // Update config depending on the current speed mode
154 CLOCK_SetHsrunModeSysClkConfig(sysClkConfig);
155 } else {
156 CLOCK_SetRunModeSysClkConfig(sysClkConfig);
157 }
158
159 // Wait for clock source switch finished.
160 do {
161 CLOCK_GetCurSysClkConfig(&curConfig);
162 } while (curConfig.src != sysClkConfig->src);
163}
const scg_sys_clk_config_t g_sysClkConfig_BOARD_BootClockRUN
const scg_sys_clk_config_t g_sysClkConfig_BOARD_BootClockRUN_HS
static void CLOCK_SetHsrunModeSysClkConfig(const scg_sys_clk_config_t *config)
Sets the system clock configuration for HSRUN mode.
Definition fsl_clock.h:809

Referenced by ke1xf_clock_init().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ clockType

Definition at line 26 of file clock_config.c.

Referenced by ke1xf_clock_get_current_type(), ke1xf_clock_init(), and setClockConfig().

◆ g_scgFircConfig_EXT_BOARD_BootClockRUN

const scg_firc_config_t g_scgFircConfig_EXT_BOARD_BootClockRUN
Initial value:
= {
.enableMode = kSCG_FircDisableRegulator,
.range = kSCG_FircRange48M,
.trimConfig = NULL,
}
@ kSCG_FircRange48M
Definition fsl_clock.h:555
@ kSCG_FircDisableRegulator
Definition fsl_clock.h:567

Definition at line 58 of file clock_config.c.

58 {
59 .enableMode = kSCG_FircDisableRegulator, /* Enable FIRC clock */
60 .div1 = kSCG_AsyncClkDisable, /* Fast IRC Clock Divider 1: Clock output is disabled */
61 .div2 = kSCG_AsyncClkDisable, /* Fast IRC Clock Divider 2: Clock output is disabled */
62 .range = kSCG_FircRange48M, /* Fast IRC is trimmed to 48MHz */
63 .trimConfig = NULL, /* Fast IRC Trim disabled */
64};

Referenced by ke1xf_clock_init().

◆ g_scgFircConfig_INT_BOARD_BootClockRUN

const scg_firc_config_t g_scgFircConfig_INT_BOARD_BootClockRUN
Initial value:
= {
.enableMode = kSCG_FircEnable,
.range = kSCG_FircRange48M,
.trimConfig = NULL,
}
@ kSCG_FircEnable
Definition fsl_clock.h:564

Definition at line 75 of file clock_config.c.

75 {
76 .enableMode = kSCG_FircEnable, /* Enable FIRC clock */
77 .div1 = kSCG_AsyncClkDisable, /* Fast IRC Clock Divider 1: Clock output is disabled */
78 .div2 = kSCG_AsyncClkDisable, /* Fast IRC Clock Divider 2: Clock output is disabled */
79 .range = kSCG_FircRange48M, /* Fast IRC is trimmed to 48MHz */
80 .trimConfig = NULL, /* Fast IRC Trim disabled */
81};

Referenced by ke1xf_clock_init().

◆ g_scgSircConfig_BOARD_BootClockRUN

const scg_sirc_config_t g_scgSircConfig_BOARD_BootClockRUN
Initial value:
= {
.range = kSCG_SircRangeHigh,
}
@ kSCG_SircEnableInLowPower
Definition fsl_clock.h:485

Definition at line 52 of file clock_config.c.

52 {
53 .enableMode = kSCG_SircEnableInLowPower,/* Enable SIRC clock, Enable SIRC in low power mode */
54 .div1 = kSCG_AsyncClkDisable, /* Slow IRC Clock Divider 1: Clock output is disabled */
55 .div2 = kSCG_AsyncClkDisable, /* Slow IRC Clock Divider 2: Clock output is disabled */
56 .range = kSCG_SircRangeHigh, /* Slow IRC high range clock (8 MHz) */
57};

◆ g_scgSysOscConfig_BOARD_BootClockRUN

const scg_sosc_config_t g_scgSysOscConfig_BOARD_BootClockRUN
Initial value:
= {
.freq = KINETIS_CLK,
.enableMode = kSCG_SysOscEnable,
.monitorMode = kSCG_SysOscMonitorDisable,
.workMode = kSCG_SysOscModeExt,
}
@ kSCG_SysOscEnable
Definition fsl_clock.h:450
@ kSCG_SysOscMonitorDisable
Definition fsl_clock.h:433
@ kSCG_SysOscModeExt
Definition fsl_clock.h:442

Definition at line 44 of file clock_config.c.

44 {
45 .freq = KINETIS_CLK, /* System Oscillator frequency: 8000000Hz */
46 .enableMode = kSCG_SysOscEnable, /* Enable System OSC clock */
47 .monitorMode = kSCG_SysOscMonitorDisable, /* Monitor disabled */
48 .div1 = kSCG_AsyncClkDisable, /* System OSC Clock Divider 1: Clock output is disabled */
49 .div2 = kSCG_AsyncClkDisable, /* System OSC Clock Divider 2: Clock output is disabled */
50 .workMode = kSCG_SysOscModeExt, /* Use external clock */
51};

Referenced by ke1xf_clock_init().

◆ g_scgSysPllConfig_EXT_BOARD_BootClockRUN

const scg_spll_config_t g_scgSysPllConfig_EXT_BOARD_BootClockRUN
Initial value:
= {
.enableMode = kSCG_SysPllEnable,
.monitorMode = kSCG_SysPllMonitorDisable,
.prediv = KINETIS_EXT_PLL_DIV,
.mult = KINETIS_EXT_PLL_MUL,
}
@ kSCG_AsyncClkDivBy8
Definition fsl_clock.h:422
@ kSCG_AsyncClkDivBy64
Definition fsl_clock.h:425
@ kSCG_SysPllSrcSysOsc
Definition fsl_clock.h:590
@ kSCG_SysPllEnable
Definition fsl_clock.h:608
@ kSCG_SysPllMonitorDisable
Definition fsl_clock.h:599

Definition at line 65 of file clock_config.c.

65 {
66 .enableMode = kSCG_SysPllEnable, /* Enable SPLL clock */
67 .monitorMode = kSCG_SysPllMonitorDisable, /* Monitor disabled */
68 .div1 = kSCG_AsyncClkDivBy64, /* System PLL Clock Divider 1: divided by 64 */
69 .div2 = kSCG_AsyncClkDivBy8, /* System PLL Clock Divider 2: divided by 8 */
70 .src = kSCG_SysPllSrcSysOsc, /* System PLL clock source is System OSC */
71 .prediv = KINETIS_EXT_PLL_DIV, /* 0=Divided by 1 */
72 .mult = KINETIS_EXT_PLL_MUL, /* Multiply Factor */
73};

Referenced by ke1xf_clock_init().

◆ g_scgSysPllConfig_INT_BOARD_BootClockRUN

const scg_spll_config_t g_scgSysPllConfig_INT_BOARD_BootClockRUN
Initial value:
= {
.enableMode = kSCG_SysPllEnable,
.monitorMode = kSCG_SysPllMonitorDisable,
.prediv = KINETIS_INT_PLL_DIV,
.mult = KINETIS_INT_PLL_MUL,
}
@ kSCG_SysPllSrcFirc
Definition fsl_clock.h:591

Definition at line 82 of file clock_config.c.

82 {
83 .enableMode = kSCG_SysPllEnable, /* Enable SPLL clock */
84 .monitorMode = kSCG_SysPllMonitorDisable, /* Monitor disabled */
85 .div1 = kSCG_AsyncClkDivBy64, /* System PLL Clock Divider 1: divided by 64 */
86 .div2 = kSCG_AsyncClkDivBy8, /* System PLL Clock Divider 2: divided by 8 */
87 .src = kSCG_SysPllSrcFirc, /* System PLL clock source is Fast IRC */
88 .prediv = KINETIS_INT_PLL_DIV, /* Divided by Factor */
89 .mult = KINETIS_INT_PLL_MUL, /* Multiply Factor */
90};

Referenced by ke1xf_clock_init().

◆ g_sysClkConfig_BOARD_BootClockRUN

const scg_sys_clk_config_t g_sysClkConfig_BOARD_BootClockRUN
Initial value:
= {
.divSlow = kSCG_SysClkDivBy7,
.divBus = kSCG_SysClkDivBy8,
.divCore = kSCG_SysClkDivBy2,
}
@ kSCG_SysClkDivBy2
Definition fsl_clock.h:360
@ kSCG_SysClkDivBy8
Definition fsl_clock.h:366
@ kSCG_SysClkDivBy7
Definition fsl_clock.h:365
@ kSCG_SysClkSrcSysPll
Definition fsl_clock.h:351

Definition at line 37 of file clock_config.c.

37 {
38 .divSlow = kSCG_SysClkDivBy7, /* Slow Clock Divider: divided by 7 */
39 .divBus = kSCG_SysClkDivBy8, /* Bus Clock Divider: divided by 8 */
40 .divCore = kSCG_SysClkDivBy2, /* Core Clock Divider: divided by 2 */
41 .src = kSCG_SysClkSrcSysPll, /* System PLL is selected as System Clock Source */
42 };

Referenced by setClockConfig().

◆ g_sysClkConfig_BOARD_BootClockRUN_HS

const scg_sys_clk_config_t g_sysClkConfig_BOARD_BootClockRUN_HS
Initial value:
= {
.divSlow = kSCG_SysClkDivBy7,
.divBus = kSCG_SysClkDivBy8,
.divCore = kSCG_SysClkDivBy1,
}

Definition at line 29 of file clock_config.c.

29 {
30 .divSlow = kSCG_SysClkDivBy7, /* Slow Clock Divider: divided by 7 */
31 .divBus = kSCG_SysClkDivBy8, /* Bus Clock Divider: divided by 8 */
32 .divCore = kSCG_SysClkDivBy1, /* Core Clock Divider: divided by 1 */
33 .src = kSCG_SysClkSrcSysPll, /* System PLL is selected as System Clock Source */
34};

Referenced by setClockConfig().

Go to the source code of this file.