Hi folks,
My question comes from when using the ti-rpmsg-char repo https://git.ti.com/cgit/rpmsg/ti-rpmsg-char/about/ as an application example of rpmsg, and trying to use it in our projects.
In the example it provided (rpmsg-char-simple.c), it performs a ping-pong rpmsg communication between linux core, and remote processor (for example m4f mcu in my case). Basically linux core send to the remote processor, then the remote processor bounce a message back, and repeat this for several times.
I have tried on AM62x board the example works as expected. My observation (please correct if not right) is, the recv_msg() method is a blocking operation, and will hang there if not receiving any message. In the ping-pong communication example this is not of concern since the incoming of message is deterministic (once every sending operation finished / number of messages pre-defined).
In our application, I hope to use the recv_msg() method to handle messages that arrives at random time / of any number, like a listening mode. I modified the scripts and tried to simply call recv_msg() method alone (no longer in a ping-pong manner), while I found if not receving anything, it will hang there and no way to elegantly exit. (ctrl-c will cause the "Application did not close some rpmsg_char devices" message), also not able to operate on other things.
could you provide some advice that if I missed something, or some better practice to use the recv_msg() method?
Regards,
Wei
My adapted codes are something like below:
#define RPROC_ID_USE 9 // .... // .... /** * @brief API for linux core get into the mode of receiving incoming rpmsg. * * @param dev_name * @param remote_endpt * @return int */ int rpmsg_recv_blob(char* dev_name, int remote_endpt) { int ret = 0; int packet_len; char eptdev_name[32] = { 0 }; char packet_buf[128] = { 0 }; rpmsg_char_dev_t *rcdev; int flags = 0; /* * Open the remote rpmsg device identified by dev_name and bind the * device to a local end-point used for receiving messages from * remote processor */ sprintf(eptdev_name, "rpmsg-char-%d-%d", RPROC_ID_USE, getpid()); rcdev = rpmsg_char_open(RPROC_ID_USE, dev_name, remote_endpt, eptdev_name, flags); if (!rcdev) { perror("Can't create an endpoint device"); return -EPERM; } ret = recv_msg(rcdev->fd, 128, (char *)packet_buf, &packet_len); if (ret < 0) { printf("recv_msg failed, ret = %d\n", ret); goto out; } // handle the received data blob if (ret >= 0) { // ... do something } goto out; out: ret = rpmsg_char_close(rcdev); if (ret < 0) perror("Can't delete the endpoint device\n"); return ret; } /******************** and in main(): ********************/ int main(int argc, char *argv[]) { int ret, status, c; int rproc_id = 0; int remote_endpt = REMOTE_ENDPT; char *dev_name = NULL; // .... status = rpmsg_recv_blob(dev_name, remote_endpt); rpmsg_char_exit(); return 0; }