I am using a dual core imx board in which Linux OS running on one core and RTOS in second core(M4). I want to communicate between the cores using RPMsg. I am looking for a userspace application in linux to access the rpmsg channel using the basic open, read, write commands. I have created the rpmsg channel as per the 'rpmsg_lite_str_echo_rtos' example from NXP. I was successfully able to create virtual tty '/dev/RPMSG'. Also i was able to send data to M4 core using 'echo' command from linux. Now i require to automate this process using a simple c code. I think i will be able to do that using simple read, write commands, right? I tried writing data in a while loop (to /dev/RPMSG) and read the acknowledgement from M4 core using simple open, read, write commands. But all i was getting in m4 was some random bytes and junk data. Also i couldn't read any data from m4 using the read command. Am i missing something here?
Asked
Active
Viewed 1,747 times
0
-
1_"Am i missing something here?"_ - We certainly are. You "tried" something, which did not work. Would it not make complete sense to show us your attempt!? The fact that your M4 part is running an RTOS hardly justifies including the RTOS tag, unless you think that fact is contributory to your issue - in which case show us the evidence. – Clifford Oct 07 '18 at 16:08
1 Answers
0
For the Linux core(s):
#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;
}

Jerry Pylarinos
- 1
- 2