All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] Ext. Interrupt with POSIX skin from user - space
@ 2011-01-17 18:10 Joerg Mohre
  2011-01-17 18:28 ` Gilles Chanteperdrix
  2011-01-17 18:35 ` Philippe Gerum
  0 siblings, 2 replies; 3+ messages in thread
From: Joerg Mohre @ 2011-01-17 18:10 UTC (permalink / raw)
  To: xenomai

[-- Attachment #1: Type: text/plain, Size: 3255 bytes --]

Hi all,

i am using a MPC52000 and try to handle external interrupts (IRQ1) with 
linux kernel 2.6.32 and Xenomai 2.5.5.2.
I use the POSIX skin functions to setup interrupt and wait for interrupt 
in user-space.

First for testing, i wrote a kernel module to setup and handle the 
interrupts.
This worked well.

Now it tried to do the same from user-space with the posix functions.
But unfortunately this wasn't successful.

I have to load the kernel module before i use my user-space application 
(see code).
Otherwise pthread_intr_control_np will fail with error -1 and errono = -19.


static int mpc5200_intr_setup(void)
{
     int                     iret = 0;
         int                                        err = 0;
     pthread_attr_t          ThreadAttribute;
         struct sched_param        sched_param;
         unsigned char                 byPriority;

         unsigned int                i = 0;

         byPriority = 90;
         sched_param.sched_priority = byPriority;
         memset (&sched_param, 0, sizeof (sched_param));

     if ( (pRegsIntCtrl = (int_ctrl_regs*)ioremap( MBAR_VALUE + 
MBAR_INT_CTRL, REMAP_SIZE )) == NULL) {
                 printf("ioremap failed for MBAR_INT_CTRL\n");
         return -1;
         }

     //pRegsIntCtrl->irqctl =  0x00201401; //bit 10,21 => 1: IRQ1 rising 
edge active; enable IRQ1
     pRegsIntCtrl->irqctl =  0x00201001; //bit 10 => 1: IRQ1 rising edge 
active; disbable IRQ1

         if (pthread_intr_attach_np (&irq_object, 65, 0)) {
         printf("Interrupt source not found!\n");
         return -1;
     }
         else {
                 printf("Interrupt source found!\n");
         }

         printf("pregs->irqctl = %08X\n",pRegsIntCtrl->irqctl);

         sleep(5);

         printf("%i\n", i+=1);
     pthread_attr_init( &ThreadAttribute);
         printf("%i\n", i+=1);
     if (pthread_attr_setstacksize(&ThreadAttribute,0x80000)) {
                 printf("Failed to set stack size\n");
                 return -1;
         }
         printf("%i\n", i+=1);
            if (pthread_create( &Thread, &ThreadAttribute, 
cyclic_interrupt_receiver, NULL)) {
                 printf("Failed to create thread\n");
                 return -1;
         }
         printf("%i\n", i+=1);
         if (pthread_setschedparam (Thread,SCHED_FIFO,&sched_param)) {
                 printf("Failed to set scheduling parameter\n");
                 return -1;
         }
         printf("%i\n", i+=1);
         iret = pthread_intr_control_np (irq_object, PTHREAD_IENABLE);
         if (iret)
         {
                 err = errno;
                 printf("Failed to enable interrupt (%i, errno = %i)\n", 
iret, err);
                 return -1;
         }

         printf("%i\n", i+=1);
     return iret;
}

If i enable IRQ1 with
//pRegsIntCtrl->irqctl =  0x00201401; //bit 10,21 => 1: IRQ1 rising edge 
active; enable IRQ1
the CPU seams to be blocked.

I searched the internet but i couldn't find any help for handling 
external interrupts with posix skin in user-space.

Is it necessary to request an irq with native functions from kernel module?

I would expect that all (request, enable setup type ....) is done by the 
posix functions.

Does any one have some ideas?

Thanks




[-- Attachment #2: Type: text/html, Size: 10771 bytes --]

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

* Re: [Xenomai-help] Ext. Interrupt with POSIX skin from user - space
  2011-01-17 18:10 [Xenomai-help] Ext. Interrupt with POSIX skin from user - space Joerg Mohre
@ 2011-01-17 18:28 ` Gilles Chanteperdrix
  2011-01-17 18:35 ` Philippe Gerum
  1 sibling, 0 replies; 3+ messages in thread
From: Gilles Chanteperdrix @ 2011-01-17 18:28 UTC (permalink / raw)
  To: Joerg Mohre; +Cc: xenomai

Joerg Mohre wrote:
> Hi all,
> 
> i am using a MPC52000 and try to handle external interrupts (IRQ1) with 
> linux kernel 2.6.32 and Xenomai 2.5.5.2.
> I use the POSIX skin functions to setup interrupt and wait for interrupt 
> in user-space.
> 
> First for testing, i wrote a kernel module to setup and handle the 
> interrupts.
> This worked well.
> 
> Now it tried to do the same from user-space with the posix functions.
> But unfortunately this wasn't successful.
> 
> I have to load the kernel module before i use my user-space application 
> (see code).
> Otherwise pthread_intr_control_np will fail with error -1 and errono = -19.
> 
> 
> static int mpc5200_intr_setup(void)
> {
>      int                     iret = 0;
>          int                                        err = 0;
>      pthread_attr_t          ThreadAttribute;
>          struct sched_param        sched_param;
>          unsigned char                 byPriority;
> 
>          unsigned int                i = 0;
> 
>          byPriority = 90;
>          sched_param.sched_priority = byPriority;
>          memset (&sched_param, 0, sizeof (sched_param));
> 
>      if ( (pRegsIntCtrl = (int_ctrl_regs*)ioremap( MBAR_VALUE + 
> MBAR_INT_CTRL, REMAP_SIZE )) == NULL) {
>                  printf("ioremap failed for MBAR_INT_CTRL\n");
>          return -1;
>          }
> 
>      //pRegsIntCtrl->irqctl =  0x00201401; //bit 10,21 => 1: IRQ1 rising 
> edge active; enable IRQ1
>      pRegsIntCtrl->irqctl =  0x00201001; //bit 10 => 1: IRQ1 rising edge 
> active; disbable IRQ1
> 
>          if (pthread_intr_attach_np (&irq_object, 65, 0)) {
>          printf("Interrupt source not found!\n");
>          return -1;
>      }
>          else {
>                  printf("Interrupt source found!\n");
>          }
> 
>          printf("pregs->irqctl = %08X\n",pRegsIntCtrl->irqctl);
> 
>          sleep(5);
> 
>          printf("%i\n", i+=1);
>      pthread_attr_init( &ThreadAttribute);
>          printf("%i\n", i+=1);
>      if (pthread_attr_setstacksize(&ThreadAttribute,0x80000)) {
>                  printf("Failed to set stack size\n");
>                  return -1;
>          }
>          printf("%i\n", i+=1);
>             if (pthread_create( &Thread, &ThreadAttribute, 
> cyclic_interrupt_receiver, NULL)) {
>                  printf("Failed to create thread\n");
>                  return -1;
>          }
>          printf("%i\n", i+=1);
>          if (pthread_setschedparam (Thread,SCHED_FIFO,&sched_param)) {
>                  printf("Failed to set scheduling parameter\n");
>                  return -1;
>          }
>          printf("%i\n", i+=1);
>          iret = pthread_intr_control_np (irq_object, PTHREAD_IENABLE);
>          if (iret)
>          {
>                  err = errno;
>                  printf("Failed to enable interrupt (%i, errno = %i)\n", 
> iret, err);
>                  return -1;
>          }
> 
>          printf("%i\n", i+=1);
>      return iret;
> }

The way you indented it, this code is unreadable.

> 
> If i enable IRQ1 with
> //pRegsIntCtrl->irqctl =  0x00201401; //bit 10,21 => 1: IRQ1 rising edge 
> active; enable IRQ1
> the CPU seams to be blocked.
> 
> I searched the internet but i couldn't find any help for handling 
> external interrupts with posix skin in user-space.
> 
> Is it necessary to request an irq with native functions from kernel module?
> 
> I would expect that all (request, enable setup type ....) is done by the 
> posix functions.

It should be done by the call to pthread_intr_attach_np. But do not take
my word for it, have a look at the code.

Anyway, handling interrupts in user-space is hard, handling them in an
RTDM driver is what we recommend.

-- 
                                                                Gilles.


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

* Re: [Xenomai-help] Ext. Interrupt with POSIX skin from user - space
  2011-01-17 18:10 [Xenomai-help] Ext. Interrupt with POSIX skin from user - space Joerg Mohre
  2011-01-17 18:28 ` Gilles Chanteperdrix
@ 2011-01-17 18:35 ` Philippe Gerum
  1 sibling, 0 replies; 3+ messages in thread
From: Philippe Gerum @ 2011-01-17 18:35 UTC (permalink / raw)
  To: Joerg Mohre; +Cc: xenomai

On Mon, 2011-01-17 at 19:10 +0100, Joerg Mohre wrote:
> Hi all, 
> 
> i am using a MPC52000 and try to handle external interrupts (IRQ1)
> with linux kernel 2.6.32 and Xenomai 2.5.5.2.
> I use the POSIX skin functions to setup interrupt and wait for
> interrupt in user-space. 
> 
> First for testing, i wrote a kernel module to setup and handle the
> interrupts.
> This worked well. 
> 
> Now it tried to do the same from user-space with the posix functions.
> But unfortunately this wasn't successful. 
> 
> I have to load the kernel module before i use my user-space
> application (see code).
> Otherwise pthread_intr_control_np will fail with error -1 and errono =
> -19. 
> 
> 
> static int mpc5200_intr_setup(void) 
> { 
>     int                     iret = 0; 
>         int                                        err = 0; 
>     pthread_attr_t          ThreadAttribute; 
>         struct sched_param        sched_param; 
>         unsigned char                 byPriority; 
> 
>         unsigned int                i = 0; 
> 
>         byPriority = 90; 
>         sched_param.sched_priority = byPriority; 
>         memset (&sched_param, 0, sizeof (sched_param)); 

Are you sure you want to do these operations in that order?

> 
>     if ( (pRegsIntCtrl = (int_ctrl_regs*)ioremap( MBAR_VALUE +
> MBAR_INT_CTRL, REMAP_SIZE )) == NULL) { 
>                 printf("ioremap failed for MBAR_INT_CTRL\n"); 
>         return -1;                 
>         } 
> 
>     //pRegsIntCtrl->irqctl =  0x00201401; //bit 10,21 => 1: IRQ1
> rising edge active; enable IRQ1 
>     pRegsIntCtrl->irqctl =  0x00201001; //bit 10 => 1: IRQ1 rising
> edge active; disbable IRQ1 
> 
>         if (pthread_intr_attach_np (&irq_object, 65, 0)) { 
>         printf("Interrupt source not found!\n"); 
>         return -1; 
>     } 
>         else { 
>                 printf("Interrupt source found!\n"); 
>         } 
> 
>         printf("pregs->irqctl = %08X\n",pRegsIntCtrl->irqctl); 
> 
>         sleep(5); 
> 
>         printf("%i\n", i+=1); 
>     pthread_attr_init( &ThreadAttribute); 
>         printf("%i\n", i+=1); 
>     if (pthread_attr_setstacksize(&ThreadAttribute,0x80000)) { 
>                 printf("Failed to set stack size\n"); 
>                 return -1; 
>         } 
>         printf("%i\n", i+=1); 
>            if (pthread_create( &Thread, &ThreadAttribute,
> cyclic_interrupt_receiver, NULL)) { 
>                 printf("Failed to create thread\n"); 
>                 return -1; 
>         } 
>         printf("%i\n", i+=1); 
>         if (pthread_setschedparam (Thread,SCHED_FIFO,&sched_param)) { 
>                 printf("Failed to set scheduling parameter\n"); 
>                 return -1; 
>         } 

Creating the thread with the proper attributes upfront would remove the
need for hairy code.

>         printf("%i\n", i+=1); 
>         iret = pthread_intr_control_np (irq_object, PTHREAD_IENABLE); 
>         if (iret) 
>         { 
>                 err = errno; 
>                 printf("Failed to enable interrupt (%i, errno = %
> i)\n", iret, err); 
>                 return -1; 
>         } 
>         
>         printf("%i\n", i+=1); 
>     return iret; 
> } 
> 
> If i enable IRQ1 with 
> //pRegsIntCtrl->irqctl =  0x00201401; //bit 10,21 => 1: IRQ1 rising
> edge active; enable IRQ1
> the CPU seams to be blocked. 
> 

If that is PCI I/O memory, using no accessor is wrong. Another reason to
create an RTDM driver for accessing it properly.

> I searched the internet but i couldn't find any help for handling
> external interrupts with posix skin in user-space. 

This interface was never documented on purpose: it is bad, for internal
use only, deprecated, and not supported. The butterfingers guy who wrote
it did it all by mistake. Actually, it has been removed from the next
Xenomai 3 API.

You should really use an RTDM driver to control your IRQ. Interrupts are
inherently kernel resources and should remain so. Synchronizing with
IRQs from userland can be done almost trivially using an ad hoc
ioctl_rt() handler your RTDM driver would expose to applications.

> 
> Is it necessary to request an irq with native functions from kernel
> module? 
> 
> I would expect that all (request, enable setup type ....) is done by
> the posix functions. 
> 
> Does any one have some ideas? 
> 
> Thanks 
> 
> 
> 
> 
> _______________________________________________
> Xenomai-help mailing list
> Xenomai-help@domain.hid
> https://mail.gna.org/listinfo/xenomai-help

-- 
Philippe.




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

end of thread, other threads:[~2011-01-17 18:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-17 18:10 [Xenomai-help] Ext. Interrupt with POSIX skin from user - space Joerg Mohre
2011-01-17 18:28 ` Gilles Chanteperdrix
2011-01-17 18:35 ` Philippe Gerum

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.