All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
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
32#ifndef CPU_CLOCK_H
33#define CPU_CLOCK_H
34
35#include <stdint.h>
36
37#ifdef __cplusplus
38extern "C"
39{
40#endif
41
47enum {
48 CPU_ATMEGA_CLK_SCALE_DIV1 = 0,
49 CPU_ATMEGA_CLK_SCALE_DIV2 = 1,
50 CPU_ATMEGA_CLK_SCALE_DIV4 = 2,
51 CPU_ATMEGA_CLK_SCALE_DIV8 = 3,
52 CPU_ATMEGA_CLK_SCALE_DIV16 = 4,
53 CPU_ATMEGA_CLK_SCALE_DIV32 = 5,
54 CPU_ATMEGA_CLK_SCALE_DIV64 = 6,
55 CPU_ATMEGA_CLK_SCALE_DIV128 = 7,
56 CPU_ATMEGA_CLK_SCALE_DIV256 = 8,
57 CPU_ATMEGA_CLK_SCALE_DIV512 = 9,
58};
59
63static inline void atmega_set_prescaler(uint8_t clk_scale)
64{
65 /* Enable clock change */
66#ifdef CLKPR
67 /* Must be assignment to set all other bits to zero, see datasheet */
68 CLKPR = (1 << CLKPCE);
69
70 /* Write clock within 4 cycles */
71 CLKPR = clk_scale;
72#else
73 (void) clk_scale;
74#endif
75}
76
77#ifdef __cplusplus
78}
79#endif
80
81#endif /* CPU_CLOCK_H */
static void atmega_set_prescaler(uint8_t clk_scale)
Initializes system clock prescaler.
Definition cpu_clock.h:63