1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
/* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
/*This file is prepared for Doxygen automatic documentation generation.*/
/*! \file *********************************************************************
*
* \brief RTC driver for AVR32 UC3.
*
* AVR32 Real Time Counter driver module.
*
* - Compiler: GNU GCC for AVR32
* - Supported devices: All AVR32 devices with an RTC and a PM module can be used.
* - AppNote:
*
* \author Atmel Corporation: http://www.atmel.com \n
* Support and FAQ: http://support.atmel.no/
*
******************************************************************************/
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The name of Atmel may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* 4. This software may only be redistributed and used in connection with an Atmel
* AVR product.
*
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*
*/
#ifndef _RTC_H_
#define _RTC_H_
#include "compiler.h"
#include <avr32/io.h>
/*! \name Oscillator Types
*/
//! @{
#define RTC_OSC_32KHZ 1
#define RTC_OSC_RC 0
//! @}
/*! \name Predefined PSEL Values
*/
//! @{
//! The PSEL value to set the RTC source clock (after the prescaler) to 1 Hz,
//! when using an external 32-kHz crystal.
#define RTC_PSEL_32KHZ_1HZ 14
//! The PSEL value to set the RTC source clock (after the prescaler) to 1.76 Hz,
//! when using the internal RC oscillator (~ 115 kHz).
#define RTC_PSEL_RC_1_76HZ 15
//! @}
/*!
* \brief This function will initialise the RTC module.
* If you use the 32 KHz oscillator, it will enable this module.
* This function also set the top value of the RTC to 0xFFFFFFFF
* and the value to 0.
* \param rtc Base address of the RTC (i.e. &AVR32_RTC).
* \param osc_type The oscillator you want to use. If you need a better
* accuracy, use the 32 KHz oscillator (i.e. RTC_OSC_32KHZ).
* \param psel The preselector value for the corresponding oscillator (4-bits).
* To obtain this value, you can use this formula:
* psel = log(Fosc/Frtc)/log(2)-1, where Fosc is the frequency of the
* oscillator you are using (32 KHz or 115 KHz) and Frtc the frequency
* desired.
* \return 1 if the initialisation succeds otherwize it will return 0.
*/
extern int rtc_init(volatile avr32_rtc_t *rtc, unsigned char osc_type, unsigned char psel);
/*!
* \brief Enable the RTC.
* \param rtc Base address of the RTC (i.e. &AVR32_RTC).
*/
extern void rtc_enable(volatile avr32_rtc_t *rtc);
/*!
* \brief Disable the RTC.
* \param rtc Base address of the RTC (i.e. &AVR32_RTC).
*/
extern void rtc_disable(volatile avr32_rtc_t *rtc);
/*!
* \brief Enable the wake up feature of the RTC.
* \param rtc Base address of the RTC (i.e. &AVR32_RTC).
*/
extern void rtc_enable_wake_up(volatile avr32_rtc_t *rtc);
/*!
* \brief Disable the wake up feature of the RTC.
* \param rtc Base address of the RTC (i.e. &AVR32_RTC).
*/
extern void rtc_disable_wake_up(volatile avr32_rtc_t *rtc);
/*!
* \brief Enable the interrupt feature of the RTC.
* An interrupt is raised when the value of the RTC
* is equal to its top value.
* \param rtc Base address of the RTC (i.e. &AVR32_RTC).
*/
extern void rtc_enable_interrupt(volatile avr32_rtc_t *rtc);
/*!
* \brief Disable the interrupt feature of the RTC.
* \param rtc Base address of the RTC (i.e. &AVR32_RTC).
*/
extern void rtc_disable_interrupt(volatile avr32_rtc_t *rtc);
/*!
* \brief Clear the interrupt flag.
* Call this function once you handled the interrupt.
* \param rtc Base address of the RTC (i.e. &AVR32_RTC).
*/
extern void rtc_clear_interrupt(volatile avr32_rtc_t *rtc);
/*!
* \brief Get the status of interrupts.
* \param rtc Base address of the RTC (i.e. &AVR32_RTC).
* \return 1 if the interrupts are enabled otherwize it returns 0.
*/
extern int rtc_interrupt_enabled(volatile avr32_rtc_t *rtc);
/*!
* \brief Check if an interrupt is raised.
* \param rtc Base address of the RTC (i.e. &AVR32_RTC).
* \return 1 if an interrupt is currently raised otherwize it returns 0.
*/
extern int rtc_is_interrupt(volatile avr32_rtc_t *rtc);
/*!
* \brief This function sets the RTC current top value.
* \param rtc Base address of the RTC (i.e. &AVR32_RTC).
* \param top The top value you want to store.
*/
extern void rtc_set_top_value(volatile avr32_rtc_t *rtc, unsigned long top);
/*!
* \brief This function returns the RTC current top value.
* \param rtc Base address of the RTC (i.e. &AVR32_RTC).
* \return The RTC current top value.
*/
extern unsigned long rtc_get_top_value(volatile avr32_rtc_t *rtc);
/*!
* \brief This function checks if the RTC is busy or not.
* \param rtc Base address of the RTC (i.e. &AVR32_RTC).
* \return 1 if the RTC is busy otherwize it will return 0.
*/
extern int rtc_is_busy(volatile avr32_rtc_t *rtc);
/*!
* \brief This function sets the RTC current value.
* \param rtc Base address of the RTC (i.e. &AVR32_RTC).
* \param val The value you want to store.
*/
extern void rtc_set_value(volatile avr32_rtc_t *rtc, unsigned long val);
/*!
* \brief This function returns the RTC current value.
* \param rtc Base address of the RTC (i.e. &AVR32_RTC).
* \return The RTC current value.
*/
extern unsigned long rtc_get_value(volatile avr32_rtc_t *rtc);
#endif // _RTC_H_
|