Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
16 years ago

PIO Interrupts and MicroC - OSStart() etc.

I had a to make a change from an approach based on an FPGA change from timer interrupts (TIMER_CONTROL) - which worked - to edge captured PIO interrupts. So consider the pseudo code


 
int const       WAIT_FOREVER  = 0 ;
INT8U           err           = 0;
void ISR20Hz ( void* context, alt_u32 id )
{
  IOWR_ALTERA_AVALON_PIO_EDGE_CAP( PRIMARY_INT_BASE, 0x0 );
  //if ( !OSRunning )  {
  //  OSStart();  // start multitasking undeer uC/OS-II 
  //}                         
  if ( OSRunning )
  { 
    err = OSSemPost ( TwentyHz_Sema ) ;
    if ( err != OS_NO_ERR ) 
    { 
     std::cout << "e" ; 
    }
  }
}
void Run20HzTask ( void* context )
{
  while ( 1 ) {
    OSSemPend ( TwentyHz_Sema, WAIT_FOREVER, &err ) ;
    if ( err != OS_NO_ERR ) {
      std::cout << "." ; 
      continue ;
    }
    std::cout << "." ;    
    // work
  }
}
 
 
int main() 
{
  std::cout << "1" ;    
  IOWR_ALTERA_AVALON_PIO_IRQ_MASK( PRIMARY_INT_BASE, 0x0 );
  // Reset the edge capture register. */
  IOWR_ALTERA_AVALON_PIO_EDGE_CAP( PRIMARY_INT_BASE, 0x0);    
  std::cout << "2" ;    
  /*
   | here I:
   | a) Setup the TwentyHz_Sema semaphore with OSSemCreate
   | b) Setup OSTaskCreateExt with the Run20HzTask
  */
  // later - start the interrupt
  IOWR_ALTERA_AVALON_PIO_IRQ_MASK( PRIMARY_INT_BASE, 0x1 );
  // Reset the edge capture register. */ 
  std::cout << "3" ;
  IOWR_ALTERA_AVALON_PIO_EDGE_CAP( PRIMARY_INT_BASE, 0x0);  
 
    //The alt_irq_register() function returns zero if successful, or non-zero otherwise.
  int const ret_val = alt_irq_register (  PRIMARY_INT_IRQ, 
                                          0, ISR20Hz  );      
  if ( ret_val != 0 ) 
  {
    return EXIT_FAILURE ;  
  }          
 
  OSStart(); 
}
 

At issue:

a) OSStart within main never executes. As a result OSRunning is never set to True for the semaphore to post.

b) If I comment out OSStart within main() and instead call OSStart once within the ISR20Hz function. i.e.


  if ( !OSRunning )  {
    OSStart();  // start multitasking under uC/OS-II 
  }        

Semaphores are/appear to be posted but the task that pends on the semaphore doesn't execute.

c) Once this line is executed


IOWR_ALTERA_AVALON_PIO_IRQ_MASK( PRIMARY_INT_BASE, 0x1 );

I no longer see stream outputs.

The question: Any ideas on what I'm doing wrong here?

Thanks in advance.
No RepliesBe the first to reply