Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - [ QNX6.5] : ISR is not calling..: (10 Items)
   
[ QNX6.5] : ISR is not calling..  
Hi,

I am working on a device driver of cPci board. In which Interrupt concept is needed. 
for this purpose i implemented a below code but ISR function is not calling
kindly give suggestion to the problem.

Target Platform: QNX 6.5
/*********************************************************************/
//header files

struct sigevent SigInt;
typedef struct pci_dev_info	 BUS_DEV;
BUS_DEV BusDevInfo;

main()
{
	short sRetVal = 0;
	pthread_t Threadid;
	pthread_attr_t Threadattr;
	
	BUS_DEV BusDevInfo.Irq = 7; // this Irq number is given by pci_attach_device system call
	
	ThreadCtl( _NTO_TCTL_IO, 0 );
		
	sRetVal = pthread_create(NULL,NULL, &ISR_CntlModule, &devicecontext);
	
	if(sRetVal != 0)
	{
		printf("Control Module Thread Creation Error: %d\n",sRetVal);
	}
	
	
}

void*  ISR_CntlModule(void * in_Handle)
{
	int  iRetVal = 0 ;
	int InterruptAttachId;
	
	SIGEV_INTR_INIT(&SigInt);
	
	/*Enabling Hardware Interrupts*/
	InterruptEnable();
	
	InterruptAttachId = InterruptAttach(BusDevInfo.Irq, ISR, in_Handle, sizeof(in_Handle),               
(_NTO_INTR_FLAGS_TRK_MSK|_NTO_INTR_FLAGS_END));
		
	if(InterruptAttachId == -1)
	{
		printf("\n interruptattach failed \n");
		return -1;
	}
		
	while (1) 
	{
		printf("\n InterruptWait is called......\n");
				
		iRetVal = InterruptWait(NULL,NULL);
		
		if(iRetVal == -1)
		{
			printf("InterruptWait Fail\n");	
		}
		printf("Interrupt event SIGINT Received\n");
		
		/*Interrupt unmasking*/
		InterruptUnmask( BusDevInfo.Irq, InterruptAttachId );
		
		printf("ISR calling ......\n");	
	}

}

/*ISR function*/
const struct sigevent* ISR(void * parameter, int id)
{
	int s16RetVal = 0;        
	s16RetVal = ReadReg();  //reading the registers will happens here
    return &SigInt;
}

/*********************************************************************/

In the above code , upto "InterruptWait" the thread is executing(InterruptWait is called...... message is printing),
when the interrupt is generated, the "ISR" function (attached in InterruptAttach() system call)is not calling.

But when checking with "pidin irqs" command , It is showing the Handler address,Address of Area passed to Handler,IRQ 
number and 
InterruptAttach id(12) as expected.

I didn't configure "startup-bios" and [b]"startup-apic".
I configured pci bios through the following command."pci-bios -B"
Is it required for irq number assignment?
If it is required how can i configure,where and when i can configure?
Note:Here Interrupt is Legacy Interrupt not MSI


Regards,
Muruganandham
Re: [ QNX6.5] : ISR is not calling..  
/* Here I done one timer example which fires for every 1 sec and it will send event. */

#include <stdio.h>
#include <time.h>
#include <sys/netmgr.h>
#include <sys/neutrino.h>
#include <sys/syspage.h>

timer_t                 timer_id;
time_t 					timer;
struct sigevent         event;
const struct sigevent * isr_handler(void * area,int id);
static volatile int g_iTemp;

/*ISR Handler function*/
const struct sigevent * isr_handler(void * area,int id)
{
	printf("******In isr function**********\n");

	InterruptMask(0,id);
	
        g_iTemp =  SYSPAGE_ENTRY(qtime);
	//event.sigev_value.sival_int = 20;
	return &event;
}


void Isr_Thread()
{
		printf("In Isr thread\n");
		event.sigev_notify = SIGEV_INTR;		
		
		printf("Isr Thread Id:%d\n",pthread_self());
		//const struct sigevent * (*ISR_handler) (void *,int ) = &isr_handler;
	
           if(InterruptAttach(0, isr_handler, NULL, 0, 0) == -1)
	   {
		   printf("\n\t\t InterruptAttach/Event Function failed \n");
		   return -1;
	   }
	   timer_create(CLOCK_REALTIME, &event, &timer_id);
	   struct itimerspec       itime;
	   	printf("Timer Thread Id:%d\n",pthread_self());
	   	itime.it_value.tv_sec = 1;
	   	   itime.it_value.tv_nsec = 0;
	   	   itime.it_interval.tv_sec = 1;	   	  
	   	   itime.it_interval.tv_nsec = 0;
	   	   timer_settime(timer_id, 0, &itime, NULL);

	   while(1)
	   {
		   printf("ISR is waiting\n");
		   printf("Before Interrupt Wait event.sigev_value:%d\n",event.sigev_value.sival_int);
	   	   InterruptWait (NULL, NULL);
	   	   timer = time(NULL);
	   	   printf("After Interrupt time is:%s\n",ctime(&timer));
	   	   printf("Interrupt Came,so InterruptWait unblocked\n");
	   	   printf("Value of g_iTemp:%d\n",g_iTemp);
	   }
}

main()
{
   struct itimerspec       itime;   
   int id;
   printf("Main Thread Id:%d\n",pthread_self());
   /* Obtain I/O privileges */
       ThreadCtl( _NTO_TCTL_IO, 0 );

   	timer = time(NULL);
   	printf("Before calling thread time is:%s\n",ctime(&timer));

   /* Start the thread that will handle interrupt events. */
   pthread_create (NULL, NULL, Isr_Thread, NULL);

   char ch = 0;
   printf("Press enter to exit\n");
   scanf("%c",ch);

}[/code]

Question1:
After every 1 sec, timer is firing,"InterruptWait" is unblocking,But "isr_handler" is not called.
Because after Interrupt came, I checked the value of g_iTemp,but it's value is 0 only why?

Question2:
If I comment "InterruptAttach" function also, Interrupt is generating.So It mean that for every 
1 sec timer will fire irrespective of interrupt registration through "InterruptAttach" function.i.e timer will
fire for every 1 sec and it will notify through signal like SIGEV_INTR,SIGEV_PULSE(whoever waiting).
Am I correct?.If i am correct, in my case(Refer earlier post) FPGA is generating interrupt. But ISR function
is not calling.How can I solve this issue?
Re: [ QNX6.5] : ISR is not calling..  
Dear Muruganandham,
there are a number of issues in your code that need to be resolved first because they can lead to totally erroneous 
behaviour.
I suggest you work through the chapter "Writing an interrupt handler" (http://www.qnx.com/developers/docs/6.5.0SP1.
update/#./com.qnx.doc.neutrino_prog/inthandler.html). It is very important to understand the differences between 
InterruptAttach() and InterruptAttachEvent() and their relation to InterruptMask/Unmask, struct sigevents, and ISR-safe 
functions.

/*Enabling Hardware Interrupts*/
InterruptEnable();
---> This is unnecessary, the kernel handles this. It may or may not cause harm, but simply remove it.

Masking/Unmasking:
If you call InterruptMask() in your ISR, OR if you use InterruptAttachEvent() you MUST call InterruptUnmask() after the 
handling in your thread-level code. In any other case you must not call InterruptUnmask().

You MUST NOT call printf() in an ISR!!

Regarding pci-bios, I think passing -B is required to detect and enumerate devices behind an unknown bridge. Since you 
did detect your device this seems to be working ok. I am somewhat suspicious, though, that an IRQ 7 is assigend to a PCI
 device. Maybe some IRQ routing needs to be adjusted in the BIOS. Could you attach the output of "pci -vvvv" to this 
discussion?

Regards,
Al
Re: [ QNX6.5] : ISR is not calling..  
> Dear Muruganandham,
> there are a number of issues in your code that need to be resolved first 
> because they can lead to totally erroneous behaviour.
> I suggest you work through the chapter "Writing an interrupt handler" (http://
> www.qnx.com/developers/docs/6.5.0SP1.update/#./com.qnx.doc.neutrino_prog/
> inthandler.html). 

----->Thanks for reply .
                               Earlier my two posts are not same.First post  is my main code(Where i am working) and 
second one is Sample Timer Interrupt. So can you give comments separately (i.e I am not getting where i need to update).


>It is very important to understand the differences between 
> InterruptAttach() and InterruptAttachEvent() and their relation to 
> InterruptMask/Unmask, struct sigevents, and ISR-safe functions.
> 
> /*Enabling Hardware Interrupts*/
> InterruptEnable();
> ---> This is unnecessary, the kernel handles this. It may or may not cause 
> harm, but simply remove it.

---->Without IntetrruptEnable() also  we tried,but isr is not calling.
 
> Masking/Unmasking:
> If you call InterruptMask() in your ISR, OR if you use InterruptAttachEvent() 
> you MUST call InterruptUnmask() after the handling in your thread-level code. 
> In any other case you must not call InterruptUnmask().
 
--->InterruptMask/Unmask removed,but isr is not calling


> You MUST NOT call printf() in an ISR!!

---> We removed printf() in isr function.

> Regarding pci-bios, I think passing -B is required to detect and enumerate 
> devices behind an unknown bridge. Since you did detect your device this seems 
> to be working ok. I am somewhat suspicious, though, that an IRQ 7 is assigend 
> to a PCI device. Maybe some IRQ routing needs to be adjusted in the BIOS. 
> Could you attach the output of "pci -vvvv" to this discussion?

--->Here I have attached the "pci -vvvv" board details, kindly check

  
Regards,
Muruganandham


Attachment: Text board_details.txt 1.42 KB
Re: [ QNX6.5] : ISR is not calling..  
My remarks are basically valid for both of your examples. 

Could you please send the full output of the pci -vvvv command? It appears to be only a small fragment.

I would also recommend to reboot the system after testing with broken interrupt handlers. I would gess that the ISR was 
called but the printf() corrupted the kernel.

Regards,
Al
Re: [ QNX6.5] : ISR is not calling..  
> My remarks are basically valid for both of your examples. 
> 
> Could you please send the full output of the pci -vvvv command? It appears to 
> be only a small fragment.
> 
> I would also recommend to reboot the system after testing with broken 
> interrupt handlers. I would gess that the ISR was called but the printf() 
> corrupted the kernel.

----> i have attached the pci -vvvv  board details, kindly check.

I haven't used any printf() in ISR, I am calling Board_ID_ISR() function,there i am enabling a interrupt(By writing a 
proper value in FPGA Register). 
Note:Here FPGA Interrupt status register is properly updating.
Attachment: Text pci_log_15_dec.txt 35.15 KB
Re: [ QNX6.5] : ISR is not calling..  
Just a dumb question:  how did you readout the IRQ number ?

Armin

Muruganandham S schrieb:
>> My remarks are basically valid for both of your examples.
>>
>> Could you please send the full output of the pci -vvvv command? It appears to
>> be only a small fragment.
>>
>> I would also recommend to reboot the system after testing with broken
>> interrupt handlers. I would gess that the ISR was called but the printf()
>> corrupted the kernel.
> ----> i have attached the pci -vvvv  board details, kindly check.
>
> I haven't used any printf() in ISR, I am calling Board_ID_ISR() function,there i am enabling a interrupt(By writing a 
proper value in FPGA Register).
> Note:Here FPGA Interrupt status register is properly updating.
>
>
>
> _______________________________________________
>
> OSTech
> http://community.qnx.com/sf/go/post118278
> To cancel your subscription to this discussion, please e-mail ostech-core_os-unsubscribe@community.qnx.com


Re: [ QNX6.5] : ISR is not calling..  
> 
> Just a dumb question:  how did you readout the IRQ number ?
> 
> Armin

---> IRQ Number is got from pci_attach_device call() as mentioned below:

-->pci_attach_device(  NULL  ,  PCI_INIT_ALL  ,  iBrdIndex  ,  &DevInfo);

DevInfo is a variable of pci_dev_info structure.
-->Here iBrdIndex is incrementing based on boards found.Initial value of iBrdIndex is 0,for every board detection it 
will increment by one.
-->DevInfo.VendorId = MY_VENDOR_ID, DevInfo.DeviceId = MY_DEVICE_ID

Regards,
Muruganandham


Re: [ QNX6.5] : ISR is not calling..  
It appears that you call printf within your isr here:

/*ISR Handler function*/
const struct sigevent * isr_handler(void * area,int id)
{
	printf("******In isr function**********\n");

	InterruptMask(0,id);
	
        g_iTemp =  SYSPAGE_ENTRY(qtime);
	//event.sigev_value.sival_int = 20;
	return &event;
}




> > My remarks are basically valid for both of your examples. 
> > 
> > Could you please send the full output of the pci -vvvv command? It appears 
> to 
> > be only a small fragment.
> > 
> > I would also recommend to reboot the system after testing with broken 
> > interrupt handlers. I would gess that the ISR was called but the printf() 
> > corrupted the kernel.
> 
> ----> i have attached the pci -vvvv  board details, kindly check.
> 
> I haven't used any printf() in ISR, I am calling Board_ID_ISR() function,there
>  i am enabling a interrupt(By writing a proper value in FPGA Register). 
> Note:Here FPGA Interrupt status register is properly updating.


Re: [ QNX6.5] : ISR is not calling..  
--->I have commented printf() in my function, but wrongly posted the same old code here.



> It appears that you call printf within your isr here:
> 
> /*ISR Handler function*/
> const struct sigevent * isr_handler(void * area,int id)
> {
> 	//printf("******In isr function**********\n");
> 
> 	InterruptMask(0,id);
> 	
>         g_iTemp =  SYSPAGE_ENTRY(qtime);
> 	//event.sigev_value.sival_int = 20;
> 	return &event;
> }
> 
> 
> 
> 
> > > My remarks are basically valid for both of your examples. 
> > > 
> > > Could you please send the full output of the pci -vvvv command? It appears
>  
> > to 
> > > be only a small fragment.
> > > 
> > > I would also recommend to reboot the system after testing with broken 
> > > interrupt handlers. I would gess that the ISR was called but the printf() 
> 
> > > corrupted the kernel.
> > 
> > ----> i have attached the pci -vvvv  board details, kindly check.
> > 
> > I haven't used any printf() in ISR, I am calling Board_ID_ISR() function,
> there
> >  i am enabling a interrupt(By writing a proper value in FPGA Register). 
> > Note:Here FPGA Interrupt status register is properly updating.
> 
>