Loading...
Searching...
No Matches
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
24#ifndef CPU_CLOCK_H
25#define CPU_CLOCK_H
26
27#include <stdint.h>
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
38enum {
39 CPU_ATXMEGA_CLK_SCALE_DIV1 = 0,
40 CPU_ATXMEGA_CLK_SCALE_DIV2 = 1,
41 CPU_ATXMEGA_CLK_SCALE_DIV4 = 3,
42 CPU_ATXMEGA_CLK_SCALE_DIV8 = 5,
43 CPU_ATXMEGA_CLK_SCALE_DIV16 = 7,
44 CPU_ATXMEGA_CLK_SCALE_DIV32 = 9,
45 CPU_ATXMEGA_CLK_SCALE_DIV64 = 11,
46 CPU_ATXMEGA_CLK_SCALE_DIV128 = 13,
47 CPU_ATXMEGA_CLK_SCALE_DIV256 = 15,
48 CPU_ATXMEGA_CLK_SCALE_DIV512 = 17,
49};
50
51enum {
52 CPU_ATXMEGA_BUS_SCALE_DIV1_1 = 0,
53 CPU_ATXMEGA_BUS_SCALE_DIV1_2 = 1,
54 CPU_ATXMEGA_BUS_SCALE_DIV4_1 = 2,
55 CPU_ATXMEGA_BUS_SCALE_DIV2_2 = 3,
56};
57
61static inline void atxmega_set_prescaler(uint8_t clk_scale, uint8_t bus_scale)
62{
63 /* Disable CCP for Protected IO register and set new value
64 * Set system clock prescalers to zero. PSCTRL contains A Prescaler
65 * Value and one value for and B and C Prescaler
66 */
67 _PROTECTED_WRITE(CLK.PSCTRL, clk_scale | bus_scale);
68}
69
70#ifdef __cplusplus
71}
72#endif
73
74#endif /* CPU_CLOCK_H */
static void atxmega_set_prescaler(uint8_t clk_scale, uint8_t bus_scale)
Initializes system clock prescaler.
Definition cpu_clock.h:61