-
Notifications
You must be signed in to change notification settings - Fork 2
/
streamtest.c
136 lines (90 loc) · 2.54 KB
/
streamtest.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
/*
Prerequisites:
- Xilinx XDMA AXI Stream Project:
github.com/mwrnd/innova2_experiments/xdma_stream
- XDMA Drivers from github.com/xilinx/dma_ip_drivers
Install Instructions at github.com/mwrnd/innova2_flex_xcku15p_notes
Compile with:
gcc -Wall streamtest.c -o streamtest -lm
Run with:
sudo ./streamtest
*/
#include <errno.h>
#include <fcntl.h>
#include <math.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define DATA_SIZE 32
int main(int argc, char **argv)
{
uint64_t addr = 0;
int xdma_fd_read;
int xdma_fd_wrte;
int count = 0;
uint8_t wrte_data[DATA_SIZE];
uint8_t read_data[DATA_SIZE];
ssize_t rc;
float num = 3.14;
char* xdma_h2c_name = "/dev/xdma0_h2c_0";
char* xdma_c2h_name = "/dev/xdma0_c2h_0";
xdma_fd_wrte = open(xdma_h2c_name, O_WRONLY);
if (xdma_fd_wrte < 0) {
fprintf(stderr, "unable to open write device %s, %d.\n",
xdma_h2c_name, xdma_fd_wrte);
perror("File Open");
}
xdma_fd_read = open(xdma_c2h_name, O_RDONLY);
if (xdma_fd_read < 0) {
fprintf(stderr, "unable to open read device %s, %d.\n",
xdma_c2h_name, xdma_fd_read);
perror("File Open");
}
printf("XDMA AXI Stream Test\n");
printf("C2H Device: %s\n", xdma_c2h_name);
printf("H2C Device: %s\n", xdma_h2c_name);
// fill the write data buffer with floating point values
printf("\nInput Floating-Point Values:\n");
count = 1;
num = 1.123;
for (int i = 0 ; i < DATA_SIZE; i = i + 4)
{
memcpy(&wrte_data[i], &num, 4);
printf("%02d: num = %f\n", count, num);
num = num * 2.01;
count++;
}
printf("\n");
// write data buffer to the AXI Stream
rc = pwrite(xdma_fd_wrte, wrte_data, DATA_SIZE, addr);
if (rc < 0) {
fprintf(stderr, "%s, write data @ 0x%lX failed, %ld.\n",
xdma_h2c_name, addr, rc);
perror("File Write");
return -EIO;
}
// read data from the AXI Stream into buffer
printf("\nOutput Floating-Point Values:\n");
rc = pread(xdma_fd_read, read_data, DATA_SIZE, addr);
if (rc < 0) {
fprintf(stderr, "%s, read data @ 0x%lX failed, %ld.\n",
xdma_c2h_name, addr, rc);
perror("File Read");
return -EIO;
}
// print the data in the return data buffer
count = 1;
for (int i = 0 ; i < DATA_SIZE; i = i + 4)
{
memcpy(&num, &read_data[i], 4);
printf("%02d: num = %f, sqrt(num)=%f\n",
count, num, sqrt(num));
count++;
}
printf("\n");
close(xdma_fd_wrte);
close(xdma_fd_read);
exit(EXIT_SUCCESS);
}