cpu_clock.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 Gerson Fernando Budke <nandojve@gmail.com>
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
9 #pragma once
10 
26 #include <stdint.h>
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
37 enum {
38  CPU_ATXMEGA_CLK_SCALE_DIV1 = 0,
39  CPU_ATXMEGA_CLK_SCALE_DIV2 = 1,
40  CPU_ATXMEGA_CLK_SCALE_DIV4 = 3,
41  CPU_ATXMEGA_CLK_SCALE_DIV8 = 5,
42  CPU_ATXMEGA_CLK_SCALE_DIV16 = 7,
43  CPU_ATXMEGA_CLK_SCALE_DIV32 = 9,
44  CPU_ATXMEGA_CLK_SCALE_DIV64 = 11,
45  CPU_ATXMEGA_CLK_SCALE_DIV128 = 13,
46  CPU_ATXMEGA_CLK_SCALE_DIV256 = 15,
47  CPU_ATXMEGA_CLK_SCALE_DIV512 = 17,
48 };
49 
50 enum {
51  CPU_ATXMEGA_BUS_SCALE_DIV1_1 = 0,
52  CPU_ATXMEGA_BUS_SCALE_DIV1_2 = 1,
53  CPU_ATXMEGA_BUS_SCALE_DIV4_1 = 2,
54  CPU_ATXMEGA_BUS_SCALE_DIV2_2 = 3,
55 };
56 
60 static inline void atxmega_set_prescaler(uint8_t clk_scale, uint8_t bus_scale)
61 {
62  /* Disable CCP for Protected IO register and set new value
63  * Set system clock prescalers to zero. PSCTRL contains A Prescaler
64  * Value and one value for and B and C Prescaler
65  */
66  _PROTECTED_WRITE(CLK.PSCTRL, clk_scale | bus_scale);
67 }
68 
69 #ifdef __cplusplus
70 }
71 #endif
72 
static void atxmega_set_prescaler(uint8_t clk_scale, uint8_t bus_scale)
Initializes system clock prescaler.
Definition: cpu_clock.h:60