1 | //-----------------------------------------------------------------------------
|
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 AT91SAM7S with 2 flash plane
|
18 | // Creation : JPP 09-May-2006
|
19 | //-----------------------------------------------------------------------------
|
20 |
|
21 | // slightly modified by Martin Thomas:
|
22 | // - Disable Watchdog first
|
23 | // - project.h -> board.h
|
24 | // - modified parentheses for AT91C_BASE_PMC->PMC_MOR to avoid compiler warning
|
25 |
|
26 | ///// board.h ersetzt
|
27 | // #include "board.h"
|
28 | #define __inline static inline
|
29 | #include "AT91SAM7S256.h"
|
30 | #include "lib_AT91SAM7S256.h"
|
31 |
|
32 | ///// AIC init auskommentiert fuer Beispiel
|
33 | #if 0
|
34 | // The following functions must be write in ARM mode this function called
|
35 | // directly by exception vector
|
36 | extern void AT91F_Spurious_handler(void);
|
37 | extern void AT91F_Default_IRQ_handler(void);
|
38 | extern void AT91F_Default_FIQ_handler(void);
|
39 | #endif
|
40 |
|
41 | //*----------------------------------------------------------------------------
|
42 | //* \fn AT91F_LowLevelInit
|
43 | //* \brief This function performs very low level HW initialization
|
44 | //* this function can use a Stack, depending the compilation
|
45 | //* optimization mode
|
46 | //*----------------------------------------------------------------------------
|
47 | void AT91F_LowLevelInit(void)
|
48 | {
|
49 | unsigned char i;
|
50 |
|
51 | ///////////////////////////////////////////////////////////////////////////
|
52 | // Disable Watchdog (write once register)
|
53 | ///////////////////////////////////////////////////////////////////////////
|
54 | AT91C_BASE_WDTC->WDTC_WDMR = AT91C_WDTC_WDDIS;
|
55 |
|
56 | ///////////////////////////////////////////////////////////////////////////
|
57 | // EFC Init
|
58 | ///////////////////////////////////////////////////////////////////////////
|
59 | AT91C_BASE_MC->MC_FMR = AT91C_MC_FWS_1FWS ;
|
60 |
|
61 | ///////////////////////////////////////////////////////////////////////////
|
62 | // Init PMC Step 1. Enable Main Oscillator
|
63 | // Main Oscillator startup time is board specific:
|
64 | // Main Oscillator Startup Time worst case (3MHz) corresponds to 15ms
|
65 | // (0x40 for AT91C_CKGR_OSCOUNT field)
|
66 | ///////////////////////////////////////////////////////////////////////////
|
67 | AT91C_BASE_PMC->PMC_MOR = ( AT91C_CKGR_OSCOUNT & (0x40 <<8)) | AT91C_CKGR_MOSCEN;
|
68 | // Wait Main Oscillator stabilization
|
69 | while(!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MOSCS));
|
70 |
|
71 | ///////////////////////////////////////////////////////////////////////////
|
72 | // Init PMC Step 2.
|
73 | // Set PLL to 96MHz (96,109MHz) and UDP Clock to 48MHz
|
74 | // PLL Startup time depends on PLL RC filter: worst case is choosen
|
75 | // UDP Clock (48,058MHz) is compliant with the Universal Serial Bus
|
76 | // Specification (+/- 0.25% for full speed)
|
77 | ///////////////////////////////////////////////////////////////////////////
|
78 | AT91C_BASE_PMC->PMC_PLLR = AT91C_CKGR_USBDIV_1 |
|
79 | (16 << 8) |
|
80 | (AT91C_CKGR_MUL & (72 << 16)) |
|
81 | (AT91C_CKGR_DIV & 14);
|
82 | // Wait for PLL stabilization
|
83 | while( !(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_LOCK) );
|
84 | // Wait until the master clock is established for the case we already
|
85 | // turn on the PLL
|
86 | while( !(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) );
|
87 |
|
88 | ///////////////////////////////////////////////////////////////////////////
|
89 | // Init PMC Step 3.
|
90 | // Selection of Master Clock MCK equal to (Processor Clock PCK) PLL/2=48MHz
|
91 | // The PMC_MCKR register must not be programmed in a single write operation
|
92 | // (see. Product Errata Sheet)
|
93 | ///////////////////////////////////////////////////////////////////////////
|
94 | AT91C_BASE_PMC->PMC_MCKR = AT91C_PMC_PRES_CLK_2;
|
95 | // Wait until the master clock is established
|
96 | while( !(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) );
|
97 |
|
98 | AT91C_BASE_PMC->PMC_MCKR |= AT91C_PMC_CSS_PLL_CLK;
|
99 | // Wait until the master clock is established
|
100 | while( !(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) );
|
101 |
|
102 |
|
103 | #if 0
|
104 | ///////////////////////////////////////////////////////////////////////////
|
105 | // Init AIC: assign corresponding handler for each interrupt source
|
106 | ///////////////////////////////////////////////////////////////////////////
|
107 | AT91C_BASE_AIC->AIC_SVR[0] = (int) AT91F_Default_FIQ_handler ;
|
108 | for (i = 1; i < 31; i++) {
|
109 | AT91C_BASE_AIC->AIC_SVR[i] = (int) AT91F_Default_IRQ_handler ;
|
110 | }
|
111 | AT91C_BASE_AIC->AIC_SPU = (unsigned int) AT91F_Spurious_handler;
|
112 | #endif
|
113 | }
|