Implement blocking read on rpmsg

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Implement blocking read on rpmsg

Jump to solution
2,321 Views
ddeyo1
Contributor I

I have been succesfully using rpmsg on an iMX8 (4 A53's, 1 M4) for a while.  I'd like to make the 'read' function blocking, as the code I've found for rpmsg on the linux side uses polling and an ioctl to determine if data is available to be read. 

The read thread has a sleep in it to keep the cpu from fly away.  That sleep amounts to a 1ms delay in all of the messages coming from the m4.  In our real time appliction, that can be a problem.

All my effrots to make the read blocking have returned no error, but the read doesn't block either.  I've tried (&(~O_NONBLOCK)) and FIONBIO set to zero.

I want to have my read thread consuming no cpu cycles until data is ready from the M4.  

Is there a way to implement blocking on a read from rpmsg on the linux side?

0 Kudos
1 Solution
2,133 Views
Dhruvit
NXP TechSupport
NXP TechSupport

Hi @ddeyo1,

You can find an example code for the M4 core which is required to communicate with the linux side rpmsg char driver on other communities like toradex.

 

----------------------------------------------------------------------------------
Note: If this answers your query, kindly close the ticket. Thank you!
----------------------------------------------------------------------------------

 

Thanks & Regards,
Dhruvit.

View solution in original post

0 Kudos
13 Replies
2,180 Views
Dhruvit
NXP TechSupport
NXP TechSupport

Hi @ddeyo1,

It should be mentioned that the example code for the rpmsg char driver is not available in rpmsg-lite MCUExpresso SDK.

 

Thanks & Regards,
Dhruvit.

0 Kudos
2,174 Views
ddeyo1
Contributor I

Thank you,

Where is it available?

0 Kudos
2,134 Views
Dhruvit
NXP TechSupport
NXP TechSupport

Hi @ddeyo1,

You can find an example code for the M4 core which is required to communicate with the linux side rpmsg char driver on other communities like toradex.

 

----------------------------------------------------------------------------------
Note: If this answers your query, kindly close the ticket. Thank you!
----------------------------------------------------------------------------------

 

Thanks & Regards,
Dhruvit.

0 Kudos
2,303 Views
Dhruvit
NXP TechSupport
NXP TechSupport

Hi @ddeyo1,

The imx_rpmsg_tty.c driver does not support blocking read from RPMSG tty.
 
However, one can try using the "/drivers/rpmsg/rpmsg_char.c (CONFIG_RPMSG_CHAR)" driver. It does have some support for blocking IO with the (~O_NONBLOCK) option.
 
One can refer to the below thread for more information about the rpmsg_char driver with i.MX processors
0 Kudos
2,227 Views
ddeyo1
Contributor I

Do you have any idea what I need to change in the M4 co-processor  code in order for it to work with the rpmsg_char driver?

0 Kudos
2,272 Views
ddeyo1
Contributor I

Thank you,

Is there any example of co-processor code using rpmsg_char, running either bare bone or FreeRTOS?

I have code for rpmsg_tty but I wouldn't expect it to act the same.

-dwd

0 Kudos
2,295 Views
kef2
Senior Contributor IV
  • The imx_rpmsg_tty.c driver does not support blocking read from RPMSG tty.

Are you sure? I've no problems with blocking read from /dev/ttyRPMSG on iMX7D and VF.

0 Kudos
2,271 Views
ddeyo1
Contributor I

It definitely appears my driver doesn't support it.  There are no 'waits' in my version, which are necessary for blocking reads (as far as I understand).  In rpmsg_char, you can clearly see waits and I see an NXP member has stated as much.

All that said, how were you able achieve a block in your linux-side application?

0 Kudos
2,269 Views
kef2
Senior Contributor IV

I believe you have the same imx_rpmsg_tty driver on iMX8. Blocking or non blocking TTY, depends on termios settings, perhaps on O_NONBLOCK in some way too, but termios matters. Like with serial port TTY, it can be both blocking and non blocking. Google suggested this , perhaps there's better reading.

I open it this way. read() blocks.

	struct termios newtio;

		rpmsg_tty = open( rpmsgdevice, O_RDWR | O_NOCTTY);
		tcflush(rpmsg_tty, TCIOFLUSH);
		tcgetattr(rpmsg_tty, &newtio);
	 	cfmakeraw(&newtio);
		tcsetattr(rpmsg_tty, TCSANOW, &newtio);

 

0 Kudos
2,262 Views
ddeyo1
Contributor I

Thanks,

I tried your version and even added VTIME and VMIN (google ref.), with no change.

The cpu on my thread goes to 1.3% with a 1ms sleep.  With a 1 second sleep, I get my test log, every second.  It doesn't appear to be acting the same using my kernel (5.4.110).

 

-dwd

0 Kudos
2,260 Views
kef2
Senior Contributor IV

Are you sure your M4 FW isn't sending, ehh, .. some empty messages? Perhaps it's just something odd on iMX8, I can't believe it.

0 Kudos
2,265 Views
ddeyo1
Contributor I

Thanks,

I'll give it a try and let you know.

-dwd

0 Kudos
2,229 Views
ddeyo1
Contributor I

Hard to say, about M4 empty rpmsg messages.

I am using an ioctl (ioctl(mFdRpmsg, FIONREAD, &byte_avail)) to check if there's anything in the buffer of the kernel driver. It says there's nothing.

On my M4 side, I have two queues, TX/RX. Those are clearly blocked, based off of previous testing.

I see no evidence that an empty message is being sent. 

I have a log being sent based off the return from the ioctl. It doesn't indicate any empty messages.

Perhaps it's not so much the iMx8, but the kernel. The kernel driver decides if blocking is supported.

In the rpmsg_char driver (on my kernel), it clearly indicates it should support blocking reads. The rpmsg_tty driver doesn't have any waits on any queues available.

I believe I will need to use rpmsg_char, but I don't have any m4 (co-processor) code for rpmsg_char. I do have working M4 code for rpmsg_tty.

0 Kudos