-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmsgboxin.c
More file actions
84 lines (76 loc) · 2.25 KB
/
msgboxin.c
File metadata and controls
84 lines (76 loc) · 2.25 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <stdint.h>
#include "rpmsg.h"
/*
// The ioctl number, replace with exact value from your kernel (may vary, typically defined in rpmsg_chrdev.h)
#define RPMSG_CREATE_EPT_IOCTL 0x4020b009
struct rpmsg_endpoint_info {
char name[32];
uint32_t src_addr;
uint32_t dst_addr;
};
*/
int main() {
int ctrlfd, rpmsgfd;
struct rpmsg_endpoint_info ept_info;
ssize_t len;
char rx_buf[512];
char tx_buf[512] = "Hello DSP from Linux!";
// Fill endpoint info (customize src/dst addresses as needed!)
memset(&ept_info, 0, sizeof(ept_info));
//strncpy(ept_info.name, "msgbox-channel", sizeof(ept_info.name));
//strncpy(ept_info.name, "sunxi,dsp-msgbox", sizeof(ept_info.name));
//strncpy(ept_info.name, "rpmsg_chrdev", sizeof(ept_info.name));
//strncpy(ept_info.name, "sunxi,msgbox-amp", sizeof(ept_info.name));
strncpy(ept_info.name, "amp", sizeof(ept_info.name));
// Example addresses. Match these to those used in DSP firmware and dts 'msgbox' node.
ept_info.src_addr = 0x01;
ept_info.dst_addr = 0x01;
// Open the control device
ctrlfd = open("/dev/rpmsg_ctrl0", O_RDWR);
if (ctrlfd < 0) {
perror("open /dev/rpmsg_ctrl0");
return 1;
}
// Issue the ioctl to create the endpoint
if (ioctl(ctrlfd, RPMSG_CREATE_EPT_IOCTL, &ept_info) < 0) {
perror("ioctl RPMSG_CREATE_EPT_IOCTL");
close(ctrlfd);
return 1;
}
close(ctrlfd);
// Now /dev/rpmsg0 should exist
rpmsgfd = open("/dev/rpmsg0", O_RDWR);
if (rpmsgfd < 0) {
perror("open /dev/rpmsg0");
return 1;
}
/*
// Write message to DSP
len = write(rpmsgfd, tx_buf, strlen(tx_buf));
if (len < 0) {
perror("write to /dev/rpmsg0");
close(rpmsgfd);
return 1;
}
printf("Sent %zd bytes: %s\n", len, tx_buf);
*/
while ( 1 ) {
// Read message from DSP
len = read(rpmsgfd, rx_buf, sizeof(rx_buf) - 1);
if (len < 0) {
perror("read from /dev/rpmsg0");
close(rpmsgfd);
return 1;
}
rx_buf[len] = '\0';
printf("Received %zd bytes: %s\n", len, rx_buf);
}
close(rpmsgfd);
return 0;
}