OpenCores
URL https://opencores.org/ocsvn/plasma/plasma/trunk

Subversion Repositories plasma

[/] [plasma/] [trunk/] [tools/] [ddr_init.c] - Blame information for rev 411

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 268 rhoads
/*--------------------------------------------------------------------
2
 * TITLE: Plasma DDR Initialization
3
 * AUTHOR: Steve Rhoads (rhoadss@yahoo.com)
4
 * DATE CREATED: 12/17/05
5
 * FILENAME: ddr_init.c
6
 * PROJECT: Plasma CPU core
7
 * COPYRIGHT: Software placed into the public domain by the author.
8
 *    Software 'as is' without warranty.  Author liable for nothing.
9
 * DESCRIPTION:
10
 *    Plasma DDR Initialization
11 348 rhoads
 *    Supports 64MB (512Mb) MT46V32M16 by default.
12
 *    For 32 MB and 128 MB DDR parts change AddressLines and Bank shift:
13
 *    For 32 MB change 13->12 and 11->10.  MT46V16M16
14
 *    For 128 MB change 13->14 and 11->12. MT46V64M16
15 268 rhoads
 *--------------------------------------------------------------------*/
16
#define DDR_BASE 0x10000000
17
#define MemoryRead(A) (*(volatile int*)(A))
18
#define MemoryWrite(A,V) *(volatile int*)(A)=(V)
19
 
20 336 rhoads
extern int putchar(int value);
21 268 rhoads
extern int puts(const char *string);
22
extern void print_hex(unsigned long num);
23
 
24
//SD_A  <= address_reg(25 downto 13);  --address row
25
//SD_BA <= address_reg(12 downto 11);  --bank_address
26
//cmd   := address_reg(6 downto 4);    --bits RAS & CAS & WE
27
int DdrInitData[] = {
28
// AddressLines    Bank        Command
29
   (0x000 << 13) | (0 << 11) | (7 << 4),  //CKE=1; NOP="111"
30
   (0x400 << 13) | (0 << 11) | (2 << 4),  //A10=1; PRECHARGE ALL="010"
31
#ifndef DLL_DISABLE
32
   (0x000 << 13) | (1 << 11) | (0 << 4),  //enable DLL; BA="01"; LMR="000"
33
#else
34
   (0x001 << 13) | (1 << 11) | (0 << 4),  //disable DLL; BA="01"; LMR="000"
35
#endif
36
   (0x121 << 13) | (0 << 11) | (0 << 4),  //reset DLL, CL=2, BL=2; LMR="000"
37
   (0x400 << 13) | (0 << 11) | (2 << 4),  //A10=1; PRECHARGE ALL="010" 
38
   (0x000 << 13) | (0 << 11) | (1 << 4),  //AUTO REFRESH="001"
39
   (0x000 << 13) | (0 << 11) | (1 << 4),  //AUTO REFRESH="001
40
   (0x021 << 13) | (0 << 11) | (0 << 4)   //clear DLL, CL=2, BL=2; LMR="000"
41
};
42
 
43
int DdrInit(void)
44
{
45
   int i, j, k=0;
46
   for(i = 0; i < sizeof(DdrInitData)/sizeof(int); ++i)
47
   {
48
      MemoryWrite(DDR_BASE + DdrInitData[i], 0);
49
      for(j = 0; j < 4; ++j)
50
         ++k;
51
   }
52
   for(j = 0; j < 100; ++j)
53
      ++k;
54
   k += MemoryRead(DDR_BASE);  //Enable DDR
55
   return k;
56
}
57
 
58
#ifdef DDR_TEST_MAIN
59
int main()
60
{
61
   volatile int *ptr = (int*)DDR_BASE;
62
   int i;
63
 
64
   DdrInit();
65
 
66
   ptr[0] = 0x12345678;
67
   if(ptr[0] != 0x12345678)
68
      putchar('X');
69
   for(i = 0; i < 10; ++i)
70
   {
71
      ptr[i] = i;
72
   }
73
 
74
   for(i = 0; i < 10; ++i)
75
   {
76
      if(ptr[i] != i)
77
         putchar('A' + i);
78
   }
79
   *(unsigned char*)DDR_BASE = 0x23;
80
   *(unsigned char*)(DDR_BASE+1) = 0x45;
81
   *(unsigned char*)(DDR_BASE+2) = 0x67;
82
   *(unsigned char*)(DDR_BASE+3) = 0x89;
83
   if(ptr[0] != 0x23456789)
84
      putchar('Y');
85
   puts("\r\ndone\r\n");
86
   return 0;
87
}
88
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.