-
Notifications
You must be signed in to change notification settings - Fork 0
/
testddr.c
134 lines (100 loc) · 3.34 KB
/
testddr.c
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
#include "ficlib2.h"
#include <time.h>
//-----------------------------------------------------------------------------
// TEST CODE
//-----------------------------------------------------------------------------
#define BITFILE "fic_ddrtest.bin"
void test_fpga_prog() {
int fd;
struct stat st;
stat(BITFILE, &st);
size_t size = st.st_size;
uint8_t *buf = malloc(sizeof(char)*size);
fd = open(BITFILE, O_RDONLY);
read(fd, buf, size);
printf("TEST for FPGA configuration\n");
// size_t tx = fic_prog_sm16(buf, size, PM_NORMAL);
size_t tx = fic_prog_sm8(buf, size, PM_NORMAL);
// size_t tx = fic_prog_sm8_fast(buf, size, PM_NORMAL);
printf("TEST: %d bytes are transffered\n", tx);
close(fd);
free(buf);
}
//-----------------------------------------------------------------------------
void test_ddrrw() {
int i, j;
uint32_t addr = 0x00000000;
//uint8_t data[] = {0xde, 0xad, 0xbe, 0xef};
//uint8_t data[] = {0xca, 0xfe, 0xba, 0xbe};
uint8_t buf[256] = {0};
int ret = 0;
clock_t t1, t2;
// Load test data file
FILE *fp_input;
if ((fp_input = fopen("1G", "rb")) == NULL) {
printf("Can not open test file\n");
exit(EXIT_FAILURE);
}
uint32_t test_size = 1024*1024*1024; // 1G
uint32_t block_size = 1024*1024*100; // 100M
uint8_t *mem = malloc(sizeof(uint8_t) * block_size);
if (!mem) {
printf("Malloc failed\n");
exit(EXIT_FAILURE);
}
fic_comm_reset(); // Reset FSM
fic_hls_reset();
fic_hls_start();
for (i = 0; i < test_size; i+=block_size) {
printf("Load next block... ");
fread(mem, block_size, 1, fp_input);
printf("OK\n");
printf("HLS RESET.. ");
fic_hls_reset();
fic_hls_start();
printf("OK\n");
printf("DDR memory write test:\n");
t1 = clock();
ret = fic_hls_ddr_write(mem, block_size, addr+i);
t2 = clock();
printf("Transfer rate = %f KB/s\n",
block_size / ((double)(t2 - t1) / CLOCKS_PER_SEC) / 1024);
if (ret < 0) {
printf("[libfic2][DEBUG]: ERROR at fic_ddr_write\n");
}
printf("DEBUG: Total write=%d\n", i+block_size);
}
fclose(fp_input);
// Read test --------------------------------------------------------------
FILE *fp_output;
if ((fp_output = fopen("test.out", "wb")) == NULL) {
printf("Can not open test output file\n");
exit(EXIT_FAILURE);
}
for (i = 0; i < test_size; i+=block_size) {
printf("HLS RESET.. ");
fic_hls_reset();
fic_hls_start();
printf("OK\n");
printf("TEST DDR memory read:\n");
t1 = clock();
ret = fic_hls_ddr_read(mem, block_size, addr+i);
t2 = clock();
printf("Transfer rate = %f KB/s\n",
block_size / ((double)(t2 - t1) / CLOCKS_PER_SEC) / 1024);
if (ret < 0) {
printf("[libfic2][DEBUG]: ERROR at fic_ddr_read\n");
}
fwrite(mem, block_size, 1, fp_output);
}
fclose(fp_output);
free(mem);
}
//-----------------------------------------------------------------------------
int main() {
int fd = fic_gpio_open(); // Open GPIO
printf("DEBUG: gpio fd %d \n", fd);
// test_fpga_prog();
test_ddrrw();
fic_gpio_close(fd); // Close GPIO
}