1 |
580 |
jeremybenn |
/* ----------------------------------------------------------------------------
|
2 |
|
|
* ATMEL Microcontroller Software Support
|
3 |
|
|
* ----------------------------------------------------------------------------
|
4 |
|
|
* Copyright (c) 2008, Atmel Corporation
|
5 |
|
|
*
|
6 |
|
|
* All rights reserved.
|
7 |
|
|
*
|
8 |
|
|
* Redistribution and use in source and binary forms, with or without
|
9 |
|
|
* modification, are permitted provided that the following conditions are met:
|
10 |
|
|
*
|
11 |
|
|
* - Redistributions of source code must retain the above copyright notice,
|
12 |
|
|
* this list of conditions and the disclaimer below.
|
13 |
|
|
*
|
14 |
|
|
* Atmel's name may not be used to endorse or promote products derived from
|
15 |
|
|
* this software without specific prior written permission.
|
16 |
|
|
*
|
17 |
|
|
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
18 |
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
19 |
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
20 |
|
|
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
21 |
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 |
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
23 |
|
|
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
24 |
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
25 |
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
26 |
|
|
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27 |
|
|
* ----------------------------------------------------------------------------
|
28 |
|
|
*/
|
29 |
|
|
|
30 |
|
|
//------------------------------------------------------------------------------
|
31 |
|
|
// Headers
|
32 |
|
|
//------------------------------------------------------------------------------
|
33 |
|
|
|
34 |
|
|
#include "rtt.h"
|
35 |
|
|
#include <utility/assert.h>
|
36 |
|
|
|
37 |
|
|
//------------------------------------------------------------------------------
|
38 |
|
|
// Exported functions
|
39 |
|
|
//------------------------------------------------------------------------------
|
40 |
|
|
|
41 |
|
|
//------------------------------------------------------------------------------
|
42 |
|
|
/// Changes the prescaler value of the given RTT and restarts it. This function
|
43 |
|
|
/// disables RTT interrupt sources.
|
44 |
|
|
/// \param rtt Pointer to a AT91S_RTTC instance.
|
45 |
|
|
/// \param prescaler Prescaler value for the RTT.
|
46 |
|
|
//------------------------------------------------------------------------------
|
47 |
|
|
void RTT_SetPrescaler(AT91S_RTTC *rtt, unsigned short prescaler)
|
48 |
|
|
{
|
49 |
|
|
rtt->RTTC_RTMR = (prescaler | AT91C_RTTC_RTTRST);
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
//------------------------------------------------------------------------------
|
53 |
|
|
/// Returns the current value of the RTT timer value.
|
54 |
|
|
/// \param rtt Pointer to a AT91S_RTTC instance.
|
55 |
|
|
//------------------------------------------------------------------------------
|
56 |
|
|
unsigned int RTT_GetTime(AT91S_RTTC *rtt)
|
57 |
|
|
{
|
58 |
|
|
return rtt->RTTC_RTVR;
|
59 |
|
|
}
|
60 |
|
|
|
61 |
|
|
//------------------------------------------------------------------------------
|
62 |
|
|
/// Enables the specified RTT interrupt sources.
|
63 |
|
|
/// \param rtt Pointer to a AT91S_RTTC instance.
|
64 |
|
|
/// \param sources Bitmask of interrupts to enable.
|
65 |
|
|
//------------------------------------------------------------------------------
|
66 |
|
|
void RTT_EnableIT(AT91S_RTTC *rtt, unsigned int sources)
|
67 |
|
|
{
|
68 |
|
|
ASSERT((sources & 0x0004FFFF) == 0,
|
69 |
|
|
"RTT_EnableIT: Wrong sources value.\n\r");
|
70 |
|
|
rtt->RTTC_RTMR |= sources;
|
71 |
|
|
}
|
72 |
|
|
|
73 |
|
|
//------------------------------------------------------------------------------
|
74 |
|
|
/// Returns the status register value of the given RTT.
|
75 |
|
|
/// \param rtt Pointer to an AT91S_RTTC instance.
|
76 |
|
|
//------------------------------------------------------------------------------
|
77 |
|
|
unsigned int RTT_GetStatus(AT91S_RTTC *rtt)
|
78 |
|
|
{
|
79 |
|
|
return rtt->RTTC_RTSR;
|
80 |
|
|
}
|
81 |
|
|
|
82 |
|
|
//------------------------------------------------------------------------------
|
83 |
|
|
/// Configures the RTT to generate an alarm at the given time.
|
84 |
|
|
/// \param pRtt Pointer to an AT91S_RTTC instance.
|
85 |
|
|
/// \param time Alarm time.
|
86 |
|
|
//------------------------------------------------------------------------------
|
87 |
|
|
void RTT_SetAlarm(AT91S_RTTC *pRtt, unsigned int time)
|
88 |
|
|
{
|
89 |
|
|
SANITY_CHECK(time > 0);
|
90 |
|
|
|
91 |
|
|
pRtt->RTTC_RTAR = time - 1;
|
92 |
|
|
}
|
93 |
|
|
|