libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
common/clock.h
Go to the documentation of this file.
1/** @addtogroup clock_defines
2 *
3 * @author @htmlonly &copy; @endhtmlonly 2016 Maxim Sloyko <maxims@google.com>
4 * @author @htmlonly &copy; @endhtmlonly 2021 Eduard Drusa <ventyl86 at netkosice dot sk>
5 *
6 **/
7
8/*
9 * This file is part of the libopencm3 project.
10 *
11 * Copyright (C) 2017-2018 Unicore MX project<dev(at)lists(dot)unicore-mx(dot)org>
12 * Copyright (C) 2021 Eduard Drusa <ventyl86(at)netkosice(dot)sk>
13 *
14 * This library is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public License
25 * along with this library. If not, see <http://www.gnu.org/licenses/>.
26 */
27
28#pragma once
29
30#include <stdbool.h>
31
34/**@{*/
35
36/* Clock tasks */
37#define CLOCK_TASK_HFCLKSTART MMIO32(CLOCK_BASE + 0x000)
38#define CLOCK_TASK_HFCLKSTOP MMIO32(CLOCK_BASE + 0x004)
39#define CLOCK_TASK_LFCLKSTART MMIO32(CLOCK_BASE + 0x008)
40#define CLOCK_TASK_LFCLKSTOP MMIO32(CLOCK_BASE + 0x00C)
41#define CLOCK_TASK_CAL MMIO32(CLOCK_BASE + 0x010)
42#define CLOCK_TASK_CTSTART MMIO32(CLOCK_BASE + 0x014)
43#define CLOCK_TASK_CTSTOP MMIO32(CLOCK_BASE + 0x018)
44
45/* Clock events */
46#define CLOCK_EVENT_HFCLKSTARTED MMIO32(CLOCK_BASE + 0x100)
47#define CLOCK_EVENT_LFCLKSTARTED MMIO32(CLOCK_BASE + 0x104)
48#define CLOCK_EVENT_DONE MMIO32(CLOCK_BASE + 0x10C)
49#define CLOCK_EVENT_CTTO MMIO32(CLOCK_BASE + 0x110)
50
51/* Clock registers */
52#define CLOCK_INTENSET MMIO32(CLOCK_BASE + 0x304)
53#define CLOCK_INTENCLR MMIO32(CLOCK_BASE + 0x308)
54#define CLOCK_HFCLKRUN MMIO32(CLOCK_BASE + 0x408)
55#define CLOCK_HFCLKSTAT MMIO32(CLOCK_BASE + 0x40C)
56#define CLOCK_LFCLKRUN MMIO32(CLOCK_BASE + 0x414)
57#define CLOCK_LFCLKSTAT MMIO32(CLOCK_BASE + 0x418)
58#define CLOCK_LFCLKSRCCOPY MMIO32(CLOCK_BASE + 0x41C)
59#define CLOCK_LFCLKSRC MMIO32(CLOCK_BASE + 0x518)
60#define CLOCK_CTIV MMIO32(CLOCK_BASE + 0x538)
61
62/* Register contents */
63#define CLOCK_INTEN_HFCLKSTARTED (1 << 0)
64#define CLOCK_INTEN_LFCLKSTARTED (1 << 1)
65#define CLOCK_INTEN_DONE (1 << 3)
66#define CLOCK_INTEN_CTTO (1 << 4)
67
68#define CLOCK_HFCLKRUN_STATUS (1 << 0)
69
70#define CLOCK_HFCLKSTAT_SRC (1 << 0)
71#define CLOCK_HFCLKSTAT_STATE (1 << 16)
72
73#define CLOCK_LFCLKRUN_STATUS (1 << 0)
74
75#define CLOCK_LFCLK_SRC_SHIFT (0)
76#define CLOCK_LFCLK_SRC_MASK (3 << CLOCK_LFCLKSTAT_SRC_SHIFT)
77#define CLOCK_LFCLK_SRC_MASKED(V) (((V) << CLOCK_LFCLKSTAT_SRC_SHIFT) & CLOCK_LFCLKSTAT_SRC_MASK)
78
79#define CLOCK_LFCLKSTAT_STATE (1 << 16)
80
85};
86/**@}*/
87
89
90void clock_start_lfclk(bool wait);
91void clock_stop_lfclk(void);
92void clock_start_hfclk(bool wait);
93void clock_stop_hfclk(void);
94void clock_set_lfclk_src(enum clock_lfclk_src lfclk_src);
95
97
98
#define END_DECLS
Definition: common.h:34
#define BEGIN_DECLS
Definition: common.h:33
clock_lfclk_src
Definition: common/clock.h:81
@ CLOCK_LFCLK_SRC_XTAL
Definition: common/clock.h:83
@ CLOCK_LFCLK_SRC_RC
Definition: common/clock.h:82
@ CLOCK_LFCLK_SRC_SYNTH
Definition: common/clock.h:84
void clock_start_lfclk(bool wait)
Start Low Frequency Clock.
Definition: clock_common.c:40
void clock_set_lfclk_src(enum clock_lfclk_src lfclk_src)
Low Frequency Clock Source.
Definition: clock_common.c:78
void clock_start_hfclk(bool wait)
Start High Frequency Crystal Oscillator.
Definition: clock_common.c:60
void clock_stop_lfclk(void)
Stop Low Frequency Clock.
Definition: clock_common.c:49
void clock_stop_hfclk(void)
Stop High Frequency Crystal Oscillator.
Definition: clock_common.c:69