libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
4l/scif.h
Go to the documentation of this file.
1/*
2 * This file is part of the libopencm3 project.
3 *
4 * This library is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef LIBOPENCM3_SCIF_H
19#define LIBOPENCM3_SCIF_H
20
23
24/* ------------ SCIF Registers ------------------------------ */
25
26/* Interrupt Enable Register IER Write Only */
27#define SCIF_IER MMIO32(SCIF_BASE)
28
29/* Interrupt Disable Register IDR Write Only */
30#define SCIF_IDR MMIO32(SCIF_BASE + 0x0004)
31
32/* Interrupt Mask Register IMR Read Only */
33#define SCIF_IMR MMIO32(SCIF_BASE + 0x0008)
34
35/* Interrupt Status Register ISR Read Only */
36#define SCIF_ISR MMIO32(SCIF_BASE + 0x000C)
37
38/* Interrupt Clear Register ICR Write Only */
39#define SCIF_ICR MMIO32(SCIF_BASE + 0x0010)
40
41/* Power and Clocks Status Register PCLKSR Read Only */
42#define SCIF_PCLKSR MMIO32(SCIF_BASE + 0x0014)
43
44/* Unlock Register UNLOCK Write Only */
45#define SCIF_UNLOCK MMIO32(SCIF_BASE + 0x0018)
46#define SCIF_UNLOCK_KEY (0xaa << 24)
47
48/* Chip Specific Configuration Register CSCR Read/Write */
49#define SCIF_CSCR MMIO32(SCIF_BASE + 0x001C)
50
51/* Oscillator Control Register OSCCTRL0 Read/Write */
52#define SCIF_OSCCTRL0 MMIO32(SCIF_BASE + 0x0020)
53#define SCIF_OSCCTRL0_KEY (SCIF_UNLOCK_KEY | 0x0020)
54
55/* PLL0 Control Register PLL0 Read/Write */
56#define SCIF_PLL0 MMIO32(SCIF_BASE + 0x0024)
57#define SCIF_PLL0_KEY (SCIF_UNLOCK_KEY | 0x0024)
58
59/* DFLL0 Config Register DFLL0CONF Read/Write */
60#define SCIF_DFLL0CONF MMIO32(SCIF_BASE + 0x0028)
61
62/* DFLL Value Register DFLL0VAL Read/Write */
63#define SCIF_DFLL0VAL MMIO32(SCIF_BASE + 0x002C)
64
65/* DFLL0 Multiplier Register DFLL0MUL Read/Write */
66#define SCIF_DFLL0MUL MMIO32(SCIF_BASE + 0x0030)
67
68/* DFLL0 Step Register DFLL0STEP Read/Write */
69#define SCIF_DFLL0STEP MMIO32(SCIF_BASE + 0x0034)
70
71/* DFLL0 Spread Spectrum Generator Control Register DFLL0SSG Read/Write */
72#define SCIF_DFLL0SSG MMIO32(SCIF_BASE + 0x0038)
73
74/* DFLL0 Ratio Register DFLL0RATIO Read Only */
75#define SCIF_DFLL0RATIO MMIO32(SCIF_BASE + 0x003C)
76
77/* DFLL0 Synchronization Register DFLL0SYNC Write Only */
78#define SCIF_DFLL0SYNC MMIO32(SCIF_BASE + 0x0040)
79
80/* System RC Oscillator Calibration Register RCCR Read/Write */
81#define SCIF_RCCR MMIO32(SCIF_BASE + 0x0044)
82
83/* 4/8/12MHz RC Oscillator Configuration Register RCFASTCFG Read/Write */
84#define SCIF_RCFASTCFG MMIO32(SCIF_BASE + 0x0048)
85
86/* 4/8/12MHz RC Oscillator Status Register RCFASTSR Read Only */
87#define SCIF_RCFASTSR MMIO32(SCIF_BASE + 0x004C)
88
89/* 80MHz RC Oscillator Register RC80MCR Read/Write */
90#define SCIF_RC80MCR MMIO32(SCIF_BASE + 0x0050)
91
92/* High Resolution Prescaler Control Register HRPCR Read/Write */
93#define SCIF_HPPCR MMIO32(SCIF_BASE + 0x0064)
94
95/* Fractional Prescaler Control Register FPCR Read/Write */
96#define SCIF_FPCR MMIO32(SCIF_BASE + 0x0068)
97
98/* Fractional Prescaler Multiplier Register FPMUL Read/Write */
99#define SCIF_FPMUL MMIO32(SCIF_BASE + 0x006C)
100
101/* Fractional Prescaler DIVIDER Register FPDIV Read/Write */
102#define SCIF_FPDIV MMIO32(SCIF_BASE + 0x006C)
103
104/* Generic Clock Control1 GCCTRL0 Read/Write */
105#define SCIF_GCCTRL0 MMIO32(SCIF_BASE + 0x0074)
106
107/* Generic Clock Control1 GCCTRL1 Read/Write */
108#define SCIF_GCCTRL1 MMIO32(SCIF_BASE + 0x0078)
109
110/* Generic Clock Control2 GCCTRL2 Read/Write */
111#define SCIF_GCCTRL2 MMIO32(SCIF_BASE + 0x007C)
112
113/* Generic Clock Control3 GCCTRL3 Read/Write */
114#define SCIF_GCCTRL3 MMIO32(SCIF_BASE + 0x0080)
115
116/* Generic Clock Control4 GCCTRL4 Read/Write */
117#define SCIF_GCCTRL4 MMIO32(SCIF_BASE + 0x0084)
118
119/* Generic Clock Control5 GCCTRL5 Read/Write */
120#define SCIF_GCCTRL5 MMIO32(SCIF_BASE + 0x0088)
121
122/* Generic Clock Control6 GCCTRL6 Read/Write */
123#define SCIF_GCCTRL6 MMIO32(SCIF_BASE + 0x008C)
124
125/* Generic Clock Control7 GCCTRL7 Read/Write */
126#define SCIF_GCCTRL7 MMIO32(SCIF_BASE + 0x0090)
127
128/* Generic Clock Control8 GCCTRL8 Read/Write */
129#define SCIF_GCCTRL8 MMIO32(SCIF_BASE + 0x0094)
130
131/* Generic Clock Control9 GCCTRL9 Read/Write */
132#define SCIF_GCCTRL9 MMIO32(SCIF_BASE + 0x0098)
133
134/* Generic Clock Control10 GCCTRL10 Read/Write */
135#define SCIF_GCCTRL10 MMIO32(SCIF_BASE + 0x009C)
136
137/* Generic Clock Control11 GCCTRL11 Read/Write */
138#define SCIF_GCCTRL11 MMIO32(SCIF_BASE + 0x00A0)
139
140#define SCIF_GCTRL(N) MMIO32(SCIF_BASE + 0x0074 + 0x0004 * (N))
141#define SCIF_GCLK_MAX_NUM 11
142
143/* 4/8/12MHz RC Oscillator Version Register RCFASTVERSION Read-only */
144#define SCIF_RCFASTVERSION MMIO32(SCIF_BASE + 0x03D8)
145
146/* Generic Clock Prescaler Version Register GCLKPRESCVERSION Read-only */
147#define SCIF_GCLKPRESCVERSION MMIO32(SCIF_BASE + 0x03DC)
148
149/* PLL Version Register PLLIFAVERSION Read-only */
150#define SCIF_PLLIFAVERSION MMIO32(SCIF_BASE + 0x03E0)
151
152/* Oscillator0 Version Register OSCIFAVERSION Read-only */
153#define SCIF_OSCIFAVERSION MMIO32(SCIF_BASE + 0x03E4)
154
155/* DFLL Version Register DFLLIFBVERSION Read-only */
156#define SCIF_DFLLIFBVERSION MMIO32(SCIF_BASE + 0x03E8)
157
158/* System RC Oscillator Version Register RCOSCIFAVERSION Read-only */
159#define SCIF_RCOSCIFAVERSION MMIO32(SCIF_BASE + 0x03EC)
160
161/* 80MHz RC Oscillator Version Register RC80MVERSION Read-only */
162#define SCIF_RC80MVERSION MMIO32(SCIF_BASE + 0x03F4)
163
164/* Generic Clock Version Register GCLKVERSION Read-only */
165#define SCIF_GCLKVERSION MMIO32(SCIF_BASE + 0x03F8)
166
167/* SCIF Version Register VERSION Read-Only */
168#define SCIF_VERSION MMIO32(SCIF_BASE + 0x03FC)
169
170
171/* ---------------- SCIF Registers' Contents ------------------- */
172
173/* Interrupt Enable/Disable/Mask/Status/Clear registers and PCLKSR
174 * have the same bit configuration */
175#define SCIF_OSC0RDY (1 << 0)
176#define SCIF_DFLL0LOCKC (1 << 1)
177#define SCIF_DFLL0LOCKF (1 << 2)
178#define SCIF_DFLL0RDY (1 << 3)
179#define SCIF_DFLL0RCS (1 << 4)
180#define SCIF_PLL0LOCK (1 << 6)
181#define SCIF_PLL0LOCKLOST (1 << 7)
182#define SCIF_RCFASTLOCK (1 << 13)
183#define SCIF_RCFASTLOCKLOST (1 << 14)
184
185#define SCIF_OSCCTRL_MODE (1 << 0)
186#define SCIF_OSCCTRL_GAIN_SHIFT 1
187#define SCIF_OSCCTRL_GAIN_MASK (3 << SCIF_OSCCTRL_GAIN_SHIFT)
188#define SCIF_OSCCTRL_AGC (1 << 3)
189#define SCIF_OSCCTRL_STARTUP_SHIFT 8
190#define SCIF_OSCCTRL_STARTUP_MASK (0xf << SCIF_OSCCTRL_STARTUP_SHIFT)
191#define SCIF_OSCCTRL_OSCEN (1 << 16)
192
193#define _MASKED_VALUE(V, S, M) (((V) << (S)) & (M))
194
195#define SCIF_PLL0_PLLEN (1 << 0)
196#define SCIF_PLL0_PLLOSC_SHIFT 1
197#define SCIF_PLL0_PLLOSC_MASK (3 << SCIF_PLL0_PLLOSC_SHIFT)
198#define SCIF_PLL0_PLLOSC_MASKED(V) _MASKED_VALUE((V), SCIF_PLL0_PLLOSC_SHIFT, SCIF_PLL0_PLLOSC_MASK)
199
200#define SCIF_PLL0_PLLOPT_SHIFT 3
201#define SCIF_PLL0_PLLOPT_MASK (7 << SCIF_PLL0_PLLOPT_SHIFT)
202#define SCIF_PLL0_PLLOPT_MASKED(V) _MASKED_VALUE((V), SCIF_PLL0_PLLOPT_SHIFT, SCIF_PLL0_PLLOPT_MASK)
203
204#define SCIF_PLL0_PLLDIV_SHIFT 8
205#define SCIF_PLL0_PLLDIV_MASK (0xf << SCIF_PLL0_PLLDIV_SHIFT)
206#define SCIF_PLL0_PLLDIV_MASKED(V) _MASKED_VALUE((V), SCIF_PLL0_PLLDIV_SHIFT, SCIF_PLL0_PLLDIV_MASK)
207
208#define SCIF_PLL0_PLLMUL_SHIFT 16
209#define SCIF_PLL0_PLLMUL_MASK (0xf << SCIF_PLL0_PLLMUL_SHIFT)
210#define SCIF_PLL0_PLLMUL_MASKED(V) _MASKED_VALUE((V), SCIF_PLL0_PLLMUL_SHIFT, SCIF_PLL0_PLLMUL_MASK)
211
212#define SCIF_PLL0_PLLCOUNT_SHIFT 24
213#define SCIF_PLL0_PLLCOUNT_MASK (0x3f << SCIF_PLL0_PLLCOUNT_SHIFT)
214#define SCIF_PLL0_PLLCOUNT_MASKED(V) _MASKED_VALUE((V), SCIF_PLL0_PLLCOUNT_SHIFT, SCIF_PLL0_PLLCOUNT_MASK)
215
216
217#define SCIF_GCCTRL_CEN (1 << 0)
218#define SCIF_GCCTRL_DIVEN (1 << 1)
219#define SCIF_GCCTRL_OSCSEL_SHIFT 8
220#define SCIF_GCCTRL_OSCSEL_MASK (0x1f << SCIF_GCCTRL_OSCSEL_SHIFT)
221#define SCIF_GCCTRL_OSCSEL_MASKED(V) _MASKED_VALUE(V, SCIF_GCCTRL_OSCSEL_SHIFT, SCIF_GCCTRL_OSCSEL_MASK)
222#define SCIF_GCCTRL_DIV_SHIFT 16
223#define SCIF_GCCTRL_DIV_MASK (0xffff << SCIF_GCCTRL_DIV_SHIFT)
224#define SCIF_GCCTRL_DIV_MASKED(V) _MASKED_VALUE(V, SCIF_GCCTRL_DIV_SHIFT, SCIF_GCCTRL_DIV_MASK)
225
226
230};
231
248};
249
253};
254
255/* Generic Clock Source
256 * 0 RCSYS System RC oscillator clock
257 * 1 OSC32K Output clock from OSC32K
258 * 2 DFLL0 Output clock from DFLL0
259 * 3 OSC0 Output clock from Oscillator0
260 * 4 RC80M Output from 80MHz RCOSC
261 * 5 RCFAST Output from 4,8,12MHz RCFAST
262 * 6 RC1M Output from 1MHz RC1M
263 * 7 CLK_CPU The clock the CPU runs on
264 * 8 CLK_HSB High Speed Bus clock
265 * 9 CLK_PBA Peripheral Bus A clock
266 * 10 CLK_PBB Peripheral Bus B clock
267 * 11 CLK_PBC Peripheral Bus C clock
268 * 12 CLK_PBD Peripheral Bus D clock
269 * 13 RC32K Output from 32kHz RCOSC
270 * 14 Reserved
271 * 15 CLK_1K 1kHz output clock from OSC32K
272 * 16 PLL0 Output clock from PLL0
273 * 17 HRP High Resolution Prescaler Output
274 * 18 FP Fractionnal Prescaler Output
275 * 19-20 GCLK_IN[0-1] GCLK_IN[0-1] pins, digital clock input
276 * 21 GCLK11 Generic Clock 11. Can not be use as input to itself.
277 */
301};
302
317};
318
320
321int scif_osc_enable(enum osc_mode mode, uint32_t freq, enum osc_startup startup);
322int scif_enable_pll(uint8_t delay, uint8_t mul, uint8_t div, uint8_t pll_opt, enum pll_clk_src source_clock);
323void scif_enable_gclk(enum generic_clock gclk, enum gclk_src source_clock, uint16_t div);
324
326
327
328#endif /* LIBOPENCM3_SCIF_H */
int scif_osc_enable(enum osc_mode mode, uint32_t freq, enum osc_startup startup)
Enable external oscillator.
Definition: scif.c:38
osc_mode
Definition: 4l/scif.h:227
@ OSC_MODE_XIN_XOUT
Definition: 4l/scif.h:229
@ OSC_MODE_XIN
Definition: 4l/scif.h:228
pll_clk_src
Definition: 4l/scif.h:250
@ PLL_CLK_SRC_GCLK9
Definition: 4l/scif.h:252
@ PLL_CLK_SRC_OSC0
Definition: 4l/scif.h:251
generic_clock
Definition: 4l/scif.h:303
@ GENERIC_CLOCK4
Definition: 4l/scif.h:308
@ GENERIC_CLOCK8
Definition: 4l/scif.h:312
@ GENERIC_CLOCK0
Definition: 4l/scif.h:304
@ GENERIC_CLOCK11
Definition: 4l/scif.h:316
@ GENERIC_CLOCK_ADCIFE
Definition: 4l/scif.h:315
@ GENERIC_CLOCK10
Definition: 4l/scif.h:314
@ GENERIC_CLOCK2
Definition: 4l/scif.h:306
@ GENERIC_CLOCK3
Definition: 4l/scif.h:307
@ GENERIC_CLOCK1
Definition: 4l/scif.h:305
@ GENERIC_CLOCK7
Definition: 4l/scif.h:311
@ GENERIC_CLOCK5
Definition: 4l/scif.h:309
@ GENERIC_CLOCK6
Definition: 4l/scif.h:310
@ GENERIC_CLOCK9
Definition: 4l/scif.h:313
void scif_enable_gclk(enum generic_clock gclk, enum gclk_src source_clock, uint16_t div)
Configure and enable Generic Clock.
Definition: scif.c:120
int scif_enable_pll(uint8_t delay, uint8_t mul, uint8_t div, uint8_t pll_opt, enum pll_clk_src source_clock)
Configure and enable PLL clock.
Definition: scif.c:82
gclk_src
Definition: 4l/scif.h:278
@ GCLK_SRC_OSC0
Definition: 4l/scif.h:282
@ GCLK_SRC_GCLK_IN1
Definition: 4l/scif.h:299
@ GCLK_SRC_PLL0
Definition: 4l/scif.h:295
@ GCLK_SRC_GCLK11
Definition: 4l/scif.h:300
@ GCLK_SRC_OSC32K
Definition: 4l/scif.h:280
@ GCLK_SRC_CLK_CPU
Definition: 4l/scif.h:286
@ GCLK_SRC_CLK_HSB
Definition: 4l/scif.h:287
@ GCLK_SRC_RCFAST
Definition: 4l/scif.h:284
@ GCLK_SRC_RCSYS
Definition: 4l/scif.h:279
@ GCLK_SRC_RC1M
Definition: 4l/scif.h:285
@ GCLK_SRC_CLK_PBB
Definition: 4l/scif.h:289
@ GCLK_SRC_CLK_PBD
Definition: 4l/scif.h:291
@ GCLK_SRC_CLK_PBA
Definition: 4l/scif.h:288
@ GCLK_SRC_CLK_1K
Definition: 4l/scif.h:294
@ GCLK_SRC_GCLK_IN0
Definition: 4l/scif.h:298
@ GCLK_SRC_DFLL0
Definition: 4l/scif.h:281
@ GCLK_SRC_CLK_PBC
Definition: 4l/scif.h:290
@ GCLK_SRC_RC32K
Definition: 4l/scif.h:292
@ GCLK_SRC_HRP
Definition: 4l/scif.h:296
@ GCLK_SRC_RC80M
Definition: 4l/scif.h:283
@ GCLK_SRC_RESERVED_
Definition: 4l/scif.h:293
@ GCLK_SRC_FP
Definition: 4l/scif.h:297
osc_startup
Definition: 4l/scif.h:232
@ OSC_STARTUP_512
Definition: 4l/scif.h:241
@ OSC_STARTUP_0
Definition: 4l/scif.h:233
@ OSC_STARTUP_32
Definition: 4l/scif.h:237
@ OSC_STARTUP_4K
Definition: 4l/scif.h:244
@ OSC_STARTUP_8
Definition: 4l/scif.h:235
@ OSC_STARTUP_256
Definition: 4l/scif.h:240
@ OSC_STARTUP_16
Definition: 4l/scif.h:236
@ OSC_STARTUP_2K
Definition: 4l/scif.h:243
@ OSC_STARTUP_32K
Definition: 4l/scif.h:247
@ OSC_STARTUP_16K
Definition: 4l/scif.h:246
@ OSC_STARTUP_1K
Definition: 4l/scif.h:242
@ OSC_STARTUP_64
Definition: 4l/scif.h:238
@ OSC_STARTUP_8K
Definition: 4l/scif.h:245
@ OSC_STARTUP_4
Definition: 4l/scif.h:234
@ OSC_STARTUP_128
Definition: 4l/scif.h:239
#define END_DECLS
Definition: common.h:34
#define BEGIN_DECLS
Definition: common.h:33