pg直营网-pg网赌游戏 >关于创龙 > 新闻资讯 > 技术文章
联系pg直营网
contact us公司总机:020-8998-6280
技术热线:020-3893-9437
技术邮箱:support@tronlong.com
销售邮箱:sales@tronlong.com
imx8 cortex-a53与cortex-m4多核通信开发详解
2021/08/05
前言:本文主要演示i.mx 8m mini基于openamp的cortex-a53和cortex-m4核心的核间通信,其中cortex-a53运行linux系统,cortex-m4运行freertos系统。
图 1
案例测试硬件平台:tlimx8-evm评估板(nxp i.mx 8m mini)
图 2 tlimx8-evm评估板
案例详细说明、源码请扫描下方二维码或点击下载链接:
http://site.tronlong.com/pfdownload
1 rpmsg_lite_pingpong_rtos案例
1.1 案例功能
(1) cortex-a53释放cortex-m4,然后初始化rpmsg,并创建端点。
(2) cortex-a53启动linux系统,执行握手服务,创建通信信道,并发送一条信息至cortex-m4。
(3) cortex-m4接收到第一条信息时,计数器自加1,然后回发计数器值至cortex-a53。
(4) cortex-a53接收cortex-m4发送的计数器数值,计数器自加1,然后回发计数器数值至cortex-m4。
(5) 当计数器数值大于100时,通信结束。
1.2 案例测试
案例bin目录下分别提供了tcm版本程序镜像文件rpmsg_lite_pingpong_rtos_linux_remote.bin和ddr版本程序镜像文件rpmsg_lite_pingpong_rtos_linux_remote_ddr.bin。
在u-boot命令行加载运行cortex-m4程序镜像文件后,rs232 uart4调试串口打印如下信息。
图 3
运行boot命令,在cortex-a53启动运行linux系统。
u-boot=> boot

图 4
进入评估板文件系统后,执行如下命令加载imx_rpmsg_pingpong模块,启动核间通信。
target# modprobe imx_rpmsg_pingpong

图 5
加载模块后,cortex-m4将接收cortex-a53发送的数据,并将其转发回cortex-a53,循环50次后结束。rs232 uart4调试串口打印信息如下。
图 6
图 7
1.3 关键代码
linux驱动程序
驱动的实现在imx_rpmsg_pingpong.c中完成,此文件位于内核"drivers/rpmsg/"路径下。
(1) linux系统加载驱动后,先发送一条hellomsg,然后发送第一条乒乓信息。

图 8
(2) 在回调函数中,每次接收到cortex-m4的计数器数据后自加1,并回发至cortex-m4,直到计数器数值大于100。
图 9
freertos程序
程序主体位于main函数中,定义位于main_remote.c中。
(1) 在main函数中首先初始化引脚等相关资源,然后创建app_task任务,并启动任务列表。

图 10
(2) 在app_task任务中定义共享内存基地址,需和设备树中指定地址一致,再初始化rpmsg资源,并等待连接上远程终端。

图 11
(3) 接收hellomsg,并循环收发乒乓信息。

图 12
(4) 信息以乒乓形式结束后注销rpmsg相关资源,并进入死循环。

图 13
2 rpmsg_lite_str_echo_rtos案例
2.1 案例功能
(1) cortex-a53释放cortex-m4,然后初始化rpmsg,并创建端点。
(2) cortex-a53启动linux,执行握手服务,并创建通信信道。
(3) linux驱动生成"/dev/ttyrpmsg30"节点,将用户输入至该节点的数据发送至cortex-m4。
(4) cortex-m4接收数据并进行打印,再将数据回发至cortex-a53。
(5) cortex-a53(linux驱动)接收数据并进行打印。
2.2 案例测试
案例bin目录下分别提供了tcm版本程序镜像文件rpmsg_lite_str_echo_rtos.bin和ddr版本程序镜像文件rpmsg_lite_str_echo_rtos_ddr.bin。
在u-boot命令行加载运行cortex-m4程序镜像文件后,rs232 uart4调试串口打印如下信息。
图 14
运行boot命令,在cortex-a53启动运行linux系统。
u-boot=> boot

图 15
进入评估板文件系统后,执行如下命令加载imx_rpmsg_tty模块,启动核间通信。
target# modprobe imx_rpmsg_tty

图 16
linux系统加载模块后,会发送数据"hello world"至cortex-m4。cortex-m4接收到数据后,在rs232 uart4调试串口将数据进行打印。

图 17
在usb to uart2调试串口执行如下命令,将接收到的数据发送至cortex-m4。
target# echo tronlong > /dev/ttyrpmsg30

图 18
cortex-m4接收到数据后,在rs232 uart4调试串口将数据进行打印,同时将数据回发至cortex-a53。

图 19
在usb to uart调试串口执行如下命令,可查看cortex-m4回发的数据。
target# dmesg | grep rpmsg_tty

图 20
2.3 关键代码
linux驱动程序
驱动的实现在imx_rpmsg_tty.c中完成,此文件位于内核"drivers/rpmsg/"路径下。
(1) imx_rpmsg_tty.c的写函数实现数据的发送,发送缓存最大设置为256byte。

图 21
(2) 在回调函数中,每次接收到cortex-m4的数据后,都以16进制的方式进行打印,打印等级为kerm_debug。

图 22
freertos程序
程序主体位于main函数中,定义位于main_remote.c中。
(1) 在main函数中初始化引脚等相关资源,然后创建app_task任务,并启动任务列表。

图 23
(2) 在app_task任务中定义共享内存基地址,需和设备树中指定地址一致,再初始化rpmsg资源,并创建通信终端。
图 24
(3) 在for循环中实现数据收发。

图 25