1 /* ----------------------------------------------------------------------------
\r
2 * SAM Software Package License
\r
3 * ----------------------------------------------------------------------------
\r
4 * Copyright (c) 2011, Atmel Corporation
\r
6 * All rights reserved.
\r
8 * Redistribution and use in source and binary forms, with or without
\r
9 * modification, are permitted provided that the following conditions are met:
\r
11 * - Redistributions of source code must retain the above copyright notice,
\r
12 * this list of conditions and the disclaimer below.
\r
14 * Atmel's name may not be used to endorse or promote products derived from
\r
15 * this software without specific prior written permission.
\r
17 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
\r
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
\r
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
\r
20 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
\r
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
\r
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
\r
23 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
\r
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
\r
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
\r
26 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
27 * ----------------------------------------------------------------------------
\r
30 /** \addtogroup rtt_module Working with RTT
\r
31 * \ingroup peripherals_module
\r
32 * The RTT driver provides the interface to configure and use the RTT
\r
35 * The Real-time Timer is used to count elapsed seconds.\n
\r
36 * This timer is clocked by the 32kHz system clock divided by a programmable
\r
37 * 16-bit balue. To be accurate, it is better to use an
\r
38 * external 32kHz crystal instead of the internal 32kHz RC.\n
\r
40 * To count elapsed seconds, the user could follow these few steps:
\r
42 * <li>Programming PTPRES in RTT_MR to feeding the timer with a 1Hz signal.</li>
\r
43 * <li>Writing the bit RTTRST in RTT_MR to restart the timer with new settings.</li>
\r
46 * An alarm can be set to happen on second by setting alarm value in RTT_AR.
\r
47 * Alarm occurence can be detected by polling or interrupt.
\r
49 * For more accurate information, please look at the RTT section of the
\r
62 * Implementation of Real Time Timer (RTT) controller.
\r
66 /*----------------------------------------------------------------------------
\r
68 *----------------------------------------------------------------------------*/
\r
73 /*----------------------------------------------------------------------------
\r
74 * Exported functions
\r
75 *----------------------------------------------------------------------------*/
\r
78 * \brief Changes the prescaler value of the given RTT and restarts it.
\r
80 * \note This function disables RTT interrupt sources.
\r
82 * \param rtt Pointer to a Rtt instance.
\r
83 * \param prescaler Prescaler value for the RTT.
\r
85 void RTT_SetPrescaler(Rtt *rtt, uint16_t prescaler)
\r
87 rtt->RTT_MR = (prescaler | RTT_MR_RTTRST);
\r
91 * \brief Returns the current value of the RTT timer value.
\r
93 * \param rtt Pointer to a Rtt instance.
\r
95 uint32_t RTT_GetTime(Rtt *rtt)
\r
101 * \brief Enables the specified RTT interrupt sources.
\r
103 * \param rtt Pointer to a Rtt instance.
\r
104 * \param sources Bitmask of interrupts to enable.
\r
106 void RTT_EnableIT(Rtt *rtt, uint32_t sources)
\r
108 assert( (sources & 0x0004FFFF) == 0 ) ;
\r
109 rtt->RTT_MR |= sources;
\r
113 * \brief Returns the status register value of the given RTT.
\r
115 * \param rtt Pointer to an Rtt instance.
\r
117 uint32_t RTT_GetStatus(Rtt *rtt)
\r
119 return rtt->RTT_SR;
\r
123 * \brief Configures the RTT to generate an alarm at the given time.
\r
125 * \param pRtt Pointer to an Rtt instance.
\r
126 * \param time Alarm time.
\r
128 void RTT_SetAlarm(Rtt *pRtt, uint32_t time)
\r
132 pRtt->RTT_AR = time - 1;
\r