OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [Common/] [drivers/] [Atmel/] [at91lib/] [boards/] [at91sam9xe-ek/] [board_lowlevel.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
#include "board_memories.h"
36
 
37
//------------------------------------------------------------------------------
38
//         Local definitions
39
//------------------------------------------------------------------------------
40
 
41
//------------------------------------------------------------------------------
42
/// \page "SAM9XE - Oscillator & PLL Parameters"
43
/// This page lists the parameters which are set for the PLL and main
44
/// oscillator configuration.
45
///
46
/// !Parameters
47
/// - BOARD_OSCOUNT
48
/// - BOARD_CKGR_PLLA
49
/// - BOARD_PLLACOUNT
50
/// - BOARD_MULA
51
/// - BOARD_DIVA
52
/// - BOARD_CKGR_PLLB
53
/// - BOARD_PLLBCOUNT
54
/// - BOARD_MULB
55
/// - BOARD_DIVB
56
/// - BOARD_USBDIV
57
/// - BOARD_PRESCALER
58
 
59
/// Main oscillator startup time (in number of slow clock ticks). 
60
#define BOARD_OSCOUNT           (AT91C_CKGR_OSCOUNT & (64 << 8))
61
 
62
/// PLLA frequency range.
63
#define BOARD_CKGR_PLLA         (AT91C_CKGR_SRCA | AT91C_CKGR_OUTA_2)
64
/// PLLA startup time (in number of slow clock ticks).
65
#define BOARD_PLLACOUNT         (63 << 8)
66
/// PLLA MUL value.
67
#define BOARD_MULA              (AT91C_CKGR_MULA & (96 << 16))
68
/// PLLA DIV value.
69
#define BOARD_DIVA              (AT91C_CKGR_DIVA & 9)
70
 
71
/// PLLB frequency range
72
#define BOARD_CKGR_PLLB         AT91C_CKGR_OUTB_1
73
/// PLLB startup time (in number of slow clock ticks).
74
#define BOARD_PLLBCOUNT         BOARD_PLLACOUNT
75
/// PLLB MUL value.
76
#define BOARD_MULB              (124 << 16)
77
/// PLLB DIV value.
78
#define BOARD_DIVB              12
79
 
80
/// USB PLL divisor value to obtain a 48MHz clock.
81
#define BOARD_USBDIV            AT91C_CKGR_USBDIV_2
82
/// Master clock prescaler value.
83
#define BOARD_PRESCALER         AT91C_PMC_MDIV_2
84
//------------------------------------------------------------------------------
85
 
86
//------------------------------------------------------------------------------
87
//         Local functions
88
//------------------------------------------------------------------------------
89
 
90
//------------------------------------------------------------------------------
91
/// Default spurious interrupt handler
92
//------------------------------------------------------------------------------
93
void DefaultSpuriousHandler(void)
94
{
95
    while (1);
96
}
97
 
98
//------------------------------------------------------------------------------
99
/// Default handler for fast interrupt requests.
100
//------------------------------------------------------------------------------
101
void DefaultFiqHandler(void)
102
{
103
    while (1);
104
}
105
 
106
//------------------------------------------------------------------------------
107
/// Default handler for standard interrupt requests.
108
//------------------------------------------------------------------------------
109
void DefaultIrqHandler(void)
110
{
111
    while (1);
112
}
113
 
114
//------------------------------------------------------------------------------
115
//         Global functions
116
//------------------------------------------------------------------------------
117
 
118
//------------------------------------------------------------------------------
119
/// Performs the low-level initialization of the chip.
120
//------------------------------------------------------------------------------
121
void LowLevelInit(void)
122
{
123
    unsigned char i;
124
 
125
    // Set flash wait states
126
    //----------------------
127
    AT91C_BASE_EFC->EFC_FMR = 6 << 8;
128
 
129
//#if !defined(sdram)
130
    // Initialize main oscillator
131
    //---------------------------
132
    AT91C_BASE_PMC->PMC_MOR = BOARD_OSCOUNT | AT91C_CKGR_MOSCEN;
133
    while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MOSCS));
134
 
135
    // Initialize PLLA at 200MHz (198.656)
136
    AT91C_BASE_PMC->PMC_PLLAR = BOARD_CKGR_PLLA
137
                                | BOARD_PLLACOUNT
138
                                | BOARD_MULA
139
                                | BOARD_DIVA;
140
    while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_LOCKA));
141
 
142
    // Initialize PLLB for USB usage
143
    AT91C_BASE_PMC->PMC_PLLBR = BOARD_USBDIV
144
                                | BOARD_CKGR_PLLB
145
                                | BOARD_PLLBCOUNT
146
                                | BOARD_MULB
147
                                | BOARD_DIVB;
148
    while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_LOCKB));
149
 
150
    // Wait for the master clock if it was already initialized
151
    while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY));
152
 
153
    // Switch to fast clock
154
    //---------------------
155
    // Switch to main oscillator + prescaler
156
    AT91C_BASE_PMC->PMC_MCKR = BOARD_PRESCALER;
157
    while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY));
158
 
159
    // Switch to PLL + prescaler
160
    AT91C_BASE_PMC->PMC_MCKR |= AT91C_PMC_CSS_PLLA_CLK;
161
    while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY));
162
//#endif //#if !defined(sdram)
163
 
164
    // Initialize AIC
165
    //---------------
166
    AT91C_BASE_AIC->AIC_IDCR = 0xFFFFFFFF;
167
    AT91C_BASE_AIC->AIC_SVR[0] = (unsigned int) DefaultFiqHandler;
168
    for (i = 1; i < 31; i++) {
169
 
170
        AT91C_BASE_AIC->AIC_SVR[i] = (unsigned int) DefaultIrqHandler;
171
    }
172
    AT91C_BASE_AIC->AIC_SPU = (unsigned int) DefaultSpuriousHandler;
173
 
174
    // Unstack nested interrupts
175
    for (i = 0; i < 8 ; i++) {
176
 
177
        AT91C_BASE_AIC->AIC_EOICR = 0;
178
    }
179
 
180
    // Watchdog initialization
181
    //------------------------
182
    AT91C_BASE_WDTC->WDTC_WDMR = AT91C_WDTC_WDDIS;
183
 
184
    // Remap
185
    //------
186
    BOARD_RemapRam();
187
 
188
    // Disable RTT and PIT interrupts (potential problem when program A
189
    // configures RTT, then program B wants to use PIT only, interrupts
190
    // from the RTT will still occur since they both use AT91C_ID_SYS)
191
    AT91C_BASE_RTTC->RTTC_RTMR &= ~(AT91C_RTTC_ALMIEN | AT91C_RTTC_RTTINCIEN);
192
    AT91C_BASE_PITC->PITC_PIMR &= ~AT91C_PITC_PITIEN;
193
}
194
 

powered by: WebSVN 2.1.0

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