本篇测评由与非网的优秀测评者“短笛君”提供。
本文将介绍基于米尔电子MYD-YD9360商显板的R5协处理器开发方案测试。
本处参考<R5协处理器开发笔记>对D9360中的协处理器进行开发测试
开发之前请确认编译环境正常可以正常对镜像进行编译
具体参考之前编译Ubuntu系统文章,自行编译buildroot系统测试
1.1打开RTOS驱动
freeRTOS的源码放在ssdk包下面,我们可以通过图形化界面启动RTOS系统。D9的ssdk图形化界面是通过menuconfig.sh脚本配置打开,此脚本在ssdk/tools下。以D9360为例,如下:
ddj@ubuntu:~/YD9X/MYD-YD9X-SDK_V1.0/source/ssdk$ pwd
/home/ddj/YD9X/MYD-YD9X-SDK_V1.0/source/ssdk
~/MYD-JD9X-ubuntu/MYD-JD9X-SDK_V1.0/source/ssdk$ ./tools/menuconfig.sh -b d9360_ref -p ref -c secure
1.2 添加RTOS例程驱动
RTOS系统例程在examples/kunlun/drivers
ddj@ubuntu:~/YD9X/MYD-YD9X-SDK_V1.0/source/ssdk/examples/kunlun/drivers$ ls
新建一个abc目录
并配置Kconfig和rules.mk文件
返回driver目录下 配置Kconfig添加ABC去东门模块初始状态和图形界面类型
ABC驱动模块的初始状态和图形界面类型
在rules.mk文件下,添加如下内容
MODULES += $(LOCAL_DIR)/abc: 如果配置选项 CONFIG_ABC_TEST 为 "y",则会将 $(LOCAL_DIR)/abc 添加到变量 MODULES 中。这意味着当启用了 "ABC Test" 功能时,会将 $(LOCAL_DIR)/abc 模块添加到模块列表中。
R5核数据发送到A55核中
将rpmsg目录下的rpmsg_test.c文件复制到abc.c文件中,该驱动描述如何通过RPMSG协议进行核间通信。我们可以在此程序基础上加入自己的协议,以下是R5核发送“Hello, RPMSG!”字符串到A55核,并打印出接收到的信息的函数。
void send_receive_string(rpmsg_channel_t channel, const char *message) {
int max_payload;
struct dcf_ccm_hdr *snd_pkg;
struct dcf_ccm_hdr *rcv_pkg;
status_t ret;
max_payload = rpmsg_channel_max_payload(channel);
snd_pkg = osAlloc(max_payload);
rcv_pkg = osAlloc(max_payload);
ASSERT(snd_pkg && rcv_pkg);
memset(snd_pkg, 0x0, max_payload);
memset(rcv_pkg, 0x0, max_payload);
snd_pkg->dmsg.msg_type = COMM_MSG_CCM_ECHO;
snd_pkg->dmsg.opflags |= DCF_MSGF_TMS;
snd_pkg->dmsg.msg_len = sizeof(struct dcf_ccm_hdr) - sizeof(struct dcf_message);
strncpy(snd_pkg->data, message, max_payload - sizeof(struct dcf_ccm_hdr));
ret = rpmsg_channel_send(channel, RPMSG_ECHO_EPT_ADDR, snd_pkg, max_payload, 3000);
if (ret == RPMSG_SUCCESS) {
printf("Sent: %sn", message);
} else {
printf("Failed to send messagen");
}
int received_len;
ret = rpmsg_channel_recv(channel, rcv_pkg, max_payload, &received_len, 3000);
if (ret == RPMSG_SUCCESS) {
printf("Received: %sn", rcv_pkg->data);
} else {
printf("Failed to receive messagen");
}
osFree(snd_pkg);
osFree(rcv_pkg);
}
将以上函数添加至abc.c文件内,并在主函数(rpmsg_test)编写调用该函数条件,如下:
const char* message_to_send = "Hello,rpmsg";
if (argc == 0) {
rpmsg_test_show();
goto exit;
}
if (argc == 2) {
test_case = 0;
type = atoi(argv[0]);
rproc = atoi(argv[1]);
}
else if (!strcmp(argv[0], "ping")) {
test_case = 1;
type = atoi(argv[1]);
rproc = atoi(argv[2]);
times = atoi(argv[3]);
}
else if (!strcmp(argv[0], "iperf")) {
test_case = 2;
type = atoi(argv[1]);
rproc = atoi(argv[2]);
times = atoi(argv[3]);
}
//新添加的条件
else if(!strcmp(argv[0], "send")){
test_case = 3;
type = atoi(argv[1]);
rproc = atoi(argv[2]);
times = atoi(argv[3]);
}
else {
printf("Unknown cmd %sn", argv[0]);
goto exit;
}
switch (test_case) {
case 0:
do_rpmsg_echo_test(channel);
break;
case 1:
do_rpmsg_ping_test(channel, times);
break;
case 2:
do_rpmsg_iperf_test(channel, times);
break;
case 3:
send_receive_string(channel, message_to_send);
break;
default:
printf("Unknown case %dn", test_case);
break;
}
//加入串口打印提示(跳至rpmsg_test_show函数)
printf("nTest command:n");
printf("trpmsg_test <type> <remote-proc>n");
printf("trpmsg_test ping <type> <remote-proc> <times>n");
printf("trpmsg_test iperf <type> <remote-proc> <times>n");
printf("trpmsg_test send <type> <remote-proc> <times>n");
printf("ne.g: test ping rpmsg.virtio 10 times with secure, use command:n");
printf("trpmsg_test ping 0 1 10n");
通过5.1小节打开图形化配置界面,进入到Driver and Application Examples/Driver Example Support下,可以看到我们新加的abc test Support驱动配置选项,需要关闭RPMSG Example Application Support选项,如下:
选中此选项编译进内核,将串口线(debug)接到10_TX,10_RX和GND,打开终端调试工具。编辑source/ssdk/ middleware/rpmsg_service/rpmsg_echo.c文件,添加代码如下:
static int echo_channel_cb(void *data, int len, unsigned long src, void *arg)
{
rpmsg_channel_t chan = arg;
struct dcf_ccm_hdr *ccm_pkg = data;
const char *char_data = (char *)data;
int ret = 0;
if (ccm_pkg->dmsg.msg_type == COMM_MSG_CCM_ECHO) {
ccm_pkg->time[2] = timer_get_current_time(g_syscnt_timer) * g_sdrv_syscnt_dev.cnt_per_us;
ret = rpmsg_channel_send(chan, src, data, len, 1000);
printf("Sending data (length %d): ", len);
for (int i = 8; i < len; i++) {
printf("%c ", char_data[i]);
}
printf("n");
}
else if (ccm_pkg->dmsg.msg_type == COMM_MSG_CCM_ACK) {
ret = rpmsg_channel_send(chan, src, (char *)"ACK", 4, 1000);
ssdk_printf(SSDK_INFO,"send ACKn");
}
else {
ssdk_printf(SSDK_WARNING, "echo_channel_cb: unknown %d bytes from addr %ldn",
len, src);
}
if (ret != 0) {
ssdk_printf(SSDK_WARNING, "echo_channel_cb: channel send failedn");
}
return ret;
}
A55发送数据给R5
自定义一个发送和接收字符串的函数,如下:
int send_receive_string(int fd, const char *send_str,int ntimes, int seconds) {
int i = 0, j = 0;
int size, bytes_rcvd, bytes_sent;
long elapse = 0;
err_cnt = 0;
i_payload = (struct _payload *)malloc(sizeof(struct _payload) + payload_max_size);
r_payload = (struct _payload *)malloc(sizeof(struct _payload) + payload_max_size);
if (i_payload == 0 || r_payload == 0) {
printf("ERROR: Failed to allocate memory for payload.n");
return -1;
}
if (seconds)
gettimeofday(&start_test, NULL);
i_payload->magic = 0xA5;
for (j = 0; j < ntimes; j++) {
i_payload->num = i;
i_payload->size = size;
strcpy(i_payload->data, send_str);
if (verbose) printf("rn sending payload number");
if (verbose) printf(" %d of size %lurn", i_payload->num,
(sizeof(struct _payload)) + strlen(i_payload->data));
bytes_sent = write(fd, i_payload, sizeof(struct _payload) + strlen(i_payload->data));
if (bytes_sent <= 0) {
if (verbose) {
perror("rn Error sending datan");
break;
} else
fprintf(stderr, "#");
err_cnt++;
continue;
}
printf("send string:%sn",i_payload->data);
r_payload->num = 0;
bytes_rcvd = read(fd, r_payload,
sizeof(struct _payload) + payload_max_size);
while (bytes_rcvd <= 0) {
usleep(10000);
bytes_rcvd = read(fd, r_payload,
sizeof(struct _payload) + payload_max_size);
}
r_payload->data[bytes_rcvd] = '';
printf("receive string:%sn",r_payload->data);
if (interval)
sleep(interval);
}
free(i_payload);
free(r_payload);
return 0;
}
在main函数内添加新增函数条件:
编辑source/linux/ drivers/rpmsg/virtio_rpmsg_bus.c文件,代码如下:
保存所有代码
编译系统 烧录
1.5结果显示
在R5核调用rpmsg_test例程,向A55核发送信息
R5界面
>rpmsg_test send 0 3 1
>Sent: 123456789
Received: 123456789
>rpmsg_test send 1 3 1
>Sent: 123456789
Received: 123456789
A55界面
root@myd-jd9x:~# [ 22.223170] virtio_rpmsg_bus virtio0: virtio send susses
[ 34.943644] sd,rpmsg-ipcc soc:ipcc@1: ipcc send susses
在A55核调用echo_test例程,向R5发送信息,打印如下:
A55界面
root@myd-jd9x:~# echo_test -d virtio0.rpmsg-echo.-1.30 -c 1
Echo test start
update rpmsg-mtu=496 from kernel
send string:Hello,RPMsg!
receive string:Hello,RPMsg!
R5界面
Sending data (length 20): H e l l o , R P M s g !
MYC-YD9360核心板及商显板
- 采用国产CPU:集成了6个ARM Cortex-A55@1.6GHz 高性能CPU和1个ARM Cortex-R5@800MHz;
- 高性能的高安全HSM安全的处理器,支持TRNG、AES、RSA、SHA、SM2/3/4/9;
- 它包含100GFLOPS 3D GPU以及H.264和H.265/VP8/VP9视频编/解码器,三屏异显;
- 集成 PCIe3.0,USB3.0,2x千兆TSN以太网,4xCAN-FD,16xUART,SPI 等丰富的外设接口;
- 工业级-40℃~85℃,邮票孔324PIN引脚,尺寸为52mmx50mm。
- 应用:高端商显、新一代电力智能设备、工业互联网设备、工业控制设备、工业机器人、工程机械、轨道交通等