我使用的是双核IMX板,其中Linux操作系统在一个内核上运行,实时操作系统在第二个内核(M4)上运行。我想使用RPMsg在内核之间进行通信。我正在寻找linux中的用户空间应用程序,以便使用基本的open、read、write命令访问rpmsg通道。我已经按照恩智浦的'rpmsg_lite_str_echo_rtos‘示例创建了rpmsg通道。我成功地创建了虚拟tty '/dev/RPMSG‘。此外,我还可以使用linux中的‘M4’命令将数据发送到echo内核。现在,我需要使用一段简单的c代码来自动化这个过程。我想我可以使用简单的读写命令来做到这一点,对吧?我尝试在while循环中写入数据(到/dev/RPMSG),并使用简单的open、read、write命令从M4内核读取确认。但我在m4中得到的只是一些随机的字节和垃圾数据。此外,我无法使用read命令从m4读取任何数据。我是不是漏掉了什么?
发布于 2019-08-14 03:07:41
对于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;
}
https://stackoverflow.com/questions/52517961
复制相似问题