[Xenomai] Toggling GPIO RT Xenomai on Dragonboard 41c

eladyaakovi at campus.technion.ac.il eladyaakovi at campus.technion.ac.il
Thu Jun 22 13:45:52 CEST 2017

Can you explain please why this is not writing to a file:

time_t t = time(NULL) + time_to_run;

while (time(NULL) <  t){




not writing 1 to the file ?

dir is a file descriptor.

(without the rt_task_sleep(1000) and the while it works fine).

any suggestions what can i do ?


מאת: Giulio Moro <g.moro at qmul.ac.uk>
‏‏נשלח: יום רביעי 21 יוני 2017 15:35:49
‏‏אל: Elad Yaakovi; xenomai at xenomai.org; xenomai-request at xenomai.org
‏‏נושא: Re: Toggling GPIO RT Xenomai on Dragonboard 41c

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