PDL for FM4  Version1.2
Peripheral Driverl Library for FM4
clk.h File Reference
#include "pdl.h"
Include dependency graph for clk.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  stc_clk_intern_data
 Datatype for holding internal data needed for CLK. More...
 
struct  stc_clk_main_config
 Main/PLL Clock configuration. More...
 
struct  stc_clk_sub_config
 Sub Clock configuration. More...
 
struct  stc_clk_vbat_config
 Clock VBAT configuration. More...
 

Macros

#define CLK_SUBCLK_TRANSITION_TIMEOUT   100000000u
 
#define PLLK_MAX   4u
 
#define PLLN_MAX   40u
 
#define PLLM_MAX   4u
 
#define BSC_PSR_MAX   0x06u
 
#define APBC0_PSR_MAX   0x03u
 
#define APBC1_PSR_MAX   0x03u
 
#define APBC2_PSR_MAX   0x03u
 
#define CSW_TMR_SOWT_MAX   0x0Bu
 
#define CSW_TMR_MOWT_MAX   0x0Fu
 
#define PSW_TMR_POWT_MAX   0x07u
 
#define PLL_CTL1_PLLK_MAX   ((uint8_t)PLLK_MAX)
 
#define PLL_CTL1_PLLM_MAX   ((uint8_t)PLLM_MAX)
 
#define PLL_CTL2_PLLN_MAX   ((uint8_t)PLLN_MAX)
 
#define CLK_SCB_SCR   *(volatile uint32_t*) 0xE000ED10ul
 
#define CLK_SCB_SCR_SLEEPDEEP_Position   2u
 
#define CLK_SCB_SCR_SLEEPDEEP_Mask   (1ul << CLK_SCB_SCR_SLEEPDEEP_Position)
 
#define FM4_PMD_CTL   *(volatile uint8_t*) 0x40035800ul
 
#define FM4_STB_CTL_DSTM_BITPOS   0x00000004ul
 
#define FM4_PSW_TMR_PINC_BITPOS   0x10u
 
#define FM4_INT_ENR_PCSE_BITPOS   0x04u
 
#define FM4_INT_ENR_SCSE_BITPOS   0x02u
 
#define FM4_INT_ENR_MCSE_BITPOS   0x01u
 
#define FM4_INT_STR_PCSI_BITPOS   0x04u
 
#define FM4_INT_STR_SCSI_BITPOS   0x02u
 
#define FM4_INT_STR_MCSI_BITPOS   0x01u
 
#define FM4_INT_CLR_PCSC_BITPOS   0x04u
 
#define FM4_INT_CLR_SCSC_BITPOS   0x02u
 
#define FM4_INT_CLR_MCSC_BITPOS   0x01u
 

Typedefs

typedef enum en_clk_source en_clk_source_t
 Clock Source. More...
 
typedef enum en_clk_mode en_clk_mode_t
 Clock Mode. More...
 
typedef enum en_clk_baseclkdiv en_clk_baseclkdiv_t
 Base Clock Prescaler Settings. More...
 
typedef enum en_clk_apb0div en_clk_apb0div_t
 APB0 Prescaler Settings. More...
 
typedef enum en_clk_apb1div en_clk_apb1div_t
 APB1 Prescaler Settings. More...
 
typedef enum en_clk_apb2div en_clk_apb2div_t
 APB2 Prescaler Settings. More...
 
typedef enum en_clk_scowaittime en_clk_scowaittime_t
 Sub Clock oscillation stablilization wait time. More...
 
typedef enum en_clk_mcowaittime en_clk_mcowaittime_t
 Main Clock oscillation stablilization wait time. More...
 
typedef enum en_clk_pllowaittime en_clk_pllowaittime_t
 PLL Clock oscillation stablilization wait time. More...
 
typedef enum en_clk_pll_src en_clk_pll_src_t
 PLL SourceClock (PINC bit of PSW_TMR) More...
 
typedef struct stc_clk_intern_data stc_clk_intern_data_t
 Datatype for holding internal data needed for CLK. More...
 
typedef enum en_clk_current en_clk_current_t
 Sustain and Boost Current. More...
 
typedef enum en_clk_boost_time en_clk_boost_time_t
 Sustain and Boost Time. More...
 
typedef enum en_clk_vbat_pins en_clk_vbat_pins_t
 VBAT pin usage. More...
 
typedef enum en_clk_vbat_pins_ddr en_clk_vbat_pins_ddr_t
 VBAT pin direction and default values. More...
 
typedef enum en_clk_gate_peripheral en_clk_gate_peripheral_t
 Clock Gate peripheral enumerators. More...
 
typedef enum
en_clk_reset_peripheral 
en_clk_reset_peripheral_t
 Reset peripheral enumerators. More...
 
typedef struct stc_clk_main_config stc_clk_main_config_t
 Main/PLL Clock configuration. More...
 
typedef struct stc_clk_sub_config stc_clk_sub_config_t
 Sub Clock configuration. More...
 
typedef struct stc_clk_vbat_config stc_clk_vbat_config_t
 Clock VBAT configuration. More...
 

Enumerations

enum  en_clk_source {
  ClkMain = 0,
  ClkSub = 1,
  ClkHsCr = 2,
  ClkLsCr = 3,
  ClkPll = 4,
  ClkHsCrPll = 5
}
 Clock Source. More...
 
enum  en_clk_mode {
  ClkRun = 0,
  ClkSleep = 1,
  ClkTimer = 2,
  ClkStop = 3,
  ClkRtc = 4,
  ClkDeepRtc = 5,
  ClkDeepStop = 6
}
 Clock Mode. More...
 
enum  en_clk_baseclkdiv {
  BaseClkDiv1 = 0,
  BaseClkDiv2 = 1,
  BaseClkDiv3 = 2,
  BaseClkDiv4 = 3,
  BaseClkDiv6 = 4,
  BaseClkDiv8 = 5,
  BaseClkDiv16 = 6,
  BaseClkErr = 7
}
 Base Clock Prescaler Settings. More...
 
enum  en_clk_apb0div {
  Apb0Div1 = 0,
  Apb0Div2 = 1,
  Apb0Div4 = 2,
  Apb0Div8 = 3
}
 APB0 Prescaler Settings. More...
 
enum  en_clk_apb1div {
  Apb1Div1 = 0,
  Apb1Div2 = 1,
  Apb1Div4 = 2,
  Apb1Div8 = 3
}
 APB1 Prescaler Settings. More...
 
enum  en_clk_apb2div {
  Apb2Div1 = 0,
  Apb2Div2 = 1,
  Apb2Div4 = 2,
  Apb2Div8 = 3
}
 APB2 Prescaler Settings. More...
 
enum  en_clk_scowaittime {
  ScoWaitExp10 = 0,
  ScoWaitExp11 = 1,
  ScoWaitExp12 = 2,
  ScoWaitExp13 = 3,
  ScoWaitExp14 = 4,
  ScoWaitExp15 = 5,
  ScoWaitExp16 = 6,
  ScoWaitExp17 = 7,
  ScoWaitExp18 = 8,
  ScoWaitExp19 = 9,
  ScoWaitExp20 = 10,
  ScoWaitExp21 = 11,
  ScoWaitErr = 12
}
 Sub Clock oscillation stablilization wait time. More...
 
enum  en_clk_mcowaittime {
  McoWaitExp11 = 0,
  McoWaitExp15 = 1,
  McoWaitExp16 = 2,
  McoWaitExp17 = 3,
  McoWaitExp18 = 4,
  McoWaitExp19 = 5,
  McoWaitExp110 = 6,
  McoWaitExp111 = 7,
  McoWaitExp112 = 8,
  McoWaitExp113 = 9,
  McoWaitExp114 = 10,
  McoWaitExp115 = 11,
  McoWaitExp117 = 12,
  McoWaitExp119 = 13,
  McoWaitExp121 = 14,
  McoWaitExp123 = 15
}
 Main Clock oscillation stablilization wait time. More...
 
enum  en_clk_pllowaittime {
  PlloWaitExp19 = 0,
  PlloWaitExp110 = 1,
  PlloWaitExp111 = 2,
  PlloWaitExp112 = 3,
  PlloWaitExp113 = 4,
  PlloWaitExp114 = 5,
  PlloWaitExp115 = 6,
  PlloWaitExp116 = 7
}
 PLL Clock oscillation stablilization wait time. More...
 
enum  en_clk_pll_src {
  PllSrcClkMo = 0,
  PllSrcClkHc = 123
}
 PLL SourceClock (PINC bit of PSW_TMR) More...
 
enum  en_clk_current {
  Clk0nA = 0,
  Clk135nA = 1,
  Clk195nA = 2,
  Clk385nA = 3,
  Clk445nA = 4,
  Clk510nA = 5,
  ClkErrorCurrent = 6
}
 Sustain and Boost Current. More...
 
enum  en_clk_boost_time {
  ClkBoost50ms = 0,
  ClkBoost63ms = 1,
  ClkBoost125ms = 2,
  ClkBoost250ms = 3
}
 Sustain and Boost Time. More...
 
enum  en_clk_vbat_pins {
  ClkVbatGpio = 0,
  ClkVbatOsc = 1,
  ClkVbatGpioOsc = 2
}
 VBAT pin usage. More...
 
enum  en_clk_vbat_pins_ddr {
  ClkVbatInput = 0,
  ClkVbatOutputL = 1,
  ClkVbatOutputH = 2
}
 VBAT pin direction and default values. More...
 
enum  en_clk_gate_peripheral {
  ClkGateGpio = 0,
  ClkGateExtif = 1,
  ClkGateDma = 2,
  ClkGateAdc0 = 3,
  ClkGateAdc1 = 4,
  ClkGateAdc2 = 5,
  ClkGateAdc3 = 6,
  ClkGateMfs0 = 7,
  ClkGateMfs1 = 8,
  ClkGateMfs2 = 9,
  ClkGateMfs3 = 10,
  ClkGateMfs4 = 11,
  ClkGateMfs5 = 12,
  ClkGateMfs6 = 13,
  ClkGateMfs7 = 14,
  ClkGateMfs8 = 15,
  ClkGateMfs9 = 16,
  ClkGateMfs10 = 17,
  ClkGateMfs11 = 18,
  ClkGateMfs12 = 19,
  ClkGateMfs13 = 20,
  ClkGateMfs14 = 21,
  ClkGateMfs15 = 22,
  ClkGateQprc0 = 23,
  ClkGateQprc1 = 24,
  ClkGateQprc2 = 25,
  ClkGateQprc3 = 26,
  ClkGateMft0 = 27,
  ClkGateMft1 = 28,
  ClkGateMft2 = 29,
  ClkGateMft3 = 30,
  ClkGateBt0 = 31,
  ClkGateBt4 = 32,
  ClkGateBt8 = 33,
  ClkGateBt12 = 34,
  ClkGateSdIf = 35,
  ClkGateCan0 = 36,
  ClkGateCan1 = 37,
  ClkGateUsb0 = 38,
  ClkGateUsb1 = 39
}
 Clock Gate peripheral enumerators. More...
 
enum  en_clk_reset_peripheral {
  ClkResetExtif = 1,
  ClkResetDma = 2,
  ClkResetAdc0 = 3,
  ClkResetAdc1 = 4,
  ClkResetAdc2 = 5,
  ClkResetAdc3 = 6,
  ClkResetMfs0 = 7,
  ClkResetMfs1 = 8,
  ClkResetMfs2 = 9,
  ClkResetMfs3 = 10,
  ClkResetMfs4 = 11,
  ClkResetMfs5 = 12,
  ClkResetMfs6 = 13,
  ClkResetMfs7 = 14,
  ClkResetMfs8 = 15,
  ClkResetMfs9 = 16,
  ClkResetMfs10 = 17,
  ClkResetMfs11 = 18,
  ClkResetMfs12 = 19,
  ClkResetMfs13 = 20,
  ClkResetMfs14 = 21,
  ClkResetMfs15 = 22,
  ClkResetQprc0 = 23,
  ClkResetQprc1 = 24,
  ClkResetQprc2 = 25,
  ClkResetQprc3 = 26,
  ClkResetMft0 = 27,
  ClkResetMft1 = 28,
  ClkResetMft2 = 29,
  ClkResetMft3 = 30,
  ClkResetBt0 = 31,
  ClkResetBt4 = 32,
  ClkResetBt8 = 33,
  ClkResetBt12 = 34,
  ClkResetSdIf = 35,
  ClkResetCan0 = 36,
  ClkResetCan1 = 37,
  ClkResetUsb0 = 38,
  ClkResetUsb1 = 39
}
 Reset peripheral enumerators. More...
 

Functions

void ClkIrqHandler (void)
 Clock Stabilization Interrupt Handler. More...
 
en_result_t Clk_MainGetParameters (stc_clk_main_config_t *pstcConfig)
 Get current Main/PLL Clock parameters. More...
 
en_result_t Clk_SubGetParameters (stc_clk_sub_config_t *pstcConfig)
 Get current Sub Clock parameters. More...
 
en_result_t Clk_VbatGetParameters (stc_clk_vbat_config_t *pstcConfig)
 Get current VBAT parameters. More...
 
en_result_t Clk_SetDividers (stc_clk_main_config_t *pstcConfig)
 Set Clock Dividers. More...
 
en_result_t Clk_MainSetStabilizationWaitTime (stc_clk_main_config_t *pstcConfig)
 Set Main Oscillation Stabilization Wait Time. More...
 
en_result_t Clk_SubSetStabilizationWaitTime (stc_clk_sub_config_t *pstcConfig)
 Set Sub Oscillation Stabilization Wait Time. More...
 
en_result_t Clk_WaitForMainOscillator (uint32_t u32MaxTimeOut)
 Wait for Main Oscillation Stabilization. More...
 
en_result_t Clk_WaitForSubOscillator (uint32_t u32MaxTimeOut)
 Wait for Sub Oscillation Stabilization. More...
 
en_result_t Clk_WaitForPllOscillator (uint32_t u32MaxTimeOut)
 Wait for PLL Oscillation Stabilization. More...
 
en_result_t Clk_MainOscillatorReady (void)
 Main Oscillation Ready? More...
 
en_result_t Clk_SubOscillatorReady (void)
 Sub Oscillation Ready? More...
 
en_result_t Clk_PllOscillatorReady (void)
 PLL Oscillation Ready? More...
 
en_result_t Clk_SetSource (stc_clk_main_config_t *pstcConfigMain, stc_clk_sub_config_t *pstcConfigSub)
 Set Clock Source. More...
 
en_result_t Clk_SetPllSource (stc_clk_main_config_t *pstcConfig)
 
en_result_t Clk_SetMode (stc_clk_main_config_t *pstcConfig)
 Set Clock Mode. More...
 
en_result_t Clk_EnableMainClock (void)
 Enable Main Clock. More...
 
en_result_t Clk_EnablePllClock (stc_clk_main_config_t *pstcConfigMain)
 Enable PLL Clock with parameter. More...
 
en_result_t Clk_EnableSubClock (void)
 Enable Sub Clock. More...
 
en_result_t Clk_DisableMainClock (void)
 Disable Main Clock. More...
 
en_result_t Clk_DisablePllClock (void)
 Disable PLL Clock. More...
 
en_result_t Clk_DisableSubClock (void)
 Disable Sub Clock. More...
 
en_result_t Clk_WaitForClockSourceReady (en_clk_source_t enSource, uint32_t u32MaxTimeOut)
 Wait for Clock Mode ready (transition finished) More...
 
en_result_t Clk_SetIrq (stc_clk_main_config_t *pstcConfigMain, stc_clk_sub_config_t *pstcConfigSub, boolean_t bTouchNvic)
 Set/Clear Clock interrupts. More...
 
en_result_t Clk_ClockVbatInit (stc_clk_vbat_config_t *pstcConfig)
 Init Sub Clock with VBAT settings. More...
 
en_result_t Clk_RequestVccPowerDown (void)
 Request VCC Power-Down. More...
 
en_result_t Clk_PeripheralClockEnable (en_clk_gate_peripheral_t enPeripheral)
 Enables the clock gate of a peripheral. More...
 
boolean_t Clk_PeripheralGetClockState (en_clk_gate_peripheral_t enPeripheral)
 Read the clock gate state of a peripheral. More...
 
en_result_t Clk_PeripheralClockDisable (en_clk_gate_peripheral_t enPeripheral)
 Disables the clock gate of a peripheral. More...
 
en_result_t Clk_PeripheralSetReset (en_clk_reset_peripheral_t enPeripheral)
 Set reset bit a peripheral. More...
 
en_result_t Clk_PeripheralClearReset (en_clk_reset_peripheral_t enPeripheral)
 Clear reset bit a peripheral. More...
 
en_result_t Clk_SwitchToMainClock (void)
 Switch to Main Clock. More...
 
en_result_t Clk_SwitchToMainPllClock (void)
 Switch to Main PLL Clock. More...
 
en_result_t Clk_SwitchToSubClock (void)
 Switch to Sub Clock. More...
 
en_result_t Clk_SwitchToLsCrClock (void)
 Switch to Low Speed CR Clock. More...
 
en_result_t Clk_SwitchToHsCrClock (void)
 Switch to High Speed CR Clock. More...
 
en_result_t Clk_SwitchToHsCrPllClock (void)
 Switch to High Speed CR PLL Clock. More...
 

Variables

stc_clk_intern_data_t stcClkInternData
 

Detailed Description

Headerfile for CLK functions

History:

  • 2013-04-24 1.0 MWi First version.
  • 2013-07-12 1.1 MWi Clk_SwitchTo* functions added
  • 2013-10-23 1.2 MWi Clk_DisablePllClock and ClkDeepStop mode added

Definition in file clk.h.