首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >rpmsg-lite协议的Linux用户空间示例

rpmsg-lite协议的Linux用户空间示例
EN

Stack Overflow用户
提问于 2018-09-26 20:38:40
回答 1查看 1K关注 0票数 0

我使用的是双核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读取任何数据。我是不是漏掉了什么?

EN

回答 1

Stack Overflow用户

发布于 2019-08-14 03:07:41

对于Linux核心:

代码语言:javascript
运行
复制
#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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52517961

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档