libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
4l/pm.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_PM_H
19#define LIBOPENCM3_PM_H
20
22
23/* --- Power Manager (PM) registers ----------------------- */
24
25/* Main Clock Control MCCTRL Read/Write */
26#define PM_MCCTRL MMIO32(PM_BASE + 0x000)
27#define PM_MCCTRL_KEY (PM_UNLOCK_KEY)
28
29/* CPU & PBx Clock Select, Read/Write */
30#define PM_CKSEL(I) MMIO32(PM_BASE + 0x004 + (0x004 * (I)))
31#define PM_CKSEL_KEY(I) (PM_UNLOCK_KEY | (0x004 + (0x004 * (I))))
32
33#define PM_MASK(I) MMIO32(PM_BASE + 0x020 + (0x004) * (I))
34#define PM_MASK_KEY(I) (PM_UNLOCK_KEY | (0x020 + (0x004) * (I)))
35
36/* CPU Mask CPUMASK Read/Write */
37#define PM_CPUMASK MMIO32(PM_BASE + 0x020)
38
39/* HSB Mask HSBMASK Read/Write */
40#define PM_HSBMASK MMIO32(PM_BASE + 0x024)
41
42/* PBA Mask PBAMASK Read/Write */
43#define PM_PBAMASK MMIO32(PM_BASE + 0x028)
44#define PM_PBAMASK_KEY (PM_UNLOCK_KEY | 0x028)
45
46/* PBB Mask PBBMASK Read/Write */
47#define PM_PBBMASK MMIO32(PM_BASE + 0x02C)
48
49/* PBC Mask PBCMASK Read/Write */
50#define PM_PBCMASK MMIO32(PM_BASE + 0x030)
51
52/* PBD Mask PBDMASK Read/Write */
53#define PM_PBDMASK MMIO32(PM_BASE + 0x034)
54
55/* PBA Divided Mask PBADIVMASK Read/Write */
56#define PM_PBADIVMASK MMIO32(PM_BASE + 0x040)
57#define PM_PBADIVMASK_KEY (PM_UNLOCK_KEY | 0x040)
58
59/* Clock Failure Detector Control CFDCTRL Read/Write */
60#define PM_CFDCTRL MMIO32(PM_BASE + 0x054)
61
62/* Unlock Register UNLOCK Write-only */
63#define PM_UNLOCK MMIO32(PM_BASE + 0x058)
64#define PM_UNLOCK_KEY (0xAA << 24)
65
66/* Interrupt Enable Register IER Write-only */
67#define PM_IER MMIO32(PM_BASE + 0x0C0)
68
69/* Interrupt Disable Register IDR Write-only */
70#define PM_IDR MMIO32(PM_BASE + 0x0C4)
71
72/* Interrupt Mask Register IMR Read-only */
73#define PM_IMR MMIO32(PM_BASE + 0x0C8)
74
75/* Interrupt Status Register ISR Read-only */
76#define PM_ISR MMIO32(PM_BASE + 0x0CC)
77
78/* Interrupt Clear Register ICR Write-only */
79#define PM_ICR MMIO32(PM_BASE + 0x0D0)
80
81/* Status Register SR Read-only */
82#define PM_SR MMIO32(PM_BASE + 0x0D4)
83
84/* Peripheral Power Control Register PPCR Read/Write */
85#define PM_PPCR MMIO32(PM_BASE + 0x160)
86
87/* Reset Cause Register RCAUSE Read-only */
88#define PM_RCAUSE MMIO32(PM_BASE + 0x180)
89
90/* Wake Cause Register WCAUSE Read-only */
91#define PM_WCAUSE MMIO32(PM_BASE + 0x184)
92
93/* Asynchronous Wake Enable AWEN Read/Write */
94#define PM_AWEN MMIO32(PM_BASE + 0x188)
95
96/* Protection Control Register PROTCTRL Read/Write */
97#define PM_PROTCTRL MMIO32(PM_BASE + 0x18C)
98
99/* Fast Sleep Register FASTSLEEP Read/Write */
100#define PM_FASTSLEEP MMIO32(PM_BASE + 0x194)
101
102/* Configuration Register CONFIG Read-only */
103#define PM_CONFIG MMIO32(PM_BASE + 0x3F8)
104
105/* Version Register VERSION Read-only */
106#define PM_VERSION MMIO32(PM_BASE + 0x3FC)
107
108
109/* --- Register contents --------------------------------------------------- */
110#define PM_MCCTRL_MCSEL_SHIFT 0
111#define PM_MCCTRL_MCSEL_MASK 3
112
113// Values common for CPUSEL and PBxSEL
114#define PM_CKSEL_DIV (1 << 7)
115#define PM_CKSEL_MASK (3)
116
117#define PM_CPUMASK_OSC (1 << 0)
118
119#define PM_HSBMASK_PDCA (1 << 0)
120#define PM_HSBMASK_FLASHCALW (1 << 1)
121#define PM_HSBMASK_FLASHCALW_PICO (1 << 2)
122#define PM_HSBMASK_USBC (1 << 3)
123#define PM_HSBMASK_CRCCU (1 << 4)
124#define PM_HSBMASK_APBA (1 << 5)
125#define PM_HSBMASK_APBB (1 << 6)
126#define PM_HSBMASK_APBC (1 << 7)
127#define PM_HSBMASK_APBD (1 << 8)
128#define PM_HSBMASK_AESA (1 << 9)
129
130#define PM_PBAMASK_IISC (1 << 0)
131#define PM_PBAMASK_SPI (1 << 1)
132#define PM_PBAMASK_TC0 (1 << 2)
133#define PM_PBAMASK_TC1 (1 << 3)
134#define PM_PBAMASK_TWIM0 (1 << 4)
135#define PM_PBAMASK_TWIS0 (1 << 5)
136#define PM_PBAMASK_TWIM1 (1 << 6)
137#define PM_PBAMASK_TWIS1 (1 << 7)
138#define PM_PBAMASK_USART0 (1 << 8)
139#define PM_PBAMASK_USART1 (1 << 9)
140#define PM_PBAMASK_USART2 (1 << 10)
141#define PM_PBAMASK_USART3 (1 << 11)
142#define PM_PBAMASK_ADCIFE (1 << 12)
143#define PM_PBAMASK_DACC (1 << 13)
144#define PM_PBAMASK_ACIFC (1 << 14)
145#define PM_PBAMASK_GLOC (1 << 15)
146#define PM_PBAMASK_ABDACB (1 << 16)
147#define PM_PBAMASK_TRNG (1 << 17)
148#define PM_PBAMASK_PARC (1 << 18)
149#define PM_PBAMASK_CATB (1 << 19)
150/* -- */
151#define PM_PBAMASK_TWIM2 (1 << 21)
152#define PM_PBAMASK_TWIM3 (1 << 22)
153#define PM_PBAMASK_LCDCA (1 << 23)
154
155#define PM_PBBMASK_FLASHCALW (1 << 0)
156#define PM_PBBMASK_HRAMC1 (1 << 1)
157#define PM_PBBMASK_HMATRIX (1 << 2)
158#define PM_PBBMASK_PDCA (1 << 3)
159#define PM_PBBMASK_CRCCU (1 << 4)
160#define PM_PBBMASK_USBC (1 << 5)
161#define PM_PBBMASK_PEVC (1 << 6)
162
163#define PM_PBCMASK_PM (1 << 0)
164#define PM_PBCMASK_CHIPID (1 << 1)
165#define PM_PBCMASK_SCIF (1 << 2)
166#define PM_PBCMASK_FREQM (1 << 3)
167#define PM_PBCMASK_GPIO (1 << 4)
168
169#define PM_PBDMASK_BPM (1 << 0)
170#define PM_PBDMASK_BSCIF (1 << 1)
171#define PM_PBDMASK_AST (1 << 2)
172#define PM_PBDMASK_WDT (1 << 3)
173#define PM_PBDMASK_EIC (1 << 4)
174#define PM_PBDMASK_PICOUART (1 << 5)
175
176#define PM_PBADIVMASK_TC2 (1 << 0)
177#define PM_PBADIVMASK_USART0 (1 << 2)
178#define PM_PBADIVMASK_USART1 (1 << 2)
179#define PM_PBADIVMASK_USART2 (1 << 2)
180#define PM_PBADIVMASK_USART3 (1 << 2)
181#define PM_PBADIVMASK_TC3 (1 << 2)
182#define PM_PBADIVMASK_TC4 (1 << 4)
183#define PM_PBADIVMASK_TC5 (1 << 6)
184
185#define PM_SR_CFD (1 << 0)
186#define PM_SR_CKRDY (1 << 5)
187#define PM_SR_WAKE (1 << 8)
188
197};
198
205};
206
207/*
208 * Ids are designed such that
209 * PM_MASK(id/32) = (1 << id % 32)
210 * would enable the peripheral clock.
211 */
266};
267
269
270void pm_select_main_clock(enum mck_src source_clock);
271void pm_enable_clock_div(enum pm_cksel sel_target, uint8_t div);
272void pm_set_divmask_clock(uint8_t mask);
275
277
278#endif
void pm_set_divmask_clock(uint8_t mask)
Definition: pm.c:47
void pm_enable_peripheral_clock(enum pm_peripheral periph)
Definition: pm.c:67
void pm_disable_peripheral_clock(enum pm_peripheral periph)
Definition: pm.c:72
mck_src
Definition: 4l/pm.h:189
@ MCK_SRC_RCFAST
Definition: 4l/pm.h:195
@ MCK_SRC_DFLL
Definition: 4l/pm.h:193
@ MCK_SRC_PLL
Definition: 4l/pm.h:192
@ MCK_SRC_RC1M
Definition: 4l/pm.h:196
@ MCK_SRC_RCSYS
Definition: 4l/pm.h:190
@ MCK_SRC_OSC0
Definition: 4l/pm.h:191
@ MCK_SRC_RC80M
Definition: 4l/pm.h:194
void pm_select_main_clock(enum mck_src source_clock)
Definition: pm.c:30
pm_peripheral
Definition: 4l/pm.h:212
@ PM_PERIPHERAL_BSCIF
Definition: 4l/pm.h:261
@ PM_PERIPHERAL_TWIM1
Definition: 4l/pm.h:230
@ PM_PERIPHERAL_TWIM2
Definition: 4l/pm.h:245
@ PM_PERIPHERAL_USART3
Definition: 4l/pm.h:235
@ PM_PERIPHERAL_HMATRIX
Definition: 4l/pm.h:250
@ PM_PERIPHERAL_USART1
Definition: 4l/pm.h:233
@ PM_PERIPHERAL_APBC_BRIDGE
Definition: 4l/pm.h:221
@ PM_PERIPHERAL_AST
Definition: 4l/pm.h:262
@ PM_PERIPHERAL_CATB
Definition: 4l/pm.h:243
@ PM_PERIPHERAL_FLASHCALW_ALT
Definition: 4l/pm.h:248
@ PM_PERIPHERAL_WDT
Definition: 4l/pm.h:263
@ PM_PERIPHERAL_FLASHCALW
Definition: 4l/pm.h:215
@ PM_PERIPHERAL_SPI
Definition: 4l/pm.h:225
@ PM_PERIPHERAL_LCDCA
Definition: 4l/pm.h:247
@ PM_PERIPHERAL_USART2
Definition: 4l/pm.h:234
@ PM_PERIPHERAL_CRCCU_ALT
Definition: 4l/pm.h:252
@ PM_PERIPHERAL_FLASHCALW_PICORAM
Definition: 4l/pm.h:216
@ PM_PERIPHERAL_TWIM0
Definition: 4l/pm.h:228
@ PM_PERIPHERAL_PEVC
Definition: 4l/pm.h:254
@ PM_PERIPHERAL_TRNG
Definition: 4l/pm.h:241
@ PM_PERIPHERAL_CRCCU
Definition: 4l/pm.h:218
@ PM_PERIPHERAL_EIC
Definition: 4l/pm.h:264
@ PM_PERIPHERAL_CHIPID
Definition: 4l/pm.h:256
@ PM_PERIPHERAL_PARC
Definition: 4l/pm.h:242
@ PM_PERIPHERAL_DACC
Definition: 4l/pm.h:237
@ PM_PERIPHERAL_TC0
Definition: 4l/pm.h:226
@ PM_PERIPHERAL_FREQM
Definition: 4l/pm.h:258
@ PM_PERIPHERAL_PM
Definition: 4l/pm.h:255
@ PM_PERIPHERAL_TWIM3
Definition: 4l/pm.h:246
@ PM_PERIPHERAL_OCD
Definition: 4l/pm.h:213
@ PM_PERIPHERAL_APBA_BRIDGE
Definition: 4l/pm.h:219
@ PM_PERIPHERAL_TWIS0
Definition: 4l/pm.h:229
@ PM_PERIPHERAL_AESA
Definition: 4l/pm.h:223
@ PM_PERIPHERAL_GPIO
Definition: 4l/pm.h:259
@ PM_PERIPHERAL_TWIS1
Definition: 4l/pm.h:231
@ PM_PERIPHERAL_USBC_ALT
Definition: 4l/pm.h:253
@ PM_PERIPHERAL_APBD_BRIDGE
Definition: 4l/pm.h:222
@ PM_PERIPHERAL_SCIF
Definition: 4l/pm.h:257
@ PM_PERIPHERAL_HRAMC1
Definition: 4l/pm.h:249
@ PM_PERIPHERAL_ADCIFE
Definition: 4l/pm.h:236
@ PM_PERIPHERAL_GLOC
Definition: 4l/pm.h:239
@ PM_PERIPHERAL_IISC
Definition: 4l/pm.h:224
@ PM_PERIPHERAL_USART0
Definition: 4l/pm.h:232
@ PM_PERIPHERAL_PDCA
Definition: 4l/pm.h:214
@ PM_PERIPHERAL_ABDACB
Definition: 4l/pm.h:240
@ PM_PERIPHERAL_RESERVED1
Definition: 4l/pm.h:244
@ PM_PERIPHERAL_PDCA_ALT
Definition: 4l/pm.h:251
@ PM_PERIPHERAL_PICOUART
Definition: 4l/pm.h:265
@ PM_PERIPHERAL_ACIFC
Definition: 4l/pm.h:238
@ PM_PERIPHERAL_TC1
Definition: 4l/pm.h:227
@ PM_PERIPHERAL_APBB_BRIDGE
Definition: 4l/pm.h:220
@ PM_PERIPHERAL_USBC
Definition: 4l/pm.h:217
@ PM_PERIPHERAL_BPM
Definition: 4l/pm.h:260
pm_cksel
Definition: 4l/pm.h:199
@ PM_CKSEL_PBB
Definition: 4l/pm.h:202
@ PM_CKSEL_CPU
Definition: 4l/pm.h:200
@ PM_CKSEL_PBA
Definition: 4l/pm.h:201
@ PM_CKSEL_PBD
Definition: 4l/pm.h:204
@ PM_CKSEL_PBC
Definition: 4l/pm.h:203
void pm_enable_clock_div(enum pm_cksel sel_target, uint8_t div)
Definition: pm.c:37
#define END_DECLS
Definition: common.h:34
#define BEGIN_DECLS
Definition: common.h:33