1 |
583 |
jeremybenn |
//-----------------------------------------------------------------------------
|
2 |
|
|
// ATMEL Microcontroller Software Support - ROUSSET -
|
3 |
|
|
//-----------------------------------------------------------------------------
|
4 |
|
|
// DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
5 |
|
|
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
6 |
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
7 |
|
|
// DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
8 |
|
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
9 |
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
10 |
|
|
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
11 |
|
|
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
12 |
|
|
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
13 |
|
|
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
14 |
|
|
//-----------------------------------------------------------------------------
|
15 |
|
|
// File Name : Cstartup_SAM7.c
|
16 |
|
|
// Object : Low level initialisations written in C for Tools
|
17 |
|
|
// For AT91SAM7X256 with 2 flash plane
|
18 |
|
|
// Creation : JPP 14-Sep-2006
|
19 |
|
|
//-----------------------------------------------------------------------------
|
20 |
|
|
|
21 |
|
|
|
22 |
|
|
#include "Board.h"
|
23 |
|
|
// The following functions must be write in ARM mode this function called
|
24 |
|
|
// directly by exception vector
|
25 |
|
|
extern void AT91F_Spurious_handler(void);
|
26 |
|
|
extern void AT91F_Default_IRQ_handler(void);
|
27 |
|
|
extern void AT91F_Default_FIQ_handler(void);
|
28 |
|
|
|
29 |
|
|
//*----------------------------------------------------------------------------
|
30 |
|
|
//* \fn AT91F_LowLevelInit
|
31 |
|
|
//* \brief This function performs very low level HW initialization
|
32 |
|
|
//* this function can use a Stack, depending the compilation
|
33 |
|
|
//* optimization mode
|
34 |
|
|
//*----------------------------------------------------------------------------
|
35 |
|
|
void AT91F_LowLevelInit(void) @ "ICODE"
|
36 |
|
|
{
|
37 |
|
|
unsigned char i;
|
38 |
|
|
///////////////////////////////////////////////////////////////////////////
|
39 |
|
|
// EFC Init
|
40 |
|
|
///////////////////////////////////////////////////////////////////////////
|
41 |
|
|
AT91C_BASE_MC->MC_FMR = AT91C_MC_FWS_1FWS ;
|
42 |
|
|
|
43 |
|
|
///////////////////////////////////////////////////////////////////////////
|
44 |
|
|
// Init PMC Step 1. Enable Main Oscillator
|
45 |
|
|
// Main Oscillator startup time is board specific:
|
46 |
|
|
// Main Oscillator Startup Time worst case (3MHz) corresponds to 15ms
|
47 |
|
|
// (0x40 for AT91C_CKGR_OSCOUNT field)
|
48 |
|
|
///////////////////////////////////////////////////////////////////////////
|
49 |
|
|
AT91C_BASE_PMC->PMC_MOR = (( AT91C_CKGR_OSCOUNT & (0x40 <<8) | AT91C_CKGR_MOSCEN ));
|
50 |
|
|
// Wait Main Oscillator stabilization
|
51 |
|
|
while(!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MOSCS));
|
52 |
|
|
|
53 |
|
|
///////////////////////////////////////////////////////////////////////////
|
54 |
|
|
// Init PMC Step 2.
|
55 |
|
|
// Set PLL to 96MHz (96,109MHz) and UDP Clock to 48MHz
|
56 |
|
|
// PLL Startup time depends on PLL RC filter: worst case is choosen
|
57 |
|
|
// UDP Clock (48,058MHz) is compliant with the Universal Serial Bus
|
58 |
|
|
// Specification (+/- 0.25% for full speed)
|
59 |
|
|
///////////////////////////////////////////////////////////////////////////
|
60 |
|
|
AT91C_BASE_PMC->PMC_PLLR = AT91C_CKGR_USBDIV_1 |
|
61 |
|
|
(16 << 8) |
|
62 |
|
|
(AT91C_CKGR_MUL & (72 << 16)) |
|
63 |
|
|
(AT91C_CKGR_DIV & 14);
|
64 |
|
|
// Wait for PLL stabilization
|
65 |
|
|
while( !(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_LOCK) );
|
66 |
|
|
// Wait until the master clock is established for the case we already
|
67 |
|
|
// turn on the PLL
|
68 |
|
|
while( !(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) );
|
69 |
|
|
|
70 |
|
|
///////////////////////////////////////////////////////////////////////////
|
71 |
|
|
// Init PMC Step 3.
|
72 |
|
|
// Selection of Master Clock MCK equal to (Processor Clock PCK) PLL/2=48MHz
|
73 |
|
|
// The PMC_MCKR register must not be programmed in a single write operation
|
74 |
|
|
// (see. Product Errata Sheet)
|
75 |
|
|
///////////////////////////////////////////////////////////////////////////
|
76 |
|
|
AT91C_BASE_PMC->PMC_MCKR = AT91C_PMC_PRES_CLK_2;
|
77 |
|
|
// Wait until the master clock is established
|
78 |
|
|
while( !(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) );
|
79 |
|
|
|
80 |
|
|
AT91C_BASE_PMC->PMC_MCKR |= AT91C_PMC_CSS_PLL_CLK;
|
81 |
|
|
// Wait until the master clock is established
|
82 |
|
|
while( !(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) );
|
83 |
|
|
|
84 |
|
|
///////////////////////////////////////////////////////////////////////////
|
85 |
|
|
// Disable Watchdog (write once register)
|
86 |
|
|
///////////////////////////////////////////////////////////////////////////
|
87 |
|
|
AT91C_BASE_WDTC->WDTC_WDMR = AT91C_WDTC_WDDIS;
|
88 |
|
|
|
89 |
|
|
///////////////////////////////////////////////////////////////////////////
|
90 |
|
|
// Init AIC: assign corresponding handler for each interrupt source
|
91 |
|
|
///////////////////////////////////////////////////////////////////////////
|
92 |
|
|
AT91C_BASE_AIC->AIC_SVR[0] = (int) AT91F_Default_FIQ_handler ;
|
93 |
|
|
for (i = 1; i < 31; i++) {
|
94 |
|
|
AT91C_BASE_AIC->AIC_SVR[i] = (int) AT91F_Default_IRQ_handler ;
|
95 |
|
|
}
|
96 |
|
|
AT91C_BASE_AIC->AIC_SPU = (unsigned int) AT91F_Spurious_handler;
|
97 |
|
|
}
|