summaryrefslogtreecommitdiff
path: root/boards/mistralRevB/board_memories.c
blob: 9d840b1334c6f03193a5b5152c20a6fd92bcf643 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/* ----------------------------------------------------------------------------
 *         ATMEL Microcontroller Software Support 
 * ----------------------------------------------------------------------------
 * Copyright (c) 2008, Atmel Corporation
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * - Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the disclaimer below.
 *
 * Atmel's name may not be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * ----------------------------------------------------------------------------
 */

//------------------------------------------------------------------------------
//  Title: Memories implementation
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
//         Headers
//------------------------------------------------------------------------------

#include "board.h"
#include "board_memories.h"
#include <pio/pio.h>

//------------------------------------------------------------------------------
//  Macros:
//      READ - Reads a register value. Useful to add trace information to read
//             accesses.
//      WRITE - Writes data in a register. Useful to add trace information to
//              write accesses.
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
//         Internal definitions
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//  Constants: Remap types
//      BOARD_ROM - ROM or EBI CS0 is mirrored in the remap zone.
//      BOARD_RAM - RAM is mirrored in the remap zone.
//------------------------------------------------------------------------------
#define BOARD_ROM               0
#define BOARD_RAM               1

//------------------------------------------------------------------------------
//         Internal function
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
//         Exported functions
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//  Function: BOARD_RemapRom
//      Changes the mapping of the chip so that the remap area mirrors the
//      internal ROM or the EBI CS0.
//------------------------------------------------------------------------------
void BOARD_RemapRom( void )
{
    AT91C_BASE_MATRIX->MATRIX_MRCR = 0;
}

//------------------------------------------------------------------------------
// Function: BOARD_RemapRam
//     Changes the mapping of the chip so that the remap area mirrors the
//     internal RAM.
//------------------------------------------------------------------------------
void BOARD_RemapRam( void )
{
    AT91C_BASE_MATRIX->MATRIX_MRCR = (AT91C_MATRIX_RCA926I | AT91C_MATRIX_RCA926D);
}


//------------------------------------------------------------------------------
// Function: BOARD_ConfigureSdram
//     Initialize and configure the SDRAM
//------------------------------------------------------------------------------
void BOARD_ConfigureSdram(unsigned char busWidth)
{
  unsigned int i;
  volatile unsigned int *pSdram = (unsigned int *) AT91C_EBI0_SDRAM;

  // Program SDRAMC : CAS = 2, 4 banks, row = 12, column = 9 SDRAM 128MB 
  // 133MHz barrette NADIA + 32 bit mode
  AT91C_BASE_SDRAMC0->SDRAMC_CR =   AT91C_SDRAMC_NC_9   
                                  | AT91C_SDRAMC_NR_13
                                  | AT91C_SDRAMC_NB_4_BANKS
                                  | AT91C_SDRAMC_CAS_2
                                  | AT91C_SDRAMC_DBW_32_BITS
                                  | AT91C_SDRAMC_TWR_1
                                  | AT91C_SDRAMC_TRC_1
                                  | AT91C_SDRAMC_TRP_1
                                  | AT91C_SDRAMC_TRCD_1
                                  | AT91C_SDRAMC_TRAS_1
                                  | AT91C_SDRAMC_TXSR_1;

  AT91C_BASE_SDRAMC0->SDRAMC_MDR = AT91C_SDRAMC_MD_SDRAM;

  for (i =0; i< 1000;i++);

  AT91C_BASE_SDRAMC0->SDRAMC_MR = AT91C_SDRAMC_MODE_PRCGALL_CMD; // Set PRCHG AL
  pSdram[0] = 0x00000000;     // Perform PRCHG

  for (i =0; i< 10000;i++);

  AT91C_BASE_SDRAMC0->SDRAMC_MR = AT91C_SDRAMC_MODE_RFSH_CMD;    // Set 1st CBR
  pSdram[0] = 0x00000000;     // Perform CBR

  AT91C_BASE_SDRAMC0->SDRAMC_MR = AT91C_SDRAMC_MODE_RFSH_CMD;    // Set 2 CBR
  pSdram[0] = 0x00000000;     // Perform CBR

  AT91C_BASE_SDRAMC0->SDRAMC_MR = AT91C_SDRAMC_MODE_RFSH_CMD;    // Set 3 CBR
  pSdram[0] = 0x00000000;     // Perform CBR

  AT91C_BASE_SDRAMC0->SDRAMC_MR = AT91C_SDRAMC_MODE_RFSH_CMD;    // Set 4 CBR
  pSdram[0] = 0x00000000;     // Perform CBR

  AT91C_BASE_SDRAMC0->SDRAMC_MR = AT91C_SDRAMC_MODE_RFSH_CMD;    // Set 5 CBR
  pSdram[0] = 0x00000000;     // Perform CBR

  AT91C_BASE_SDRAMC0->SDRAMC_MR = AT91C_SDRAMC_MODE_RFSH_CMD;    // Set 6 CBR
  pSdram[0] = 0x00000000;     // Perform CBR

  AT91C_BASE_SDRAMC0->SDRAMC_MR = AT91C_SDRAMC_MODE_RFSH_CMD;    // Set 7 CBR
  pSdram[0] = 0x00000000;     // Perform CBR

  AT91C_BASE_SDRAMC0->SDRAMC_MR = AT91C_SDRAMC_MODE_RFSH_CMD;    // Set 8 CBR
  pSdram[0] = 0x00000000;     // Perform CBR

  AT91C_BASE_SDRAMC0->SDRAMC_MR = AT91C_SDRAMC_MODE_LMR_CMD;    // Set LMR operation
  pSdram[9] = 0xCAFEDADA; // Perform LMR burst=1, lat=2

  // Set Refresh Timer 390 for 25MHz (TR= 15.6 * F ) : (F : system clock freq. MHz)
  AT91C_BASE_SDRAMC0->SDRAMC_TR = (AT91C_SDRAMC_COUNT & (BOARD_MCK *15)/1000000);

  AT91C_BASE_SDRAMC0->SDRAMC_MR = AT91C_SDRAMC_MODE_NORMAL_CMD;    // Set Normal mode
  pSdram[0] = 0x00000000;     // Perform Normal mode

  AT91C_BASE_SDRAMC0->SDRAMC_HSR = AT91C_SDRAMC_DA_ENABLE;    // Set Decode Cycle NECESAIRE pour NADIA a 22MHz 25aug03

  pSdram[20] = 0xD4C3B2A1; // test

}

personal git repositories of Harald Welte. Your mileage may vary