OSDN Git Service

Added env script.
[kozos-expbrd/kozos_expbrd.git] / firm / hwtest / 02 / bootload / dram.c
1 #include "defines.h"
2 #include "lib.h"
3 #include "dram.h"
4
5 #define H8_3069F_ABWCR  ((volatile uint8 *)0xfee020)
6 #define H8_3069F_ASTCR  ((volatile uint8 *)0xfee021)
7 #define H8_3069F_RTCOR  ((volatile uint8 *)0xfee02a)
8 #define H8_3069F_RTMCSR ((volatile uint8 *)0xfee028)
9 #define H8_3069F_DRCRB  ((volatile uint8 *)0xfee027)
10 #define H8_3069F_DRCRA  ((volatile uint8 *)0xfee026)
11
12 #define H8_3069F_P1DDR  ((volatile uint8 *)0xfee000)
13 #define H8_3069F_P2DDR  ((volatile uint8 *)0xfee001)
14 #define H8_3069F_P8DDR  ((volatile uint8 *)0xfee007)
15 #define H8_3069F_PBDDR  ((volatile uint8 *)0xfee00a)
16
17 #define H8_3069F_WCRH   ((volatile uint8 *)0xfee022)
18 #define H8_3069F_WCRL   ((volatile uint8 *)0xfee023)
19
20 typedef struct {
21   union {
22     volatile uint8  val8[4];
23     volatile uint16 val16[2];
24     volatile uint32 val32[1];
25   } u;
26 } val_t;
27
28 int dram_init()
29 {
30   /*
31    * dram_check2()¤Ç¥Á¥§¥Ã¥¯¤·¤¿¤é¡¤Ãͤò¤¦¤Þ¤¯ÊÝ»ý¤Ç¤­¤Ê¤¤¥Ó¥Ã¥È¤¬Â¸ºß¤·¤¿
32    * ¤Î¤Ç¡¤¥ê¥Õ¥ì¥Ã¥·¥å¥ì¡¼¥È¤ò¾å¤²¤¿¤é²ò¾Ã¤µ¤ì¤¿¡¥(¥¦¥¨¥¤¥È¤ò¿¤á¤Ë¤·¤Æ¤â
33    * ¸ú²Ì¤Ï̵¤«¤Ã¤¿)
34    * ¤È¤ê¤¢¤¨¤º¡¤¥ê¥Õ¥ì¥Ã¥·¥å¥ì¡¼¥È¹â¤á¤ÎÀßÄê¤Ë¤·¤Æ¤ª¤¯¡¥
35    */
36
37   *H8_3069F_ABWCR  = 0xff;
38 #if 0
39   *H8_3069F_RTCOR  = 0x07;
40 #else
41   *H8_3069F_RTCOR  = 0x03; /* ¥ê¥Õ¥ì¥Ã¥·¥å¼þ´ü¤òû¤á¤ËÀßÄê */
42 #endif
43 #if 1
44   *H8_3069F_RTMCSR = 0x37;
45 #else
46   *H8_3069F_RTMCSR = 0x2f; /* ¥ê¥Õ¥ì¥Ã¥·¥å¼þÇÈ¿ôUP */
47 #endif
48 #if 1
49   *H8_3069F_DRCRB  = 0x98;
50 #else
51   *H8_3069F_DRCRB  = 0x9f; /* ¥¦¥¨¥¤¥ÈÁÞÆþ */
52 #endif
53   *H8_3069F_DRCRA  = 0x30;
54
55   *H8_3069F_P1DDR  = 0xff;
56   *H8_3069F_P2DDR  = 0x07;
57   *H8_3069F_P8DDR  = 0xe4;
58   /* *H8_3069F_PBDDR = ...; */
59
60   /* H8_3069F_WCRH = ...; */
61 #if 1
62   *H8_3069F_WCRL = 0xcf;
63 #else
64   *H8_3069F_WCRL = 0xff; /* ¥¦¥¨¥¤¥ÈÁÞÆþ */
65 #endif
66
67 #if 1
68   *H8_3069F_ASTCR = 0xfb; /* 2¥¹¥Æ¡¼¥È¥¢¥¯¥»¥¹ */
69 #else
70   *H8_3069F_ASTCR = 0xff; /* 3¥¹¥Æ¡¼¥È¥¢¥¯¥»¥¹ */
71 #endif
72
73   return 0;
74 }
75
76 static int check_val(volatile val_t *p, volatile val_t *wval)
77 {
78   volatile val_t rval;
79
80   p->u.val8[0] = wval->u.val8[0]; p->u.val8[1] = wval->u.val8[1];
81   p->u.val8[2] = wval->u.val8[2]; p->u.val8[3] = wval->u.val8[3];
82   rval.u.val8[0] = p->u.val8[0]; rval.u.val8[1] = p->u.val8[1];
83   rval.u.val8[2] = p->u.val8[2]; rval.u.val8[3] = p->u.val8[3];
84
85   if (rval.u.val32[0] != wval->u.val32[0])
86     return -1;
87
88   p->u.val16[0] = wval->u.val16[0]; p->u.val16[1] = wval->u.val16[1];
89   rval.u.val16[0] = p->u.val16[0]; rval.u.val16[1] = p->u.val16[1];
90
91   if (rval.u.val32[0] != wval->u.val32[0])
92     return -1;
93
94   p->u.val32[0] = wval->u.val32[0];
95   rval.u.val32[0] = p->u.val32[0];
96
97   if (rval.u.val32[0] != wval->u.val32[0])
98     return -1;
99
100   return 0;
101 }
102
103 int dram_check()
104 {
105   uint32 *p;
106   int err;
107   val_t val;
108
109   puts("DRAM checking...\n");
110
111   for (p = (uint32 *)DRAM_START; p < (uint32 *)DRAM_END; p++) {
112     putxval((unsigned long)p, 8);
113     err = 1;
114
115     val.u.val32[0] = (uint32)p;
116     if (check_val((val_t *)p, &val) < 0)
117       goto err;
118
119     val.u.val32[0] = 0;
120     if (check_val((val_t *)p, &val) < 0)
121       goto err;
122
123     val.u.val32[0] = 0xffffffffUL;
124     if (check_val((val_t *)p, &val) < 0)
125       goto err;
126
127     puts("\x08\x08\x08\x08\x08\x08\x08\x08");
128   }
129   puts("\nall check OK.\n");
130   return 0;
131
132 err:
133   puts("\nERROR: ");
134   putxval((unsigned long)*p, 8);
135   puts("\n");
136   return -1;
137 }
138
139 static uint32 dram_check2_val0(uint32 *addr) {  return  0x55555555UL; }
140 static uint32 dram_check2_val1(uint32 *addr) {  return  0xaaaaaaaaUL; }
141 static uint32 dram_check2_val2(uint32 *addr) {  return  0x00000000UL; }
142 static uint32 dram_check2_val3(uint32 *addr) {  return  0xffffffffUL; }
143 static uint32 dram_check2_val4(uint32 *addr) {  return  (uint32)addr; }
144 static uint32 dram_check2_val5(uint32 *addr) {  return ~(uint32)addr; }
145
146 int dram_check2()
147 {
148   uint32 *p;
149   int ret = 0, i;
150   uint32 (*getval[])(uint32 *) = {
151     dram_check2_val0,
152     dram_check2_val1,
153     dram_check2_val2,
154     dram_check2_val3,
155     dram_check2_val4,
156     dram_check2_val5,
157     NULL
158   };
159
160   for (i = 0; getval[i]; i++) {
161
162     puts("DRAM check pattern: ");
163     putxval(i, 0);
164
165     puts("\nDRAM setting...\n");
166
167     for (p = (uint32 *)DRAM_START; p < (uint32 *)DRAM_END; p++) {
168       *p = getval[i](p);
169       if (!((uint32)p & 0xfff)) {
170         putxval((unsigned long)p, 8);
171         puts("\x08\x08\x08\x08\x08\x08\x08\x08");
172       }
173     }
174
175     puts("\nDRAM checking...\n");
176
177     for (p = (uint32 *)DRAM_START; p < (uint32 *)DRAM_END; p++) {
178       if (*p != getval[i](p)) {
179         puts("\nERROR! :");
180         putxval((unsigned long)p, 8);
181         puts(" ");
182         putxval((unsigned long)*p, 8);
183         puts("\n");
184         ret = -1;
185       }
186       if (!((uint32)p & 0xfff)) {
187         putxval((unsigned long)p, 8);
188         puts("\x08\x08\x08\x08\x08\x08\x08\x08");
189       }
190     }
191
192     puts("\n");
193
194   }
195
196   if (ret == 0) {
197     puts("\nall check OK.\n");
198   }
199
200   return ret;
201 }
202
203 int dram_clear()
204 {
205   uint32 *p;
206
207   puts("DRAM clearing...\n");
208
209   for (p = (uint32 *)DRAM_START; p < (uint32 *)DRAM_END; p++)
210     *p = 0;
211
212   puts("DRAM cleared.\n");
213
214   return 0;
215 }