【问题标题】:Linux userspace example for rpmsg-lite protocolrpmsg-lite 协议的 Linux 用户空间示例
【发布时间】:2019-03-02 05:53:29
【问题描述】:

我正在使用双核 imx 板,其中 Linux 操作系统在一个核心上运行,RTOS 在第二个核心 (M4) 上运行。我想使用 RPMsg 在内核之间进行通信。我正在寻找 linux 中的用户空间应用程序,以使用基本的打开、读取、写入命令访问 rpmsg 通道。我根据 NXP 的“rpmsg_lite_str_echo_rtos”示例创建了 rpmsg 通道。我成功地创建了虚拟 tty '/dev/RPMSG'。我还能够使用来自 linux 的“echo”命令将数据发送到 M4 核心。 现在我需要使用一个简单的 c 代码来自动化这个过程。我想我可以使用简单的读、写命令来做到这一点,对吧?我尝试在 while 循环中写入数据(到 /dev/RPMSG),并使用简单的打开、读取、写入命令从 M4 核心读取确认。但我在 m4 中得到的只是一些随机字节和垃圾数据。我也无法使用 read 命令从 m4 读取任何数据。我在这里错过了什么吗?

【问题讨论】:

  • “我错过了什么吗?” - 我们当然是。你“尝试”了一些东西,但没有奏效。向我们展示你的尝试不是很有意义吗!?您的 M4 部件正在运行 RTOS 的事实很难证明包含 RTOS 标签的合理性,除非您认为该事实对您的问题有影响 - 在这种情况下,请向我们展示证据。

标签: c embedded-linux multicore rtos imx6


【解决方案1】:

对于 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-18
    相关资源
    最近更新 更多