Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - InterruptAttach(): (4 Items)
   
InterruptAttach()  
Hi All,

I am developing SPI driver for i.Mx6 in QNX. I have used interrupt attach to attach the interrupts.
I get one interrupt intially (i is printed as 1 continously), but i dont receive subsequent interrupts.
I have used InterruptAttach in the following way.Please let me know if I am using it right.

volatile int n_interrupt = 0;
int main(int argc, char *argv[])
{
     //Initializations
    if(SPIConfigure( &dev, config.phas, config.pol, config.cs - 1 ))
    {
           printf("Configuration failed!\r\n");
           exit(1);
    }
    while(1)
    {
        printf("i - %d\n",GetNoOfInterrupt());
    }

}

uint8_t SPIConfigure(spiHwData_adt *dev, uint8_t phase, uint8_t polarity, uint8_t ss)
{
	//Initialize variables

	if (ThreadCtl(_NTO_TCTL_IO, 0) == -1) {
		printf("ThreadCtl\r\n");
		return (!EOK);
	}

	//Configure SPI

	//Clear Rx FIFO

	tmp = InterruptAttach( dev->irq, spi_intr, dev, sizeof(spiHwData_adt), _NTO_INTR_FLAGS_PROCESS);
	

	if(tmp == -1)
	{
		if (errno == EAGAIN)
		{
			printf("Interrupt are in use\r\n");
		}else if (errno == EFAULT)
		{
			printf("A fault occurred when the kernel tried to access the buffers provided.\r\n");
		}else if (errno == EINVAL)
		{
			printf("The value of intr is not a valid interrupt number.\r\n");
		}else if (errno == EPERM)
		{
			printf("The process doesn't have I/O privileges.\r\n");
		}
	}else
	{
		printf("Attached IRQ ID = %d\r\n", tmp);
	}

	//Enable SPI interrupts

	return 0;
}


static const struct sigevent *spi_intr(void *area, int id)
{
	//Clear Interrupt status
                  n_interrupt++;
	return NULL;
}
int GetNoOfInterrupt(void)
{
    return n_interrupt;
}

Please let me know if you need more details
Thanks in advance. 
Re: InterruptAttach()  
Il 28/08/2014 11:38, Aarthi CR ha scritto:
> Hi All,
>
> I am developing SPI driver for i.Mx6 in QNX. I have used interrupt attach to attach the interrupts.
> I get one interrupt intially (i is printed as 1 continously), but i dont receive subsequent interrupts.
> I have used InterruptAttach in the following way.Please let me know if I am using it right.
Try to use a thread instead of the ISR, so You will be able to debug 
your code,
maybe You do not correctly handle SPI ...

 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Just run a thread  like this one...

void* spi_event_thread(void* p)
{
     struct  sigevent        event;
     int                     j;
     int                     irqLev;
     int                     irqId;

     ThreadCtl( _NTO_TCTL_IO, 0 );

     //Configure SPI
     //Clear Rx FIFO

     memset(&event, 0, (sizeof(struct sigevent)) );
     event.sigev_notify= (SIGEV_INTR);

     irqLev= SPI_IRQ_LEVEL;
     irqId= InterruptAttachEvent( (irqLev|_NTO_INTR_CLASS_EXTERNAL ),
                                 &event,
                                 _NTO_INTR_FLAGS_TRK_MSK
                                );
     //Enable SPI interrupts

      while(1)
     {
/*****************************************************************/
          j= InterruptWait(0,NULL);
/*****************************************************************/

          // Handle here SPI event... reset SPI interrupt!

          InterruptUnmask(irqLev,irqId);
     }
     return(NULL);
}
 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

RE: InterruptAttach()  
Hi,

is the ISR shown below the original one from your code? I'm asking because of the comment, "//Clear Interrupt status" --
 is that a note to yourself about what you still need to implement, or is it just a placeholder for some code you 
removed before posting it here?

In the former case (not yet implemented), it could be that your SPI controller is still waiting for you to acknowledge 
the interrupt - so actually implementing that part might indeed help.

Kind regards,
Thomas



-----Original Message-----
From: Aarthi CR [mailto:community-noreply@qnx.com] 
Sent: Donnerstag, 28. August 2014 11:38
To: ostech-core_os
Subject: InterruptAttach()

Hi All,

I am developing SPI driver for i.Mx6 in QNX. I have used interrupt attach to attach the interrupts.
I get one interrupt intially (i is printed as 1 continously), but i dont receive subsequent interrupts.
I have used InterruptAttach in the following way.Please let me know if I am using it right.

volatile int n_interrupt = 0;
int main(int argc, char *argv[])
{
     //Initializations
    if(SPIConfigure( &dev, config.phas, config.pol, config.cs - 1 ))
    {
           printf("Configuration failed!\r\n");
           exit(1);
    }
    while(1)
    {
        printf("i - %d\n",GetNoOfInterrupt());
    }

}

uint8_t SPIConfigure(spiHwData_adt *dev, uint8_t phase, uint8_t polarity, uint8_t ss) {
	//Initialize variables

	if (ThreadCtl(_NTO_TCTL_IO, 0) == -1) {
		printf("ThreadCtl\r\n");
		return (!EOK);
	}

	//Configure SPI

	//Clear Rx FIFO

	tmp = InterruptAttach( dev->irq, spi_intr, dev, sizeof(spiHwData_adt), _NTO_INTR_FLAGS_PROCESS);
	

	if(tmp == -1)
	{
		if (errno == EAGAIN)
		{
			printf("Interrupt are in use\r\n");
		}else if (errno == EFAULT)
		{
			printf("A fault occurred when the kernel tried to access the buffers provided.\r\n");
		}else if (errno == EINVAL)
		{
			printf("The value of intr is not a valid interrupt number.\r\n");
		}else if (errno == EPERM)
		{
			printf("The process doesn't have I/O privileges.\r\n");
		}
	}else
	{
		printf("Attached IRQ ID = %d\r\n", tmp);
	}

	//Enable SPI interrupts

	return 0;
}


static const struct sigevent *spi_intr(void *area, int id) {
	//Clear Interrupt status
                  n_interrupt++;
	return NULL;
}
int GetNoOfInterrupt(void)
{
    return n_interrupt;
}

Please let me know if you need more details Thanks in advance. 



_______________________________________________

OSTech
http://community.qnx.com/sf/go/post111584
To cancel your subscription to this discussion, please e-mail ostech-core_os-unsubscribe@community.qnx.com
Re: RE: InterruptAttach()  
Hi Thomas,

Thanks much for your reply. 
I have removed that portion of code before posting. 
In the actual code, I am clearing the interrupt.

thanks,
Aarthi