1 | void LowLevelInit(void)
|
2 | {
|
3 | int i;
|
4 | AT91PS_PMC pPMC = AT91C_BASE_PMC;
|
5 |
|
6 | //* Set Flash Wait sate
|
7 | // Single Cycle Access at Up to 30 MHz, or 40
|
8 | // if MCK = 48054841 I have 50 Cycle for 1 usecond ( flied MC_FMR->FMCN
|
9 | AT91C_BASE_MC->MC_FMR = ((AT91C_MC_FMCN)&(50 <<16)) | AT91C_MC_FWS_1FWS;
|
10 |
|
11 | //* Watchdog Disable
|
12 | AT91C_BASE_WDTC->WDTC_WDMR= AT91C_WDTC_WDDIS;
|
13 |
|
14 | //* Set MCK at 48 054 841
|
15 | // 1 Enabling the Main Oscillator:
|
16 | // SCK = 1/32768 = 30.51 uSecond
|
17 | // Start up time = 8 * 6 / SCK = 56 * 30.51 = 1,46484375 ms
|
18 | pPMC->PMC_MOR = (( AT91C_CKGR_OSCOUNT & (0x09 <<8) | AT91C_CKGR_MOSCEN ));
|
19 |
|
20 | // Wait the startup time
|
21 | while(!(pPMC->PMC_SR & AT91C_PMC_MOSCS));
|
22 |
|
23 | // PMC Clock Generator PLL Register setup
|
24 | //
|
25 | // The following settings are used: DIV = 14
|
26 | // MUL = 72
|
27 | // PLLCOUNT = 10
|
28 | //
|
29 | // Main Clock (MAINCK from crystal oscillator) = 18432000 hz (see AT91SAM7-EK schematic)
|
30 | // MAINCK / DIV = 18432000/14 = 1316571 hz
|
31 | // PLLCK = 1316571 * (MUL + 1) = 1316571 * (72 + 1) = 1316571 * 73 = 96109683 hz
|
32 | //
|
33 | // PLLCOUNT = number of slow clock cycles before the LOCK bit is set
|
34 | // in PMC_SR after CKGR_PLLR is written.
|
35 | //
|
36 | // PLLCOUNT = 10
|
37 | //
|
38 | // OUT = 0 (not used)
|
39 |
|
40 | // 16 MHz * (5+1) / 1 = 96 MHz
|
41 |
|
42 | pPMC->PMC_PLLR = ((AT91C_CKGR_DIV & 1) | // 14
|
43 | (AT91C_CKGR_PLLCOUNT & (10<<8)) | // 10
|
44 | (AT91C_CKGR_MUL & (5<<16))); // 72
|
45 |
|
46 | // Wait the startup time (until PMC Status register LOCK bit is set)
|
47 | while(!(pPMC->PMC_SR & AT91C_PMC_LOCK));
|
48 |
|
49 | // PMC Master Clock (MCK) Register setup
|
50 | //
|
51 | // CSS = 3 (PLLCK clock selected)
|
52 | //
|
53 | // PRES = 1 (MCK = PLLCK / 2) = 96109683/2 = 48054841 hz
|
54 | //
|
55 | // Note: Master Clock MCK = 48054841 hz (this is the CPU clock speed)
|
56 | pPMC->PMC_MCKR = AT91C_PMC_CSS_PLL_CLK | AT91C_PMC_PRES_CLK_2;
|
57 |
|
58 | // Set up the default interrupts handler vectors
|
59 | AT91C_BASE_AIC->AIC_SVR[0] = (int) AT91F_Default_FIQ_handler;
|
60 | for (i=1;i < 31; i++)
|
61 | {
|
62 | AT91C_BASE_AIC->AIC_SVR[i] = (int) AT91F_Default_IRQ_handler;
|
63 | }
|
64 | AT91C_BASE_AIC->AIC_SPU = (int) AT91F_Spurious_handler;
|
65 |
|
66 | }
|