* [Xenomai] Can rtdm_read, rtdm_write, be used in userspace in Xenomai 3.x
@ 2015-05-08 11:28 Helder Daniel
2015-05-08 13:37 ` Philippe Gerum
0 siblings, 1 reply; 3+ messages in thread
From: Helder Daniel @ 2015-05-08 11:28 UTC (permalink / raw)
To: Xenomai@xenomai.org
Hi,
I am writing a driver that implements read_rt and read_nrt handlers for
Xenomai 3-rc4 Cobalt.
But I am having problems when trying to read from user space in comand line:
$> cat /dev/rtdm/device0
cat: /dev/rtdm/device0: Invalid argument
and also from a user space real time thread:
f = open("/dev/rtdm/device0");
for(;;){
rt_task_wait_period(NULL);
read (f, &count, 1);
//...
This read gives me garbage.
The handler is registered with:
static struct rtdm_driver device_driver = {
.profile_info = RTDM_PROFILE_INFO(DEVICENAME,
RTDM_CLASS_MISC,
RTDM_SUBCLASS_IOPORTS,
DRIVERVER),
.device_flags = RTDM_NAMED_DEVICE|RTDM_EXCLUSIVE,
.device_count = 1,
.context_size = 0,
.ops = {
.open = device_open,
.close = device_close,
//.write_rt = device_write_rt,
.read_rt = device_read_rt,
.read_nrt = device_read_rt,
},
};
static struct rtdm_device device_devices[2] = {
[ 0 ... 1 ] = {
.driver = &device_driver,
.label = DEVICENAMEN,
}
};
And the rt and nrt read handlers are the same function:
//Read from the device
static ssize_t device_read_rt(struct rtdm_fd *fd, void __user *buf, size_t
size) {
int err;
unsigned char rawdata[2];
rawdata[0] = 'A';
rawdata[1] = '\0';
rtdm_printk("rtdm_read called\n");
if ((err=rtdm_safe_copy_to_user(fd, buf, rawdata, RAWDATALEN))) {
rtdm_printk("radaradcdriverRTDM: rtdm_safe_copy_to_user, error %d\n", err);
return -EFAULT;
}
rtdm_printk("rtdm_safe_copy_to_user, send %d bytes\n", err);
return err;
}
Open and close have just printks to show if they were called:
//Open the device
static int device_open(struct rtdm_fd *fd, int oflags){
rtdm_printk("rtdm_open called\n");
return 0;
}
//Close the device
static void device_close(struct rtdm_fd *fd) {
rtdm_printk("rtdm_close called\n");
}
Looking at kernel log, after accessing the driver from user spcae both:
in cmd line with:
$> cat /dev/rtdm/device0
and from a real time task
it seems that the open, close and read are never called, since there is no
entry in kernel log.
I am doing something wrong?
Should I use rtdm_read in user space to access the driver?
I tried to use it including <rtdm/rtdm.h> on user space app, but when
linking it gave me the error:
radarserver.c:(.text+0x138): undefined reference to `rtdm_read'
I thought that if I set read_nrt I can use just read.
rtdm_read will only be necessary for read_rt.
But I never implemented this kernel/user space transfer before with Xenomai
(only Linux), I just took a look at the implementation of some RTDM drivers
from xenomai sources: <xenomai-3.0-rc4>/kernel/drivers/testing/
But I might have missed something and doing something wrong.
Thanks for any suggestion
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Xenomai] Can rtdm_read, rtdm_write, be used in userspace in Xenomai 3.x
2015-05-08 11:28 [Xenomai] Can rtdm_read, rtdm_write, be used in userspace in Xenomai 3.x Helder Daniel
@ 2015-05-08 13:37 ` Philippe Gerum
2015-05-08 14:38 ` Helder Daniel
0 siblings, 1 reply; 3+ messages in thread
From: Philippe Gerum @ 2015-05-08 13:37 UTC (permalink / raw)
To: Helder Daniel, Xenomai@xenomai.org
On 05/08/2015 01:28 PM, Helder Daniel wrote:
> Hi,
>
> I am writing a driver that implements read_rt and read_nrt handlers for
> Xenomai 3-rc4 Cobalt.
> But I am having problems when trying to read from user space in comand line:
>
> $> cat /dev/rtdm/device0
> cat: /dev/rtdm/device0: Invalid argument
>
> and also from a user space real time thread:
>
> f = open("/dev/rtdm/device0");
> for(;;){
> rt_task_wait_period(NULL);
> read (f, &count, 1);
> //...
>
> This read gives me garbage.
>
>
[snip]
> Looking at kernel log, after accessing the driver from user spcae both:
>
> in cmd line with:
>
> $> cat /dev/rtdm/device0
>
> and from a real time task
>
> it seems that the open, close and read are never called, since there is no
> entry in kernel log.
>
> I am doing something wrong?
The Cobalt read() service must be called for invoking the related
read_[n]rt handler in your RTDM driver. Since the cat command will use
the regular glibc read() call instead, this won't work. Your test
program is likely missing the wrapping step, which is performed by a
linker trick, substituting calls to read() and other POSIX services to
the corresponding Cobalt implementation. In your test, the glibc
counterpart is still used, which won't work either.
You need to make sure to pass --posix to xeno-config --ldflags for
retrieving the proper LDFLAGS that do the magic for wrapping POSIX
calls. You can combine APIs with xeno-config, such as --alchemy --posix.
>
> Should I use rtdm_read in user space to access the driver?
>
No, this is a kernel-space only service, for inter-driver communication.
This is the reason why you can't pull the related declarations in a
user-space program.
--
Philippe.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Xenomai] Can rtdm_read, rtdm_write, be used in userspace in Xenomai 3.x
2015-05-08 13:37 ` Philippe Gerum
@ 2015-05-08 14:38 ` Helder Daniel
0 siblings, 0 replies; 3+ messages in thread
From: Helder Daniel @ 2015-05-08 14:38 UTC (permalink / raw)
To: Philippe Gerum; +Cc: Xenomai@xenomai.org
Ok, the problem was indeed that the wrappers was not linked.
After telling xeno-config to generate switches for APIs --alchemy and
--posix its working fine.
Thanks
On 8 May 2015 at 14:37, Philippe Gerum <rpm@xenomai.org> wrote:
> On 05/08/2015 01:28 PM, Helder Daniel wrote:
> > Hi,
> >
> > I am writing a driver that implements read_rt and read_nrt handlers for
> > Xenomai 3-rc4 Cobalt.
> > But I am having problems when trying to read from user space in comand
> line:
> >
> > $> cat /dev/rtdm/device0
> > cat: /dev/rtdm/device0: Invalid argument
> >
> > and also from a user space real time thread:
> >
> > f = open("/dev/rtdm/device0");
> > for(;;){
> > rt_task_wait_period(NULL);
> > read (f, &count, 1);
> > //...
> >
> > This read gives me garbage.
> >
> >
>
> [snip]
>
> > Looking at kernel log, after accessing the driver from user spcae both:
> >
> > in cmd line with:
> >
> > $> cat /dev/rtdm/device0
> >
> > and from a real time task
> >
> > it seems that the open, close and read are never called, since there is
> no
> > entry in kernel log.
> >
> > I am doing something wrong?
>
> The Cobalt read() service must be called for invoking the related
> read_[n]rt handler in your RTDM driver. Since the cat command will use
> the regular glibc read() call instead, this won't work. Your test
> program is likely missing the wrapping step, which is performed by a
> linker trick, substituting calls to read() and other POSIX services to
> the corresponding Cobalt implementation. In your test, the glibc
> counterpart is still used, which won't work either.
>
> You need to make sure to pass --posix to xeno-config --ldflags for
> retrieving the proper LDFLAGS that do the magic for wrapping POSIX
> calls. You can combine APIs with xeno-config, such as --alchemy --posix.
>
> >
> > Should I use rtdm_read in user space to access the driver?
> >
>
> No, this is a kernel-space only service, for inter-driver communication.
> This is the reason why you can't pull the related declarations in a
> user-space program.
>
> --
> Philippe.
>
--
Helder Daniel
UALG - FCT
DEEI
http://w3.ualg.pt/~hdaniel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-05-08 14:38 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-08 11:28 [Xenomai] Can rtdm_read, rtdm_write, be used in userspace in Xenomai 3.x Helder Daniel
2015-05-08 13:37 ` Philippe Gerum
2015-05-08 14:38 ` Helder Daniel
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.