1 |
577 |
jeremybenn |
// ---------------------------------------------------------
|
2 |
|
|
// ATMEL Microcontroller Software Support - ROUSSET -
|
3 |
|
|
// ---------------------------------------------------------
|
4 |
|
|
// The software is delivered "AS IS" without warranty or
|
5 |
|
|
// condition of any kind, either express, implied or
|
6 |
|
|
// statutory. This includes without limitation any warranty
|
7 |
|
|
// or condition with respect to merchantability or fitness
|
8 |
|
|
// for any particular purpose, or against the infringements of
|
9 |
|
|
// intellectual property rights of others.
|
10 |
|
|
// ---------------------------------------------------------
|
11 |
|
|
// File: SAM9XE_SRAM.mac
|
12 |
|
|
// User setup file for CSPY debugger.
|
13 |
|
|
// 1.1 08/Aug/06 jpp : Creation
|
14 |
|
|
//
|
15 |
|
|
// $Revision: 2 $
|
16 |
|
|
//
|
17 |
|
|
// ---------------------------------------------------------
|
18 |
|
|
__var __mac_i;
|
19 |
|
|
__var __mac_pt;
|
20 |
|
|
|
21 |
|
|
/*********************************************************************
|
22 |
|
|
*
|
23 |
|
|
* execUserReset() : JTAG set initially to Full Speed
|
24 |
|
|
*/
|
25 |
|
|
execUserReset()
|
26 |
|
|
{
|
27 |
|
|
__message "------------------------------ execUserReset ---------------------------------";
|
28 |
|
|
_MapRAMAt0(); //* Set the RAM memory at 0x00200000 & 0x00000000
|
29 |
|
|
__PllSetting(); //* Init PLL
|
30 |
|
|
__PllSetting100MHz();
|
31 |
|
|
__message "-------------------------------Set PC Reset ----------------------------------";
|
32 |
|
|
}
|
33 |
|
|
|
34 |
|
|
/*********************************************************************
|
35 |
|
|
*
|
36 |
|
|
* execUserPreload() : JTAG set initially to 32kHz
|
37 |
|
|
*/
|
38 |
|
|
execUserPreload()
|
39 |
|
|
{
|
40 |
|
|
__message "------------------------------ execUserPreload ---------------------------------";
|
41 |
|
|
__hwReset(0); //* Hardware Reset: CPU is automatically halted after the reset (JTAG is already configured to 32kHz)
|
42 |
|
|
__writeMemory32(0xD3,0x98,"Register"); //* Set CPSR
|
43 |
|
|
__PllSetting(); //* Init PLL
|
44 |
|
|
__PllSetting100MHz();
|
45 |
|
|
_MapRAMAt0(); //* Set the RAM memory at 0x0020 0000 & 0x0000 0000
|
46 |
|
|
_InitRSTC(); //* Enable User Reset to allow execUserReset() execution
|
47 |
|
|
}
|
48 |
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
|
|
/*********************************************************************
|
52 |
|
|
*
|
53 |
|
|
* _InitRSTC()
|
54 |
|
|
*
|
55 |
|
|
* Function description
|
56 |
|
|
* Initializes the RSTC (Reset controller).
|
57 |
|
|
* This makes sense since the default is to not allow user resets, which makes it impossible to
|
58 |
|
|
* apply a second RESET via J-Link
|
59 |
|
|
*/
|
60 |
|
|
_InitRSTC() {
|
61 |
|
|
__writeMemory32(0xA5000001, 0xFFFFFD08,"Memory"); // Allow user reset
|
62 |
|
|
}
|
63 |
|
|
|
64 |
|
|
|
65 |
|
|
|
66 |
|
|
/*********************************************************************
|
67 |
|
|
*
|
68 |
|
|
* _MapRAMAt0()
|
69 |
|
|
* Function description
|
70 |
|
|
* Remap RAM at 0
|
71 |
|
|
*/
|
72 |
|
|
_MapRAMAt0()
|
73 |
|
|
{
|
74 |
|
|
// AT91C_MATRIX_MRCR ((AT91_REG *) 0xFFFFEF00) // (MATRIX) Master Remp Control Register
|
75 |
|
|
__mac_i=__readMemory32(0xFFFFEF00,"Memory");
|
76 |
|
|
__message "----- AT91C_MATRIX_MRCR : 0x",__mac_i:%X;
|
77 |
|
|
|
78 |
|
|
if ( ((__mac_i & 0x01) == 0) || ((__mac_i & 0x02) == 0)){
|
79 |
|
|
__message "------------------------------- The Remap is NOT & REMAP ----------------------------";
|
80 |
|
|
__writeMemory32(0x00000003,0xFFFFEF00,"Memory");
|
81 |
|
|
__mac_i=__readMemory32(0xFFFFEF00,"Memory");
|
82 |
|
|
__message "----- AT91C_MATRIX_MRCR : 0x",__mac_i:%X;
|
83 |
|
|
} else {
|
84 |
|
|
__message "------------------------------- The Remap is done -----------------------------------";
|
85 |
|
|
}
|
86 |
|
|
}
|
87 |
|
|
|
88 |
|
|
|
89 |
|
|
/*********************************************************************
|
90 |
|
|
*
|
91 |
|
|
* __PllSetting()
|
92 |
|
|
* Function description
|
93 |
|
|
* Initializes the PMC.
|
94 |
|
|
* 1. Enable the Main Oscillator
|
95 |
|
|
* 2. Configure PLL
|
96 |
|
|
* 3. Switch Master
|
97 |
|
|
*/
|
98 |
|
|
__PllSetting()
|
99 |
|
|
{
|
100 |
|
|
if ((__readMemory32(0xFFFFFC30,"Memory")&0x3) != 0 ) {
|
101 |
|
|
//* Disable all PMC interrupt ( $$ JPP)
|
102 |
|
|
//* AT91C_PMC_IDR ((AT91_REG *) 0xFFFFFC64) //(PMC) Interrupt Disable Register
|
103 |
|
|
//* pPmc->PMC_IDR = 0xFFFFFFFF;
|
104 |
|
|
__writeMemory32(0xFFFFFFFF,0xFFFFFC64,"Memory");
|
105 |
|
|
//* AT91C_PMC_PCDR ((AT91_REG *) 0xFFFFFC14) //(PMC) Peripheral Clock Disable Register
|
106 |
|
|
__writeMemory32(0xFFFFFFFF,0xFFFFFC14,"Memory");
|
107 |
|
|
// Disable all clock only Processor clock is enabled.
|
108 |
|
|
__writeMemory32(0xFFFFFFFE,0xFFFFFC04,"Memory");
|
109 |
|
|
|
110 |
|
|
// AT91C_PMC_MCKR ((AT91_REG *) 0xFFFFFC30) // (PMC) Master Clock Register
|
111 |
|
|
__writeMemory32(0x00000001,0xFFFFFC30,"Memory");
|
112 |
|
|
__sleep(10000);
|
113 |
|
|
|
114 |
|
|
// write reset value to PLLA and PLLB
|
115 |
|
|
// AT91C_PMC_PLLAR ((AT91_REG *) 0xFFFFFC28) // (PMC) PLL A Register
|
116 |
|
|
__writeMemory32(0x00003F00,0xFFFFFC28,"Memory");
|
117 |
|
|
|
118 |
|
|
// AT91C_PMC_PLLBR ((AT91_REG *) 0xFFFFFC2C) // (PMC) PLL B Register
|
119 |
|
|
__writeMemory32(0x00003F00,0xFFFFFC2C,"Memory");
|
120 |
|
|
__sleep(10000);
|
121 |
|
|
|
122 |
|
|
__message "------------------------------- PLL Enable -----------------------------------------";
|
123 |
|
|
} else {
|
124 |
|
|
__message " ********* Core in SLOW CLOCK mode ********* "; }
|
125 |
|
|
}
|
126 |
|
|
|
127 |
|
|
|
128 |
|
|
/*********************************************************************
|
129 |
|
|
*
|
130 |
|
|
* __PllSetting100MHz()
|
131 |
|
|
* Function description
|
132 |
|
|
* Set core at 200 MHz and MCK at 100 MHz
|
133 |
|
|
*/
|
134 |
|
|
__PllSetting100MHz()
|
135 |
|
|
{
|
136 |
|
|
|
137 |
|
|
__message "------------------------------- PLL Set at 100 MHz ----------------------------------";
|
138 |
|
|
|
139 |
|
|
//* pPmc->PMC_MOR = (( AT91C_CKGR_OSCOUNT & (0x40 <<8) | AT91C_CKGR_MOSCEN ));
|
140 |
|
|
__writeMemory32(0x00004001,0xFFFFFC20,"Memory");
|
141 |
|
|
__sleep(10000);
|
142 |
|
|
// AT91C_PMC_MCKR ((AT91_REG *) 0xFFFFFC30) // (PMC) Master Clock Register
|
143 |
|
|
__writeMemory32(0x00000001,0xFFFFFC30,"Memory");
|
144 |
|
|
__sleep(10000);
|
145 |
|
|
//* AT91C_BASE_CKGR->CKGR_PLLAR = (AT91C_CKGR_SRCA | ((96 << 16) & AT91C_CKGR_MULA) |
|
146 |
|
|
// (AT91C_CKGR_PLLACOUNT | (AT91C_CKGR_OUTA_0 | (9);
|
147 |
|
|
__writeMemory32(0x2060BF09,0xFFFFFC28,"Memory");
|
148 |
|
|
__sleep(10000);
|
149 |
|
|
//* AT91C_BASE_PMC->PMC_MCKR = AT91C_PMC_CSS_PLLA_CLK | AT91C_PMC_PRES_CLK | AT91C_PMC_MDIV_2;;
|
150 |
|
|
__writeMemory32(0x00000102,0xFFFFFC30,"Memory");
|
151 |
|
|
__sleep(10000);
|
152 |
|
|
|
153 |
|
|
}
|
154 |
|
|
|