本篇測評由與非網的優秀測評者“短笛君”提供。
本文將介紹基于米爾電子MYD-YD9360商顯板的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: %s\n", message); } else { printf("Failed to send message\n"); }
int received_len; ret = rpmsg_channel_recv(channel, rcv_pkg, max_payload, &received_len, 3000); if (ret == RPMSG_SUCCESS) { printf("Received: %s\n", rcv_pkg->data); } else { printf("Failed to receive message\n"); }
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 %s\n", 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 %d\n", test_case); break; }
//加入串口打印提示(跳至rpmsg_test_show函數)printf("\nTest command:\n"); printf("\trpmsg_test \n"); printf("\trpmsg_test ping \n"); printf("\trpmsg_test iperf \n"); printf("\trpmsg_test send \n");
printf("\ne.g: test ping rpmsg.virtio 10 times with secure, use command:\n"); printf("\trpmsg_test ping 0 1 10\n");
通過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 ACK\n"); } else { ssdk_printf(SSDK_WARNING, "echo_channel_cb: unknown %d bytes from addr %ld\n", len, src); }
if (ret != 0) { ssdk_printf(SSDK_WARNING, "echo_channel_cb: channel send failed\n"); }
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("\r\n sending payload number"); if (verbose) printf(" %d of size %lu\r\n", 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("\r\n Error sending data\n"); break; } else fprintf(stderr, "#");
err_cnt++; continue; } printf("send string:%s\n",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] = '\0'; printf("receive string:%s\n",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: 123456789Received: 123456789
>rpmsg_test send 1 3 1>Sent: 123456789Received: 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 startupdate rpmsg-mtu=496 from kernelsend 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。
- 應用:高端商顯、新一代電力智能設備、工業互聯網設備、工業控制設備、工業機器人、工程機械、軌道交通等
-
處理器
+關注
關注
68文章
18797瀏覽量
226245 -
實時系統
+關注
關注
0文章
33瀏覽量
14387 -
米爾電子
+關注
關注
0文章
84瀏覽量
411
發布評論請先 登錄
相關推薦
評論