本篇測評由與非網(wǎng)的優(yōu)秀測評者“短笛君”提供。
本文將介紹基于米爾電子MYD-YD9360商顯板的R5協(xié)處理器開發(fā)方案測試。
本處參考<R5協(xié)處理器開發(fā)筆記>對D9360中的協(xié)處理器進行開發(fā)測試
開發(fā)之前請確認編譯環(huán)境正常可以正常對鏡像進行編譯
具體參考之前編譯Ubuntu系統(tǒng)文章,自行編譯buildroot系統(tǒng)測試
1.1打開RTOS驅(qū)動
freeRTOS的源碼放在ssdk包下面,我們可以通過圖形化界面啟動RTOS系統(tǒng)。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例程驅(qū)動
RTOS系統(tǒng)例程在examples/kunlun/drivers
ddj@ubuntu:~/YD9X/MYD-YD9X-SDK_V1.0/source/ssdk/examples/kunlun/drivers$ ls
新建一個abc目錄
并配置Kconfig和rules.mk文件
返回driver目錄下 配置Kconfig添加ABC去東門模塊初始狀態(tài)和圖形界面類型
ABC驅(qū)動模塊的初始狀態(tài)和圖形界面類型
在rules.mk文件下,添加如下內(nèi)容
MODULES += $(LOCAL_DIR)/abc: 如果配置選項 CONFIG_ABC_TEST 為 "y",則會將 $(LOCAL_DIR)/abc 添加到變量 MODULES 中。這意味著當啟用了 "ABC Test" 功能時,會將 $(LOCAL_DIR)/abc 模塊添加到模塊列表中。
R5核數(shù)據(jù)發(fā)送到A55核中
將rpmsg目錄下的rpmsg_test.c文件復制到abc.c文件中,該驅(qū)動描述如何通過RPMSG協(xié)議進行核間通信。我們可以在此程序基礎(chǔ)上加入自己的協(xié)議,以下是R5核發(fā)送“Hello, RPMSG!”字符串到A55核,并打印出接收到的信息的函數(shù)。
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);
}
將以上函數(shù)添加至abc.c文件內(nèi),并在主函數(shù)(rpmsg_test)編寫調(diào)用該函數(shù)條件,如下:
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函數(shù))
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小節(jié)打開圖形化配置界面,進入到Driver and Application Examples/Driver Example Support下,可以看到我們新加的abc test Support驅(qū)動配置選項,需要關(guān)閉RPMSG Example Application Support選項,如下:
選中此選項編譯進內(nèi)核,將串口線(debug)接到10_TX,10_RX和GND,打開終端調(diào)試工具。編輯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發(fā)送數(shù)據(jù)給R5
自定義一個發(fā)送和接收字符串的函數(shù),如下:
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函數(shù)內(nèi)添加新增函數(shù)條件:
編輯source/linux/ drivers/rpmsg/virtio_rpmsg_bus.c文件,代碼如下:
保存所有代碼
編譯系統(tǒng) 燒錄
1.5結(jié)果顯示
在R5核調(diào)用rpmsg_test例程,向A55核發(fā)送信息
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核調(diào)用echo_test例程,向R5發(fā)送信息,打印如下:
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核心板及商顯板
- 采用國產(chǎn)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以太網(wǎng),4xCAN-FD,16xUART,SPI 等豐富的外設(shè)接口;
- 工業(yè)級-40℃~85℃,郵票孔324PIN引腳,尺寸為52mmx50mm。
- 應(yīng)用:高端商顯、新一代電力智能設(shè)備、工業(yè)互聯(lián)網(wǎng)設(shè)備、工業(yè)控制設(shè)備、工業(yè)機器人、工程機械、軌道交通等