Project

General

Profile

Download (4.6 KB) Statistics
| Branch: | Revision:

root / fw / boot / at91sam7xx-sram.mac @ 14:d3713e2e39d0

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           : SAM7_RAM.mac
16
//  Object              : Generic Macro File for IAR
17
//  1.0 17/Aug/05 FBr   : Creation
18
//  ----------------------------------------------------------------------------
19

    
20
__var __mac_i;
21
__var __mac_mem;
22
__var __mac_next;
23

    
24
/*********************************************************************
25
*
26
*       _MapFlashAt0()
27
*
28
* Function description
29
*   Maps FLASH at 0.
30
*/
31
_MapFlashAt0(){
32
    __mac_mem =__readMemory32(0x00000000,"Memory");
33
    __mac_i =__mac_mem+1;
34
    __writeMemory32(__mac_i,0x00,"Memory");
35
    __mac_next =__readMemory32(0x00000000,"Memory");
36
    
37
    if (__mac_i == __mac_next) {
38
        __writeMemory32( __mac_mem,0x00000000,"Memory");
39
         __message "Changing mapping: mapping FLASH at 0x0000_0000";
40
        __writeMemory32(0x00000001,0xFFFFFF00,"Memory");
41
        __message "RAM at 0x0000_0000";  
42
    } else {  
43
        __message "Flash is mapped at 0x0000 0000";  
44
    }
45
}
46

    
47
/*********************************************************************
48
*
49
*       _MapRAMAt0()
50
*
51
* Function description
52
*   Maps RAM at 0.
53
*/
54
_MapRAMAt0(){
55
    __message "Changing mapping: RAM mapped to 0";
56
    __writeMemory32(0x00000001,0xFFFFFF00,"Memory");
57
}
58

    
59
/*********************************************************************
60
*
61
*       _InitRSTC()
62
*
63
* Function description
64
*   Initializes the RSTC (Reset controller).
65
*   This makes sense since the default is to not allow user resets, which makes it impossible to
66
*   apply a second RESET via J-Link
67
*/
68
_InitRSTC() {
69
    __writeMemory32(0xA5000001, 0xFFFFFD08,"Memory");    // Allow user reset
70
}
71

    
72

    
73

    
74

    
75
/*********************************************************************
76
*
77
*       _InitPLL()
78
* Function description
79
*   Initializes the PMC.
80
*   1. Enable the Main Oscillator
81
*   2. Configure PLL to 96MHz
82
*   3. Switch Master Clock (MCK) on PLL/2 = 48MHz
83
*/
84
_InitPLL() {
85
    __message "Set Main Oscillator";
86
    __writeMemory32(0x00004001,0xFFFFFc20,"Memory");    // MOSC
87
    while( !(__readMemory32(0xFFFFFc68,"Memory") & 0x1)  );
88

    
89
    __message "Set PLL to 96MHz";
90
    __writeMemory32(0x10483f0e,0xFFFFFc2c,"Memory");    // LOCK
91
    while( !(__readMemory32(0xFFFFFc68,"Memory") & 0x4)  );
92

    
93
    __message "Set Master Clock to 48MHz";
94
    __writeMemory32(0x00000004,0xFFFFFc30,"Memory");    // MCKRDY
95
    while( !(__readMemory32(0xFFFFFc68,"Memory") & 0x8)  );
96
    __writeMemory32(0x00000007,0xFFFFFc30,"Memory");    // MCKRDY
97
    while( !(__readMemory32(0xFFFFFc68,"Memory") & 0x8)  );
98
}
99

    
100
/*********************************************************************
101
*
102
*       execUserReset() : JTAG set initially to Full Speed
103
*/
104
execUserReset() {
105
    __message "execUserReset()";
106
    __hwReset(0);                       // Hardware Reset: CPU is automatically halted after the reset
107
    _InitPLL();                         // Allow to debug at JTAG Full Speed
108
    _MapRAMAt0();                       // Remap FLASH to address 0
109
}
110

    
111
/*********************************************************************
112
*
113
*       execUserPreload() : JTAG set initially to 32kHz
114
*/
115
execUserPreload() {
116
    __message "execUserPreload()";
117
    __hwReset(0);                       // Hardware Reset: CPU is automatically halted after the reset (JTAG is already configured to 32kHz)
118
    _InitPLL();                         // Allow to load Code at JTAG Full Speed
119
   // __initSRAM();
120
    _MapRAMAt0();                       // Remap FLASH to address 0
121
    _InitRSTC();                        // Enable User Reset to allow execUserReset() execution
122
}
(2-2/7)