30#ifndef LIBOPENCM3_PAC55XX_CCS_H_
31#define LIBOPENCM3_PAC55XX_CCS_H_
43#define CCS_ROSC_FREQ (16000000U)
45#define CCS_CLKREF_FREQ (4000000U)
47#define CCS_EXTCLK_MAX_FREQ (20000000U)
52#define CCSCTL MMIO32(SCC_BASE)
53#define CCS_CTL_FRCLKMUXSEL_MASK (0x03)
54#define CCS_CTL_FRCLKMUXSEL(sel) ((sel) & CCS_CTL_FRCLKMUXSEL_MASK)
55#define CCS_CTL_FRCLKMUXSEL_ROSC (0)
56#define CCS_CTL_FRCLKMUXSEL_CLKREF (1)
57#define CCS_CTL_FRCLKMUXSEL_EXTCLK (3)
58#define CCS_CTL_ROSCEN BIT2
59#define CCS_CTL_SCLKMUXSEL BIT4
60#define CCS_CTL_SCLKMUXSEL_FRCLK (0)
61#define CCS_CTL_SCLKMUXSEL_PLLCLK (1)
62#define CCS_CTL_CLKFAILEN BIT5
63#define CCS_CTL_CLKFAILMUXSEL BIT6
64#define CCS_CTL_CLKFAILIF BIT7
65#define CCS_CTL_LDOEN BIT8
66#define CCS_CTL_SWRESET BIT11
67#define CCS_CTL_PCLKEN BIT12
68#define CCS_CTL_ACLKEN BIT13
69#define CCS_CTL_ADCCLKEN BIT14
70#define CCS_CTL_STCLKSLPEN BIT15
71#define CCS_CTL_PCLKDIV_MASK (0x07)
72#define CCS_CTL_PCLKDIV_SHIFT (16)
74#define CCS_CTL_PCLKDIV(div) (((div-1) & CCS_CTL_PCLKDIV_MASK) << CCS_CTL_PCLKDIV_SHIFT)
75#define CCS_CTL_ACLKDIV_MASK (0x07)
76#define CCS_CTL_ACLKDIV_SHIFT (20)
78#define CCS_CTL_ACLKDIV(div) (((div-1) & CCS_CTL_ACLKDIV_MASK) << CCS_CTL_ACLKDIV_SHIFT)
79#define CCS_CTL_HCLKDIV_MASK (0x07)
80#define CCS_CTL_HCLKDIV_SHIFT (24)
82#define CCS_CTL_HCLKDIV(div) (((div-1) & CCS_CTL_HCLKDIV_MASK) << CCS_CTL_HCLKDIV_SHIFT)
83#define CCS_CTL_USAMODE BIT28
84#define CCS_CTL_USBMODE BIT29
85#define CCS_CTL_USCMODE BIT30
86#define CCS_CTL_USDMODE BIT31
91#define CCSPLLCTL MMIO32(SCC_BASE + 0x04)
93#define CCS_PLLCTL_PLLEN BIT0
95#define CCS_PLLCTL_PLLBP BIT1
96#define CCS_PLLCTL_PLLOUTDIV_MASK (0x03)
97#define CCS_PLLCTL_PLLOUTDIV_SHIFT (2)
99#define CCS_PLLCTL_PLLOUTDIV(div) (((div) & CCS_PLLCTL_PLLOUTDIV_MASK) << CCS_PLLCTL_PLLOUTDIV_SHIFT)
100#define CCS_PLLCTL_PLLOUTDIV1 (0)
101#define CCS_PLLCTL_PLLOUTDIV2 (1)
102#define CCS_PLLCTL_PLLOUTDIV4 (2)
103#define CCS_PLLCTL_PLLOUTDIV8 (3)
104#define CCS_PLLCTL_PLLINDIV_MASK (0x0F)
105#define CCS_PLLCTL_PLLINDIV_SHIFT (4)
107#define CCS_PLLCTL_PLLINDIV(div) (((div) & CCS_PLLCTL_PLLINDIV_MASK) << CCS_PLLCTL_PLLINDIV_SHIFT)
108#define CCS_PLLCTL_PLLFBDIV_MASK (0x3FFF)
109#define CCS_PLLCTL_PLLFBDIV_SHIFT (8)
111#define CCS_PLLCTL_PLLFBDIV(div) (((div) & CCS_PLLCTL_PLLFBDIV_MASK) << CCS_PLLCTL_PLLFBDIV_SHIFT)
113#define CCS_PLLCTL_PLLLOCK BIT24
118#define CCSROSCTRIM_MASK (0x7F)
119#define CCSROSCTRIM MMIO32(SCC_BASE + 0x08)
125#define CCS_PORTA (SCC_BASE + 0x0C)
126#define CCS_PORTB (SCC_BASE + 0x10)
127#define CCS_PORTC (SCC_BASE + 0x14)
128#define CCS_PORTD (SCC_BASE + 0x18)
129#define CCS_PORTE (SCC_BASE + 0x1C)
130#define CCS_PORTF (SCC_BASE + 0x20)
131#define CCS_PORTG (SCC_BASE + 0x24)
137#define CCS_MUXSELR(base) MMIO32(base)
138#define CCS_PAMUXSELR CCS_MUXSELR(CCS_PORTA)
139#define CCS_PBMUXSELR CCS_MUXSELR(CCS_PORTB)
140#define CCS_PCMUXSELR CCS_MUXSELR(CCS_PORTC)
141#define CCS_PDMUXSELR CCS_MUXSELR(CCS_PORTD)
142#define CCS_PEMUXSELR CCS_MUXSELR(CCS_PORTE)
143#define CCS_PFMUXSELR CCS_MUXSELR(CCS_PORTF)
144#define CCS_PGMUXSELR CCS_MUXSELR(CCS_PORTG)
145#define CCS_MUXSELR_MASK 0x7
146#define CCS_MUXSELR_MASK_PIN(pin) (CCS_MUXSELR_MASK << ((pin) * 4))
147#define CCS_MUXSELR_VAL(pin, muxsel) (((muxsel) & CCS_MUXSELR_MASK) << ((pin) * 4))
165#define CCS_PUENR(base) MMIO32(base + 0x1C)
166#define CCS_PAPUENR CCS_PUENR(CCS_PORTA)
167#define CCS_PBPUENR CCS_PUENR(CCS_PORTB)
168#define CCS_PCPUENR CCS_PUENR(CCS_PORTC)
169#define CCS_PDPUENR CCS_PUENR(CCS_PORTD)
170#define CCS_PEPUENR CCS_PUENR(CCS_PORTE)
171#define CCS_PFPUENR CCS_PUENR(CCS_PORTF)
172#define CCS_PGPUENR CCS_PUENR(CCS_PORTG)
173#define CCS_PDENR(base) MMIO32(base + 0x38)
174#define CCS_PAPDENR CCS_PDENR(CCS_PORTA)
175#define CCS_PBPDENR CCS_PDENR(CCS_PORTB)
176#define CCS_PCPDENR CCS_PDENR(CCS_PORTC)
177#define CCS_PDPDENR CCS_PDENR(CCS_PORTD)
178#define CCS_PEPDENR CCS_PDENR(CCS_PORTE)
179#define CCS_PFPDENR CCS_PDENR(CCS_PORTF)
180#define CCS_PGPDENR CCS_PDENR(CCS_PORTG)
192#define CCS_DSR(base) MMIO32(base + 0x54)
193#define CCS_PADSR CCS_DSR(CCS_PORTA)
194#define CCS_PBDSR CCS_DSR(CCS_PORTB)
195#define CCS_PCDSR CCS_DSR(CCS_PORTC)
196#define CCS_PDDSR CCS_DSR(CCS_PORTD)
197#define CCS_PEDSR CCS_DSR(CCS_PORTE)
198#define CCS_PFDSR CCS_DSR(CCS_PORTF)
199#define CCS_PGDSR CCS_DSR(CCS_PORTG)
200#define CCS_DSR_MASK 0x7
201#define CCS_DSR_MASK_PIN(pin) (CCS_DSR_MASK << ((pin) * 4))
202#define CCS_DSR_DS_VAL(pin, ds) (((ds)&CCS_DSR_MASK) << ((pin)*4))
203#define CCS_DSR_SCHMIDT_PIN(pin) (BIT0 << (((pin)*4) + 3))
void ccs_clkfail_disable(void)
Disable Clock Fail Detection.
void ccs_stclk_sleep_disable(void)
Disable SysTick clock gating in deep sleep mode.
void ccs_pll_bypass_enable(void)
Enable the PLL bypass.
void ccs_set_pclkdiv(uint32_t div)
Set the divisor for the Peripheral Clock.
bool ccs_pll_locked(void)
Check if the PLL is locked.
void ccs_aclk_disable(void)
Disable the Auxiliary Clock.
void ccs_configure_clocks(const struct ccs_clk_config *config)
Setup the PAC55xx clocks with the given struct.
void ccs_pll_set_indiv(uint32_t div)
Set the PLL input divisor.
void ccs_clkfail_enable(void)
Enable Clock Fail Detection.
void ccs_clkfailmux_select_pllclk(void)
Select PLLCLK for Clock Fail Detection.
void ccs_reset_clocks(void)
Restores CCSCTL and CCSPLLCTL registers to default/safe values.
void ccs_pll_set_fbdiv(uint32_t div)
Set the PLL feedback divisor.
void ccs_stclk_sleep_enable(void)
Enable SysTick clock gating in deep sleep mode.
void ccs_aclk_enable(void)
Enable the Auxiliary Clock.
void ccs_ldo_enable(void)
Enable the LDO.
void ccs_ldo_disable(void)
Disable the LDO.
void ccs_rosc_enable(void)
Enable the 16MHz Ring oscillator.
void ccs_frclkmux_select(uint32_t sel)
Select the source for FRCLK.
void ccs_pll_enable(void)
Enable the PLL.
void ccs_clkfailmux_select_frclk(void)
Select FRCLK for Clock Fail Detection.
void ccs_set_hclkdiv(uint32_t div)
Set the divisor for the AHB Clock.
void ccs_pll_set_outdiv(uint32_t div)
Set the output divisor.
void ccs_set_aclkdiv(uint32_t div)
Set the divisor for the Auxiliary Clock.
uint32_t ccs_get_peripheral_clk_freq(uint32_t periph, uint32_t select)
Get the clock rate (in Hz) of the specified peripheral.
void css_pll_config_enable(uint32_t indiv, uint32_t fbdiv, uint32_t outdiv)
Configure the CCS PLL, enable it, and wait for lock.
void ccs_pclk_disable(void)
Disable the Peripheral Clock.
void ccs_pclk_enable(void)
Enable the Peripheral Clock.
void ccs_pll_disable(void)
Disable the PLL.
void ccs_sclkmux_select_pllclk(void)
Select PLLCLK for SCLK.
void ccs_pll_bypass_disable(void)
Disable the PLL bypass.
void ccs_adcclk_enable(void)
Enable the ADC Clock.
void ccs_adcclk_disable(void)
Disable the ADC Clock.
void ccs_rosc_disable(void)
Disable the 16MHz Ring oscillator.
void ccs_sclkmux_select_frclk(void)
Select FRCLK for SCLK.
ccs_drive_strength_t
Drive strength enumeration for type specificity.
ccs_pull_updown_t
Pull Up/Down enum for type specificity.
CCS Clock Configuration structure.
uint32_t pll_outdiv
PLL Output Divider.
uint32_t aclkdiv
Divisor from SCLK to ACLK.
uint32_t frclk_source
FRCLK source input selection.
bool mem_mclksel
false: ROSCLK, true: HCLK/MCLK
uint32_t hclkdiv
Divisor from SCLK to HCLK.
uint32_t mem_wstate
Number of Flash Read wait states.
uint32_t pll_indiv
PLL Input Divider 1-15.
uint32_t sclk_source
SCLK source selection.
uint32_t mem_mclkdiv
Divisor from HCLK to MCLK.
uint32_t extclk_frequency
EXTCLK frequency, 0 if none.
bool mem_enable_cache
false: disable cache, true: enable cache
uint32_t pll_fbdiv
PLL Feedback Divider 4-16383.
uint32_t pclkdiv
Divisor from HCLK to PCLK.