cpu_clock.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de>
3  * 2014 Freie Universität Berlin, Hinnerk van Bruinehsen
4  * 2018 RWTH Aachen, Josua Arndt <jarndt@ias.rwth-aachen.de>
5  * 2021 Gerson Fernando Budke <nandojve@gmail.com>
6  *
7  * This file is subject to the terms and conditions of the GNU Lesser
8  * General Public License v2.1. See the file LICENSE in the top level
9  * directory for more details.
10  */
11 
12 #pragma once
13 
34 #include <stdint.h>
35 
36 #ifdef __cplusplus
37 extern "C"
38 {
39 #endif
40 
46 enum {
47  CPU_ATMEGA_CLK_SCALE_DIV1 = 0,
48  CPU_ATMEGA_CLK_SCALE_DIV2 = 1,
49  CPU_ATMEGA_CLK_SCALE_DIV4 = 2,
50  CPU_ATMEGA_CLK_SCALE_DIV8 = 3,
51  CPU_ATMEGA_CLK_SCALE_DIV16 = 4,
52  CPU_ATMEGA_CLK_SCALE_DIV32 = 5,
53  CPU_ATMEGA_CLK_SCALE_DIV64 = 6,
54  CPU_ATMEGA_CLK_SCALE_DIV128 = 7,
55  CPU_ATMEGA_CLK_SCALE_DIV256 = 8,
56  CPU_ATMEGA_CLK_SCALE_DIV512 = 9,
57 };
58 
62 static inline void atmega_set_prescaler(uint8_t clk_scale)
63 {
64  /* Enable clock change */
65 #ifdef CLKPR
66  /* Must be assignment to set all other bits to zero, see datasheet */
67  CLKPR = (1 << CLKPCE);
68 
69  /* Write clock within 4 cycles */
70  CLKPR = clk_scale;
71 #else
72  (void) clk_scale;
73 #endif
74 }
75 
76 #ifdef __cplusplus
77 }
78 #endif
79 
static void atmega_set_prescaler(uint8_t clk_scale)
Initializes system clock prescaler.
Definition: cpu_clock.h:62