// 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; }
/****************************************************************************** * @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; }