我正在使用双核imx板,其中Linux OS在一个核上运行,RTOS在第二核(M4)中。我想使用RPMsg在内核之间进行通信。我正在寻找Linux中的用户空间应用程序,以使用基本的打开,读取,写入命令来访问rpmsg通道。我已经根据NXP的“ rpmsg_lite_str_echo_rtos”示例创建了rpmsg通道。我成功地创建了虚拟tty'/ dev / RPMSG'。我也能够使用来自Linux的'echo'命令将数据发送到M4核心。
现在,我需要使用简单的C代码自动执行此过程。我想我将能够使用简单的读取,写入命令来做到这一点,对吗?我尝试在while循环(到/ dev / RPMSG)中写入数据,并使用简单的open,read,write命令从M4内核读取确认。但是我在m4中获得的只是一些随机字节和垃圾数据。我也无法使用read命令从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;
}


资源:
https://www.toradex.com/community/questions/30653/rpmsg-protocol-failing-with-ims-rpmsg-tty-on-linux.html

关于c - rpmsg-lite协议(protocol)的Linux用户空间示例,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52517961/

10-11 15:51