1
|
//*----------------------------------------------------------------------------
|
2
|
//* ATMEL Microcontroller Software Support - ROUSSET -
|
3
|
//*----------------------------------------------------------------------------
|
4
|
//* The software is delivered "AS IS" without warranty or condition of any
|
5
|
//* kind, either express, implied or statutory. This includes without
|
6
|
//* limitation any warranty or condition with respect to merchantability or
|
7
|
//* fitness for any particular purpose, or against the infringements of
|
8
|
//* intellectual property rights of others.
|
9
|
//*----------------------------------------------------------------------------
|
10
|
//* File Name : Cstartup_SAM7.c
|
11
|
//* Object : Low level initializations written in C for IAR
|
12
|
//* tools
|
13
|
//* 1.0 08/Sep/04 JPP : Creation
|
14
|
//* 1.10 10/Sep/04 JPP : Update AT91C_CKGR_PLLCOUNT filed
|
15
|
//*----------------------------------------------------------------------------
|
16
|
|
17
|
|
18
|
// Include the board file description
|
19
|
#include <board.h>
|
20
|
// For memcpy
|
21
|
#include <string.h>
|
22
|
|
23
|
//*----------------------------------------------------------------------------
|
24
|
//* \fn AT91F_LowLevelInit
|
25
|
//* \brief This function performs very low level HW initialization
|
26
|
//* this function can be use a Stack, depending the compilation
|
27
|
//* optimization mode
|
28
|
//*----------------------------------------------------------------------------
|
29
|
void AT91F_LowLevelInit (void)
|
30
|
{
|
31
|
AT91PS_PMC pPMC = AT91C_BASE_PMC;
|
32
|
|
33
|
//* Set flash wait state
|
34
|
// Single Cycle Access at Up to 30 MHz, or 40
|
35
|
// if MCK = 47923200 I have 50 Cycle for 1 useconde ( flied MC_FMR->FMCN
|
36
|
AT91C_BASE_MC->MC_FMR = ((AT91C_MC_FMCN) & (75 << 16)) | AT91C_MC_FWS_1FWS;
|
37
|
|
38
|
//* Watchdog Enable
|
39
|
AT91C_BASE_WDTC->WDTC_WDMR = (0x180 << 16) | AT91C_WDTC_WDRSTEN | 0x180;
|
40
|
//AT91C_BASE_WDTC->WDTC_WDMR = 0x8000;
|
41
|
|
42
|
//* Set MCK at 47 923 200
|
43
|
// 1 Enabling the Main Oscillator:
|
44
|
// SCK = 1/32768 = 30.51 uSeconde
|
45
|
// Start up time = 8 * 6 / SCK = 56 * 30.51 = 1,46484375 ms
|
46
|
pPMC->PMC_MOR = (((AT91C_CKGR_OSCOUNT & (0x06 << 8)) | AT91C_CKGR_MOSCEN));
|
47
|
// Wait the startup time
|
48
|
|
49
|
while (!(pPMC->PMC_SR & AT91C_PMC_MOSCS));
|
50
|
// 2 Checking the Main Oscillator Frequency (Optional)
|
51
|
// 3 Setting PLL and divider:
|
52
|
// - div by 5 Fin = 3,6864 =(18,432 / 5)
|
53
|
// - Mul 25+1: Fout = 95,8464 =(3,6864 *26)
|
54
|
// for 96 MHz the erroe is 0.16%
|
55
|
//eld out NOT USED = 0 Fi
|
56
|
pPMC->PMC_PLLR = ((AT91C_CKGR_DIV & 5) |
|
57
|
(AT91C_CKGR_PLLCOUNT & (28 << 8)) |
|
58
|
(AT91C_CKGR_MUL & (25 << 16)));
|
59
|
|
60
|
// Wait the startup time
|
61
|
while (!(pPMC->PMC_SR & AT91C_PMC_LOCK));
|
62
|
|
63
|
// 4. Selection of Master Clock and Processor Clock
|
64
|
// select the PLL clock divided by 2
|
65
|
pPMC->PMC_MCKR = AT91C_PMC_PRES_CLK_2;
|
66
|
while (!(pPMC->PMC_SR & AT91C_PMC_MCKRDY));
|
67
|
|
68
|
pPMC->PMC_MCKR |= AT91C_PMC_CSS_PLL_CLK;
|
69
|
while (!(pPMC->PMC_SR & AT91C_PMC_MCKRDY));
|
70
|
|
71
|
/* Copy first 0x200 bytes (IRQ vector table and FIQ) to RAM */
|
72
|
memcpy((void*)0x00200000, (void*)0x00100000, 0x200);
|
73
|
/* Perform remap FIXME doesn't work*/
|
74
|
// AT91C_BASE_MC->MC_RCR = AT91C_MC_RCB;
|
75
|
}
|