OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [Common/] [drivers/] [Atmel/] [at91lib/] [peripherals/] [rstc/] [rstc.c] - Blame information for rev 608

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 608 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 <board.h>
35
 
36
//-----------------------------------------------------------------------------
37
//         Macros
38
//-----------------------------------------------------------------------------
39
 
40
/// WRITE_RSTC: Write RSTC register
41
#define WRITE_RSTC(pRstc, regName, value) pRstc->regName = (value)
42
 
43
/// READ_RSTC: Read RSTC registers
44
#define READ_RSTC(pRstc, regName) (pRstc->regName)
45
 
46
//-----------------------------------------------------------------------------
47
//         Defines
48
//-----------------------------------------------------------------------------
49
 
50
/// Keywords to write to the reset registers
51
#define RSTC_KEY_PASSWORD       (0xA5UL << 24)
52
 
53
//-----------------------------------------------------------------------------
54
//         Exported functions
55
//-----------------------------------------------------------------------------
56
 
57
//-----------------------------------------------------------------------------
58
/// Configure the mode of the RSTC peripheral.
59
/// The configuration is computed by the lib (AT91C_RSTC_*).
60
/// \param rstc  Pointer to an RSTC peripheral.
61
/// \param rmr Desired mode configuration.
62
//-----------------------------------------------------------------------------
63
void RSTC_ConfigureMode(AT91PS_RSTC rstc, unsigned int rmr)
64
{
65
    rmr &= ~AT91C_RSTC_KEY;
66
    WRITE_RSTC(rstc, RSTC_RMR, rmr | RSTC_KEY_PASSWORD);
67
}
68
 
69
//-----------------------------------------------------------------------------
70
/// Enable/Disable the detection of a low level on the pin NRST as User Reset
71
/// \param rstc   Pointer to an RSTC peripheral.
72
/// \param enable 1 to enable & 0 to disable.
73
//-----------------------------------------------------------------------------
74
void RSTC_SetUserResetEnable(AT91PS_RSTC rstc, unsigned char enable)
75
{
76
    unsigned int rmr = READ_RSTC(rstc, RSTC_RMR) & (~AT91C_RSTC_KEY);
77
    if (enable) {
78
 
79
        rmr |=  AT91C_RSTC_URSTEN;
80
    }
81
    else {
82
 
83
        rmr &= ~AT91C_RSTC_URSTEN;
84
    }
85
    WRITE_RSTC(rstc, RSTC_RMR, rmr | RSTC_KEY_PASSWORD);
86
}
87
 
88
//-----------------------------------------------------------------------------
89
/// Enable/Disable the interrupt of a User Reset (USRTS bit in RSTC_RST).
90
/// \param rstc   Pointer to an RSTC peripheral.
91
/// \param enable 1 to enable & 0 to disable.
92
//-----------------------------------------------------------------------------
93
void RSTC_SetUserResetInterruptEnable(AT91PS_RSTC rstc, unsigned char enable)
94
{
95
    unsigned int rmr = READ_RSTC(rstc, RSTC_RMR) & (~AT91C_RSTC_KEY);
96
    if (enable) {
97
 
98
        rmr |=  AT91C_RSTC_URSTIEN;
99
    }
100
    else {
101
 
102
        rmr &= ~AT91C_RSTC_URSTIEN;
103
    }
104
    WRITE_RSTC(rstc, RSTC_RMR, rmr | RSTC_KEY_PASSWORD);
105
}
106
 
107
//-----------------------------------------------------------------------------
108
/// Setup the external reset length. The length is asserted during a time of
109
/// pow(2, powl+1) Slow Clock(32KHz). The duration is between 60us and 2s.
110
/// \param rstc   Pointer to an RSTC peripheral.
111
/// \param powl   Power length defined.
112
//-----------------------------------------------------------------------------
113
void RSTC_SetExtResetLength(AT91PS_RSTC rstc, unsigned char powl)
114
{
115
    unsigned int rmr = READ_RSTC(rstc, RSTC_RMR);
116
    rmr &= ~(AT91C_RSTC_KEY | AT91C_RSTC_ERSTL);
117
    rmr |=  (powl << 8) & AT91C_RSTC_ERSTL;
118
    WRITE_RSTC(rstc, RSTC_RMR, rmr | RSTC_KEY_PASSWORD);
119
}
120
 
121
 
122
//-----------------------------------------------------------------------------
123
/// Resets the processor.
124
/// \param rstc  Pointer to an RSTC peripheral.
125
//-----------------------------------------------------------------------------
126
void RSTC_ProcessorReset(AT91PS_RSTC rstc)
127
{
128
    WRITE_RSTC(rstc, RSTC_RCR, AT91C_RSTC_PROCRST | RSTC_KEY_PASSWORD);
129
}
130
 
131
//-----------------------------------------------------------------------------
132
/// Resets the peripherals.
133
/// \param rstc  Pointer to an RSTC peripheral.
134
//-----------------------------------------------------------------------------
135
void RSTC_PeripheralReset(AT91PS_RSTC rstc)
136
{
137
    WRITE_RSTC(rstc, RSTC_RCR, AT91C_RSTC_PERRST | RSTC_KEY_PASSWORD);
138
}
139
 
140
//-----------------------------------------------------------------------------
141
/// Asserts the NRST pin for external resets.
142
/// \param rstc  Pointer to an RSTC peripheral.
143
//-----------------------------------------------------------------------------
144
void RSTC_ExtReset(AT91PS_RSTC rstc)
145
{
146
    WRITE_RSTC(rstc, RSTC_RCR, AT91C_RSTC_EXTRST | RSTC_KEY_PASSWORD);
147
}
148
 
149
//-----------------------------------------------------------------------------
150
/// Return NRST pin level ( 1 or 0 ).
151
/// \param rstc  Pointer to an RSTC peripheral.
152
//-----------------------------------------------------------------------------
153
unsigned char RSTC_GetNrstLevel(AT91PS_RSTC rstc)
154
{
155
    if (READ_RSTC(rstc, RSTC_RSR) & AT91C_RSTC_NRSTL) {
156
 
157
        return 1;
158
    }
159
    return 0;
160
}
161
 
162
//-----------------------------------------------------------------------------
163
/// Returns 1 if at least one high-to-low transition of NRST (User Reset) has
164
/// been detected since the last read of RSTC_RSR.
165
/// \param rstc  Pointer to an RSTC peripheral.
166
//-----------------------------------------------------------------------------
167
unsigned char RSTC_IsUserReseetDetected(AT91PS_RSTC rstc)
168
{
169
    if (READ_RSTC(rstc, RSTC_RSR) & AT91C_RSTC_URSTS) {
170
 
171
        return 1;
172
    }
173
    return 0;
174
}
175
 
176
//-----------------------------------------------------------------------------
177
/// Return 1 if a software reset command is being performed by the reset
178
/// controller. The reset controller is busy.
179
/// \param rstc  Pointer to an RSTC peripheral.
180
//-----------------------------------------------------------------------------
181
unsigned char RSTC_IsBusy(AT91PS_RSTC rstc)
182
{
183
    if (READ_RSTC(rstc, RSTC_RSR) & AT91C_RSTC_SRCMP) {
184
 
185
        return 1;
186
    }
187
    return 0;
188
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.