* Re: RTDM Kernel Driver exchanging with Linux Application via /dev/rtp0/ using RTIPC Protocol and XDDP socket
2020-05-09 0:59 ` ayaida marwane
@ 2020-05-11 6:44 ` Jan Kiszka
2022-05-23 22:16 ` ayaida marwane
1 sibling, 0 replies; 5+ messages in thread
From: Jan Kiszka @ 2020-05-11 6:44 UTC (permalink / raw)
To: ayaida marwane; +Cc: xenomai
On 09.05.20 02:59, ayaida marwane wrote:
>
>
>> Le 5 mai 2020 à 21:22, Jan Kiszka <jan.kiszka@siemens.com
>> <mailto:jan.kiszka@siemens.com>> a écrit :
>>
>> On 29.04.20 23:21, ayaida marwane via Xenomai wrote:
>>> Dear all,
>>> I am trying to develop a simple example of a RTDM driver running from
>>> Xenomai Kernel, that exchanges a string ("Hello world!") with a Linux
>>> Application using /dev/rtp0.
>>> I already succeeded doing this with Xenomai 2 using RT_PIPE. However,
>>> as I understand, this using RT_PIPE from the Kernel depreciated in
>>> Xenomai 3 and it is recommended to use RTIPC Protocol and a XDDP socket.
>>> In the documentation, there are some examples (xddp-echo.c,
>>> xddp-label.c and xddp-stream.c), that worked well in my Xenomai 3.0.7
>>> installed on a Raspberry Pi3.
>>> However, these examples are using a simple socket Protocol (socket(),
>>> bind(), sendto() and recvfrom()) using the POSIX Skin. So, using this
>>> in a RTDM module, will surely not work.
>>> Therefore, as I understand, I have to use the Real-time IPC defined
>>> in the RTDM Skin (socket__AF_RTIPC(), bind__AF_RTIPC(),
>>> sendmsg__AF_RTIPC() and recvmsg__AF_RTIPC()).
>>
>> These calls do not exist (where did you find them?) as your build
>> error also says. Check the inter-driver API for such a stacking
>> scenario. It provides rtdm_socket, rtdm_sendmsg etc.
>>
>> Depending on what kind of Linux application shall use the API in the
>> end, it can be simpler to compile that for Xenomai and use the RTDM
>> userspace API directly to talk to the RTDM driver.
>>
>> Jan
>>
>> --
>> Siemens AG, Corporate Technology, CT RDA IOT SES-DE
>> Corporate Competence Center Embedded Linux
>
> Dear Jan,
>
> Thank you for your replay. I tried to use the inter-driver API to
> communicate between the RTDM driver and the Linux side using /dev/rtp0.
> The exemple is given below (inspired from xddp-echo.c):
>
> ——————————————————————————————————————————————
>
> #include <rtdm/driver.h>
> #include <rtdm/ipc.h>
>
> #define XDDP_PORT 0 /* [0..CONFIG-XENO_OPT_PIPE_NRDEV - 1] and
> /dev/rtpX */
>
> static const char *msg = "Hello world!";
>
> static int __init my_module_init (void)
> {
> struct sockaddr_ipc saddr;
> int ret, s, len;
> size_t poolsz;
> char buf[128];
>
> rtdm_printk(KERN_INFO "%s.%s()\n", THIS_MODULE->name, __FUNCTION__);
>
> s = rtdm_socket(AF_RTIPC, SOCK_DGRAM, IPCPROTO_XDDP);
> if (s < 0) {
> rtdm_printk(KERN_INFO "socket error\n");
> }
>
> poolsz = 16384; /* bytes */
> ret = rtdm_setsockopt(s, SOL_XDDP, XDDP_POOLSZ,
> &poolsz, sizeof(poolsz));
> if (ret)
> rtdm_printk(KERN_INFO "setsockopt error\n");
>
> memset(&saddr, 0, sizeof(saddr));
> saddr.sipc_family = AF_RTIPC;
> saddr.sipc_port = XDDP_PORT;
> ret = rtdm_bind(s, (struct sockaddr *)&saddr, sizeof(saddr));
> if (ret)
> rtdm_printk(KERN_INFO "bind error\n");
>
> len = strlen(msg);
>
> rtdm_printk(KERN_INFO "%s: sent %d bytes, \"%.*s\"\n",
> __FUNCTION__, len, len, msg);
>
> ret = rtdm_sendto(s, msg, len, 0, NULL, 0);
>
> if (ret != len)
> rtdm_printk(KERN_INFO "sendto error = %d \n", ret);
>
> ret = rtdm_recvfrom(s, buf, sizeof(buf), 0, NULL, 0);
> if (ret <= 0)
> rtdm_printk(KERN_INFO "recvfrom error\n");
>
> rtdm_printk(KERN_INFO "%s: ==> Received from Linux %d bytes :
> %.*s\n", __FUNCTION__, ret, ret, buf);
>
> return 0;
> }
>
> static void __exit my_module_exit (void)
> {
> rtdm_printk(KERN_INFO "%s.%s()\n", THIS_MODULE->name, __FUNCTION__);
> }
> module_init(my_module_init);
> module_exit(my_module_exit);
> MODULE_LICENSE("GPL");
>
> ——————————————————————————————————————————————
>
> Now, the RTDM driver compiles. However, the problem is that when I
> execute it, it gives:
>
> ——————————————————————————————————————————————
>
> [ 5939.538234] rtdm_xddp.my_module_init()
> [ 5939.538437] my_module_init: sent 12 bytes, "Hello world!"
> [ 5939.538451] sendto error = -38
> [ 5939.538458] recvfrom error
> [ 5939.538468] my_module_init: ==> Received from Linux -38 bytes :
> [ 5944.279224] rtdm_xddp.my_module_exit()
>
> ——————————————————————————————————————————————
>
> The sendto fails. When I see the signification of this error is:
>
> ——————————————————————————————————————————————
>
> /*
> * This error code is special: arch syscall entry code will return
> * -ENOSYS if users try to call a syscall that doesn't exist. To keep
> * failures of syscalls that really do exist distinguishable from
> * failures due to attempts to use a nonexistent syscall, syscall
> * implementations should refrain from returning -ENOSYS.
> */
> #define ENOSYS 38 /* Invalid system call number */
>
> ——————————————————————————————————————————————
>
> Why it does not work? I found that the parameters of sendto() and
> rtdm_sendto() are the same.
>
The init function of a module is running in the context of a non-RT
Linux task (e.g. that of the modprobe process). You can't call any RTDM
blocking services from there. Your driver needs to run its RT code paths
inside a RTDM kernel task or (more commonly) inside the RT handler of
its all RTDM services and, thus, in RT task context of a Xenomai
application using it.
Jan
--
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: RTDM Kernel Driver exchanging with Linux Application via /dev/rtp0/ using RTIPC Protocol and XDDP socket
2020-05-09 0:59 ` ayaida marwane
2020-05-11 6:44 ` Jan Kiszka
@ 2022-05-23 22:16 ` ayaida marwane
1 sibling, 0 replies; 5+ messages in thread
From: ayaida marwane @ 2022-05-23 22:16 UTC (permalink / raw)
To: Jan Kiszka; +Cc: xenomai
Dear Jan,
I am coming back to the same question since I did not succeed in this task, now my example looks like :
——————————————————————————————————————————————
#include <rtdm/driver.h>
#include <rtdm/ipc.h>
#define XDDP_PORT 0
int ret;
rtdm_task_t task_desc;
static const char *msg = "Hello world!";
void task(void *arg){
int count = 0;
struct sockaddr_ipc saddr;
int s, len;
size_t poolsz;
/*
* Get a datagram socket to bind to the RT endpoint. Each
* endpoint is represented by a port number within the XDDP
* protocol namespace.
*/
s = rtdm_socket(AF_RTIPC, SOCK_DGRAM, IPCPROTO_XDDP);
if (s < 0) {
rtdm_printk(KERN_INFO "socket error = %d\n",s);
}
else{
rtdm_printk(KERN_INFO "socket succeed = %d\n",s);
}
/*
* Set a local 16k pool for the RT endpoint. Memory needed to
* convey datagrams will be pulled from this pool, instead of
* Xenomai's system pool.
*/
poolsz = 16384; /* bytes */
ret = rtdm_setsockopt(s, SOL_XDDP, XDDP_POOLSZ,
&poolsz, sizeof(poolsz));
if (ret)
rtdm_printk(KERN_INFO "setsockopt error= %d\n",ret);
else{
rtdm_printk(KERN_INFO "setsockopt succeed = %d\n",ret);
}
/*
* Bind the socket to the port, to setup a proxy to channel
* traffic to/from the Linux domain.
*
* saddr.sipc_port specifies the port number to use.
*/
memset(&saddr, 0, sizeof(saddr));
saddr.sipc_family = AF_RTIPC;
saddr.sipc_port = XDDP_PORT;
ret = rtdm_bind(s, (struct sockaddr *)&saddr, sizeof(saddr));
if (ret)
rtdm_printk(KERN_INFO "bind error = %d\n", ret);
else{
rtdm_printk(KERN_INFO "bind succeed = %d\n",ret);
}
}
static int __init my_module_init (void)
{
rtdm_printk(KERN_INFO "%s.%s()\n", THIS_MODULE->name, __FUNCTION__);
ret = rtdm_task_init(&task_desc, "rtdm-example", task, NULL, 30, 0);
if (ret) {
rtdm_printk(KERN_INFO "%s.%s() : error rtdm_task_init\n", THIS_MODULE->name, __FUNCTION__);
}
else rtdm_printk(KERN_INFO "%s.%s() : success rtdm_task_init\n", THIS_MODULE->name, __FUNCTION__);
return 0;
}
static void __exit my_module_exit (void)
{
rtdm_task_destroy(&task_desc);
rtdm_printk(KERN_INFO "%s.%s()\n", THIS_MODULE->name, __FUNCTION__);
}
module_init(my_module_init);
module_exit(my_module_exit);
MODULE_LICENSE("GPL");
——————————————————————————————————————————————
Now, the RTDM driver compiles. However, the problem is that when I execute it, it gives:
——————————————————————————————————————————————
[ 470.184417] rtdm_xddp.my_module_init()
[ 470.184932] rtdm_xddp.my_module_init() : success rtdm_task_init
[ 470.185003] socket succeed = 1
[ 470.185013] setsockopt succeed = 0
[ 470.185022] bind error = -38
[ 470.271916] rtdm_xddp.my_module_exit()
——————————————————————————————————————————————
The bind fails. When I see the signification of this error is:
——————————————————————————————————————————————
/*
* This error code is special: arch syscall entry code will return
* -ENOSYS if users try to call a syscall that doesn't exist. To keep
* failures of syscalls that really do exist distinguishable from
* failures due to attempts to use a nonexistent syscall, syscall
* implementations should refrain from returning -ENOSYS.
*/
#define ENOSYS 38 /* Invalid system call number */
——————————————————————————————————————————————
Why it does not work?
Thanks for your help.
BR,Marwane.
Le samedi 9 mai 2020 à 02:59:50 UTC+2, ayaida marwane <ayaida_marwane@yahoo.fr> a écrit :
Le 5 mai 2020 à 21:22, Jan Kiszka <jan.kiszka@siemens.com> a écrit :
On 29.04.20 23:21, ayaida marwane via Xenomai wrote:
Dear all,
I am trying to develop a simple example of a RTDM driver running from Xenomai Kernel, that exchanges a string ("Hello world!") with a Linux Application using /dev/rtp0.
I already succeeded doing this with Xenomai 2 using RT_PIPE. However, as I understand, this using RT_PIPE from the Kernel depreciated in Xenomai 3 and it is recommended to use RTIPC Protocol and a XDDP socket.
In the documentation, there are some examples (xddp-echo.c, xddp-label.c and xddp-stream.c), that worked well in my Xenomai 3.0.7 installed on a Raspberry Pi3.
However, these examples are using a simple socket Protocol (socket(), bind(), sendto() and recvfrom()) using the POSIX Skin. So, using this in a RTDM module, will surely not work.
Therefore, as I understand, I have to use the Real-time IPC defined in the RTDM Skin (socket__AF_RTIPC(), bind__AF_RTIPC(), sendmsg__AF_RTIPC() and recvmsg__AF_RTIPC()).
These calls do not exist (where did you find them?) as your build error also says. Check the inter-driver API for such a stacking scenario. It provides rtdm_socket, rtdm_sendmsg etc.
Depending on what kind of Linux application shall use the API in the end, it can be simpler to compile that for Xenomai and use the RTDM userspace API directly to talk to the RTDM driver.
Jan
--
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux
Dear Jan,
Thank you for your replay. I tried to use the inter-driver API to communicate between the RTDM driver and the Linux side using /dev/rtp0. The exemple is given below (inspired from xddp-echo.c):
——————————————————————————————————————————————
#include <rtdm/driver.h>#include <rtdm/ipc.h>
#define XDDP_PORT 0 /* [0..CONFIG-XENO_OPT_PIPE_NRDEV - 1] and /dev/rtpX */
static const char *msg = "Hello world!";
static int __init my_module_init (void){ struct sockaddr_ipc saddr; int ret, s, len; size_t poolsz; char buf[128];
rtdm_printk(KERN_INFO "%s.%s()\n", THIS_MODULE->name, __FUNCTION__);
s = rtdm_socket(AF_RTIPC, SOCK_DGRAM, IPCPROTO_XDDP); if (s < 0) { rtdm_printk(KERN_INFO "socket error\n"); }
poolsz = 16384; /* bytes */ ret = rtdm_setsockopt(s, SOL_XDDP, XDDP_POOLSZ, &poolsz, sizeof(poolsz)); if (ret) rtdm_printk(KERN_INFO "setsockopt error\n");
memset(&saddr, 0, sizeof(saddr)); saddr.sipc_family = AF_RTIPC; saddr.sipc_port = XDDP_PORT; ret = rtdm_bind(s, (struct sockaddr *)&saddr, sizeof(saddr)); if (ret) rtdm_printk(KERN_INFO "bind error\n");
len = strlen(msg);
rtdm_printk(KERN_INFO "%s: sent %d bytes, \"%.*s\"\n", __FUNCTION__, len, len, msg);
ret = rtdm_sendto(s, msg, len, 0, NULL, 0);
if (ret != len) rtdm_printk(KERN_INFO "sendto error = %d \n", ret);
ret = rtdm_recvfrom(s, buf, sizeof(buf), 0, NULL, 0); if (ret <= 0) rtdm_printk(KERN_INFO "recvfrom error\n");
rtdm_printk(KERN_INFO "%s: ==> Received from Linux %d bytes : %.*s\n", __FUNCTION__, ret, ret, buf);
return 0;}
static void __exit my_module_exit (void){ rtdm_printk(KERN_INFO "%s.%s()\n", THIS_MODULE->name, __FUNCTION__);}module_init(my_module_init);module_exit(my_module_exit);MODULE_LICENSE("GPL");
——————————————————————————————————————————————
Now, the RTDM driver compiles. However, the problem is that when I execute it, it gives:
——————————————————————————————————————————————
[ 5939.538234] rtdm_xddp.my_module_init()[ 5939.538437] my_module_init: sent 12 bytes, "Hello world!"[ 5939.538451] sendto error = -38 [ 5939.538458] recvfrom error[ 5939.538468] my_module_init: ==> Received from Linux -38 bytes : [ 5944.279224] rtdm_xddp.my_module_exit()
——————————————————————————————————————————————
The sendto fails. When I see the signification of this error is:
——————————————————————————————————————————————
/*
* This error code is special: arch syscall entry code will return
* -ENOSYS if users try to call a syscall that doesn't exist. To keep
* failures of syscalls that really do exist distinguishable from
* failures due to attempts to use a nonexistent syscall, syscall
* implementations should refrain from returning -ENOSYS.
*/
#define ENOSYS 38 /* Invalid system call number */
——————————————————————————————————————————————
Why it does not work? I found that the parameters of sendto() and rtdm_sendto() are the same.
Thanks for your help.
BR,Marwane.
^ permalink raw reply [flat|nested] 5+ messages in thread