1 /* ----------------------------------------------------------------------------
\r
2 * SAM Software Package License
\r
3 * ----------------------------------------------------------------------------
\r
4 * Copyright (c) 2012, 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
33 * Provides the low-level initialization function that called on chip startup.
\r
36 /*----------------------------------------------------------------------------
\r
38 *----------------------------------------------------------------------------*/
\r
42 /*----------------------------------------------------------------------------
\r
43 * Internal functions
\r
44 *----------------------------------------------------------------------------*/
\r
46 * \brief Default spurious interrupt handler. Infinite loop.
\r
48 void defaultSpuriousHandler( void )
\r
54 * \brief Default handler for fast interrupt requests. Infinite loop.
\r
56 void defaultFiqHandler( void )
\r
62 * \brief Default handler for standard interrupt requests. Infinite loop.
\r
64 void defaultIrqHandler( void )
\r
70 * \brief Performs the low-level initialization of the chip.
\r
71 * This includes EFC and master clock configuration.
\r
72 * It also enable a low level on the pin NRST triggers a user reset.
\r
74 extern WEAK void LowLevelInit( void )
\r
77 if ((uint32_t)LowLevelInit < DDR_CS_ADDR) /* Code not in external mem */ {
\r
78 PMC_SelectExt12M_Osc();
\r
79 PMC_SwitchMck2Main();
\r
80 PMC_SetPllA( CKGR_PLLAR_STUCKTO1 |
\r
81 CKGR_PLLAR_PLLACOUNT(0x3F) |
\r
82 CKGR_PLLAR_OUTA(0x0) |
\r
83 CKGR_PLLAR_MULA(65) |
\r
84 CKGR_PLLAR_DIVA(1),
\r
86 PMC_SetMckPllaDiv(PMC_MCKR_PLLADIV2_DIV2);
\r
87 PMC_SetMckPrescaler(PMC_MCKR_PRES_CLOCK);
\r
88 PMC_SetMckDivider(PMC_MCKR_MDIV_PCK_DIV3);
\r
89 PMC_SwitchMck2Pll();
\r
94 /* Configure PCK1 to measure MCK */
\r
95 PIOD->PIO_IDR = (1<<31);
\r
96 abcdsr = PIOD->PIO_ABCDSR[0];
\r
97 PIOD->PIO_ABCDSR[0] = ((1<<31) | abcdsr);
\r
98 abcdsr = PIOD->PIO_ABCDSR[1];
\r
99 PIOD->PIO_ABCDSR[1] &= (~(1<<31) & abcdsr);
\r
100 PIOD->PIO_PDR = (1<<31);
\r
102 /* Disable programmable clock 1 output */
\r
103 REG_PMC_SCDR = PMC_SCER_PCK1;
\r
104 /* Enable the DAC master clock */
\r
105 PMC->PMC_PCK[1] = PMC_PCK_CSS_MCK_CLK | PMC_PCK_PRES_CLOCK;
\r
106 /* Enable programmable clock 1 output */
\r
107 REG_PMC_SCER = PMC_SCER_PCK1;
\r
108 /* Wait for the PCKRDY1 bit to be set in the PMC_SR register*/
\r
109 while ((REG_PMC_SR & PMC_SR_PCKRDY1) == 0);
\r
113 AIC->AIC_SVR = (unsigned int) defaultFiqHandler;
\r
115 for (i = 1; i < 31; i++)
\r
118 AIC->AIC_SVR = (unsigned int) defaultIrqHandler;
\r
121 AIC->AIC_SPU = (unsigned int) defaultSpuriousHandler;
\r
123 /* Disable all interrupts */
\r
124 for (i = 1; i < 31; i++)
\r
127 AIC->AIC_IDCR = 1 ;
\r
129 /* Clear All pending interrupts flags */
\r
130 for (i = 1; i < 31; i++)
\r
133 AIC->AIC_ICCR = 1 ;
\r
135 /* Perform 8 IT acknoledge (write any value in EOICR) */
\r
136 for (i = 0; i < 8 ; i++)
\r
138 AIC->AIC_EOICR = 0;
\r