Toggle navigation
Documentation
The friendly Operating System for the Internet of Things
atmega_regs_common.h
Go to the documentation of this file.
1
/*
2
* SPDX-FileCopyrightText: 2016 Freie Universität Berlin
3
* SPDX-FileCopyrightText: 2016 INRIA
4
* SPDX-FileCopyrightText: 2017 Thomas Perrot <thomas.perrot@tupi.fr>
5
* SPDX-FileCopyrightText: 2023 Hugues Larrive
6
* SPDX-License-Identifier: LGPL-2.1-only
7
*/
8
9
#pragma once
10
25
#include <avr/io.h>
26
#include <avr/power.h>
27
28
#ifdef __cplusplus
29
extern
"C"
{
30
#endif
31
36
#define REG8 volatile uint8_t
37
#define REG16 volatile uint16_t
43
#ifdef TCCR1C
44
typedef
struct
{
45
REG8
CRA;
46
REG8
CRB;
47
REG8
CRC;
48
REG8
reserved;
49
REG16
CNT;
50
REG16
ICR;
51
REG16
OCR[3];
52
}
mega_timer_t
;
53
#else
/* atmega8 */
54
typedef
struct
{
55
REG16
ICR;
56
REG16
OCR[2];
57
REG16
CNT;
58
REG8
CRB
;
59
REG8
CRA
;
60
}
mega_timer_t
;
61
#endif
62
66
typedef
struct
{
67
#if ((defined(TCCR0A) && defined(TCCR0B)) || (defined(TCCR2A) && defined(TCCR2B)))
68
REG8
CRA;
69
REG8
CRB;
70
REG8
CNT;
71
REG8
OCR[2];
72
#elif defined(TCCR2)
73
REG8
OCR;
74
REG8
CNT;
75
REG8
CR;
76
#endif
77
}
mini_timer_t
;
78
82
typedef
struct
{
83
#if defined(UCSR0A) || defined(UCSR1A)
84
REG8
CSRA;
85
REG8
CSRB;
86
REG8
CSRC;
87
#ifdef UCSR1D
/* 32u4 */
88
REG8
CSRD;
89
#else
90
REG8
reserved;
91
#endif
92
REG16
BRR;
93
REG8
DR;
94
#elif defined(UCSRA)
/* atmega8 */
95
REG8
BRRL;
96
REG8
CSRB;
97
REG8
CSRA;
98
REG8
DR;
99
REG8
padding[19];
101
REG8
CSRC;
103
#endif
104
}
mega_uart_t
;
105
110
#if defined(TCCR0A)
111
#define MINI_TIMER0 ((mini_timer_t *)(uint16_t *)(&TCCR0A))
112
#define MINI_TIMER0_DIV TIMER_DIV1_8_64_128_1024
113
#endif
114
115
#if defined(TCCR1C)
116
#define MEGA_TIMER1_BASE (uint16_t *)(&TCCR1A)
117
#define MEGA_TIMER1 ((mega_timer_t *)MEGA_TIMER1_BASE)
118
#elif defined(TCCR1A)
/* atmega8 */
119
#define MEGA_TIMER1_BASE (uint16_t *)(&ICR1L)
120
#define MEGA_TIMER1 ((mega_timer_t *)MEGA_TIMER1_BASE)
121
#endif
122
123
#if defined(TCCR2A)
124
#define MINI_TIMER2 ((mini_timer_t *)(uint16_t *)(&TCCR2A))
125
#define MINI_TIMER2_DIV TIMER_DIV1_8_32_64_128_256_1024
126
#elif defined(TCCR2)
/* atmega8 */
127
#define MINI_TIMER2 ((mini_timer_t *)(uint16_t *)(&OCR2))
128
#define MINI_TIMER2_DIV TIMER_DIV1_8_32_64_128_256_1024
129
#endif
130
131
#if defined(TCCR3A)
132
#define MEGA_TIMER3_BASE (uint16_t *)(&TCCR3A)
133
#define MEGA_TIMER3 ((mega_timer_t *)MEGA_TIMER3_BASE)
134
#endif
135
136
#if defined(TCCR4A)
137
#define MEGA_TIMER4_BASE (uint16_t *)(&TCCR4A)
138
#define MEGA_TIMER4 ((mega_timer_t *)MEGA_TIMER4_BASE)
139
#endif
140
141
#if defined(TCCR5A)
142
#define MEGA_TIMER5_BASE (uint16_t *)(&TCCR5A)
143
#define MEGA_TIMER5 ((mega_timer_t *)MEGA_TIMER5_BASE)
144
#endif
151
#if defined(UCSRA)
152
#define MEGA_UART_BASE ((uint16_t *)(&UBRRL))
153
#define MEGA_UART ((mega_uart_t *)MEGA_UART_BASE)
154
#endif
155
156
#if defined(UCSR0A)
157
#define MEGA_UART0_BASE ((uint16_t *)(&UCSR0A))
158
#define MEGA_UART0 ((mega_uart_t *)MEGA_UART0_BASE)
159
#endif
160
161
#if defined(UCSR1A)
162
#define MEGA_UART1_BASE ((uint16_t *)(&UCSR1A))
163
#define MEGA_UART1 ((mega_uart_t *)MEGA_UART1_BASE)
164
#endif
165
166
#if defined(UCSR2A)
167
#define MEGA_UART2_BASE ((uint16_t *)(&UCSR2A))
168
#define MEGA_UART2 ((mega_uart_t *)MEGA_UART2_BASE)
169
#endif
170
171
#if defined(UCSR3A)
172
#define MEGA_UART3_BASE ((uint16_t *)(&UCSR3A))
173
#define MEGA_UART3 ((mega_uart_t *)MEGA_UART3_BASE)
174
#endif
177
#ifdef __cplusplus
178
}
179
#endif
180
REG8
#define REG8
Register types.
Definition:
atmega_regs_common.h:36
REG16
#define REG16(ADDR)
Type for 16-bit registers.
Definition:
periph_gba.h:36
mega_timer_t
Timer register map.
Definition:
atmega_regs_common.h:54
mega_timer_t::CRA
REG8 CRA
control A
Definition:
atmega_regs_common.h:59
mega_timer_t::CRB
REG8 CRB
control B
Definition:
atmega_regs_common.h:58
mega_uart_t
UART register map.
Definition:
atmega_regs_common.h:82
mini_timer_t
8-bit timer register map
Definition:
atmega_regs_common.h:66
Generated on Sat Sep 6 2025 20:14:01 by
1.9.1