1 /* ----------------------------------------------------------------------------
\r
2 * ATMEL Microcontroller Software Support
\r
3 * ----------------------------------------------------------------------------
\r
4 * Copyright (c) 2008, 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 //-----------------------------------------------------------------------------
\r
32 //-----------------------------------------------------------------------------
\r
36 //-----------------------------------------------------------------------------
\r
38 //-----------------------------------------------------------------------------
\r
40 /// WRITE_RSTC: Write RSTC register
\r
41 #define WRITE_RSTC(pRstc, regName, value) pRstc->regName = (value)
\r
43 /// READ_RSTC: Read RSTC registers
\r
44 #define READ_RSTC(pRstc, regName) (pRstc->regName)
\r
46 //-----------------------------------------------------------------------------
\r
48 //-----------------------------------------------------------------------------
\r
50 /// Keywords to write to the reset registers
\r
51 #define RSTC_KEY_PASSWORD (0xA5UL << 24)
\r
53 //-----------------------------------------------------------------------------
\r
54 // Exported functions
\r
55 //-----------------------------------------------------------------------------
\r
57 //-----------------------------------------------------------------------------
\r
58 /// Configure the mode of the RSTC peripheral.
\r
59 /// The configuration is computed by the lib (AT91C_RSTC_*).
\r
60 /// \param rstc Pointer to an RSTC peripheral.
\r
61 /// \param rmr Desired mode configuration.
\r
62 //-----------------------------------------------------------------------------
\r
63 void RSTC_ConfigureMode(AT91PS_RSTC rstc, unsigned int rmr)
\r
65 rmr &= ~AT91C_RSTC_KEY;
\r
66 WRITE_RSTC(rstc, RSTC_RMR, rmr | RSTC_KEY_PASSWORD);
\r
69 //-----------------------------------------------------------------------------
\r
70 /// Enable/Disable the detection of a low level on the pin NRST as User Reset
\r
71 /// \param rstc Pointer to an RSTC peripheral.
\r
72 /// \param enable 1 to enable & 0 to disable.
\r
73 //-----------------------------------------------------------------------------
\r
74 void RSTC_SetUserResetEnable(AT91PS_RSTC rstc, unsigned char enable)
\r
76 unsigned int rmr = READ_RSTC(rstc, RSTC_RMR) & (~AT91C_RSTC_KEY);
\r
79 rmr |= AT91C_RSTC_URSTEN;
\r
83 rmr &= ~AT91C_RSTC_URSTEN;
\r
85 WRITE_RSTC(rstc, RSTC_RMR, rmr | RSTC_KEY_PASSWORD);
\r
88 //-----------------------------------------------------------------------------
\r
89 /// Enable/Disable the interrupt of a User Reset (USRTS bit in RSTC_RST).
\r
90 /// \param rstc Pointer to an RSTC peripheral.
\r
91 /// \param enable 1 to enable & 0 to disable.
\r
92 //-----------------------------------------------------------------------------
\r
93 void RSTC_SetUserResetInterruptEnable(AT91PS_RSTC rstc, unsigned char enable)
\r
95 unsigned int rmr = READ_RSTC(rstc, RSTC_RMR) & (~AT91C_RSTC_KEY);
\r
98 rmr |= AT91C_RSTC_URSTIEN;
\r
102 rmr &= ~AT91C_RSTC_URSTIEN;
\r
104 WRITE_RSTC(rstc, RSTC_RMR, rmr | RSTC_KEY_PASSWORD);
\r
107 //-----------------------------------------------------------------------------
\r
108 /// Setup the external reset length. The length is asserted during a time of
\r
109 /// pow(2, powl+1) Slow Clock(32KHz). The duration is between 60us and 2s.
\r
110 /// \param rstc Pointer to an RSTC peripheral.
\r
111 /// \param powl Power length defined.
\r
112 //-----------------------------------------------------------------------------
\r
113 void RSTC_SetExtResetLength(AT91PS_RSTC rstc, unsigned char powl)
\r
115 unsigned int rmr = READ_RSTC(rstc, RSTC_RMR);
\r
116 rmr &= ~(AT91C_RSTC_KEY | AT91C_RSTC_ERSTL);
\r
117 rmr |= (powl << 8) & AT91C_RSTC_ERSTL;
\r
118 WRITE_RSTC(rstc, RSTC_RMR, rmr | RSTC_KEY_PASSWORD);
\r
122 //-----------------------------------------------------------------------------
\r
123 /// Resets the processor.
\r
124 /// \param rstc Pointer to an RSTC peripheral.
\r
125 //-----------------------------------------------------------------------------
\r
126 void RSTC_ProcessorReset(AT91PS_RSTC rstc)
\r
128 WRITE_RSTC(rstc, RSTC_RCR, AT91C_RSTC_PROCRST | RSTC_KEY_PASSWORD);
\r
131 //-----------------------------------------------------------------------------
\r
132 /// Resets the peripherals.
\r
133 /// \param rstc Pointer to an RSTC peripheral.
\r
134 //-----------------------------------------------------------------------------
\r
135 void RSTC_PeripheralReset(AT91PS_RSTC rstc)
\r
137 WRITE_RSTC(rstc, RSTC_RCR, AT91C_RSTC_PERRST | RSTC_KEY_PASSWORD);
\r
140 //-----------------------------------------------------------------------------
\r
141 /// Asserts the NRST pin for external resets.
\r
142 /// \param rstc Pointer to an RSTC peripheral.
\r
143 //-----------------------------------------------------------------------------
\r
144 void RSTC_ExtReset(AT91PS_RSTC rstc)
\r
146 WRITE_RSTC(rstc, RSTC_RCR, AT91C_RSTC_EXTRST | RSTC_KEY_PASSWORD);
\r
149 //-----------------------------------------------------------------------------
\r
150 /// Return NRST pin level ( 1 or 0 ).
\r
151 /// \param rstc Pointer to an RSTC peripheral.
\r
152 //-----------------------------------------------------------------------------
\r
153 unsigned char RSTC_GetNrstLevel(AT91PS_RSTC rstc)
\r
155 if (READ_RSTC(rstc, RSTC_RSR) & AT91C_RSTC_NRSTL) {
\r
162 //-----------------------------------------------------------------------------
\r
163 /// Returns 1 if at least one high-to-low transition of NRST (User Reset) has
\r
164 /// been detected since the last read of RSTC_RSR.
\r
165 /// \param rstc Pointer to an RSTC peripheral.
\r
166 //-----------------------------------------------------------------------------
\r
167 unsigned char RSTC_IsUserReseetDetected(AT91PS_RSTC rstc)
\r
169 if (READ_RSTC(rstc, RSTC_RSR) & AT91C_RSTC_URSTS) {
\r
176 //-----------------------------------------------------------------------------
\r
177 /// Return 1 if a software reset command is being performed by the reset
\r
178 /// controller. The reset controller is busy.
\r
179 /// \param rstc Pointer to an RSTC peripheral.
\r
180 //-----------------------------------------------------------------------------
\r
181 unsigned char RSTC_IsBusy(AT91PS_RSTC rstc)
\r
183 if (READ_RSTC(rstc, RSTC_RSR) & AT91C_RSTC_SRCMP) {
\r