[Xenomai] Toggling GPIO RT Xenomai on Dragonboard 41c

Giulio Moro g.moro at qmul.ac.uk
Wed Jun 21 14:35:49 CEST 2017

As you ask "Can't we work without device driver ?": here is a driver-less solution which may work on your platform (if it supports memmapping the GPIO banks) and may suit your needs.

I have some working user-space code to read and toggle GPIOs on a BeagleBone Black, which simply uses memory mapping and is real-time safe.
It consists of these files:

The GPIOcontrol stuff (by Derek Molloy) exports the pin through the sysfs interface, but then in Gpio.h the actual memory mapping takes place.
You will have to replace these constants with the ones for your architecture (the technical reference manual for your hardware should give you the correct addresses):

static const uint32_t GPIO_SIZE =  0x198;
static const uint32_t GPIO_DATAIN = (0x138 / 4);
static const uint32_t GPIO_CLEARDATAOUT = (0x190 / 4);
static const uint32_t GPIO_SETDATAOUT = (0x194 / 4);
static const uint32_t GPIO_ADDRESSES[4] = {

Hope this helps,

From: Xenomai <xenomai-bounces at xenomai.org> on behalf of eladyaakovi at campus.technion.ac.il <eladyaakovi at campus.technion.ac.il>
Sent: 21 June 2017 09:10
To: xenomai at xenomai.org; xenomai-request at xenomai.org
Subject: [Xenomai] Toggling GPIO RT Xenomai on Dragonboard 41c

Hi, I wrote a code that up and down (toggling) gpio.
I want to do the same with RT function.

Here pessudo code:

void not_rt_func(void *arg)
time_t t = time(NULL) + 10;
while (time(NULL) < t) {
                //gpio up
//gpio down
return NULL;

That code worked well (with up and down function, we used files:

        FILE *dir;
 dir = fopen("/sys/class/gpio/gpio13/value","w");

        fprintf(dir, "%d", 1);  //gpio up

        fprintf(dir, "%d", 0);  //gpio down



I want to make the same as real time.
I saw examples worked with PWM but it is too complicated to my "problem".
I just want to make this toggling with a RT process (and realtime up and down GPIO)
He used device driver, should i use it too ?
Can't we work without device driver ?

if we might use it, so i thought to write it like this:

user function:

int dev = open("/dev/rtdm/my_gpio",O_RDWR);
RT_TASK rt_task;

void rt_func(void *arg)
time_t t = time(NULL) + 10;
while (time(NULL) < t) {
ioctl(dev, GPIO_UP,NULL); //gpio up
ioctl(dev, GPIO_DOWN,NULL); //gpio down
return NULL;

device driver:
struct gpio_data {
int gpio;

static int gpio_ioctl_rt(struct rtdm_fd *fd, unsigned int request, void __user *arg)
struct gpio_data*ctx = rtdm_fd_to_private(fd);
switch (request) {
case GPIO_UP:
if (ctx->gpio > 0)
return -EBUSY;
gpio_set_value(ctx->gpio, 1);
if (ctx->gpio == 0)
return -EBUSY;
gpio_set_value(ctx->gpio, 0);
return -EINVAL;

Do you think it is OK ?

Xenomai mailing list
Xenomai at xenomai.org

More information about the Xenomai mailing list