Project

General

Profile

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

root / fw / boot / board_memories.c @ 14:d3713e2e39d0

1
/* ----------------------------------------------------------------------------
2
 *         ATMEL Microcontroller Software Support 
3
 * ----------------------------------------------------------------------------
4
 * Copyright (c) 2008, Atmel Corporation
5
 *
6
 * All rights reserved.
7
 *
8
 * Redistribution and use in source and binary forms, with or without
9
 * modification, are permitted provided that the following conditions are met:
10
 *
11
 * - Redistributions of source code must retain the above copyright notice,
12
 * this list of conditions and the disclaimer below.
13
 *
14
 * Atmel's name may not be used to endorse or promote products derived from
15
 * this software without specific prior written permission.
16
 *
17
 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
20
 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23
 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 * ----------------------------------------------------------------------------
28
 */
29

    
30
//------------------------------------------------------------------------------
31
//         Headers
32
//------------------------------------------------------------------------------
33

    
34
#include "board_memories.h"
35
#include "board.h"
36

    
37
//------------------------------------------------------------------------------
38
//         Internal definitions
39
//------------------------------------------------------------------------------
40

    
41
/// \internal Flash is mirrored in the remap zone.
42
#define BOARD_FLASH             0
43

    
44
/// \internal RAM is mirrored in the remap zone.
45
#define BOARD_RAM               1
46

    
47
//------------------------------------------------------------------------------
48
//         Internal function
49
//------------------------------------------------------------------------------
50
//------------------------------------------------------------------------------
51
/// Returns the current remap, either BOARD_FLASH or BOARD_RAM.
52
//------------------------------------------------------------------------------
53
static unsigned char BOARD_GetRemap( void )
54
{
55
    unsigned int *remap = (unsigned int *) 0;
56
    unsigned int *ram = (unsigned int *) AT91C_ISRAM;
57

    
58
    // Try to write in 0 and see if this affects the RAM
59
    unsigned int temp = *ram;
60
    *ram = temp + 1;
61
    if (*remap == *ram) {
62

    
63
        *ram = temp;
64
        return BOARD_RAM;
65
    }
66
    else {
67

    
68
        *ram = temp;
69
        return BOARD_FLASH;
70
    }
71
}
72

    
73
//------------------------------------------------------------------------------
74
//         Exported functions
75
//------------------------------------------------------------------------------
76
//------------------------------------------------------------------------------
77
/// Changes the mapping of the chip so that the remap area mirrors the
78
/// internal flash.
79
//------------------------------------------------------------------------------
80
void BOARD_RemapFlash( void )
81
{
82
    if (BOARD_GetRemap() != BOARD_FLASH) {
83

    
84
        AT91C_BASE_MC->MC_RCR = AT91C_MC_RCB;
85
    }
86
}
87

    
88
//------------------------------------------------------------------------------
89
/// Changes the mapping of the chip so that the remap area mirrors the
90
/// internal RAM.
91
//------------------------------------------------------------------------------
92
void BOARD_RemapRam( void )
93
{
94
    if (BOARD_GetRemap() != BOARD_RAM) {
95

    
96
        AT91C_BASE_MC->MC_RCR = AT91C_MC_RCB;
97
    }
98
}
99

    
(6-6/7)