Page 1 of 1

QSPi in interrupt

Posted: Thu Aug 19, 2010 10:01 am
by chrispol
Is it possible to use qspi in an interrupt?

code snippet causes an exception, reading from a 3201

Code: Select all

  
SHORT ReadADC()
{
  BYTE  l_data[2];
  SHORT l_value;

  OS_SEM QSPI_SEM;

  OSSemInit(&QSPI_SEM, 0);
  QSPIStart( NULL,&l_data[0], 2, &QSPI_SEM );
  OSSemPend( &QSPI_SEM, 0 );

  l_value = ((l_data[0]<<8)|l_data[1]) & 0x0FFF;

  return l_value;
}

INTERRUPT(XAxisTimer,0x2400)
{
  USER_ENTER_CRITICAL();

  WORD tmp = sim.pit[1].pcsr;
  tmp &= 0xFF0F;
  tmp |= 0x0F;
  sim.pit[1].pcsr = tmp;

  SHORT l_val = ReadADC();

  USER_EXIT_CRITICAL();
}

Re: QSPi in interrupt

Posted: Thu Aug 19, 2010 10:08 am
by rsg
No, you cannot pend on anything in an ISR. Basically, you only want to trigger tasks in an ISR; tasks are free to pend as necessary.

Also, you code will initializes the semaphore many times - you should only call OSSemInit once.

Re: QSPi in interrupt

Posted: Thu Aug 19, 2010 10:50 am
by chrispol
Ok right now i am using my timer for stepper timing on movement, and i have to make an adc reading for each step.

so i guess in my main function i would have to check a flag that the interrupt sets to take a step then read the adc?

Re: QSPi in interrupt

Posted: Thu Aug 19, 2010 12:22 pm
by pbreed
For doing this sort of thing I talk directly to the QSPI hardware not the QSPI library.
Take a look at the Freesscale Manual, you can set it up so QSPI continiously updates values from the A/D then just read a register, no pending.

Paul

Re: QSPi in interrupt

Posted: Thu Aug 19, 2010 1:45 pm
by lgitlitz
Paul is correct here. You should just set up the A2D to work in continuous mode so it is always reading form the A/D. There is no need to pend since the QSPI data registers are already holding fresh data that is less then 1uS old. Since the QSPI is in continuous (looping) mode there is no CPU interaction required except when you want to read a result, no interrupt required.

I am attaching some a driver I did for a board that had 2 TI TLV2548 A/Ds. So 2 8-channel A/Ds gave me 16-channels of A/D data. I have the QSPI running in continuous mode where each channel will be stored in one of the 16 data queues on the QSPI peripheral. Then when I want to get data I disable the QSPI, read the data from the corresponding channels QSPI queue and then re-enable the QSPI peripheral. Not sure if this code is completely bug free but it should give you a good starting point.

-Larry