我使用的是双核imx板,其中Linux操作系统在一个核心上运行,RTOS在第二个核心(M4)上运行。我想使用 RPMsg 在内核之间进行通信。我正在寻找 Linux 中的用户空间应用程序,以使用基本的打开、读取、写入命令访问 rpmsg channel 。我已经根据 NXP 的“rpmsg_lite_str_echo_rtos”示例创建了 rpmsg channel 。我成功地创建了虚拟 tty '/dev/RPMSG'。我还能够使用 Linux 中的“echo”命令将数据发送到 M4 核心。 现在我需要使用简单的 C 代码自动执行此过程。我想我可以使用简单的读取、写入命令来做到这一点,对吧?我尝试在 while 循环中写入数据(写入/dev/RPMSG),并使用简单的打开、读取、写入命令从 M4 核心读取确认。但我在 m4 中得到的只是一些随机字节和垃圾数据。另外,我无法使用读取命令从 m4 读取任何数据。我在这里错过了什么吗?
最佳答案
对于 Linux 核心:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h> // file control
#include <termios.h> // POSIX terminal control
#include <sched.h>
#define DEVICE "/dev/ttyRPMSG0"
int main(void)
{
int fd;
struct termios tty;
char buf[100];
int len;
printf("Opening device...\n");
fd = open( DEVICE, O_RDWR | O_NOCTTY | O_NDELAY ); // read/write, no console, no delay
if ( fd < 0 )
{
printf("Error, cannot open device\n");
return 1;
}
tcgetattr( fd, &tty ); // get current attributes
cfmakeraw( &tty ); // raw input
tty.c_cc[ VMIN ] = 0; // non blocking
tty.c_cc[ VTIME ] = 0; // non blocking
tcsetattr( fd, TCSANOW, &tty ); // write attributes
printf( "Device is open\n" );
for ( ;; )
{
len = read( fd, buf, sizeof( buf ) );
if ( len > 0 )
{
buf[ len ] = '\0';
printf( "%s \r\n", buf );
}
else
{
sched_yield();
}
}
return EXIT_SUCCESS;
}
关于c - rpmsg-lite 协议(protocol)的 Linux 用户空间示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52517961/