-
Notifications
You must be signed in to change notification settings - Fork 5
/
helloworld.c
219 lines (180 loc) · 7.37 KB
/
helloworld.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/******************************************************************************
*
* Copyright (C) 2009 - 2014 Xilinx, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* Use of the Software is limited solely to applications:
* (a) running on a Xilinx device, or
* (b) that interact with a Xilinx device through a bus or interconnect.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of the Xilinx shall not be used
* in advertising or otherwise to promote the sale, use or other dealings in
* this Software without prior written authorization from Xilinx.
*
******************************************************************************/
/*
* helloworld.c: simple test application
*
* This application configures UART 16550 to baud rate 9600.
* PS7 UART (Zynq) is not initialized by this application, since
* bootrom/bsp configures it to baud rate 115200
*
* ------------------------------------------------
* | UART TYPE BAUD RATE |
* ------------------------------------------------
* uartns550 9600
* uartlite Configurable only in HW design
* ps7_uart 115200 (configured by bootrom/bsp)
*/
#include <stdio.h>
#include "platform.h"
#include "xil_printf.h"
#include "xil_io.h"
#include "xscugic.h"
#include "xkernel_2mm_wrapper.h"
#include "xtimer.h"
#include "2mm_control.h"
#include "test.h"
// HLS macc HW instance
XKernel_2mm_wrapper hls_2mm;
XTimer hls_timer;
//Interrupt Controller Instance
XScuGic ScuGic;
volatile int RunHlsMacc_2mm = 0;
volatile int ResultAvailHlsMacc_2mm = 0;
volatile int RunHlsMacc_timer = 0;
volatile int ResultAvailHlsMacc_timer = 0;
int main()
{
init_platform();
print("Start\n\r");
int i, j, k;
int status;
/////////////////////////////////////////////////////////////////////
/////////////// Setup the control of the HLS module /////////////////
/////////////////////////////////////////////////////////////////////
status = xkernel_2mm_wrapper_init(&hls_2mm); // you need to modify this function according to your HLS function
if(status != XST_SUCCESS){
print("HLS 2mm setup failed\n\r");
exit(-1);
}
status = xtimer_init(&hls_timer); // you need to modify this function according to your HLS function
if(status != XST_SUCCESS){
print("HLS timer setup failed\n\r");
exit(-1);
}
//Setup the interrupt
status = setup_interrupt(); // you need to modify this function according to your HLS function
if(status != XST_SUCCESS){
print("Interrupt setup failed\n\r");
exit(-1);
}
print("HLS started\n\r");
/////////////////////////////////////////////////////////////////////
//////////////// initialize the data in DDR //////////////////
/////////////////////////////////////////////////////////////////////
int *D_output_AXI = (int *)(0x10000000);
int *A_AXI = (int *)(0x11000000);
int *B_AXI = (int *)(0x12000000);
int *C_AXI = (int *)(0x13000000);
int *D_input_AXI = (int *)(0x14000000);
int D_output_AXI_check[NI][NL];
arrayInitialize(A_AXI, B_AXI, C_AXI, D_input_AXI, D_output_AXI);
XKernel_2mm_wrapper_Set_D_output_AXI(&hls_2mm,D_output_AXI);
XKernel_2mm_wrapper_Set_A_AXI(&hls_2mm,A_AXI);
XKernel_2mm_wrapper_Set_B_AXI(&hls_2mm,B_AXI);
XKernel_2mm_wrapper_Set_C_AXI(&hls_2mm,C_AXI);
XKernel_2mm_wrapper_Set_D_input_AXI(&hls_2mm,D_input_AXI);
/////////////////////////////////////////////////////////////////////
///// start the acceleration of FPGA and monitor its ending. ///////
/////////////////////////////////////////////////////////////////////
unsigned int ticks;
xtimer_start(&hls_timer); // enable the timer
int ticks_array[100];
for (i=0;i<10;i++)
{
int timer_user = 0;
if (0) { // use interrupt
XTimer_Set_reset_signal(&hls_timer,1);
XTimer_Set_reset_signal(&hls_timer,0);
xkernel_2mm_wrapper_start(&hls_2mm); // you need to modify this function according to your HLS function
// print("Detecting interrupt from HLS HW.\n\r");
while(!ResultAvailHlsMacc_2mm)
{
timer_user++;
}
ticks_array[i] = XTimer_Get_timeTicks(&hls_timer);
; // spin
// print("Interrupt received from HLS HW.\n\r");
} else
{ // Simple non-interrupt driven test
XTimer_Set_reset_signal(&hls_timer,1); // reset the timer
XTimer_Set_reset_signal(&hls_timer,0);
xkernel_2mm_wrapper_start(&hls_2mm); // you need to modify this function according to your HLS function
// print("Detecting HLS peripheral complete.\n\r");
do {
timer_user++;
}
while (!XKernel_2mm_wrapper_IsReady(&hls_2mm)); // because we are implementing dataflow, we should check IsReady but not IsDone
// you need to modify this function according to your HLS function
ticks_array[i] = XTimer_Get_timeTicks(&hls_timer);
//print("Detected HLS peripheral complete. Result received.\n\r");
}
}
for (i=0;i<10;i++)
{
// the initial interval will be raised gradually
// since the dataflow will go through faster until the data congest at the bottleneck module in the dataflow
printf("For data batch#%d: Timer FPGA ticks=%u.\n\r", i, ticks_array[i]);
}
/////////////////////////////////////////////////////////////////////
//////// run the application on the host CPU for check ////////
/////////////////////////////////////////////////////////////////////
printf("\n\r");
// run the application on CPU for checking
kernel_2mm_wrapper(
A_AXI,
B_AXI,
C_AXI,
D_input_AXI,
D_output_AXI_check);
// printf("ticks: %d\n\r",timer_user);
print("-------------------------------------------------done and check as below\n\r");
// for(i=0;i<1000000000;i++);
Xil_DCacheInvalidateRange(D_output_AXI, 10000000*8);
int check_result = 0;
int check_list[] = {123, 85, 222, 111, 77, 93, 21, 13, 24, 64 };
for(i=0;i<10;i++)
{
int check_i = check_list[i] / NL;
int check_j = check_list[i] % NL;
int data_check = D_output_AXI[check_list[i]];
printf("addr=%d: expected:%d=== result:%u\n\r",check_list[i], D_output_AXI_check[check_i][check_j],data_check);
if (D_output_AXI_check[check_i][check_j] == data_check)
{
check_result++;
}
}
if (check_result==10) printf("check passed\n\r");
else printf("check failed\n\r");
printf("----------------------------------------------\n\r");
cleanup_platform();
return 0;
}