Ejemplo n.º 1
0
// the isr's...
static void uart_tx_irq( void )
  {    
  unsigned char c;
    {
    uart_get_tx_data_type handler;
    BSP_CRITICAL_STATEMENT( handler = uart_tx_handler );

    // if not currently in suspend mode and a handler exists
    if( uart_tx_suspend == false && handler != NULL )
      {
      if( (*handler)( &c ) != false ) // if data available, reset the interrupt
        {
        UART_SEND( UART_NUMBER, UART_LOCATION, c ); // send the byte
        }
      else // if no data suspend transmission
        {
        uart_tx_message_suspend( handler );
        UART_IRQ_FLAG_SET( UART_NUMBER, UART_LOCATION, TX );
        }
      }
    else
      {
      bspIState_t istate;
      BSP_ENTER_CRITICAL_SECTION( istate );
      // if we are in suspended mode or we just sent an xon or xoff character
      // while transmits were disabled or the message has been completely sent,
      // then simply disable irq's so we don't get stuck in an infinite loop
      UART_IRQ_DISABLE( UART_NUMBER, UART_LOCATION, TX );
      UART_IRQ_FLAG_SET( UART_NUMBER, UART_LOCATION, TX );
      BSP_EXIT_CRITICAL_SECTION( istate );
      }
    }
  return;
}
Ejemplo n.º 2
0
/******************************************************************************
 * @fn          uart1_tx_irq
 *
 * @brief       TX interrupt service routine
 *
 * input parameters
 *
 * output parameters
 *
 * @return
 */
void uart0_tx_irq( void )
  {
  unsigned char c;
  uart_get_tx_data_type handler;

  BSP_CRITICAL_STATEMENT( handler = uart0_tx_handler );

  /* if a handler exists */
  if( handler != NULL )
    {
    if( (*handler)( &c ) != false ) /* if this is not the last byte to send */
      {
      bspIState_t intState;
      BSP_ENTER_CRITICAL_SECTION( intState );

      /* only reset the interrupt flag if we have additional data to send
       * that way, if we are done then the interrupt is still pending and
       * will be immediately entered upon re-enabling it.*/
      UART_IRQ_FLAG_CLR( UART_NUMBER_0, UART0_LOCATION, TX ); /* eset the interrupt */

      BSP_EXIT_CRITICAL_SECTION( intState );
      }
    else
      {
      bspIState_t intState;
      BSP_ENTER_CRITICAL_SECTION( intState );

      /* we're done sending data.  since we left the interrupt pending,
       * disable it so we don't re-enter the isr.  the interrupt will be
       * re-enabled when there is another message to send. */
      UART_IRQ_DISABLE( UART_NUMBER_0, UART0_LOCATION, TX );

      /* no more data to send, reset the handler to flag not busy */
      uart0_tx_handler = NULL;

      BSP_EXIT_CRITICAL_SECTION( intState );
      }

    UART_SEND( UART_NUMBER_0, UART0_LOCATION, c ); /* send the byte */
    }
  else /* if no handler exists?!?!?!? */
    /* something went wrong, disable interrupts so we don't get stuck here */
    UART_IRQ_DISABLE( UART_NUMBER_0, UART0_LOCATION, TX );

  return;
}
Ejemplo n.º 3
0
// user interface functions
void uart_init( void )
  {
  volatile unsigned int i;
  bspIState_t istate;
  BSP_ENTER_CRITICAL_SECTION( istate );

  // disable the receive and transmit interrupts for the moment
  UART_IRQ_DISABLE( UART_NUMBER, UART_LOCATION, TX ); 
  UART_IRQ_DISABLE( UART_NUMBER, UART_LOCATION, RX ); 

  BSP_EXIT_CRITICAL_SECTION( istate );

  // make sure the handler functions are cleared in case we are re-initialized
  uart_tx_handler = NULL;
  uart_rx_handler = NULL;

  // clear transmit suspend semaphore
  uart_tx_suspend = false;
  
  // initialize the uart interface for operations
  UART_INIT( UART_NUMBER,
             UART_LOCATION,
             UART_FLOW_CONTROL,    // enable/disable flow control
             UART_PARITY_MODE,     // enable/disable parity
             UART_STOP_BITS,       // number of stop bits
             UART_BAUD_RATE );     // baud rate to use

  i = UART_BAUD_RATE >> 5; // delay approximately 1 bit time
  while( --i != 0 ) // give the uart some time to initialize
      ; // null statement

  // enable receive interrupts, they are always welcome.
  UART_IRQ_ENABLE( UART_NUMBER, UART_LOCATION, RX ); 

  return;
  }
Ejemplo n.º 4
0
/******************************************************************************
 * @fn          uart_init
 *
 * @brief       Configures UART and sets up transmit and receive interrupts
 *
 * input parameters
 *
 * output parameters
 *
 * @return
 */
void uart_init( void )
  {
  volatile unsigned int i;

  /* make sure the handler functions are cleared in case we are re-initialized */
  uart1_tx_handler = NULL;
  uart0_tx_handler = NULL;
  uart_rx_handler = NULL;

  /* initialize the uart interface for operations */
  UART_INIT( UART_NUMBER_1,
             UART_LOCATION_2,
             UART_FLOW_CONTROL,    /* enable/disable flow control */
             UART_PARITY_MODE,     /* enable/disable parity */
             UART_STOP_BITS,       /* number of stop bits */
             UART1_BAUD_RATE );     /* baud rate to use */

  i = UART1_BAUD_RATE >> 5; /* delay approximately 1 bit time */
  while( --i != 0 ) /* give the uart some time to initialize */
      ; /* null statement */

  /* set the interrupt flag so that a transmit interrupt will be pending
   * that way when a message is sent and the irq is enabled, the interrupt
   * will happen immediately to start the transmission */
  UART_IRQ_FLAG_SET( UART_NUMBER_1, UART1_LOCATION, TX ); /* set the interrupt */

  /* enable receive interrupts, they are always welcome. */
  UART_IRQ_ENABLE( UART_NUMBER_1, UART1_LOCATION, RX );

  /* initialize the uart interface for operations */
  UART_INIT( UART_NUMBER_0,
             UART_LOCATION_2,
             UART_FLOW_CONTROL,    /* enable/disable flow control */
             UART_PARITY_MODE,     /* enable/disable parity */
             UART_STOP_BITS,       /* number of stop bits */
             UART0_BAUD_RATE );     /* baud rate to use */

  UART_IRQ_FLAG_SET( UART_NUMBER_0, UART0_LOCATION, TX ); /* set the interrupt */

  UART_IRQ_DISABLE(UART_NUMBER_0,UART_LOCATION_2,RX);

  return;
  }