Xmega IEC60730 Class B Library
1.0
All
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Groups
Pages
classb_rtc_common.h
Go to the documentation of this file.
1
/* This file has been prepared for Doxygen automatic documentation generation.*/
2
/**
3
* \file
4
*
5
* \brief Settings for the RTC driver.
6
*
7
* \par Application note:
8
* AVR1610: Guide to IEC60730 Class B compliance with XMEGA
9
*
10
* \par Documentation
11
* For comprehensive code documentation, supported compilers, compiler
12
* settings and supported devices see readme.html
13
*
14
* \author
15
* Atmel Corporation: http://www.atmel.com \n
16
* Support email: avr@atmel.com
17
*
18
* Copyright (C) 2012 Atmel Corporation. All rights reserved.
19
*
20
* \page License
21
*
22
* Redistribution and use in source and binary forms, with or without
23
* modification, are permitted provided that the following conditions are met:
24
*
25
* 1. Redistributions of source code must retain the above copyright notice,
26
* this list of conditions and the following disclaimer.
27
*
28
* 2. Redistributions in binary form must reproduce the above copyright notice,
29
* this list of conditions and the following disclaimer in the documentation
30
* and/or other materials provided with the distribution.
31
*
32
* 3. The name of Atmel may not be used to endorse or promote products derived
33
* from this software without specific prior written permission.
34
*
35
* 4. This software may only be redistributed and used in connection with an
36
* Atmel AVR product.
37
*
38
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
39
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
40
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
41
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
42
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
43
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
44
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
45
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
46
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
47
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
48
* DAMAGE.
49
*/
50
51
#ifndef CLASSB_RTC_COMMON_H
52
#define CLASSB_RTC_COMMON_H
53
54
#include "
avr_compiler.h
"
55
#include "
error_handler.h
"
56
57
58
//! \defgroup rtc_driver Real Time Counter Driver
59
//!
60
//! \brief This is a basic driver for the Real Time Counter (RTC).
61
//!
62
//! The RTC is used to generate interrupts periodically for both the CPU frequency
63
//! and the interrupt self-diagnostic routines. Depending on the specific device,
64
//! an RTC or an RTC32 will be used. In both cases the RTC is clocked independently
65
//! from the CPU with a 32.768 kHz oscillator scaled down to 1024 Hz.
66
//!
67
//! The interrupt period can be configured in the driver through \ref CLASSB_RTC_INT_PERIOD.
68
//! Further, the RTC module is setup with \ref classb_rtc_setup(). Note that interrupts
69
//! should be enabled in the main application with \c sei().
70
//!
71
//! Note that it is possible to use a different RTC driver. The only requirement is
72
//! that it defines the constants for the interrupt period \ref CLASSB_RTC_INT_PERIOD and the
73
//! RTC frequency \ref CLASSB_RTC_FREQ.
74
//!
75
//!
76
//@{
77
78
//! \name RTC Settings and Class B Interface.
79
//!
80
//! \brief Settings and RTC information.
81
//!
82
//! These two constants give information about the RTC to the Class B tests. Therefore, they need
83
//! to be defined with correct values. As long as these are defined, any RTC driver can be used.
84
//!
85
//@{
86
87
/**
88
* \brief RTC interrupt period.
89
*
90
* This constant is used to configure the period of the RTC compare interrupt. In addition, it is
91
* used in the Class B tests. An example value is \c 2048UL.
92
*
93
* \note This is a 16- or 32-bit value depending on the RTC hardware module.
94
*/
95
#define CLASSB_RTC_INT_PERIOD 2048UL
96
97
/**
98
* \brief RTC frequency.
99
100
* This gives information to the Class B tests. However, the RTC frequency is hard coded in this
101
* driver to 1024 Hz. More details in \ref classb_rtc_setup().
102
*/
103
#define CLASSB_RTC_FREQ 1024UL
104
105
//@}
106
107
#ifdef __DOXYGEN__
108
//! \name Test declarations.
109
//!
110
//! \brief Set which Class B tests are included in the RTC interrupt.
111
//!
112
//! These symbols can be defined at the compiler level or in this file.
113
//@{
114
//! \brief Test for the CPU frequency.
115
#define CLASSB_FREQ_TEST
116
//! \brief Interrupt monitor.
117
#define CLASSB_INT_MON
118
//@}
119
#else
120
//#define CLASSB_FREQ_TEST
121
//#define CLASSB_INT_MON
122
#endif
123
124
125
// Include header files for the callbacks in the RTC interrupt.
126
#ifdef CLASSB_FREQ_TEST
127
# include "
classb_freq.h
"
128
#endif
129
#ifdef CLASSB_INT_MON
130
# include "
classb_interrupt_monitor.h
"
131
#endif
132
133
134
// Workaround for missing CNT, PER and COMP in device header files.
135
#ifdef RTC32
136
#ifdef __ICCAVR__
137
# define _DWORDREGISTER DWORDREGISTER
138
#endif
139
140
typedef
struct
RTC32_struct2 {
141
register8_t CTRL;
142
register8_t SYNCCTRL;
143
register8_t INTCTRL;
144
register8_t INTFLAGS;
145
_DWORDREGISTER(CNT);
146
_DWORDREGISTER(PER);
147
_DWORDREGISTER(COMP);
148
} RTC32_t2;
149
150
#undef RTC32
151
#define RTC32 (*(RTC32_t2 *)0x0420)
152
#endif
153
154
155
//! \internal \name Compatibility with RTC and RTC32.
156
//! Depending on the XMEGA device there will be a 16- or 32-bits RTC.
157
//! To make this transparent we define the following constants.
158
//@{
159
#if defined(RTC32) || defined(__DOXYGEN__)
160
//! \internal \brief Name of the RTC module.
161
#define RTC_TEST RTC32
162
//! \internal \brief Bit mask used to start RTC.
163
#define RTC_TEST_START_bm RTC32_ENABLE_bm
164
//! \internal \brief Compare interrupt level group configuration
165
#define RTC_TEST_COMPINTLVL_LO_gc RTC32_COMPINTLVL_LO_gc
166
//! \internal \brief Compare interrupt disable group configuration
167
#define RTC_TEST_COMPINTLVL_OFF_gc RTC32_COMPINTLVL_OFF_gc
168
//! \internal \brief Compare interrupt flag bit mask
169
#define RTC_TEST_COMPIF_bm RTC32_COMPIF_bm
170
//! \internal \brief Compare interrupt vector
171
#define RTC_TEST_COMP_vect RTC32_COMP_vect
172
//! \internal \brief Overflow Interrupt Flag bit mask
173
#define RTC_TEST_OVFIF_bm RTC32_OVFIF_bm
174
#else
175
#define RTC_TEST RTC
176
#define RTC_TEST_START_bm RTC_PRESCALER_DIV1_gc
177
#define RTC_TEST_COMPINTLVL_LO_gc RTC_COMPINTLVL_LO_gc
178
#define RTC_TEST_COMPINTLVL_OFF_gc RTC_COMPINTLVL_OFF_gc
179
#define RTC_TEST_COMPIF_bm RTC_COMPIF_bm
180
#define RTC_TEST_COMP_vect RTC_COMP_vect
181
#define RTC_TEST_OVFIF_bm RTC_OVFIF_bm
182
#endif
183
184
185
186
187
188
//! \name Functions
189
//@{
190
void
classb_rtc_setup
();
191
void
vbat_init(
void
);
192
bool
rtc_is_busy(
void
);
193
//@}
194
195
196
//@}
197
198
#endif //CLASSB_RTC_COMMON_H
tests
classb_rtc_common.h
Generated by
1.8.1