5 #include "microwatt_soc.h"
12 static inline uint32_t read32(const void *addr
)
14 return *(volatile uint32_t *)addr
;
17 static inline void write32(void *addr
, uint32_t value
)
19 *(volatile uint32_t *)addr
= value
;
29 uint32_t zero0
; // reserved
30 uint32_t zero1
; // reserved
36 void memcpy(void *dest
, void *src
, size_t n
) {
38 //cast src and dest to char*
39 char *src_char
= (char *)src
;
40 char *dest_char
= (char *)dest
;
42 dest_char
[i
] = src_char
[i
]; //copy contents byte by byte
45 void uart_writeuint32(uint32_t val
) {
46 const char lut
[] = { '0', '1', '2', '3', '4', '5', '6', '7',
47 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
48 uint8_t *val_arr
= &val
;
51 for (i
= 0; i
< 4; i
++) {
52 putchar(lut
[(val_arr
[3-i
] >> 4) & 0xF]);
53 putchar(lut
[val_arr
[3-i
] & 0xF]);
62 const int kNumIterations
= 14;
65 volatile uint32_t *ram
= DRAM_BASE
;
67 //puts("Firmware launched...\n");
69 puts("DRAM init... ");
71 struct gramProfile profile
= {
73 0x320, 0x6, 0x200, 0x0
78 struct gramProfile profile2
;
79 gram_init(&ctx
, &profile
, (void*)DRAM_BASE
, //0x10000000,
80 (void*)DRAM_CTRL_BASE
, //0x00009000,
81 (void*)DRAM_INIT_BASE
); //0x00008000);
86 writel(0xDEAF0000, (unsigned long)&(ram
[0]));
87 tmp
= readl((unsigned long)&(ram
[0]));
89 uart_writeuint32(tmp
);
96 for (size_t i
= 0; i
< 8; i
++) {
98 gram_load_calibration(&ctx
, &profile2
);
99 gram_reset_burstdet(&ctx
);
101 for (size_t j
= 0; j
< 128; j
++) {
102 tmp
= readl((unsigned long)&(ram
[i
]));
104 if (gram_read_burstdet(&ctx
, 0)) {
113 for (size_t i
= 0; i
< 8; i
++) {
114 profile2
.rdly_p1
= i
;
115 gram_load_calibration(&ctx
, &profile2
);
116 gram_reset_burstdet(&ctx
);
117 for (size_t j
= 0; j
< 128; j
++) {
118 tmp
= readl((unsigned long)&(ram
[i
]));
120 if (gram_read_burstdet(&ctx
, 1)) {
128 puts("Auto calibrating... ");
129 res
= gram_generate_calibration(&ctx
, &profile2
);
130 if (res
!= GRAM_ERR_NONE
) {
132 gram_load_calibration(&ctx
, &profile
);
134 gram_load_calibration(&ctx
, &profile2
);
140 puts("Auto calibration profile:");
142 uart_writeuint32(profile2
.rdly_p0
);
144 uart_writeuint32(profile2
.rdly_p1
);
147 puts("DRAM test... \n");
148 for (size_t i
= 0; i
< kNumIterations
; i
++) {
149 writel(0xDEAF0000 | i
*4, (unsigned long)&(ram
[i
]));
152 for (int dly
= 0; dly
< 8; dly
++) {
154 profile2
.rdly_p0
= dly
;
155 profile2
.rdly_p1
= dly
;
157 uart_writeuint32(profile2
.rdly_p0
);
159 uart_writeuint32(profile2
.rdly_p1
);
160 gram_load_calibration(&ctx
, &profile2
);
161 for (size_t i
= 0; i
< kNumIterations
; i
++) {
162 if (readl((unsigned long)&(ram
[i
])) != (0xDEAF0000 | i
*4)) {
164 uart_writeuint32(&ram
[i
]);
166 uart_writeuint32(ram
[i
]);
171 puts("Test canceled (more than 10 errors)\n");