Exemplo n.º 1
0
/**
 * UART 1 - for gps module
 */
void uart4InturruptHandle(void) {
	unsigned long ulStatus1, val;
	ulStatus1 = ROM_UARTIntStatus(UART1_BASE, true);
	ROM_UARTIntClear(UART1_BASE, ulStatus1);

	while (UARTCharsAvail(UART1_BASE)) {
		val = UARTCharGetNonBlocking(UART1_BASE);
//    inputBuffer[j]=val;

		if ((val == '$')) {
			//gpsSentence[1][82] = '\0';
			gpsSentence[!toggle][j] = '\0';
			gpsBufferSize[!toggle] = j;
//			gpsSentence[!toggle][0] = j;
			j = 0;	//0 index to hold end point
			toggle = !toggle;
			message = true;

		}
		gpsSentence[!toggle][j] = val;

		if (val == '\n' || val == '\r' || val == ' ' || val == '\t') {
			j--; //if some newline is in the message, simply ignore that charater by
			//shifting the increment backwardsso
		}

		j++;
	}

}
Exemplo n.º 2
0
void UART1IntHandler(void)
{
    uint32_t 	ui32Status;
    //
    // Get the interrrupt status.
    //
    ui32Status = ROM_UARTIntStatus(UART1_BASE, true);

    //
    // Clear the asserted interrupts.
    //
    ROM_UARTIntClear(UART1_BASE, ui32Status);
    PRINTF("INT:\n");
    //
    // Loop while there are characters in the receive FIFO.
    //
    while(ROM_UARTCharsAvail(UART1_BASE)) {
        //
        // Read the next character from the UART and write it back to the UART.
        //
        uart1buffer[RX_PTR1]=ROM_UARTCharGetNonBlocking(UART1_BASE);
        /// echo
        ROM_UARTCharPutNonBlocking(UART0_BASE, uart1buffer[RX_PTR1]);
        RX_PTR1++;
        RX_PTR1 &= DIM_READ_BUFF - 1;
        //UARTCharPutNonBlocking(UART1_BASE,
        //		dato);
    }
}
Exemplo n.º 3
0
Arquivo: uart.c Projeto: daniel-k/RIOT
/**
 * The UART interrupt handler.
 */
void isr_uart0(void)
{
    unsigned long ulStatus;

    ulStatus = ROM_UARTIntStatus(UART0_BASE, true);
    ROM_UARTIntClear(UART0_BASE, ulStatus);

    /* Are we interrupted due to TX done */
    if(ulStatus & UART_INT_TX)
    {
        if (config[UART_0].tx_cb(config[UART_0].arg) == 0){
            UART0_IM_R &= ~UART_IM_TXIM;
        }
    }

    /* Are we interrupted due to a recieved character */
    if(ulStatus & (UART_INT_RX | UART_INT_RT))
    {
        while(ROM_UARTCharsAvail(UART0_BASE))
        {
            char cChar;
            long lChar;
            lChar = ROM_UARTCharGetNonBlocking(UART0_BASE);
            cChar = (unsigned char)(lChar & 0xFF);
            config[UART_0].rx_cb(config[UART_0].arg, cChar);
        }
    }
    if (sched_context_switch_request) {
        thread_yield();
    }
}
//frame=START_BYTE + CMD_ID + LENGTH_BYTE + payload (LSB first)
void UartRFIntHandler()
{
	static uint8_t msgRF[20];
	static uint32_t msgRFLen=0;
	static uint32_t numBytes=0;
	uint32_t status = ROM_UARTIntStatus(UART_RF,true);
	ROM_UARTIntClear(UART_RF,status);
	while (ROM_UARTCharsAvail(UART_RF))
	{
		char temp=ROM_UARTCharGetNonBlocking(UART_RF);
		if (numBytes==0)
		{
			if (temp==START_BYTE)
			{
				msgRF[numBytes++]=temp;
			}
			continue;
		}
		msgRF[numBytes++]=temp;
		if (numBytes==3)
			msgRFLen = msgRF[2] + 3;
		if ((numBytes==msgRFLen) && (msgRFLen!=0))
		{
			processRFMsg(msgRF);
			numBytes=0;
			msgRFLen=0;
		}
	}
}
Exemplo n.º 5
0
//*****************************************************************************
//
// The UART interrupt handler.
//
//*****************************************************************************
void
UARTIntHandler(void)
{
    uint32_t ui32Status;

    //
    // Get the interrrupt status.
    //
    ui32Status = ROM_UARTIntStatus(UART0_BASE, true);

    //
    // Clear the asserted interrupts.
    //
    ROM_UARTIntClear(UART0_BASE, ui32Status);

    //
    // Loop while there are characters in the receive FIFO.
    //
    while(ROM_UARTCharsAvail(UART0_BASE))
    {
        //
        // Read the next character from the UART and write it back to the UART.
        //
        ROM_UARTCharPutNonBlocking(UART0_BASE,
                                   ROM_UARTCharGetNonBlocking(UART0_BASE));
    }
}
Exemplo n.º 6
0
void
UART1IntHandler(void)
{
	uint32_t ui32Status;
	ui32Status = ROM_UARTIntStatus(UART1_BASE, true);
	UARTBridge(UART1_BASE, UART0_BASE);
	ROM_UARTIntClear(UART1_BASE, ui32Status);
}
Exemplo n.º 7
0
void
UARTIntHandler(void) //This is triggered when the pc sends data - it is the virtual serial port interrupt.
{
    ROM_UARTIntClear(UART0_BASE, ROM_UARTIntStatus(UART0_BASE, true));

    while(ROM_UARTCharsAvail(UART0_BASE))
    {
        ROM_UARTCharPutNonBlocking(UART3_BASE,ROM_UARTCharGetNonBlocking(UART0_BASE));
    }
}
void HardwareSerial::UARTIntHandler(void){
    unsigned long ulInts;
    long lChar;
    // Get and clear the current interrupt source(s)
    //
    ulInts = ROM_UARTIntStatus(UART_BASE, true);
    ROM_UARTIntClear(UART_BASE, ulInts);

    // Are we being interrupted because the TX FIFO has space available?
    //
    if(ulInts & UART_INT_TX)
    {
        //
        // Move as many bytes as we can into the transmit FIFO.
        //
        primeTransmit(UART_BASE);

        //
        // If the output buffer is empty, turn off the transmit interrupt.
        //
        if(TX_BUFFER_EMPTY)
        {
            ROM_UARTIntDisable(UART_BASE, UART_INT_TX);
        }
    }
    if(ulInts & (UART_INT_RX | UART_INT_RT))
    {
        while(ROM_UARTCharsAvail(UART_BASE))
            {

            //
            // Read a character
            //
            lChar = ROM_UARTCharGetNonBlocking(UART_BASE);
            //
            // If there is space in the receive buffer, put the character
            // there, otherwise throw it away.
            //
            uint8_t volatile full = RX_BUFFER_FULL;
            if(full) break;

            rxBuffer[rxWriteIndex] =
                (unsigned char)(lChar & 0xFF);
            rxWriteIndex = ((rxWriteIndex) + 1) % rxBufferSize;

            //
            // If we wrote anything to the transmit buffer, make sure it actually
            // gets transmitted.
            //
        }
        primeTransmit(UART_BASE);
        ROM_UARTIntEnable(UART_BASE, UART_INT_TX);
    }
}
Exemplo n.º 9
0
void UARTIntHandler(void){
    uint32_t ui32Status;
    ui32Status = ROM_UARTIntStatus(UART0_BASE, true);
    ROM_UARTIntClear(UART0_BASE, ui32Status);
    while(ROM_UARTCharsAvail(UART0_BASE)){
        ROM_UARTCharPutNonBlocking(UART0_BASE, ROM_UARTCharGetNonBlocking(UART0_BASE));
        GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);
        SysCtlDelay(SysCtlClockGet() / (1000 * 3));
        GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);
    }
}
Exemplo n.º 10
0
void UARTIntHandler(void)
{
    uint32_t ui32Status;

    // Get the interrrupt status.
    ui32Status = ROM_UARTIntStatus(UART0_BASE, true);

    // Clear the asserted interrupts.
    ROM_UARTIntClear(UART0_BASE, ui32Status);

}
Exemplo n.º 11
0
/*---------------------------------------------------------------------------*/
void UART0IntHandler(void)
{
	unsigned long ulStatus;

	ulStatus = ROM_UARTIntStatus(UART0_BASE, true);
	ROM_UARTIntClear(UART0_BASE, ulStatus);

	while(ROM_UARTCharsAvail(UART0_BASE))
	{
		uart0_input_handler(ROM_UARTCharGetNonBlocking(UART0_BASE));
	}
}
Exemplo n.º 12
0
void UART1_ISR(){
	 uint32_t ui32Status;

	//
	// Get the interrrupt status.
	//
	ui32Status = ROM_UARTIntStatus(UART1_BASE, true);

	//
	// Clear the asserted interrupts.
	//
	ROM_UARTIntClear(UART1_BASE, ui32Status);

}
Exemplo n.º 13
0
//*****************************************************************************
//
// Interrupt handler for the UART which we are redirecting via USB.
//
//*****************************************************************************
void
USBUARTIntHandler(void)
{
    uint32_t ui32Ints;
    int32_t i32Errors;

    //
    // Get and clear the current interrupt source(s)
    //
    ui32Ints = ROM_UARTIntStatus(USB_UART_BASE, true);
    ROM_UARTIntClear(USB_UART_BASE, ui32Ints);

    //
    // Are we being interrupted because the TX FIFO has space available?
    //
    if(ui32Ints & UART_INT_TX)
    {
        //
        // Move as many bytes as we can into the transmit FIFO.
        //
        USBUARTPrimeTransmit(USB_UART_BASE);

        //
        // If the output buffer is empty, turn off the transmit interrupt.
        //
        if(!USBBufferDataAvailable(&g_sRxBuffer))
        {
            ROM_UARTIntDisable(USB_UART_BASE, UART_INT_TX);
        }
    }

    //
    // Handle receive interrupts.
    //
    // gjs if(ui32Ints & (UART_INT_RX))
    if(ui32Ints & (UART_INT_RX | UART_INT_RT))
    {
        //
        // Read the UART's characters into the buffer.
        //
        i32Errors = ReadUARTData();

        //
        // Check to see if we need to notify the host of any errors we just
        // detected.
        //
        CheckForSerialStateChange(&g_sCDCDevice, i32Errors);
    }
}
Exemplo n.º 14
0
void
UART3IntHandler(void) //This is triggered when the UART3 gets data - PC6/7
{
    unsigned long ulStatus;
    char character;

    ulStatus = ROM_UARTIntStatus(UART3_BASE, true);

    ROM_UARTIntClear(UART3_BASE, ulStatus);

    while(ROM_UARTCharsAvail(UART3_BASE))
    {
        ROM_UARTCharPutNonBlocking(UART0_BASE,ROM_UARTCharGetNonBlocking(UART3_BASE));
    }
}
//*****************************************************************************
//
// Interrupt handler for the UART which is being redirected via USB.
//
//*****************************************************************************
void
USBUARTIntHandler(void)
{
    unsigned long ulInts;
    long lErrors;

    //
    // Get and clear the current interrupt source(s)
    //
    ulInts = ROM_UARTIntStatus(UART0_BASE, true);
    ROM_UARTIntClear(UART0_BASE, ulInts);

    //
    // Handle transmit interrupts.
    //
    if(ulInts & UART_INT_TX)
    {
        //
        // Move as many bytes as possible into the transmit FIFO.
        //
        USBUARTPrimeTransmit();

        //
        // If the output buffer is empty, turn off the transmit interrupt.
        //
        if(!USBBufferDataAvailable(&g_sRxBuffer))
        {
            ROM_UARTIntDisable(UART0_BASE, UART_INT_TX);
        }
    }

    //
    // Handle receive interrupts.
    //
    if(ulInts & (UART_INT_RX | UART_INT_RT))
    {
        //
        // Read the UART's characters into the buffer.
        //
        lErrors = ReadUARTData();

        //
        // Check to see if the host needs to be notified of any errors just
        // detected.
        //
        CheckForSerialStateChange(&g_sCDCDevice, lErrors);
    }
}
//*****************************************************************************
//
// The UART interrupt handler.
//
//*****************************************************************************]
void UARTIntHandler4(void) {
	uint32_t ui32Status;

	//
	// Get the interrrupt status.
	//
	ui32Status = ROM_UARTIntStatus(UART4_BASE, true);

	//
	// Clear the asserted interrupts.
	//
	ROM_UARTIntClear(UART4_BASE, ui32Status);

	if (ROM_UARTCharsAvail(UART4_BASE))
		input();
}
Exemplo n.º 17
0
// Called when UART RX FIFO has data in it
static void flushReadFIFO(uint8_t UART)
{
    // Read from the FIFO and place in the circular buffer in memory
    while (ROM_UARTCharsAvail(UARTBASE[UART]))
    {
        if (rxQSize(UART) < UART_BUFFSIZE - 1)
            rxEnqueue(UART, ROM_UARTCharGet(UARTBASE[UART]));
        else
            ROM_UARTCharGet(UARTBASE[UART]);
    }

    // If the circular queue is full, set the overflow flag and return
    if (rxQSize(UART) == UART_BUFFSIZE - 1) overflow |= bit8[UART];

    // Clear the appropriate interrupt flag
    ROM_UARTIntClear(UARTBASE[UART], UART_INT_RX);
}
Exemplo n.º 18
0
/*
 * This is the UART3RX interrupt handler for the Optode
 * The handler simply writes characters out to the desktop.
 */
void UART3IntHandler(void)
{
	unsigned long ulStatus;

	// Get the interrupt status.
	ulStatus = ROM_UARTIntStatus(UART3_BASE, true);

	// Clear the asserted interrupts.
	ROM_UARTIntClear(UART3_BASE, ulStatus);


	// Loop while there are characters in the receive FIFO
	while(ROM_UARTCharsAvail(UART3_BASE))
	{
		// Read the next character from the UART and write it to desktop.
		ROM_UARTCharPutNonBlocking(UART1_BASE, ROM_UARTCharGetNonBlocking(UART3_BASE));
	}
}
//*****************************************************************************
//
// The UART interrupt handler.
//
//*****************************************************************************
void
UARTIntHandler(void)
{
    uint32_t ui32Status;

    //
    // Get the interrrupt status.
    //
    ui32Status = ROM_UARTIntStatus(UART0_BASE, true);

    //
    // Clear the asserted interrupts.
    //
    ROM_UARTIntClear(UART0_BASE, ui32Status);

    //
    // Loop while there are characters in the receive FIFO.
    //
    while(ROM_UARTCharsAvail(UART0_BASE))
    {
        //
        // Read the next character from the UART and write it back to the UART.
        //
        ROM_UARTCharPutNonBlocking(UART0_BASE,
                                   ROM_UARTCharGetNonBlocking(UART0_BASE));

        //
        // Blink the LED to show a character transfer is occuring.
        //
        GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);

        //
        // Delay for 1 millisecond.  Each SysCtlDelay is about 3 clocks.
        //
        SysCtlDelay(SysCtlClockGet() / (1000 * 3));

        //
        // Turn off the LED
        //
        GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);

    }
}
void UartGPSIntHandler()
{
	uint32_t status = ROM_UARTIntStatus(UART_GPS,true);
	static uint32_t numBytes=0;
	ROM_UARTIntClear(UART_GPS,status);
	while (ROM_UARTCharsAvail(UART_GPS))
	{
		if ((MsgBuf[numBytes++]=ROM_UARTCharGetNonBlocking(UART_GPS))=='\n')
		{
			HandleGPSMsg(MsgBuf);
			flagNewGPSMsg=true;
			msgLen=numBytes;
			numBytes = 0;
		}
		if (numBytes==MAX_GPS_MSG_BYTE)
			numBytes=0;

	}
}
Exemplo n.º 21
0
/**
 * The UART interrupt handler.
 */
void isr_uart0(void)
{
    unsigned long ulStatus;

    ulStatus = ROM_UARTIntStatus(UART0_BASE, true);
    ROM_UARTIntClear(UART0_BASE, ulStatus);

    /* Are we interrupted due to a recieved character */
    if(ulStatus & (UART_INT_RX | UART_INT_RT))
    {
        while(ROM_UARTCharsAvail(UART0_BASE))
        {
            long lchar = ROM_UARTCharGetNonBlocking(UART0_BASE);
            config[UART_0].rx_cb(config[UART_0].arg, (uint8_t)lchar);
        }
    }
    if (sched_context_switch_request) {
        thread_yield();
    }
}
Exemplo n.º 22
0
void
UARTIntHandler(void)
{
    uint32_t ui32Status;

    ui32Status = ROM_UARTIntStatus(UART7_BASE, true);
    ROM_UARTIntClear(UART7_BASE, ui32Status);

    while(ROM_UARTCharsAvail(UART7_BASE))
    {
        // ROM_UARTCharPutNonBlocking(UART7_BASE,ROM_UARTCharGetNonBlocking(UART7_BASE));

		UARTLed(LED1);

		message[ptr] = ROM_UARTCharGetNonBlocking(UART7_BASE);

		if(message[ptr] == '\n')
		{
			  if(ptr == 32) /* hard coded message size ;-) */
			  {
				/* answer first, then display */
				transform_message(message);
				for(uint8_t i = 0; i < ptr; ++i)
				{
				  UARTSend(&message[i],1);
				}
				UARTSend((const uint8_t*) '\n',1);
			  }
			  ptr = 0;
		}
		else
		{
			  ++ptr;
			  
			  if(ptr >= 64)
			  {
				ptr = 0;
			  }
		}
    }
}
Exemplo n.º 23
0
//*****************************************************************************
// UART interrupt handler.
//*****************************************************************************
void UART0_IntHandler(void)
{
    uint32_t status = ROM_UARTIntStatus(UART0_BASE, true);
    ROM_UARTIntClear(UART0_BASE, status);
    
    // drain rx FIFO
    while(ROM_UARTCharsAvail(UART0_BASE))
    {
        char ch = ROM_UARTCharGetNonBlocking(UART0_BASE);
        
        if(inputRB.nbytes < DBG_IN_BUFFER_SIZE)
        {
            RB_Push(dbg_inputBuffer, inputRB, ch, DBG_IN_BUFFER_SIZE);
            if(ch == '\r')
                ++newlines;
        }
        else
        {
            // Attempt to report overflow and clear buffer
            // Must do this to avoid condition where buffer is full and code
            // is waiting for a newline that can not fit in the buffer.
            dbg_putstr_nb("\rRXOVF\r\n");
            RB_Clear(inputRB);
            newlines = 0;
        }
    }
    
    // feed tx FIFO
    // Echo received characters
    while(ROM_UARTSpaceAvail(UART0_BASE) && echoPtr != inputRB.wp)
    {
        ROM_UARTCharPutNonBlocking(UART0_BASE, dbg_inputBuffer[echoPtr]);
        echoPtr = (echoPtr + 1) % DBG_IN_BUFFER_SIZE;
    }
    // Write pending characters
    while(ROM_UARTSpaceAvail(UART0_BASE) && outputRB.nbytes > 0)
    {
        ROM_UARTCharPutNonBlocking(UART0_BASE, RB_Front(dbg_outputBuffer, outputRB));
        RB_Pop(outputRB, DBG_OUT_BUFFER_SIZE);
    }
} // UART0_IntHandler()
Exemplo n.º 24
0
//*****************************************************************************
//
// The UART1 interrupt handler.
// Get response from XBee (UART1), print to terminal (UART0)
//
//*****************************************************************************
void
UART1IntHandler(void)
{
	unsigned char x;
    uint32_t ui32Status;

    //
    // Get the interrrupt status.
    //
    ui32Status = ROM_UARTIntStatus(UART1_BASE, true);

    //
    // Clear the asserted interrupts.
    //
    ROM_UARTIntClear(UART1_BASE, ui32Status);

	  UARTprintf("Response:'");
    //
    // Loop while there are characters in the receive FIFO.
    //
    while(ROM_UARTCharsAvail(UART1_BASE))
    {
        //
        // Read the next character from the UART and write it back to the UART.
        // if special character print out the integer for it
			  //
				x=ROM_UARTCharGetNonBlocking(UART1_BASE);
				if(x<' ' | x>'~')
				{
					UARTprintf("/%d",(int)x);
					//ROM_UARTCharPutNonBlocking(UART0_BASE,x);
				}
				else
				{
					ROM_UARTCharPutNonBlocking(UART0_BASE,x);
				}
					
    }
		UARTprintf("'\n");
}
Exemplo n.º 25
0
static inline void irq_handler(uart_t uartnum, unsigned long ulBase, unsigned long ulRxInt)
{
    unsigned long ulStatus;

    ulStatus = ROM_UARTIntStatus(ulBase, true);
    ROM_UARTIntClear(ulBase, ulStatus);

    /* Are we interrupted due to a recieved character */
    if(ulStatus & (UART_INT_RX | UART_INT_RT))
    {
        while(ROM_UARTCharsAvail(ulBase))
        {
            char cChar;
            long lChar;
            lChar = ROM_UARTCharGetNonBlocking(ulBase);
            cChar = (unsigned char)(lChar & 0xFF);
            config[uartnum].rx_cb(config[uartnum].arg, cChar);
        }
    }
    if (sched_context_switch_request) {
        thread_yield();
    }
}
Exemplo n.º 26
0
void UpstreamUARTIntHandler(void) {
    uint32_t ui32Status;
    uint8_t data;
    static luxframe_t* lframe;
    static uint8_t lbuffer[LUX_MAX_FRAME_SIZE + 8];

    // Get the interrrupt status.
    ui32Status = ROM_UARTIntStatus(UART1_BASE, true);
    // Clear the asserted interrupts.
    ROM_UARTIntClear(UART1_BASE, ui32Status);
    // Loop while there are characters in the receive FIFO.
    while(ROM_UARTCharsAvail(UART1_BASE)){
        data = ROM_UARTCharGetNonBlocking(UART1_BASE);
        // Read the next character from the UART and write it back to the UART.
        //ROM_UARTCharPutNonBlocking(UART1_BASE, data);
        // Update lux framing
        lframe = lux_usart_poll(data);
        if(lframe){
            lux_calculate_crc(lframe);
            lux_serialize(lframe, lbuffer);
            //UARTSend(UART0_BASE, lbuffer, lframe->length + 6);
            //UARTSend(UART1_BASE, lbuffer, lframe->length + 6);
            //UARTSend(UART2_BASE, lbuffer, lframe->length + 6);
            //UARTSend(UART3_BASE, lbuffer, lframe->length + 6);
            //UARTSend(UART4_BASE, lbuffer, lframe->length + 6);
            UARTSend(UART5_BASE, lbuffer, lframe->length + 6);
            //UARTSend(UART6_BASE, lbuffer, lframe->length + 6);
            //UARTSend(UART7_BASE, lbuffer, lframe->length + 6);
        }
        // Blink the LED to show a character transfer is occuring.
        GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_6, GPIO_PIN_6);
        // Delay for 1 millisecond.  Each SysCtlDelay is about 3 clocks.
        SysCtlDelay(SysCtlClockGet() / (1000 * 3));
        // Turn off the LED
        GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_6, 0);
    }
}
//*****************************************************************************
//
// This is the main application entry function.
//
//*****************************************************************************
int
main(void)
{
    //
    // Set the clocking to run from the PLL at 50MHz
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    //
    // Enable the UART.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

    //
    // Enable and configure the UART RX and TX pins
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    GPIOPinConfigure(GPIO_PA0_U0RX);
    GPIOPinConfigure(GPIO_PA1_U0TX);
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Set the default UART configuration.
    //
    ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), 115200,
                            UART_CONFIG_WLEN_8 | UART_CONFIG_PAR_NONE |
                            UART_CONFIG_STOP_ONE);
    ROM_UARTFIFOLevelSet(UART0_BASE, UART_FIFO_TX4_8, UART_FIFO_RX4_8);

    //
    // Configure and enable UART interrupts.
    //
    ROM_UARTIntClear(UART0_BASE, ROM_UARTIntStatus(UART0_BASE, false));
    ROM_UARTIntEnable(UART0_BASE, (UART_INT_OE | UART_INT_BE | UART_INT_PE |
                                   UART_INT_FE | UART_INT_RT | UART_INT_RX));

    //
    // Enable and configure the user LED pin.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_0);

    //
    // Turn off the user LED.
    //
    GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0, 0);

    //
    // Initialize the transmit and receive buffers.
    //
    USBBufferInit(&g_sTxBuffer);
    USBBufferInit(&g_sRxBuffer);

    //
    // Set the USB stack mode to Device mode with VBUS monitoring.
    //
    USBStackModeSet(0, USB_MODE_DEVICE, 0);

    //
    // Pass the device information to the USB library and place the device
    // on the bus.
    //
    USBDCDCInit(0, &g_sCDCDevice);

    //
    // Enable interrupts now that the application is ready to start.
    //
    ROM_IntEnable(INT_UART0);

    //
    // Main application loop.
    //
    while(1)
    {
    }
}
Exemplo n.º 28
0
//*****************************************************************************
//
// This is the main application entry function.
//
//*****************************************************************************
int
main(void)
{
    uint32_t ui32TxCount;
    uint32_t ui32RxCount;
    tRectangle sRect;
    char pcBuffer[16];
    uint32_t ui32Fullness;

    //
    // Enable lazy stacking for interrupt handlers.  This allows floating-point
    // instructions to be used within interrupt handlers, but at the expense of
    // extra stack usage.
    //
    ROM_FPULazyStackingEnable();

    //
    // Set the clocking to run from the PLL at 50MHz
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    //
    // Configure the required pins for USB operation.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
    ROM_GPIOPinConfigure(GPIO_PG4_USB0EPEN);
    ROM_GPIOPinTypeUSBDigital(GPIO_PORTG_BASE, GPIO_PIN_4);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL);
    ROM_GPIOPinTypeUSBAnalog(GPIO_PORTL_BASE, GPIO_PIN_6 | GPIO_PIN_7);
    ROM_GPIOPinTypeUSBAnalog(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Erratum workaround for silicon revision A1.  VBUS must have pull-down.
    //
    if(CLASS_IS_BLIZZARD && REVISION_IS_A1)
    {
        HWREG(GPIO_PORTB_BASE + GPIO_O_PDR) |= GPIO_PIN_1;
    }

    //
    // Not configured initially.
    //
    g_bUSBConfigured = false;

    //
    // Initialize the display driver.
    //
    CFAL96x64x16Init();

    //
    // Initialize the graphics context.
    //
    GrContextInit(&g_sContext, &g_sCFAL96x64x16);

    //
    // Fill the top 15 rows of the screen with blue to create the banner.
    //
    sRect.i16XMin = 0;
    sRect.i16YMin = 0;
    sRect.i16XMax = GrContextDpyWidthGet(&g_sContext) - 1;
    sRect.i16YMax = 9;
    GrContextForegroundSet(&g_sContext, ClrDarkBlue);
    GrRectFill(&g_sContext, &sRect);

    //
    // Put a white box around the banner.
    //
    GrContextForegroundSet(&g_sContext, ClrWhite);
    GrRectDraw(&g_sContext, &sRect);

    //
    // Put the application name in the middle of the banner.
    //
    GrContextFontSet(&g_sContext, g_psFontFixed6x8);
    GrStringDrawCentered(&g_sContext, "usb-dev-serial", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 4, 0);

    //
    // Show the various static text elements on the color STN display.
    //
    GrStringDraw(&g_sContext, "Tx #",-1, 0, 12, false);
    GrStringDraw(&g_sContext, "Tx buf", -1, 0, 22, false);
    GrStringDraw(&g_sContext, "Rx #", -1, 0, 32, false);
    GrStringDraw(&g_sContext, "Rx buf", -1, 0, 42, false);
    DrawBufferMeter(&g_sContext, 40, 22);
    DrawBufferMeter(&g_sContext, 40, 42);

    //
    // Enable the UART that we will be redirecting.
    //
    ROM_SysCtlPeripheralEnable(USB_UART_PERIPH);

    //
    // Enable and configure the UART RX and TX pins
    //
    ROM_SysCtlPeripheralEnable(TX_GPIO_PERIPH);
    ROM_SysCtlPeripheralEnable(RX_GPIO_PERIPH);
    ROM_GPIOPinTypeUART(TX_GPIO_BASE, TX_GPIO_PIN);
    ROM_GPIOPinTypeUART(RX_GPIO_BASE, RX_GPIO_PIN);

    //
    // TODO: Add code to configure handshake GPIOs if required.
    //

    //
    // Set the default UART configuration.
    //
    ROM_UARTConfigSetExpClk(USB_UART_BASE, ROM_SysCtlClockGet(),
                            DEFAULT_BIT_RATE, DEFAULT_UART_CONFIG);
    ROM_UARTFIFOLevelSet(USB_UART_BASE, UART_FIFO_TX4_8, UART_FIFO_RX4_8);

    //
    // Configure and enable UART interrupts.
    //
    ROM_UARTIntClear(USB_UART_BASE, ROM_UARTIntStatus(USB_UART_BASE, false));
    ROM_UARTIntEnable(USB_UART_BASE, (UART_INT_OE | UART_INT_BE | UART_INT_PE |
                      UART_INT_FE | UART_INT_RT | UART_INT_TX | UART_INT_RX));

    //
    // Enable the system tick.
    //
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND);
    ROM_SysTickIntEnable();
    ROM_SysTickEnable();

    //
    // Tell the user what we are up to.
    //
    DisplayStatus(&g_sContext, " Configuring... ");

    //
    // Initialize the transmit and receive buffers.
    //
    USBBufferInit(&g_sTxBuffer);
    USBBufferInit(&g_sRxBuffer);

    //
    // Set the USB stack mode to Device mode with VBUS monitoring.
    //
    USBStackModeSet(0, eUSBModeDevice, 0);

    //
    // Pass our device information to the USB library and place the device
    // on the bus.
    //
    USBDCDCInit(0, &g_sCDCDevice);

    //
    // Wait for initial configuration to complete.
    //
    DisplayStatus(&g_sContext, "Waiting for host");

    //
    // Clear our local byte counters.
    //
    ui32RxCount = 0;
    ui32TxCount = 0;

    //
    // Enable interrupts now that the application is ready to start.
    //
    ROM_IntEnable(USB_UART_INT);

    //
    // Main application loop.
    //
    while(1)
    {

        //
        // Have we been asked to update the status display?
        //
        if(g_ui32Flags & COMMAND_STATUS_UPDATE)
        {
            //
            // Clear the command flag
            //
            ROM_IntMasterDisable();
            g_ui32Flags &= ~COMMAND_STATUS_UPDATE;
            ROM_IntMasterEnable();

            DisplayStatus(&g_sContext, g_pcStatus);
        }

        //
        // Has there been any transmit traffic since we last checked?
        //
        if(ui32TxCount != g_ui32UARTTxCount)
        {
            //
            // Take a snapshot of the latest transmit count.
            //
            ui32TxCount = g_ui32UARTTxCount;

            //
            // Update the display of bytes transmitted by the UART.
            //
            usnprintf(pcBuffer, 16, "%d ", ui32TxCount);
            GrStringDraw(&g_sContext, pcBuffer, -1, 40, 12, true);

            //
            // Update the RX buffer fullness. Remember that the buffers are
            // named relative to the USB whereas the status display is from
            // the UART's perspective. The USB's receive buffer is the UART's
            // transmit buffer.
            //
            ui32Fullness = ((USBBufferDataAvailable(&g_sRxBuffer) * 100) /
                          UART_BUFFER_SIZE);

            UpdateBufferMeter(&g_sContext, ui32Fullness, 40, 22);
        }

        //
        // Has there been any receive traffic since we last checked?
        //
        if(ui32RxCount != g_ui32UARTRxCount)
        {
            //
            // Take a snapshot of the latest receive count.
            //
            ui32RxCount = g_ui32UARTRxCount;

            //
            // Update the display of bytes received by the UART.
            //
            usnprintf(pcBuffer, 16, "%d ", ui32RxCount);
            GrStringDraw(&g_sContext, pcBuffer, -1, 40, 32, true);

            //
            // Update the TX buffer fullness. Remember that the buffers are
            // named relative to the USB whereas the status display is from
            // the UART's perspective. The USB's transmit buffer is the UART's
            // receive buffer.
            //
            ui32Fullness = ((USBBufferDataAvailable(&g_sTxBuffer) * 100) /
                          UART_BUFFER_SIZE);

            UpdateBufferMeter(&g_sContext, ui32Fullness, 40, 42);
        }
    }
}
//*****************************************************************************
//
// This is the main application entry function.
//
//*****************************************************************************
int
main(void)
{
    uint32_t ui32TxCount, ui32RxCount, ui32Fullness, ui32SysClock, ui32PLLRate;
    tRectangle sRect;
    char pcBuffer[16];
#ifdef USE_ULPI
    uint32_t ui32Setting;
#endif

    //
    // Set the system clock to run at 120MHz from the PLL.
    //
    ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                           SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
                                           SYSCTL_CFG_VCO_480), 120000000);

    //
    // Configure the device pins.
    //
    PinoutSet();

#ifdef USE_ULPI
    //
    // Switch the USB ULPI Pins over.
    //
    USBULPIPinoutSet();

    //
    // Enable USB ULPI with high speed support.
    //
    ui32Setting = USBLIB_FEATURE_ULPI_HS;
    USBOTGFeatureSet(0, USBLIB_FEATURE_USBULPI, &ui32Setting);

    //
    // Setting the PLL frequency to zero tells the USB library to use the
    // external USB clock.
    //
    ui32PLLRate = 0;
#else
    //
    // Save the PLL rate used by this application.
    //
    ui32PLLRate = 480000000;
#endif

    //
    // Enable the system tick.
    //
    ROM_SysTickPeriodSet(ui32SysClock / TICKS_PER_SECOND);
    ROM_SysTickIntEnable();
    ROM_SysTickEnable();

    //
    // Not configured initially.
    //
    g_ui32Flags = 0;

    //
    // Initialize the display driver.
    //
    Kentec320x240x16_SSD2119Init(ui32SysClock);

    //
    // Initialize the graphics context.
    //
    GrContextInit(&g_sContext, &g_sKentec320x240x16_SSD2119);

    //
    // Draw the application frame.
    //
    FrameDraw(&g_sContext, "usb-dev-serial");

    //
    // Fill the top 15 rows of the screen with blue to create the banner.
    //
    sRect.i16XMin = 0;
    sRect.i16YMin = 0;
    sRect.i16XMax = GrContextDpyWidthGet(&g_sContext) - 1;
    sRect.i16YMax = 23;
    GrContextForegroundSet(&g_sContext, ClrDarkBlue);
    GrRectFill(&g_sContext, &sRect);

    //
    // Put a white box around the banner.
    //
    GrContextForegroundSet(&g_sContext, ClrWhite);
    GrRectDraw(&g_sContext, &sRect);

    //
    // Show the various static text elements on the color STN display.
    //
    GrContextFontSet(&g_sContext, TEXT_FONT);
    GrStringDraw(&g_sContext, "Tx bytes:", -1, 8, 80, false);
    GrStringDraw(&g_sContext, "Tx buffer:", -1, 8, 105, false);
    GrStringDraw(&g_sContext, "Rx bytes:", -1, 8, 160, false);
    GrStringDraw(&g_sContext, "Rx buffer:", -1, 8, 185, false);
    DrawBufferMeter(&g_sContext, 150, 105);
    DrawBufferMeter(&g_sContext, 150, 185);

    //
    // Enable the UART that we will be redirecting.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

    //
    // Change the UART clock to the 16 MHz PIOSC.
    //
    UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);

    //
    // Set the default UART configuration.
    //
    ROM_UARTConfigSetExpClk(UART0_BASE, UART_CLOCK,
                            DEFAULT_BIT_RATE, DEFAULT_UART_CONFIG);
    ROM_UARTFIFOLevelSet(UART0_BASE, UART_FIFO_TX4_8, UART_FIFO_RX4_8);

    //
    // Configure and enable UART interrupts.
    //
    ROM_UARTIntClear(UART0_BASE, ROM_UARTIntStatus(UART0_BASE, false));
    ROM_UARTIntEnable(UART0_BASE, (UART_INT_OE | UART_INT_BE | UART_INT_PE |
                      UART_INT_FE | UART_INT_RT | UART_INT_TX | UART_INT_RX));

    //
    // Tell the user what we are up to.
    //
    DisplayStatus(&g_sContext, " Configuring USB... ");

    //
    // Initialize the transmit and receive buffers.
    //
    USBBufferInit(&g_sTxBuffer);
    USBBufferInit(&g_sRxBuffer);

    //
    // Set the USB stack mode to Device mode with VBUS monitoring.
    //
    USBStackModeSet(0, eUSBModeDevice, 0);

    //
    // Tell the USB library the CPU clock and the PLL frequency.  This is a
    // new requirement for TM4C129 devices.
    //
    USBDCDFeatureSet(0, USBLIB_FEATURE_CPUCLK, &ui32SysClock);
    USBDCDFeatureSet(0, USBLIB_FEATURE_USBPLL, &ui32PLLRate);

    //
    // Pass our device information to the USB library and place the device
    // on the bus.
    //
    USBDCDCInit(0, (tUSBDCDCDevice *)&g_sCDCDevice);

    //
    // Wait for initial configuration to complete.
    //
    DisplayStatus(&g_sContext, " Waiting for host... ");

    //
    // Clear our local byte counters.
    //
    ui32RxCount = 0;
    ui32TxCount = 0;
    g_ui32UARTTxCount = 0;
    g_ui32UARTRxCount = 0;
#ifdef DEBUG
    g_ui32UARTRxErrors = 0;
#endif

    //
    // Enable interrupts now that the application is ready to start.
    //
    ROM_IntEnable(INT_UART0);

    //
    // Main application loop.
    //
    while(1)
    {
        //
        // Have we been asked to update the status display?
        //
        if(HWREGBITW(&g_ui32Flags, FLAG_STATUS_UPDATE))
        {
            //
            // Clear the command flag
            //
            HWREGBITW(&g_ui32Flags, FLAG_STATUS_UPDATE) = 0;

            DisplayStatus(&g_sContext, g_pcStatus);
        }

        //
        // Has there been any transmit traffic since we last checked?
        //
        if(ui32TxCount != g_ui32UARTTxCount)
        {
            //
            // Take a snapshot of the latest transmit count.
            //
            ui32TxCount = g_ui32UARTTxCount;

            //
            // Update the display of bytes transmitted by the UART.
            //
            usnprintf(pcBuffer, 16, "%d ", ui32TxCount);
            GrStringDraw(&g_sContext, pcBuffer, -1, 150, 80, true);

            //
            // Update the RX buffer fullness. Remember that the buffers are
            // named relative to the USB whereas the status display is from
            // the UART's perspective. The USB's receive buffer is the UART's
            // transmit buffer.
            //
            ui32Fullness = ((USBBufferDataAvailable(&g_sRxBuffer) * 100) /
                          UART_BUFFER_SIZE);

            UpdateBufferMeter(&g_sContext, ui32Fullness, 150, 105);
        }

        //
        // Has there been any receive traffic since we last checked?
        //
        if(ui32RxCount != g_ui32UARTRxCount)
        {
            //
            // Take a snapshot of the latest receive count.
            //
            ui32RxCount = g_ui32UARTRxCount;

            //
            // Update the display of bytes received by the UART.
            //
            usnprintf(pcBuffer, 16, "%d ", ui32RxCount);
            GrStringDraw(&g_sContext, pcBuffer, -1, 150, 160, true);

            //
            // Update the TX buffer fullness. Remember that the buffers are
            // named relative to the USB whereas the status display is from
            // the UART's perspective. The USB's transmit buffer is the UART's
            // receive buffer.
            //
            ui32Fullness = ((USBBufferDataAvailable(&g_sTxBuffer) * 100) /
                          UART_BUFFER_SIZE);

            UpdateBufferMeter(&g_sContext, ui32Fullness, 150, 185);
        }
    }
}
Exemplo n.º 30
0
//*****************************************************************************
//
// This is the main application entry function.
//
//*****************************************************************************
int
main(void)
{
    uint32_t ui32TxCount;
    uint32_t ui32RxCount;
    //uint32_t ui32Loop;

    //
    // Enable lazy stacking for interrupt handlers.  This allows floating-point
    // instructions to be used within interrupt handlers, but at the expense of
    // extra stack usage.
    //
    ROM_FPULazyStackingEnable();

    //
    // Set the clocking to run from the PLL at 50MHz
    //
#if 1
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    //
    // Configure the required pins for USB operation.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    ROM_GPIOPinTypeUSBAnalog(GPIO_PORTD_BASE, GPIO_PIN_5 | GPIO_PIN_4);
       //ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / 100);

    /* This code taken from: http://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/t/311237.aspx
    */
#else       
#include "hw_nvic.h"
       FlashErase(0x00000000);
       ROM_IntMasterDisable();
       ROM_SysTickIntDisable();
       ROM_SysTickDisable();
       uint32_t ui32SysClock;
       ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
       ui32SysClock = ROM_SysCtlClockGet();
       ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
       ROM_GPIOPinTypeUSBAnalog(GPIO_PORTD_BASE, GPIO_PIN_4 | GPIO_PIN_5);
       ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / 100);
       HWREG(NVIC_DIS0) = 0xffffffff;
       HWREG(NVIC_DIS1) = 0xffffffff;
       HWREG(NVIC_DIS2) = 0xffffffff;
       HWREG(NVIC_DIS3) = 0xffffffff;
       HWREG(NVIC_DIS4) = 0xffffffff;
       int ui32Addr;
       for(ui32Addr = NVIC_PRI0; ui32Addr <= NVIC_PRI34; ui32Addr+=4)
       {
          HWREG(ui32Addr) = 0;
       }
       HWREG(NVIC_SYS_PRI1) = 0;
       HWREG(NVIC_SYS_PRI2) = 0;
       HWREG(NVIC_SYS_PRI3) = 0;
       ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0);
       ROM_SysCtlPeripheralReset(SYSCTL_PERIPH_USB0);
       ROM_SysCtlUSBPLLEnable();
       ROM_SysCtlDelay(ui32SysClock*2 / 3);
       ROM_IntMasterEnable();
       ROM_UpdateUSB(0);
       while(1)
           {
           }
#endif
#define BOOTLOADER_TEST 0
#if BOOTLOADER_TEST
#include "hw_nvic.h"
    
    //ROM_UpdateUART();
    // May need to do the following here:
    //  0. See if this will cause bootloader to start
    //ROM_FlashErase(0); 
    //ROM_UpdateUSB(0);
    
#define SYSTICKS_PER_SECOND 100
    uint32_t ui32SysClock = ROM_SysCtlClockGet();
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND);
    ROM_SysTickIntEnable();
    ROM_SysTickEnable();
    
    //USBDCDTerm(0);
    
    // Disable all interrupts
    ROM_IntMasterDisable();
    ROM_SysTickIntDisable();
    ROM_SysTickDisable();
    HWREG(NVIC_DIS0) = 0xffffffff;
    HWREG(NVIC_DIS1) = 0xffffffff;
    HWREG(NVIC_DIS2) = 0xffffffff;
    HWREG(NVIC_DIS3) = 0xffffffff;
    HWREG(NVIC_DIS4) = 0xffffffff;
       int ui32Addr;
       for(ui32Addr = NVIC_PRI0; ui32Addr <= NVIC_PRI34; ui32Addr+=4)
       {
          HWREG(ui32Addr) = 0;
       }
       HWREG(NVIC_SYS_PRI1) = 0;
       HWREG(NVIC_SYS_PRI2) = 0;
       HWREG(NVIC_SYS_PRI3) = 0;
    
    //  1. Enable USB PLL
    //ROM_SysCtlUSBPLLEnable();
    //  2. Enable USB controller
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0);
    ROM_SysCtlPeripheralReset(SYSCTL_PERIPH_USB0);
    //USBClockEnable(USB0_BASE, 8, USB_CLOCK_INTERNAL);
    //HWREG(USB0_BASE + USB_O_CC) = (8 - 1) | USB_CLOCK_INTERNAL;

    ROM_SysCtlUSBPLLEnable();
    
    //  3. Enable USB D+ D- pins

    //  4. Activate USB DFU
    ROM_SysCtlDelay(ui32SysClock * 2 / 3);
    ROM_IntMasterEnable();  // Re-enable interrupts at NVIC level
    ROM_UpdateUSB(0);
    //  5. Should never get here since update is in progress
#endif // BOOTLOADER_TEST

    //
    // Enable the GPIO port that is used for the on-board LED.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);    // gjs Our board uses GPIOB for LEDs
    // gjs original ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

    //
    // Enable the GPIO pins for the LED (PF2 & PF3).
    //
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_0|GPIO_PIN_1);
    // gjs original ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3|GPIO_PIN_2);

    //
    // Not configured initially.
    //
    g_bUSBConfigured = false;

    //
    // Enable the UART that we will be redirecting.
    //
    ROM_SysCtlPeripheralEnable(USB_UART_PERIPH);

    //
    // Enable and configure the UART RX and TX pins
    //
    ROM_SysCtlPeripheralEnable(TX_GPIO_PERIPH);
    ROM_SysCtlPeripheralEnable(RX_GPIO_PERIPH);
    ROM_GPIOPinTypeUART(TX_GPIO_BASE, TX_GPIO_PIN);
    ROM_GPIOPinTypeUART(RX_GPIO_BASE, RX_GPIO_PIN);

    //
    // TODO: Add code to configure handshake GPIOs if required.
    //

    //
    // Set the default UART configuration.
    //
    ROM_UARTConfigSetExpClk(USB_UART_BASE, ROM_SysCtlClockGet(),
                            DEFAULT_BIT_RATE, DEFAULT_UART_CONFIG);
    ROM_UARTFIFOLevelSet(USB_UART_BASE, UART_FIFO_TX4_8, UART_FIFO_RX4_8);

    //
    // Configure and enable UART interrupts.
    //
    ROM_UARTIntClear(USB_UART_BASE, ROM_UARTIntStatus(USB_UART_BASE, false));
    ROM_UARTIntEnable(USB_UART_BASE, (UART_INT_OE | UART_INT_BE | UART_INT_PE |
                      UART_INT_FE | UART_INT_RT | UART_INT_TX | UART_INT_RX));

    //
    // Enable the system tick.
    //
#if 0    
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND);
    ROM_SysTickIntEnable();
    ROM_SysTickEnable();
#endif
    //
    // Initialize the transmit and receive buffers.
    //
    USBBufferInit(&g_sTxBuffer);
    USBBufferInit(&g_sRxBuffer);

    //
    // Set the USB stack mode to Device mode with VBUS monitoring.
    //
    USBStackModeSet(0, eUSBModeDevice, 0);

    //
    // Pass our device information to the USB library and place the device
    // on the bus.
    //
    USBDCDCInit(0, &g_sCDCDevice);

    //
    // Clear our local byte counters.
    //
    ui32RxCount = 0;
    ui32TxCount = 0;

    //
    // Enable interrupts now that the application is ready to start.
    //
    ROM_IntEnable(USB_UART_INT);

    // Enable FreeRTOS
    mainA(); // FreeRTOS. Will not return
    
#if 0    
    //
    // Main application loop.
    //
    while(1)
    {
        //
        // Have we been asked to update the status display?
        //
        if(g_ui32Flags & COMMAND_STATUS_UPDATE)
        {
            //
            // Clear the command flag
            //
            ROM_IntMasterDisable();
            g_ui32Flags &= ~COMMAND_STATUS_UPDATE;
            ROM_IntMasterEnable();
        }

        //
        // Has there been any transmit traffic since we last checked?
        //
        if(ui32TxCount != g_ui32UARTTxCount)
        {
            //
            // Turn on the Green LED.
            //
            // gjs ROM_UARTCharPutNonBlocking(USB_UART_BASE, 'b');

#if 1
            if (ui32TxCount & 1) {
                GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0, GPIO_PIN_0);
            } else {
                GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0, 0);
            }
#else            
            if (1 || g_ui32UARTTxCount & 0x01) {
                GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, GPIO_PIN_3);
            } else {
                //GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, 0);
            }

            //
            // Delay for a bit.
            //
            for(uint32_t ui32Loop = 0; ui32Loop < 150000; ui32Loop++)
            {
            }

            //
            // Turn off the Green LED.
            //
            GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, 0);
#endif            

            //
            // Take a snapshot of the latest transmit count.
            //
            ui32TxCount = g_ui32UARTTxCount;
        }

        //
        // Has there been any receive traffic since we last checked?
        //
        if(ui32RxCount != g_ui32UARTRxCount)
        {
            //
            // Turn on the Blue LED.
            //
#if 1
            if (ui32RxCount & 1) {
                GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_1, GPIO_PIN_1);
            } else {
                GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_1, 0);
            }
#else            
            GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);

            //
            // Delay for a bit.
            //
            for(uint32_t ui32Loop = 0; ui32Loop < 150000; ui32Loop++)
            {
            }

            //
            // Turn off the Blue LED.
            //
            GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);
#endif
            //
            // Take a snapshot of the latest receive count.
            //
            ui32RxCount = g_ui32UARTRxCount;

        }
    }
#endif    
}