* [Xenomai] Transfer data from a kernel module to user
@ 2014-03-14 9:52 ashwin damle
2014-03-14 10:02 ` Gilles Chanteperdrix
0 siblings, 1 reply; 4+ messages in thread
From: ashwin damle @ 2014-03-14 9:52 UTC (permalink / raw)
To: xenomai
Hello Developers,
I am trying to pass data from the Xenomai kernel module, using RTDM driver,
to a user program. I am using the default examples-tut01-skeleton-drv.c and
tut01-skeleton-app.c. The examples are working nicely and I could get the
right expected results. I am using Linux raspberrypi 3.5.7-xenomai #4
PREEMPT Tue Mar 11 16:49:44 IST 2014 armv6l GNU/Linux, Xenomai used for
during compilation was xenomai-2.6.2.1. The target is RaspberryPi.
The intention is to transfer a integer variable from the kernel to user. I
tried changing the default example program only to reeive the error message
""ERROR : can't copy data from driver". I am unable to figure-out the
problem. Attach is the program which I edited. I have written a comment
wherever I define my variable, which is freq. Below is a snap
"
static ssize_t simple_rtdm_read_nrt(struct rtdm_dev_context *context,
rtdm_user_info_t * user_info, void *buf,
size_t nbyte)
{
buffer_t * buffer = (buffer_t *) context->dev_private;
int size = (buffer->size > nbyte) ? nbyte : buffer->size;
buffer->size = sizeof(buffer->freq);
buffer->freq = 50; //my variable, this is printed correctly
as seen in dmesg
if (rtdm_safe_copy_to_user(user_info, buf, &buffer->freq,
sizeof(buffer->freq)))
rtdm_printk("ERROR : can't copy data from driver\n");
return size;
}
"
Attached is the user program, too.
Also, I wanted to know whether it is explicitly required to write to the
device before reading it? I only want to read the device.( My application
is noting the time of GPIO interrupts. )
Could you please help me with this? Request you to help me solve the
problem.
Thanks.
Ashwin
--
Support the
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tut01-skeleton-app.c
Type: text/x-csrc
Size: 3667 bytes
Desc: not available
URL: <http://www.xenomai.org/pipermail/xenomai/attachments/20140314/6a2404f5/attachment.c>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tut01-skeleton-drv.c
Type: text/x-csrc
Size: 5110 bytes
Desc: not available
URL: <http://www.xenomai.org/pipermail/xenomai/attachments/20140314/6a2404f5/attachment-0001.c>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Xenomai] Transfer data from a kernel module to user
2014-03-14 9:52 [Xenomai] Transfer data from a kernel module to user ashwin damle
@ 2014-03-14 10:02 ` Gilles Chanteperdrix
[not found] ` <CAC-NLww-JD_q2pfW1L0EgxQGA6O400GcmYaQxsgvx7=oY9KD8A@mail.gmail.com>
0 siblings, 1 reply; 4+ messages in thread
From: Gilles Chanteperdrix @ 2014-03-14 10:02 UTC (permalink / raw)
To: ashwin damle; +Cc: xenomai
On 03/14/2014 10:52 AM, ashwin damle wrote:
> Hello Developers,
>
> I am trying to pass data from the Xenomai kernel module, using RTDM driver,
> to a user program. I am using the default examples-tut01-skeleton-drv.c and
> tut01-skeleton-app.c. The examples are working nicely and I could get the
> right expected results. I am using Linux raspberrypi 3.5.7-xenomai #4
> PREEMPT Tue Mar 11 16:49:44 IST 2014 armv6l GNU/Linux, Xenomai used for
> during compilation was xenomai-2.6.2.1. The target is RaspberryPi.
>
> The intention is to transfer a integer variable from the kernel to user. I
> tried changing the default example program only to reeive the error message
> ""ERROR : can't copy data from driver". I am unable to figure-out the
> problem. Attach is the program which I edited. I have written a comment
> wherever I define my variable, which is freq. Below is a snap
>
> "
> static ssize_t simple_rtdm_read_nrt(struct rtdm_dev_context *context,
> rtdm_user_info_t * user_info, void *buf,
> size_t nbyte)
> {
> buffer_t * buffer = (buffer_t *) context->dev_private;
> int size = (buffer->size > nbyte) ? nbyte : buffer->size;
>
> buffer->size = sizeof(buffer->freq);
> buffer->freq = 50; //my variable, this is printed correctly
> as seen in dmesg
>
> if (rtdm_safe_copy_to_user(user_info, buf, &buffer->freq,
> sizeof(buffer->freq)))
> rtdm_printk("ERROR : can't copy data from driver\n");
>
> return size;
> }
> "
> Attached is the user program, too.
>
> Also, I wanted to know whether it is explicitly required to write to the
> device before reading it? I only want to read the device.( My application
> is noting the time of GPIO interrupts. )
>
> Could you please help me with this? Request you to help me solve the
> problem.
copy_to_user operates on addresses, so you should pass &freq instead of
(void *)freq to rt_dev_read, otherwise the current value of freq, which
is a random value, is used by copy_to_user as an address which causes a
fault.
--
Gilles.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Xenomai] Transfer data from a kernel module to user
[not found] ` <CAC-NLww-JD_q2pfW1L0EgxQGA6O400GcmYaQxsgvx7=oY9KD8A@mail.gmail.com>
@ 2014-03-14 15:41 ` Gilles Chanteperdrix
2014-03-15 2:58 ` ashwin damle
0 siblings, 1 reply; 4+ messages in thread
From: Gilles Chanteperdrix @ 2014-03-14 15:41 UTC (permalink / raw)
To: ashwin damle, Xenomai
On 03/14/2014 03:13 PM, ashwin damle wrote:
> Hi Gilles,
>
> I got it working. Thanks for your help. I am very grateful to you. You
> responded really fast.
>
> There is one more small doubt. I want the kernel module to run with
> highest priority. I saw the APIs for setting priority but they refer to
> rtdm_task_init() which is not used in my program tut01-skeleton-drv.c-so
> how do I set priority?
You do not seem to understand much about C and kernel modules
programming. I suggest you read some documentation, or buy some training
on C language programming. When you are done, read the "Linux device
drivers" book:
https://lwn.net/Kernel/LDD3/
Then come back to Xenomai, and start by reading the documentation here:
http://xenomai.org/index.php/Included_documentation_summary
Please do not send me private messages.
--
Gilles.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Xenomai] Transfer data from a kernel module to user
2014-03-14 15:41 ` Gilles Chanteperdrix
@ 2014-03-15 2:58 ` ashwin damle
0 siblings, 0 replies; 4+ messages in thread
From: ashwin damle @ 2014-03-15 2:58 UTC (permalink / raw)
To: Xenomai
Hello Gilles,
Yes, you are correct.
Sorry to bother you with trivial questions. I will start reading the
documentation you mentioned. Also, the e-mail sent to you was not
intentional. Sorry again.
Thanks for your help.
Ashwin
On 14 March 2014 21:11, Gilles Chanteperdrix <
gilles.chanteperdrix@xenomai.org> wrote:
> On 03/14/2014 03:13 PM, ashwin damle wrote:
>
>> Hi Gilles,
>>
>> I got it working. Thanks for your help. I am very grateful to you. You
>> responded really fast.
>>
>> There is one more small doubt. I want the kernel module to run with
>> highest priority. I saw the APIs for setting priority but they refer to
>> rtdm_task_init() which is not used in my program tut01-skeleton-drv.c-so
>> how do I set priority?
>>
>
> You do not seem to understand much about C and kernel modules programming.
> I suggest you read some documentation, or buy some training on C language
> programming. When you are done, read the "Linux device drivers" book:
>
> https://lwn.net/Kernel/LDD3/
>
> Then come back to Xenomai, and start by reading the documentation here:
> http://xenomai.org/index.php/Included_documentation_summary
>
> Please do not send me private messages.
>
> --
> Gilles.
>
Support the
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-03-15 2:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-14 9:52 [Xenomai] Transfer data from a kernel module to user ashwin damle
2014-03-14 10:02 ` Gilles Chanteperdrix
[not found] ` <CAC-NLww-JD_q2pfW1L0EgxQGA6O400GcmYaQxsgvx7=oY9KD8A@mail.gmail.com>
2014-03-14 15:41 ` Gilles Chanteperdrix
2014-03-15 2:58 ` ashwin damle
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.