All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai] Toggling GPIO RT Xenomai on Dragonboard 41c
@ 2017-06-21  8:10 eladyaakovi
  2017-06-21 12:35 ` Giulio Moro
  0 siblings, 1 reply; 7+ messages in thread
From: eladyaakovi @ 2017-06-21  8:10 UTC (permalink / raw)
  To: xenomai, xenomai-request


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
sleep(1000);
//gpio down
                sleep(1000);
}
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






        fclose(dir);

)


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
rt_task_sleep(1000);
ioctl(dev, GPIO_DOWN,NULL); //gpio down
rt_task_sleep(1000);
}
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);
case GPIO_DOWN:
if (ctx->gpio == 0)
return -EBUSY;
gpio_set_value(ctx->gpio, 0);
default:
return -EINVAL;
}
}





Do you think it is OK ?


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-06-22 15:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-21  8:10 [Xenomai] Toggling GPIO RT Xenomai on Dragonboard 41c eladyaakovi
2017-06-21 12:35 ` Giulio Moro
2017-06-22 11:45   ` eladyaakovi
2017-06-22 12:30     ` Giulio Moro
2017-06-22 15:05       ` eladyaakovi
2017-06-22 15:12         ` Giulio Moro
2017-06-22 15:21           ` eladyaakovi

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.