-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathacp_dummy_test.c
152 lines (119 loc) · 3.79 KB
/
acp_dummy_test.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
* @brief simple bare-metal test application for the AXI ACP
* @author Konstantin Luebeck (University of Tuebingen, Chair for Embedded Systems)
*/
#include <stdio.h>
#include "platform.h"
#include "xil_printf.h"
#include "xil_io.h"
// AX_CACHE value
#define AX_CACHE 0xF
// AX_USER value
#define AX_USER 0x2
// from where in the DDR should data be read by the AXI-Master
#define SOURCE_ADDRESS 0x21000000
// to which location in the DDR should the AXI-Master write
#define TARGET_ADDRESS 0x28000000
// to whcih and from which address should the AXI-Master write in the BRAM
#define BRAM_ADDRESS 1024
// how many consecutive bursts should be executed
#define NUM_BURSTS 3
// how many 128 Bit values should be transmitted in each burst
#define BURST_LENGTH 4
void _Xil_Out32(volatile u32* addr, u32 data) {
// lower 32bit
if(((u32) addr) % 8 == 0) {
Xil_Out64(addr, (Xil_In64(addr) & 0xFFFFFFFF00000000) | data);
}
// upper 32bit
else {
u64 temp;
temp = ((u64) data) << 32;
Xil_Out64(addr-1, (Xil_In64(addr-1) & 0x00000000FFFFFFFF) | temp);
}
}
u32 _Xil_In32(volatile u32* addr) {
u64 temp;
// lower 32bit
if(((u32) addr) % 8 == 0) {
temp = Xil_In64(addr);
return (u32) (temp & 0x00000000FFFFFFFF);
}
// upper 32bit
else {
temp = Xil_In64(addr-1);
return (u32) ((temp & 0xFFFFFFFF00000000) >> 32);
}
}
void initMemory(u32 start_address, u32 length) {
int i,j;
i = start_address;
j = 0;
for(i = start_address; i < start_address+(8*length); i = i + 8) {
Xil_Out64(i, ((u64) (j*2+1) << 32) | (u64) (j*2));
j = j + 1;
}
}
void printMemory(u32 start_address, u32 length) {
int i;
printf("DDR:\n\r");
for(i = start_address; i < start_address+(8*length); i = i + 8) {
printf("%08x : 0x%016lx\n\r", i, Xil_In64(i));
}
}
int main()
{
init_platform();
int i;
volatile u32* volatile slaveaddr_p = (u32*) XPAR_ACP_DUMMY_0_S00_AXI_BASEADDR;
printf("START\n\r");
// load data into DDR/L2-Cache
initMemory(SOURCE_ADDRESS, 2*BURST_LENGTH*NUM_BURSTS);
printMemory(SOURCE_ADDRESS, 2*BURST_LENGTH*NUM_BURSTS);
// set AX_CACHE
_Xil_Out32(slaveaddr_p+29, AX_CACHE);
// set AX_USER
_Xil_Out32(slaveaddr_p+30, AX_USER);
// clear interrupts
_Xil_Out32(slaveaddr_p+1, (1 << 31));
// read values from DDR into BRAM
// ddr_start_address
_Xil_Out32(slaveaddr_p+2, SOURCE_ADDRESS);
// burst_length
_Xil_Out32(slaveaddr_p+3, BURST_LENGTH-1);
// num_bursts
_Xil_Out32(slaveaddr_p+4, NUM_BURSTS);
// bram_start_address
_Xil_Out32(slaveaddr_p+5, BRAM_ADDRESS);
// read_data
_Xil_Out32(slaveaddr_p+1, (1 << 0));
// poll slave until burst transactions are done
while((_Xil_In32(slaveaddr_p+0) & (1 << 0)) != (1 << 0)) {}
// clear interrupts
_Xil_Out32(slaveaddr_p+1, (1 << 31));
// write values from BRAM into DDR
// ddr_start_address
_Xil_Out32(slaveaddr_p+2, TARGET_ADDRESS);
// burst_length
_Xil_Out32(slaveaddr_p+3, BURST_LENGTH-1);
// num_bursts
_Xil_Out32(slaveaddr_p+4, NUM_BURSTS);
// bram_start_address
_Xil_Out32(slaveaddr_p+5, BRAM_ADDRESS);
// write_data
_Xil_Out32(slaveaddr_p+1, (1 << 1));
// poll slave until burst transactions are done
while((_Xil_In32(slaveaddr_p+0) & (1 << 0)) != (1 << 0)) {}
// clear interrupts
_Xil_Out32(slaveaddr_p+1, (1 << 31));
//printMemory(TARGET_ADDRESS, 2*BURST_LENGTH*NUM_BURSTS);
// check if data in DDR is okay
printf("Check data in DDR:\n\r");
printf("SOURCE: TARGET:\n\r");
for(int i = 0; i < 0+(8*NUM_BURSTS*4*2); i = i + 8) {
printf("%08x : 0x%016lx %08x : 0x%016lx %s\n\r", i+SOURCE_ADDRESS, Xil_In64(i+SOURCE_ADDRESS), i+TARGET_ADDRESS, Xil_In64(i+TARGET_ADDRESS), (Xil_In64(i+SOURCE_ADDRESS) == Xil_In64(i+TARGET_ADDRESS)) ? "OK" : "FAILED");
}
printf("END\n\r");
cleanup_platform();
return 0;
}