From: Jan Kiszka <jan.kiszka@domain.hid>
To: Marcel Soulot <msoulot@domain.hid>
Cc: Xenomai help <xenomai@xenomai.org>
Subject: Re: [Xenomai-help] driver: IOCTL command behavior
Date: Thu, 16 Apr 2009 17:15:22 +0200 [thread overview]
Message-ID: <49E74B8A.2090909@domain.hid> (raw)
In-Reply-To: <37f89760904160755y2e056c3cq1b86d3adf2160b0b@domain.hid>
Marcel Soulot wrote:
> Hi,
> here is the my ioctl function and the header file below.
>
>
> /*****************************************************************************************/
> int rt_gpio_ioctl(struct rtdm_dev_context *context,
> rtdm_user_info_t *user_info,
> unsigned int request, void *arg)
> {
> struct rt_gpio_context *ctx_gpio;
> int err = 0;
> unsigned long base;
> int mode;
>
> ctx_gpio = (struct rt_gpio_context *)context->dev_private;
> base = ctx_gpio->base_addr;
> mode = rt_gpio_io_mode_from_ctx_gpio(ctx_gpio);
>
> printk(KERN_INFO "IOCTL : request %x\n", request);
> switch (request)
> {
> case RT_GPIO_RTIOC_GET_DIRECTION:
> {
> /*
> ** 1 = input and 0 = output, by default all are inputs.
> */
> int gpio_dir;
>
> gpio_dir = rt_gpio_reg_in(mode, base, OFF_MPIOSEL);
> printk(KERN_INFO "GET_DIRECTION %x\n", gpio_dir);
>
> if (user_info)
> {
> err = rtdm_safe_copy_to_user(user_info, arg,
> &gpio_dir, sizeof(int));
> }
> else
> {
> *(int *)arg = gpio_dir;
> }
>
> break;
> }
>
> case RT_GPIO_RTIOC_SET_DIRECTION:
> {
> /*
> ** 1 = input and 0 = output, by default all are inputs.
> */
> unsigned int gpio_dir = (unsigned int)arg;
>
> rt_gpio_reg_out(mode, base, OFF_MPIOSEL, gpio_dir);
> printk(KERN_INFO "SET_DIRECTION %x\n", gpio_dir);
>
> break;
> }
>
> default:
> err = -ENOTTY;
> }
>
> return err;
> }
>
>
> /**************************************************************************************************/
> header file
> /**************************************************************************************************/
>
> #ifndef _RTGPIO_H
> #define _RTGPIO_H
>
> #include <rtdm/rtdm.h>
>
> #define RT_GPIO_PROFILE_VER 2
>
> #define RTIOC_TYPE_GPIO RTDM_CLASS_GPIO
> #define RTDM_SUBCLASS_GPIO 0
>
> #define RT_GPIO_RTIOC_GET_DIRECTION\
> _IOR(RTIOC_TYPE_GPIO, 0x00, int)
>
> #define RT_GPIO_RTIOC_SET_DIRECTION\
> _IOR(RTIOC_TYPE_GPIO, 0x01, int)
>
> #endif /* _RTGPIO_H */
>
> /**************************************************************************************************/
>
> So for the "RT_GPIO_RTIOC_SET_DIRECTION" when I switch "_IOR(RTIOC_TYPE_GPIO,
> 0x01, int)" to "_IOW(RTIOC_TYPE_GPIO, 0x01, int)" or "_IOWR(RTIOC_TYPE_GPIO,
> 0x01, int)", the switch pass in "default".
>
> Someone as an explanation ?
Did you cleanly rebuild both kernel and user space after fiddling with
_IO*? The numerical value of RT_GPIO_RTIOC_SET_DIRECTION changes each time.
BTW, _IO* are conventions between driver and user, nothing is checked or
enforced elsewhere.
Jan
--
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
next prev parent reply other threads:[~2009-04-16 15:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-16 11:47 [Xenomai-help] driver: IOCTL command behavior Marcel Soulot
2009-04-16 12:59 ` Gilles Chanteperdrix
[not found] ` <37f89760904160654g43fde4f0l6cd228faa65d6baf@domain.hid>
2009-04-16 14:17 ` Gilles Chanteperdrix
2009-04-16 14:55 ` Marcel Soulot
2009-04-16 15:15 ` Jan Kiszka [this message]
2009-04-16 15:47 ` Marcel Soulot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=49E74B8A.2090909@domain.hid \
--to=jan.kiszka@domain.hid \
--cc=msoulot@domain.hid \
--cc=xenomai@xenomai.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.