Example #1
0
/** @Function Description:  This function registers an interrupt handler. 
  * If the function is succesful, then the requested interrupt will be enabled
  * upon return. Registering a NULL handler will disable the interrupt.
  *
  * @API Type:              External
  * @param ic_id            Interrupt controller ID
  * @param irq              IRQ ID number
  * @param isr              Pointer to interrupt service routine
  * @param isr_context      Opaque pointer passed to ISR
  * @param flags            
  * @return                 0 if successful, else error (-1)
  */
int alt_iic_isr_register(alt_u32 ic_id, alt_u32 irq, alt_isr_func isr, 
  void *isr_context, void *flags)
{
  int rc = -EINVAL;  
  int id = irq;             /* IRQ interpreted as the interrupt ID. */
  alt_irq_context status;

  if (id < ALT_NIRQ)
  {
    /* 
     * interrupts are disabled while the handler tables are updated to ensure
     * that an interrupt doesn't occur while the tables are in an inconsistant
     * state.
     */

    status = alt_irq_disable_all();

    alt_irq[id].handler = isr;
    alt_irq[id].context = isr_context;

    rc = (isr) ? alt_ic_irq_enable(ic_id, id) : alt_ic_irq_disable(ic_id, id);

    alt_irq_enable_all(status);
  }

  return rc; 
}
Example #2
0
/* initfix_int - unregister unused interrupt handlers
 * Returns 0 if successful, a nonzero value otherwise. */
int intfix( void )
{
  /* Declare a temporary for checking return values
   * from system-calls and library functions. */
  register int ret_val_check = 0;
  register int irq_number;
  for( irq_number = LOWEST_IRQ_NUMBER;
       irq_number < HIGHEST_IRQ_NUMBER;
       irq_number += 1 )
  {
    ret_val_check |= alt_ic_irq_disable( 0, irq_number );
  }
  UART_0[3] = UART_1[3] = 0; /* Serial ports */
  return( ret_val_check );
}
Example #3
0
void disable_tpad()
{

#ifdef ALT_VIP_VFR_0_BASE
  // Remove LCD display DMA activity
  Frame_Reader_init();
  Frame_Reader_stop(1);
#endif

#ifdef FRAME_WRITER_0_BASE
  // Remove camera DMA activity
  alt_ic_irq_disable( 0, FRAME_WRITER_0_IRQ );

  //Clear frame writer registers
  IOWR(FRAME_WRITER_0_BASE, 0/*FRAME_WRITER_CONTROL*/, 0x0);
  while(IORD(FRAME_WRITER_0_BASE, 3/*FRAME_WRITER_NEXT*/));
  while(IORD(FRAME_WRITER_0_BASE, 2/*FRAME_WRITER_CURRENT*/));
  while(IORD(FRAME_WRITER_0_BASE, 1/*FRAME_WRITER_LAST*/));

  // NULL de-registers a pre-existing service routine and disables interrupt
  alt_ic_isr_register( 0, FRAME_WRITER_0_IRQ, NULL, (void *)(&frame_writer_isr_context), 0 );
#endif
}
Example #4
0
File: main.c Project: gri6507/QMS
int main(void)
{
    // Prepare for UART communication with external world. The default baud rate
    // is 921,600 bps
    IOWR_FIFOED_AVALON_UART_DIVISOR(UART_BASE, BAUD_RATE(921600.0f));

    // Make sure UART interrupts are disabled
    alt_ic_irq_disable(UART_IRQ_INTERRUPT_CONTROLLER_ID, UART_IRQ);

    // Clear the input and output buffers
    FlushRx(UART_BASE);
    FlushTx(UART_BASE);
    
    #define MAX_CMD_LEN 64
    char cmd[MAX_CMD_LEN];
    s8 cmdIndex = 0;

    // Sit in an infinite loop waiting for serial commands
    while(1)
    {
        while (IORD_FIFOED_AVALON_UART_STATUS(UART_BASE) & FIFOED_AVALON_UART_CONTROL_RRDY_MSK)
        {
            // Read the Uart
            char rx = IORD_FIFOED_AVALON_UART_RXDATA(UART_BASE);
            
            // If this is the end of a command, then try to parse it
            if (('\r' == rx) || ('\n' == rx))
            {
                cmd[cmdIndex] = '\0';
                ExecuteCmd(cmd, UART_BASE);
                FlushRx(UART_BASE);
                FlushTx(UART_BASE);
                cmdIndex = 0;
            }
            
            // If this is a backspace
            else if ('\b' == rx)
            {
                SendStr("\b \b", UART_BASE);
                if (cmdIndex > 0)
                    cmdIndex--;
            }
            
            // This is any other character
            else
            {
                // echo the character
                SendChar(rx, UART_BASE);
                
                // Add it to the buffer, if possible, making sure to save the 
                // space for the null terminator (when completing the command)
                if (cmdIndex < (MAX_CMD_LEN - 1))
                    cmd[cmdIndex++] = rx;
                
                // Otherwise, report the error and reset the buffer
                else
                {
                    cmdIndex = 0;
                    SendStr(NO_ANSWER, UART_BASE);
                }
            }
        }
    }
}