Project Home
Project Home
Trackers
Trackers
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - May I ask how to write a interrupt handlers.: (2 Items)
   
May I ask how to write a interrupt handlers.  

Dear  Eric and Boudreau: 


 



May I ask how to write a interrupt handlers.

 

Now I wrote the following codes.

But did not work interrupt sequence regarding isr_handler1 and isr_handler2.
 
It is not use signal and event only use return value of ISR(interrupt service routine).

 

Please teach me where points of existing bugs.

 


Regards, 


Kengo Kinoshita



 
#include <sys/siginfo.h>

 

const struct sigevent *isr_handler1( void *arg, int id)
{

 

 InterruptMask(  TIM0  , id);
 event_.sigev_code  = _TM0;

 

 return( &event_);

 

// procmgr_event_notify()

 

}

 

const struct sigevent *isr_handler2( void *arg, int id)
{

 

 InterruptMask(TIM0-1 , id);
 event_.sigev_code  = _TM1;

 

 return( &event_);

 

// procmgr_event_notify()

 

}

 

main()
       pthread_attr_t attr;
        int breakFlg;

 

         pthread_attr_init( &attr );

 

        SIGEV_INTR_INIT (&event_);

 

        memset( ¶m, 0x0, sizeof(param) );
        memset( &idle_param, 0x0, sizeof(idle_param) );

 

       interruptID1 = InterruptAttach     (
                        TIM0,
                        isr_handler1,
                        NULL,
                        0,
                        0);

 

        interruptID2 =   InterruptAttach     (
                         TIM0-1,
                        isr_handler2,
                        NULL,
                        0,
                        0);

 

       for(i=0;i<evaluateCycle;){
           while(1){ 



 

                printf( "Wait interrupt\n"); 


                InterruptWait(NULL, NULL); 


                printf( “Exit interrupt\n"); 



 

                switch( event_.sigev_code ){ 


                        case _TM1: 


//                                    breakFlg=1; 


                                      event_.sigev_code=0; 


                                      InterruptUnmask(irq+ InterruptT0-1, interruptID2 );
                               break;

 

                       case _TM0: 


                                     event_.sigev_code=0; 


                                     breakFlg=1; 



 

                                             InterruptUnmask(irq+ Interru 


ptT0     , interruptID1 );
                               break; 


               } 



 

                if (breakFlg==1) { 


                    breakFlg=0; 


                    break; 


                } 


            } 


        }
RE: May I ask how to write a interrupt handlers.  
You need to obtain I/O privileges before you call InterruptAttach():

  ThreadCtl( _NTO_TCTL_IO, 0 );

You should also check return codes to make sure everything is working.
For more information, see the Writing an Interrupt Handler chapter in
the Neutrino Programmer's Guide:

 
http://www.qnx.com/developers/docs/6.5.0/topic/com.qnx.doc.neutrino_prog
/inthandler.html


Steve Reid (stever@qnx.com)
Technical Editor
QNX Software Systems 
 

> -----Original Message-----
> From: Kengo Kinoshita [mailto:community-noreply@qnx.com] 
> Sent: Tuesday, August 17, 2010 9:00 AM
> To: general-community
> Subject: May I ask how to write a interrupt handlers.
> 
> 
> 
> Dear  Eric and Boudreau: 
> 
> 
>  
> 
> 
> 
> May I ask how to write a interrupt handlers.
> 
>  
> 
> Now I wrote the following codes.
> 
> But did not work interrupt sequence regarding isr_handler1 
> and isr_handler2.
>  
> It is not use signal and event only use return value of 
> ISR(interrupt service routine).
> 
>  
> 
> Please teach me where points of existing bugs.
> 
>  
> 
> 
> Regards, 
> 
> 
> Kengo Kinoshita
> 
> 
> 
>  
> #include <sys/siginfo.h>
> 
>  
> 
> const struct sigevent *isr_handler1( void *arg, int id)
> {
> 
>  
> 
>  InterruptMask(  TIM0  , id);
>  event_.sigev_code  = _TM0;
> 
>  
> 
>  return( &event_);
> 
>  
> 
> // procmgr_event_notify()
> 
>  
> 
> }
> 
>  
> 
> const struct sigevent *isr_handler2( void *arg, int id)
> {
> 
>  
> 
>  InterruptMask(TIM0-1 , id);
>  event_.sigev_code  = _TM1;
> 
>  
> 
>  return( &event_);
> 
>  
> 
> // procmgr_event_notify()
> 
>  
> 
> }
> 
>  
> 
> main()
>        pthread_attr_t attr;
>         int breakFlg;
> 
>  
> 
>          pthread_attr_init( &attr );
> 
>  
> 
>         SIGEV_INTR_INIT (&event_);
> 
>  
> 
>         memset( ¶m, 0x0, sizeof(param) );
>         memset( &idle_param, 0x0, sizeof(idle_param) );
> 
>  
> 
>        interruptID1 = InterruptAttach     (
>                         TIM0,
>                         isr_handler1,
>                         NULL,
>                         0,
>                         0);
> 
>  
> 
>         interruptID2 =   InterruptAttach     (
>                          TIM0-1,
>                         isr_handler2,
>                         NULL,
>                         0,
>                         0);
> 
>  
> 
>        for(i=0;i<evaluateCycle;){
>            while(1){ 
> 
> 
> 
>  
> 
>                 printf( "Wait interrupt\n"); 
> 
> 
>                 InterruptWait(NULL, NULL); 
> 
> 
>                 printf( "Exit interrupt\n"); 
> 
> 
> 
>  
> 
>                 switch( event_.sigev_code ){ 
> 
> 
>                         case _TM1: 
> 
> 
> //                                    breakFlg=1; 
> 
> 
>                                       event_.sigev_code=0; 
> 
> 
>                                       InterruptUnmask(irq+ 
> InterruptT0-1, interruptID2 );
>                                break;
> 
>  
> 
>                        case _TM0: 
> 
> 
>                                      event_.sigev_code=0; 
> 
> 
>                                      breakFlg=1; 
> 
> 
> 
>  
> 
>                                              
> InterruptUnmask(irq+ Interru 
> 
> 
> ptT0     , interruptID1 );
>              ...