d85ae7682260037ed20be709d4a4644264f687c4
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
= 65536;
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);
85 for (size_t i
= 0; i
< 8; i
++) {
87 gram_load_calibration(&ctx
, &profile2
);
89 gram_reset_burstdet(&ctx
);
91 for (size_t j
= 0; j
< 128; j
++) {
92 tmp
= readl((unsigned long)&ram
[i
]);
94 if (gram_read_burstdet(&ctx
, 0)) {
103 for (size_t i
= 0; i
< 8; i
++) {
104 profile2
.rdly_p1
= i
;
105 gram_load_calibration(&ctx
, &profile2
);
107 gram_reset_burstdet(&ctx
);
109 for (size_t j
= 0; j
< 128; j
++) {
110 tmp
= readl((unsigned long)&ram
[i
]);
112 if (gram_read_burstdet(&ctx
, 1)) {
120 puts("Auto calibrating... ");
121 res
= gram_generate_calibration(&ctx
, &profile2
);
122 if (res
!= GRAM_ERR_NONE
) {
124 gram_load_calibration(&ctx
, &profile
);
126 gram_load_calibration(&ctx
, &profile2
);
130 puts("Auto calibration profile:");
132 uart_writeuint32(profile2
.rdly_p0
);
134 uart_writeuint32(profile2
.rdly_p1
);
137 puts("DRAM test... \n");
138 for (size_t i
= 0; i
< kNumIterations
; i
++) {
139 ram
[i
] = 0xDEAF0000 | i
*4;
142 for (size_t i
= 0; i
< kNumIterations
; i
++) {
143 if (ram
[i
] != (0xDEAF0000 | i
*4)) {
145 uart_writeuint32(&ram
[i
]);
147 uart_writeuint32(ram
[i
]);
152 puts("Test canceled (more than 10 errors)\n");