All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
19 #ifndef CLK_CONF_H
20 #define CLK_CONF_H
21 
22 #include "macros/units.h"
23 #include "kernel_defines.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
33 #ifndef CONFIG_USE_CLOCK_HFXOSC_PLL
34 #if IS_ACTIVE(CONFIG_USE_CLOCK_HFXOSC) || \
35  IS_ACTIVE(CONFIG_USE_CLOCK_HFROSC_PLL) || \
36  IS_ACTIVE(CONFIG_USE_CLOCK_HFROSC)
37 #define CONFIG_USE_CLOCK_HFXOSC_PLL 0
38 #else
39 #define CONFIG_USE_CLOCK_HFXOSC_PLL 1 /* Use PLL clocked by HFXOSC by default */
40 #endif
41 #endif /* CONFIG_USE_CLOCK_HFXOSC_PLL */
42 
43 #ifndef CONFIG_USE_CLOCK_HFXOSC
44 #define CONFIG_USE_CLOCK_HFXOSC 0
45 #endif /* CONFIG_USE_CLOCK_HFXOSC */
46 
47 #ifndef CONFIG_USE_CLOCK_HFROSC_PLL
48 #define CONFIG_USE_CLOCK_HFROSC_PLL 0
49 #endif /* CONFIG_USE_CLOCK_HFROSC_PLL */
50 
51 #ifndef CONFIG_USE_CLOCK_HFROSC
52 #define CONFIG_USE_CLOCK_HFROSC 0
53 #endif /* CONFIG_USE_CLOCK_HFROSC */
54 
55 #if CONFIG_USE_CLOCK_HFXOSC_PLL && \
56  (CONFIG_USE_CLOCK_HFROSC_PLL || CONFIG_USE_CLOCK_HFROSC || \
57  CONFIG_USE_CLOCK_HFXOSC)
58 #error "Cannot use HFXOSC_PLL with other clock configurations"
59 #endif
60 
61 #if CONFIG_USE_CLOCK_HFXOSC && \
62  (CONFIG_USE_CLOCK_HFROSC_PLL || CONFIG_USE_CLOCK_HFROSC || \
63  CONFIG_USE_CLOCK_HFXOSC_PLL)
64 #error "Cannot use HFXOSC with other clock configurations"
65 #endif
66 
67 #if CONFIG_USE_CLOCK_HFROSC_PLL && \
68  (CONFIG_USE_CLOCK_HFXOSC_PLL || CONFIG_USE_CLOCK_HFXOSC || \
69  CONFIG_USE_CLOCK_HFROSC)
70 #error "Cannot use HFROSC_PLL with other clock configurations"
71 #endif
72 
73 #if CONFIG_USE_CLOCK_HFROSC && \
74  (CONFIG_USE_CLOCK_HFXOSC_PLL || CONFIG_USE_CLOCK_HFXOSC || \
75  CONFIG_USE_CLOCK_HFROSC_PLL)
76 #error "Cannot use HFROSC with other clock configurations"
77 #endif
78 
79 #define CONFIG_CLOCK_PLL_R (1) /* Divide input clock by 2, mandatory with HFXOSC */
80 #ifndef CONFIG_CLOCK_PLL_F
81 #define CONFIG_CLOCK_PLL_F (39) /* Multiply REFR by 80, e.g 2 * (39 + 1) */
82 #endif
83 #ifndef CONFIG_CLOCK_PLL_Q
84 #define CONFIG_CLOCK_PLL_Q (1) /* Divide VCO by 2, e.g 2^1 */
85 #endif
86 
87 #if CONFIG_USE_CLOCK_HFXOSC_PLL
88 #define CLOCK_PLL_INPUT_CLOCK MHZ(16)
89 #define CLOCK_PLL_REFR (CLOCK_PLL_INPUT_CLOCK / \
90  (CONFIG_CLOCK_PLL_R + 1))
91 #define CLOCK_PLL_VCO (CLOCK_PLL_REFR * \
92  (2 * (CONFIG_CLOCK_PLL_F + 1)))
93 #define CLOCK_PLL_OUT (CLOCK_PLL_VCO / \
94  (1 << CONFIG_CLOCK_PLL_Q))
95 #define CLOCK_CORECLOCK (CLOCK_PLL_OUT) /* 320000000Hz with the values used above */
96 
97 /* Check PLL settings */
98 #if CLOCK_PLL_REFR != MHZ(8)
99 #error "Only R=2 can be used when using HFXOSC"
100 #endif
101 #if (CLOCK_PLL_VCO < MHZ(384)) || (CLOCK_PLL_VCO > MHZ(768))
102 #error \
103  "VCO frequency must be in the range [384MHz - 768MHz], check the CLOCK_PLL_F value"
104 #endif
105 #if (CLOCK_PLL_OUT < MHZ(48)) || (CLOCK_PLL_OUT > MHZ(384))
106 #error \
107  "PLL output frequency must be in the range [48MHz - 384MHz], check the CLOCK_PLL_Q value"
108 #endif
109 
110 #elif CONFIG_USE_CLOCK_HFXOSC
111 #define CLOCK_CORECLOCK MHZ(16)
112 #endif
113 
114 /*
115  When using HFROSC input clock, the core clock cannot be computed from settings,
116  in this case, coreclk() returns the configured CPU frequency.
117  */
118 #ifndef CONFIG_CLOCK_DESIRED_FREQUENCY
119 #define CONFIG_CLOCK_DESIRED_FREQUENCY MHZ(320)
120 #endif
121 
122 #ifndef CONFIG_CLOCK_HFROSC_TRIM
123 #define CONFIG_CLOCK_HFROSC_TRIM (6) /* ~72000000Hz input freq */
124 #endif
125 #ifndef CONFIG_CLOCK_HFROSC_DIV
126 #define CONFIG_CLOCK_HFROSC_DIV (1) /* Divide by 2 */
127 #endif
130 #ifdef __cplusplus
131 }
132 #endif
133 
134 #endif /* CLK_CONF_H */
Common macros and compiler attributes/pragmas configuration.
Unit helper macros.