Skip to contentSkip to conversation

RT GPIO with Raspberry Pi

Xenomai Marco Poli 4 participants 11 messages Dec 11, 2012 – Dec 12, 2012 1 message not in the archive

lore
Share & tools
lore

Marco Poli

author
#1 lore raw
In reply to a message not in the archive

Hello all!

I would like to apologize if this is a somehow recurrent or previously addressed question, but all the answers I got on the topic were inconclusive, at least for someone with so far minimal experience with Xenomai.

Raspberry Pi patched kernels have GPIO and GPIO generated-interrupts working and exported to userland, but it is unclear to me if the in-kernel drivers are able to deal with RT applications in primary mode, or would it be necessary to make changes to the Linux Kernel Drivers or new GPIO RTDM drivers to be able to access GPIO from a RT application in primary mode? Maybe Analogy?

Is it possible to use these sort of Linux Kernel GPIO drivers and still be able to have my application not leave primary mode? Is there some source of documentation someone can point me to that might be of assistence?

Thanks in advance.

#2 lore raw
Quoted 16 lines · Marco Poli

Hello all!

I would like to apologize if this is a somehow recurrent or previously addressed question, but all the answers I got on the topic were inconclusive, at least for someone with so far minimal experience with Xenomai.

Raspberry Pi patched kernels have GPIO and GPIO generated-interrupts working and exported to userland, but it is unclear to me if the in-kernel drivers are able to deal with RT applications in primary mode, or would it be necessary to make changes to the Linux Kernel Drivers or new GPIO RTDM drivers to be able to access GPIO from a RT application in primary mode? Maybe Analogy?

Quoted 4 lines

Is it possible to use these sort of Linux Kernel GPIO drivers and still be able to have my application not leave primary mode? Is there some source of documentation someone can point me to that might be of assistence?

It is unclear what interfaces you are talking about. The kernel gpiolib interface may usually be used from drivers, if you are careful to get it working, see:
http://www.xenomai.org/index.php/I-pipe-core:ArmPorting#GPIOs

If you are talking about the user-space interfaces, they are Linux drivers, using Linux syscalls, and as such will cause any Xenomai user-space thread running in primary mode to switch to secondary mode.

Signature · 1 line
                                                                Gilles.
#3 lore raw
In reply to Marco Poli

not strictly a Xenomai issue, but I'd completely bypass the kernel GPIO support and manipulate the GPIO registers directly - they are all memory mapped

some inspiration here: http://git.mah.priv.at/gitweb/emc2-dev.git/blob/refs/heads/rtos-integration-preview1:/src/hal/drivers/hal_gpio.c

this runs from a userland thread but kernel shouldnt be much different

-m

Am 11.12.2012 um 21:32 schrieb Marco Poli:

Quoted 17 lines

Hello all!

I would like to apologize if this is a somehow recurrent or previously addressed question, but all the answers I got on the topic were inconclusive, at least for someone with so far minimal experience with Xenomai.

Raspberry Pi patched kernels have GPIO and GPIO generated-interrupts working and exported to userland, but it is unclear to me if the in-kernel drivers are able to deal with RT applications in primary mode, or would it be necessary to make changes to the Linux Kernel Drivers or new GPIO RTDM drivers to be able to access GPIO from a RT application in primary mode? Maybe Analogy?

Is it possible to use these sort of Linux Kernel GPIO drivers and still be able to have my application not leave primary mode? Is there some source of documentation someone can point me to that might be of assistence?

Thanks in advance.

_______________________________________________
Xenomai mailing list
[email protected]
http://www.xenomai.org/mailman/listinfo/xenomai

#4 lore raw
Quoted 9 lines · Michael Haberler

not strictly a Xenomai issue, but I'd completely bypass the kernel GPIO support and manipulate the GPIO registers directly - they are all memory mapped

some inspiration here:
http://git.mah.priv.at/gitweb/emc2-dev.git/blob/refs/heads/rtos-integration-preview1:/src/hal/drivers/hal_gpio.c

this runs from a userland thread but kernel shouldnt be much
different

Yeah, good idea, depending on the way to access registers, you get concurrence issues, conflicts between applications, a lot of fun.

Signature · 1 line
                                                                Gilles.
#5 lore raw

Am 12.12.2012 um 08:32 schrieb Gilles Chanteperdrix:

Quoted 9 lines · Michael Haberler
Quoted 8 lines

not strictly a Xenomai issue, but I'd completely bypass the kernel GPIO support and manipulate the GPIO registers directly - they are all memory mapped

some inspiration here:
http://git.mah.priv.at/gitweb/emc2-dev.git/blob/refs/heads/rtos-integration-preview1:/src/hal/drivers/hal_gpio.c

Quoted 6 lines
Quoted 2 lines

this runs from a userland thread but kernel shouldnt be much different

Yeah, good idea, depending on the way to access registers, you get concurrence issues, conflicts between applications, a lot of fun.

just to make sure I understand your suggestion:

in kernel mode you'd suggest to go through gpiolib and use gpio_get_value/gpio_set_value if possible ?

in user mode you can prepare things through sysfs but I dont see an alternative to memory-mapped register manipulation in that case if one wants to avoid system calls like read/write/open/ioctl which likely will be a dog on top of switching to secondary domain

-m

Quoted 3 lines
Signature · 2 lines
-- 
                                                               Gilles.
#6 lore raw
Quoted 14 lines · Michael Haberler

Am 12.12.2012 um 08:32 schrieb Gilles Chanteperdrix:

Quoted 11 lines · Michael Haberler
Quoted 10 lines

not strictly a Xenomai issue, but I'd completely bypass the kernel GPIO support and manipulate the GPIO registers directly - they are all memory mapped

some inspiration here:
http://git.mah.priv.at/gitweb/emc2-dev.git/blob/refs/heads/rtos-integration-preview1:/src/hal/drivers/hal_gpio.c

this runs from a userland thread but kernel shouldnt be much

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

different

Yeah, good idea, depending on the way to access registers, you get concurrence issues, conflicts between applications, a lot of fun.

just to make sure I understand your suggestion:

Quoted 7 lines

in kernel mode you'd suggest to go through gpiolib and use gpio_get_value/gpio_set_value if possible ?

in user mode you can prepare things through sysfs but I dont see an alternative to memory-mapped register manipulation in that case if one wants to avoid system calls like read/write/open/ioctl which likely will be a dog on top of switching to secondary domain

This happens if you put the kernel/user split in the wrong place. For instance, if your GPIOS are used to implement an I2C master, implementing the I2C master in user-space manipulating GPIOS in kernel-space is the wrong thing to do. What you should do is implement the I2C master in kernel-space, and use it either in other drivers, or in user-space. This way, you will get a write for a whole I2C transfer instead of a write for each GPIO change. The same goes for a PWM, SPI master, RS232 why not, etc... If your GPIOs are used to power on/power off some devices, then using them in primary mode is probably not relevant.

Quoted 9 lines

-m

Quoted 2 lines

-- Gilles.

Signature · 1 line
					    Gilles.
#7 lore raw

Am 12.12.2012 um 10:09 schrieb Gilles Chanteperdrix:

Quoted 14 lines · Michael Haberler
Quoted 5 lines
Quoted 2 lines

...

just to make sure I understand your suggestion:

Quoted 7 lines

in kernel mode you'd suggest to go through gpiolib and use gpio_get_value/gpio_set_value if possible ?

in user mode you can prepare things through sysfs but I dont see an alternative to memory-mapped register manipulation in that case if one wants to avoid system calls like read/write/open/ioctl which likely will be a dog on top of switching to secondary domain

Quoted 9 lines

This happens if you put the kernel/user split in the wrong place. For instance, if your GPIOS are used to implement an I2C master, implementing the I2C master in user-space manipulating GPIOS in kernel-space is the wrong thing to do. What you should do is implement the I2C master in kernel-space, and use it either in other drivers, or in user-space. This way, you will get a write for a whole I2C transfer instead of a write for each GPIO change. The same goes for a PWM, SPI master, RS232 why not, etc... If your GPIOs are used to power on/power off some devices, then using them in primary mode is probably not relevant.

in that particular application, the GPIO's are used, among others, for generating stepper pulses, and the thread running this should be as fast as possible; in the RTAI/parport version of that code that's anywhere from 20-50uSec

nothing else though except wiggling pins, in particular no interrupt-driven input; so I dont see any extra functionality a kernel driver could provide

-m

#8 lore raw
Quoted 27 lines · Michael Haberler

Am 12.12.2012 um 10:09 schrieb Gilles Chanteperdrix:

Quoted 14 lines · Michael Haberler
Quoted 5 lines
Quoted 2 lines

...

just to make sure I understand your suggestion:

Quoted 7 lines

in kernel mode you'd suggest to go through gpiolib and use gpio_get_value/gpio_set_value if possible ?

in user mode you can prepare things through sysfs but I dont see an alternative to memory-mapped register manipulation in that case if one wants to avoid system calls like read/write/open/ioctl which likely will be a dog on top of switching to secondary domain

Quoted 9 lines

This happens if you put the kernel/user split in the wrong place. For instance, if your GPIOS are used to implement an I2C master, implementing the I2C master in user-space manipulating GPIOS in kernel-space is the wrong thing to do. What you should do is implement the I2C master in kernel-space, and use it either in other drivers, or in user-space. This way, you will get a write for a whole I2C transfer instead of a write for each GPIO change. The same goes for a PWM, SPI master, RS232 why not, etc... If your GPIOs are used to power on/power off some devices, then using them in primary mode is probably not relevant.

Quoted 3 lines

in that particular application, the GPIO's are used, among others, for generating stepper pulses, and the thread running this should be as fast as possible; in the RTAI/parport version of that code that's anywhere from 20-50uSec

nothing else though except wiggling pins, in particular no interrupt-driven input; so I dont see any extra functionality a kernel driver could provide

A stepper pulse driver ? You name it...

Signature · 1 line
					    Gilles.
#9 lore raw
In reply to Michael Haberler
Quoted 29 lines · Michael Haberler

Am 12.12.2012 um 10:09 schrieb Gilles Chanteperdrix:

Quoted 15 lines · Michael Haberler
Quoted 5 lines
Quoted 2 lines

...

just to make sure I understand your suggestion:

Quoted 8 lines

in kernel mode you'd suggest to go through gpiolib and use gpio_get_value/gpio_set_value if possible ?

in user mode you can prepare things through sysfs but I dont see an alternative to memory-mapped register manipulation in that case if one wants to avoid system calls like read/write/open/ioctl which likely will be a dog on top of switching to secondary domain

Quoted 10 lines

This happens if you put the kernel/user split in the wrong place. For instance, if your GPIOS are used to implement an I2C master, implementing the I2C master in user-space manipulating GPIOS in kernel-space is the wrong thing to do. What you should do is implement the I2C master in kernel-space, and use it either in other drivers, or in user-space. This way, you will get a write for a whole I2C transfer instead of a write for each GPIO change. The same goes for a PWM, SPI master, RS232 why not, etc... If your GPIOs are used to power on/power off some devices, then using them in primary mode is probably not relevant.

Quoted 8 lines

in that particular application, the GPIO's are used, among others, for generating stepper pulses, and the thread running this should be as fast as possible; in the RTAI/parport version of that code that's anywhere from 20-50uSec

nothing else though except wiggling pins, in particular no interrupt-driven input; so I dont see any extra functionality a kernel driver could provide

A kernel driver provides an interface which allows changing the driver implementation and the underlying hardware without changing either the kernel/user interface, or the application (I did not invent that, I read it for instance in the excellent "Linux device drivers" which I suggest you read or reread if you missed that point), in addition to allowing implementing for instance a reliable 50us pulse with a lower jitter. I will stop answering your posts at this point.

Signature · 1 line
					    Gilles.
#10 lore raw
In reply to Michael Haberler
Quoted 8 lines

in that particular application, the GPIO's are used, among others, for generating stepper pulses, and the thread running this should be as fast as possible; in the RTAI/parport version of that code that's anywhere from 20-50uSec

nothing else though except wiggling pins, in particular no interrupt-driven input; so I dont see any extra functionality a kernel driver could provide

If pulses should be preciese with low jitter (and I assume that in case of steppers they should), then, most probably, kernel driver is anavoidable because the timing precission achievable in the kernel is much higher then in the user-space. You might be interesting to take a look at our blog post here:
http://veter-project.blogspot.de/2012/04/precise-pwms-with-gpio-using-xenomai.html
where we describe our attempts to generate precise PWMs to drive the servo motor. We end up with RTDM kernel module which uses timers (instead of periodic tasks) to get acceptable jitter.

#11 lore raw

Am 12.12.2012 um 10:47 schrieb Andrey Nechypurenko:

Quoted 9 lines
Quoted 8 lines

in that particular application, the GPIO's are used, among others, for generating stepper pulses, and the thread running this should be as fast as possible; in the RTAI/parport version of that code that's anywhere from 20-50uSec

nothing else though except wiggling pins, in particular no interrupt-driven input; so I dont see any extra functionality a kernel driver could provide

Quoted 9 lines

If pulses should be preciese with low jitter (and I assume that in case of steppers they should), then, most probably, kernel driver is anavoidable because the timing precission achievable in the kernel is much higher then in the user-space. You might be interesting to take a look at our blog post here:
http://veter-project.blogspot.de/2012/04/precise-pwms-with-gpio-using-xenomai.html
where we describe our attempts to generate precise PWMs to drive the servo motor. We end up with RTDM kernel module which uses timers (instead of periodic tasks) to get acceptable jitter.

Andrey,

thanks - I read your post on the issue, and that was quite valuable. Yes, jitter is an issue with loss of torque and eventually loosing steps; long thread periods also limit the granularity of frequencies the stepgen code can generate.

I did report what is being used in the RTAI/parport version of the code (which I didnt write to start with), and I am painfully aware this approach doesnt scale well

in the case of the beaglebone port, the stepper code will be in the Programmable Realtime Unit which is capable of achieving very high rates at next to no jitter, so the RT OS is out of the loop except for feeding a stream of control values at > 1mS intervals

-m