Loading...
Searching...
No Matches
clk_conf.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2019-2020 Inria
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser General
5 * Public License v2.1. See the file LICENSE in the top level directory for more
6 * details.
7 */
8
9#pragma once
10
20
21#include "macros/units.h"
22#include "kernel_defines.h"
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
32#ifndef CONFIG_USE_CLOCK_HFXOSC_PLL
33#if IS_ACTIVE(CONFIG_USE_CLOCK_HFXOSC) || \
34 IS_ACTIVE(CONFIG_USE_CLOCK_HFROSC_PLL) || \
35 IS_ACTIVE(CONFIG_USE_CLOCK_HFROSC)
36#define CONFIG_USE_CLOCK_HFXOSC_PLL 0
37#else
38#define CONFIG_USE_CLOCK_HFXOSC_PLL 1 /* Use PLL clocked by HFXOSC by default */
39#endif
40#endif /* CONFIG_USE_CLOCK_HFXOSC_PLL */
41
42#ifndef CONFIG_USE_CLOCK_HFXOSC
43#define CONFIG_USE_CLOCK_HFXOSC 0
44#endif /* CONFIG_USE_CLOCK_HFXOSC */
45
46#ifndef CONFIG_USE_CLOCK_HFROSC_PLL
47#define CONFIG_USE_CLOCK_HFROSC_PLL 0
48#endif /* CONFIG_USE_CLOCK_HFROSC_PLL */
49
50#ifndef CONFIG_USE_CLOCK_HFROSC
51#define CONFIG_USE_CLOCK_HFROSC 0
52#endif /* CONFIG_USE_CLOCK_HFROSC */
53
54#if CONFIG_USE_CLOCK_HFXOSC_PLL && \
55 (CONFIG_USE_CLOCK_HFROSC_PLL || CONFIG_USE_CLOCK_HFROSC || \
56 CONFIG_USE_CLOCK_HFXOSC)
57#error "Cannot use HFXOSC_PLL with other clock configurations"
58#endif
59
60#if CONFIG_USE_CLOCK_HFXOSC && \
61 (CONFIG_USE_CLOCK_HFROSC_PLL || CONFIG_USE_CLOCK_HFROSC || \
62 CONFIG_USE_CLOCK_HFXOSC_PLL)
63#error "Cannot use HFXOSC with other clock configurations"
64#endif
65
66#if CONFIG_USE_CLOCK_HFROSC_PLL && \
67 (CONFIG_USE_CLOCK_HFXOSC_PLL || CONFIG_USE_CLOCK_HFXOSC || \
68 CONFIG_USE_CLOCK_HFROSC)
69#error "Cannot use HFROSC_PLL with other clock configurations"
70#endif
71
72#if CONFIG_USE_CLOCK_HFROSC && \
73 (CONFIG_USE_CLOCK_HFXOSC_PLL || CONFIG_USE_CLOCK_HFXOSC || \
74 CONFIG_USE_CLOCK_HFROSC_PLL)
75#error "Cannot use HFROSC with other clock configurations"
76#endif
77
78#define CONFIG_CLOCK_PLL_R (1) /* Divide input clock by 2, mandatory with HFXOSC */
79#ifndef CONFIG_CLOCK_PLL_F
80#define CONFIG_CLOCK_PLL_F (39) /* Multiply REFR by 80, e.g 2 * (39 + 1) */
81#endif
82#ifndef CONFIG_CLOCK_PLL_Q
83#define CONFIG_CLOCK_PLL_Q (1) /* Divide VCO by 2, e.g 2^1 */
84#endif
85
86#if CONFIG_USE_CLOCK_HFXOSC_PLL
87#define CLOCK_PLL_INPUT_CLOCK MHZ(16)
88#define CLOCK_PLL_REFR (CLOCK_PLL_INPUT_CLOCK / \
89 (CONFIG_CLOCK_PLL_R + 1))
90#define CLOCK_PLL_VCO (CLOCK_PLL_REFR * \
91 (2 * (CONFIG_CLOCK_PLL_F + 1)))
92#define CLOCK_PLL_OUT (CLOCK_PLL_VCO / \
93 (1 << CONFIG_CLOCK_PLL_Q))
94#define CLOCK_CORECLOCK (CLOCK_PLL_OUT) /* 320000000Hz with the values used above */
95
96/* Check PLL settings */
97#if CLOCK_PLL_REFR != MHZ(8)
98#error "Only R=2 can be used when using HFXOSC"
99#endif
100#if (CLOCK_PLL_VCO < MHZ(384)) || (CLOCK_PLL_VCO > MHZ(768))
101#error \
102 "VCO frequency must be in the range [384MHz - 768MHz], check the CLOCK_PLL_F value"
103#endif
104#if (CLOCK_PLL_OUT < MHZ(48)) || (CLOCK_PLL_OUT > MHZ(384))
105#error \
106 "PLL output frequency must be in the range [48MHz - 384MHz], check the CLOCK_PLL_Q value"
107#endif
108
109#elif CONFIG_USE_CLOCK_HFXOSC
110#define CLOCK_CORECLOCK MHZ(16)
111#endif
112
113/*
114 When using HFROSC input clock, the core clock cannot be computed from settings,
115 in this case, coreclk() returns the configured CPU frequency.
116 */
117#ifndef CONFIG_CLOCK_DESIRED_FREQUENCY
118#define CONFIG_CLOCK_DESIRED_FREQUENCY MHZ(320)
119#endif
120
121#ifndef CONFIG_CLOCK_HFROSC_TRIM
122#define CONFIG_CLOCK_HFROSC_TRIM (6) /* ~72000000Hz input freq */
123#endif
124#ifndef CONFIG_CLOCK_HFROSC_DIV
125#define CONFIG_CLOCK_HFROSC_DIV (1) /* Divide by 2 */
126#endif
128
129#ifdef __cplusplus
130}
131#endif
132
Common macros and compiler attributes/pragmas configuration.
Unit helper macros.