-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy_rpmsg_test.c
More file actions
66 lines (47 loc) · 1.34 KB
/
my_rpmsg_test.c
File metadata and controls
66 lines (47 loc) · 1.34 KB
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
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#define EXAMPLE_DMA_SIZE 4096
int main(int argc, char * argv[]){
FILE * f_size = fopen("/sys/kernel/my_dma_allocator/dma_size", "r+");
if (!f_size) {
perror("device dma open size failed.");
return -1;
}
FILE * f_phys = fopen("/sys/kernel/my_dma_allocator/addr_phys", "r");
if (!f_phys) {
perror("device dma open phys failed.");
return -1;
}
FILE * f_rpmsg = fopen("/dev/ttyRPMSG30", "w");
if (f_rpmsg < 0) {
perror("device rpmsg open failed.");
return -1;
}
printf("Found dma allocator device\n");
size_t size = EXAMPLE_DMA_SIZE;
fprintf(f_size, "%lu\n", size);
fflush(f_size);
unsigned long addr_phys = 0;
do {
fscanf(f_phys, "%lx", &addr_phys);
rewind(f_phys);
} while (addr_phys == 0);
printf("Allocation done\n");
printf("Found physical adress : %lx\n", addr_phys);
fprintf(f_rpmsg, "%lx %lu", addr_phys, size);
fflush(f_rpmsg);
printf("Write done ! \n Waiting for 10s ...\n");
sleep(10);
fprintf(f_size, "0\n");
fflush(f_size);
do {
fscanf(f_phys, "%lx", &addr_phys);
rewind(f_phys);
} while (addr_phys != 0);
printf("DONE\n");
fclose(f_size);
fclose(f_phys);
return 0;
}