Ejemplo n.º 1
0
void UARTINtHandler(void)
{
	uint32_t ui32Status;
	ui32Status = UARTIntStatus(UART0_BASE, true); // Thuc hien lay trang thai ngat
	UARTIntClear(UART0_BASE, ui32Status); //Xoa co ngat uart
	while(UARTCharsAvail(UART0_BASE))	//Thuc hien cho ki tu
	{
		UARTCharPutNonBlocking(UART0_BASE, UARTCharGetNonBlocking(UART0_BASE));	//nhan ki tu
		GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2); //chop tat led
		SysCtlDelay(SysCtlClockGet()/(1000*3)); //Thuc hien delay khoang 1ms
		GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0); 	//Tat LED
	}
}
Ejemplo n.º 2
0
void UARTIntHandler()
{
  u32 temp;
  int c;

  temp = UARTIntStatus(uart_base[ CON_UART_ID ], true);
  UARTIntClear(uart_base[ CON_UART_ID ], temp);
  while( UARTCharsAvail( uart_base[ CON_UART_ID ] ) )
  {
    c = UARTCharGetNonBlocking( uart_base[ CON_UART_ID ] );
    buf_write( BUF_ID_UART, CON_UART_ID, ( t_buf_data* )&c );
  }
}
Ejemplo n.º 3
0
/*
 * @brief Wait and get a byte from UART/USB with interrupt disabled.
 * Program is indefinitely blocked until there's an available byte.
 *
 * @return the byte value on success;
 */
int getSerialByte() {
	uint32 i;

	while (1) {
		if (UARTCharsAvail(UART0_BASE)) {
			return UARTCharGetNonBlocking(UART0_BASE);
		}
		systemDelayTenMicroSecond(1);
	}

	// Control should not reach here
	return -1;
}
Ejemplo n.º 4
0
void UARTIntHandler(void) {
	uint32_t ui32Status;
	ui32Status = UARTIntStatus(UART0_BASE, true); //get interrupt status
	UARTIntClear(UART0_BASE, ui32Status); //clear the asserted interrupts
	while(UARTCharsAvail(UART0_BASE)) //loop while there are chars
		{
		car = UARTCharGetNonBlocking(UART0_BASE);
		UARTCharPut(UART0_BASE, car);
		//UARTCharPutNonBlocking(UART0_BASE, UARTCharGetNonBlocking(UART0_BASE)); //echo character
		//GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2); //blink LED
		SysCtlDelay(SysCtlClockGet() / (1000 * 3)); //delay ~1 msec
		//GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0); //turn off LED
		}
}
Ejemplo n.º 5
0
/**
 * @brief  Guarda los datos en el buffer del software.
 *
 * @return    -
 *
 * Guardado de los datos del buffer de hardware en el buffer de
 * software para su posterior tratamiento por la logica del usuario.
*/
static void fromHwFIFO(int nPort)
{
  int n; /*Numero de huecos en el buffer de hardware*/
  unsigned int l; /*Variable temporal donde se guardan los caracteres recibidos*/

  n=nHuecosIn(nPort);
  while(UARTCharsAvail(gs_ul_uarts_bases[nPort])&& (n-->0))
  {
    l=UARTCharGetNonBlocking(gs_ul_uarts_bases[nPort]);
	gs_cu_uarts[nPort].inBuf[gs_cu_uarts[nPort].inHead]=(unsigned char)l;
	gs_cu_uarts[nPort].inHead++;
	if(gs_cu_uarts[nPort].inHead==BUFF_SIZE) gs_cu_uarts[nPort].inHead=0;
  }
}
Ejemplo n.º 6
0
Archivo: Base.c Proyecto: ilabmp/micro
void UARTIntHandler1(void) {
	int i, k = 0;
	unsigned long ulStatus;
	char temp_char = 0;
	char before_temp_char = 0;
	ulStatus = UARTIntStatus(UART1_BASE, true);
	UARTIntClear(UART1_BASE, ulStatus);

	while (UARTCharsAvail(UART1_BASE)) {
		temp_char = UARTCharGetNonBlocking(UART1_BASE);
		if ((temp_char != 0x0A) && (before_temp_char != 0x0D)) {
			myIMU[count_start] = temp_char;
			count_start++;
		} else if ((temp_char == 0x0A) && (before_temp_char == 0x0D)) {
			for (i = 0; i < count_start; i++) {
				if (myIMU[i] == ',') {
					size[index_j] = k;
					index_j++;
					k = 0;
				} else if (myIMU[i] == '*') {
					index_j = 0;
					k = 0;
				} else {
					mydata[index_j][k] = myIMU[i];
					k++;
				}
			}
			memset(mydata_char, 0, sizeof(mydata_char));
			strcpy(mydata_char[0], mydata[0]); //pitch
			strcpy(mydata_char[1], mydata[1]);
			strcpy(mydata_char[2], mydata[2]); //yaw

			/*초기화*/
			count_start = 0;
			memset(size, 0, sizeof(size));
			memset(myIMU, 0, sizeof(myIMU));
			memset(mydata, 0, sizeof(mydata));


			yaw = atoi(mydata_char[2]);
			pitch = atoi(mydata_char[0]);



		}
		before_temp_char = temp_char;
	}
}
Ejemplo n.º 7
0
int main(void)
{
  FPUEnable();
  
  led_Init();
	button_Init();
  
  can_Init();
  pcsr_Init();
  
  //can_SetLogging(0, 0x001, 0x3FF, LogHandler);
  //uint8_t new_data[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
  //uint8_t new_data_mask[] = { 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF };
  //can_SetFiltering(0, 0x001, 0x3FF, new_data, new_data_mask);
  
  //uint8_t data[] = { 0xFF, 0x00, 0xFF, 0x00, '\n' };
  //pcsr_WriteData("READY!\r\n", 8);
  
  while(UARTCharsAvail(UART2_BASE))
  {
    led_Byte(UARTCharGetNonBlocking(UART2_BASE));
  }
	
  while(1)
  {
    uint8_t buf[22];
    pcsr_ReadData(buf, 1);
    if(buf[0] == FUNCTION_LOG)
    {
      pcsr_ReadData(buf + 1, 5);
      uint16_t arbid = buf[2] + (buf[3] << 8);
      uint16_t arbid_mask = buf[4] + (buf[5] << 8);
      can_SetLogging(buf[1], arbid, arbid_mask, LogHandler);
    }
    else if(buf[0] == FUNCTION_FILTER)
    {
      pcsr_ReadData(buf + 1, 21);
      uint16_t arbid = buf[2] + (buf[3] << 8);
      uint16_t arbid_mask = buf[4] + (buf[5] << 8);
      can_SetFiltering(buf[1], arbid, arbid_mask, buf + 6, buf + 14);
    }
    else if(buf[0] == FUNCTION_RESET)
    {
      can_ResetFunctions();
      //led_Byte(buf[0]);
    }
  }
}
Ejemplo n.º 8
0
void ISR_uartBt(void) {
    unsigned long status;
    unsigned long commandSize;
    char byte;

    status = UARTIntStatus(UARTBT_BASE, true);
    UARTIntClear(UARTBT_BASE, status);

    // Loop while there are characters in the receive FIFO.
    while(UARTCharsAvail(UARTBT_BASE)) {
        // Read the next character from the UART and write it back to the UART.
        byte = UARTCharGetNonBlocking(UARTBT_BASE);

        commandSize = CurrentCommandByte - CurrentCommandStartPointer;

        if(byte == '\n' || commandSize==UARTBT_BUFFER_SIZE) { // \r is used to indicate end-of-command
            if((CurrentCommandByte>CommandBuffer || CurrentCommandByte>(CommandBuffer + UARTBT_BUFFER_SIZE)) && *(CurrentCommandByte-1)=='\r') {
                // Command ended with \r\n
                LastCommandSize = commandSize - 1;
            }
            else {
                // Command ended with \n\r
                LastCommandSize = commandSize;
            }

            // Select the next buffer
            if(CurrentCommandStartPointer == CommandBuffer) {
                CurrentCommandByte = CommandBuffer + UARTBT_BUFFER_SIZE;
            }
            else {
                CurrentCommandByte = CommandBuffer;
            }

            CurrentCommandStartPointer = CurrentCommandByte;

            if(commandSize != UARTBT_BUFFER_SIZE) { // If the command is too long, ignore it
                NewCommandArrived = true;
            }
        }
        else {
            *CurrentCommandByte = byte;
            CurrentCommandByte++;
        }

    }
}
Ejemplo n.º 9
0
/**
 Debug console interrupt service routine, called when a byte is received on UART.
 @pre In startup_ccs.c, UARTIntHandler is set as the ISR for the UART0 Rx and Tx interrupt
 @pre In startup_ccs.c, this function is declared, e.g:
 <pre>
 extern void UARTIntHandler(void);
 </pre>
 @pre Interrupts have been enabled, e.g:
 <pre>
 IntMasterEnable();
 IntEnable(INT_UART0);
 UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
 </pre>
 @pre UART has been configured
 @post a byte received on the UART will result in debugConsoleIsr() function pointer called
 */
void UARTIntHandler(void)
{
    unsigned long ulStatus;

    // Get the interrupt status.
    ulStatus = UARTIntStatus(UART0_BASE, true);

    // Clear the asserted interrupts.
    UARTIntClear(UART0_BASE, ulStatus);

    // Loop while there are characters in the receive FIFO.
    while(UARTCharsAvail(UART0_BASE))
    {
        // Read the next character from the UART
    	uint8_t c = (uint8_t) UARTCharGetNonBlocking(UART0_BASE);
        debugConsoleIsr(c);    // call the function pointer
    }
}
Ejemplo n.º 10
0
void UARTIntHandler(void) {
    unsigned long ulStatus;
    long UART_character = 0;
    // Get the interrupt status.
    //
    ulStatus = UARTIntStatus(UART0_BASE, true);
    // Clear the asserted interrupts.
    //
    UARTIntClear(UART0_BASE, ulStatus);
    // Loop while there are characters in the receive FIFO.
    //
    while(UARTCharsAvail(UART0_BASE)) {
        // Read the next character from the UART and write it back to the UART.
        //
    	//UARTCharPutNonBlocking(UART0_BASE, UARTCharGetNonBlocking(UART0_BASE));
        UART_character = UARTCharGetNonBlocking(UART0_BASE);
        store_char(UART_character);
    }
}
Ejemplo n.º 11
0
//*****************************************************************************
//
// The UART interrupt handler.
//
//*****************************************************************************
void UARTIntHandler(void) {
	unsigned long ulStatus;

	//
	// Get the interrrupt status.
	//
	ulStatus = UARTIntStatus(UART0_BASE, true);

	//
	// Clear the asserted interrupts.
	//
	UARTIntClear(UART0_BASE, ulStatus);

	//
	// Loop while there are characters in the receive FIFO.
	//
	while (UARTCharsAvail(UART0_BASE)) {
		//
		// Read the next character from the UART and write it back to the UART.
		//
		unsigned char b;
		b = UARTCharGetNonBlocking(UART0_BASE);

		UARTCharPutNonBlocking(UART0_BASE,b);
//		UARTCharPutNonBlocking(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);

	}
}
Ejemplo n.º 12
0
/*************************************************************************************************
 * @fn      procRx
 *
 * @brief   Process Tx bytes.
 *
 * @param   void
 *
 * @return  void
 *************************************************************************************************/
static void procRx(void)
{
  uint16 tail = uartRecord.rx.bufferTail;

  while (UARTCharsAvail(HAL_UART_PORT))
  {
    uartRecord.rx.pBuffer[tail++] = UARTCharGetNonBlocking(HAL_UART_PORT);

    if (tail >= uartRecord.rx.maxBufSize)
    {
      tail = 0;
    }
  }

  if (uartRecord.rx.bufferTail != tail)
  {
    uartRecord.rx.bufferTail = tail;
    uartRecord.rxChRvdTime = osal_GetSystemClock();
  }
}
Ejemplo n.º 13
0
/**
 Debug console interrupt service routine, called when a byte is received on UART.
 @pre In startup_ccs.c, UARTIntHandler is set as the ISR for the UART0 Rx and Tx interrupt
 @pre In startup_ccs.c, this function is declared, e.g:
 <pre>
 extern void UARTIntHandler(void);
 </pre>
 @pre Interrupts have been enabled, e.g:
 <pre>
 IntMasterEnable();
 IntEnable(INT_UART0);
 UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
 </pre>
 @pre UART has been configured
 @post a byte received on the UART will result in debugConsoleIsr() function pointer called
 */
void UARTIntHandler(void)
{
    toggleLed(4);
    //printf("$");
    unsigned long ulStatus;

    // Get the interrupt status.
    ulStatus = UARTIntStatus(UART0_BASE, true);

    // Clear the asserted interrupts.
    UARTIntClear(UART0_BASE, ulStatus);

    // Loop while there are characters in the receive FIFO.
    while(UARTCharsAvail(UART0_BASE))
    {
        // Read the next character from the UART and write it back to the UART.
        uint8_t c = (uint8_t) UARTCharGetNonBlocking(UART0_BASE);
        debugConsoleIsr(c);    //reading this register clears the interrupt flag
    }
}
Ejemplo n.º 14
0
zcm_trans_t* __zcm_trans_tiva_uart_create(uint32_t uart_base,
                                          uint32_t sysctl_uart_base,
                                          uint32_t rx_port_base,
                                          uint32_t sysctl_rx_port_base,
                                          uint32_t pinmap_rx,
                                          uint32_t pinnum_rx,
                                          uint32_t tx_port_base,
                                          uint32_t sysctl_tx_port_base,
                                          uint32_t pinmap_tx,
                                          uint32_t pinnum_tx,
                                          uint32_t baud,
                                          uint64_t (*timestamp_now)(void*),
                                          void*    usr)
{
	SysCtlPeripheralEnable(sysctl_rx_port_base);
	SysCtlPeripheralEnable(sysctl_tx_port_base);
	SysCtlPeripheralEnable(sysctl_uart_base);

	GPIOPinConfigure(pinmap_rx);
	GPIOPinConfigure(pinmap_tx);

	GPIOPinTypeUART(rx_port_base, pinnum_rx);
	GPIOPinTypeUART(tx_port_base, pinnum_tx);
    GPIOPadConfigSet(rx_port_base, pinnum_rx, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);

    UARTConfigSetExpClk(uart_base, SysCtlClockGet(), uart_validate_baud(baud),
                        (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));

    UARTFIFOEnable(uart_base);

	UARTEnable(uart_base);

	while (UARTCharsAvail(uart_base)) UARTCharGetNonBlocking(uart_base);

	// This is sort of a gross hack to not have to allocate memory for the put and get usr pointer
    assert(sizeof(void*) >= sizeof(uint32_t));
    return zcm_trans_generic_serial_create(uartGet, uartPut, (void*)uart_base,
                                           timestamp_now, usr,
                                           ZCM_GENERIC_SERIAL_MTU,
                                           ZCM_GENERIC_SERIAL_BUFFER_SIZE);
}
Ejemplo n.º 15
0
void UARTinterrupcion(void)
{
	char cThisChar;
	int n=0;
	int m_nTxBuffIn1 = 16;
    unsigned long ulStatus;

    //
    // Obtengo el estado de la interrupcion
    //
    ulStatus = UARTIntStatus(UART1_BASE, true);
    //
    // Limpio los flags de interrupcion
    //
    UARTIntClear(UART1_BASE, ulStatus);

    //if(RIGHT_BUTTON){}

    if(ulStatus && UART_INT_RX)
    {
     while(m_nTxBuffIn1>0 && UARTCharsAvail(UART1_BASE))
     {
               //
               // Lee el proximo caracter de la FIFO de recepcion.
               //
     cThisChar = UARTCharGetNonBlocking(UART1_BASE);

     UARTCharPut(UART0_BASE, cThisChar);

     //rc = f_write(&Fil, "Hello world!\r\n", 14, &bw);

     m_nTxBuffIn1--;

     n=n+1;
     }

    }

}
Ejemplo n.º 16
0
int main(void)
{
	unsigned long ulADC0_Value[1];
	bool running;
	int LED=2;
	int i=0;
	SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);

    //
    // Enable GPIO port A which is used for UART0 pins.
    // TODO: change this to whichever GPIO port you are using.
    //
	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    //
    // Configure the pin muxing for UART0 functions on port A0 and A1.
    // This step is not necessary if your part does not support pin muxing.
    // TODO: change this to select the port/pin you are using.
    //
    GPIOPinConfigure(GPIO_PA0_U0RX);
    GPIOPinConfigure(GPIO_PA1_U0TX);

    //
    // Select the alternate (UART) function for these pins.
    // TODO: change this to select the port/pin you are using.
    //
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
	GPIOPinTypeGPIOOutput(LED_PORT, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|TEST_PIN);
    // Initialize the UART for console I/O.
    //
    UARTStdioInit(0);
    running = false;
    //
    // Display the setup on the console.
    //
//    UARTprintf("ADC ->\n");
//    UARTprintf("  Type: Single Ended\n");
//    UARTprintf("  Samples: One\n");
//    UARTprintf("  Update Rate: 250ms\n");
//    UARTprintf("  Input Pin: AIN0/PE3\n\n");

	// >>>>>>>>>>>>> ADC CONFIGURATION <<<<<<<<<<<<<<<<<

	// Enable the clock to the ADC0 module
	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);


	// >>>>>>>>>>>>> GPI CONFIGURATION <<<<<<<<<<<<<<<<<

	// Configure the pin as analog input
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);

	GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);

	// Configure the ADC to sample at 500KSps
	SysCtlADCSpeedSet(SYSCTL_ADCSPEED_500KSPS);

	// Disable sample sequences 3
	ADCSequenceDisable(ADC0_BASE, 3);

	// Configure sample sequence 3: timer trigger, priority = 0
	ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);

	// Configure sample sequence 3 steps 0
	ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END);

	ADCSequenceEnable(ADC0_BASE, 3);

    ADCIntEnable(ADC0_BASE, 0);

    // Clear the interrupt status flag.  This is done to make sure the
    // interrupt flag is cleared before we sample.
    ADCIntClear(ADC0_BASE, 3);

    // Sample AIN0 forever.  Display the value on the console.
    while(1)
    {
    	i++;
        if (UARTCharsAvail(UART0_BASE)) {
            char temp;

            temp = UARTCharGetNonBlocking(UART0_BASE);

            if (temp == '1') running = true;
            else if (temp == '0') running = false;
        }
        if (running) {
        	if (i==100){
               	GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, LED);
        	}
 
        	// Trigger the ADC conversion.
        	ADCProcessorTrigger(ADC0_BASE, 3);

        	// Wait for conversion to be completed.
            while(!ADCIntStatus(ADC0_BASE, 3, false))
            {
            }

            // Clear the ADC interrupt flag.
            ADCIntClear(ADC0_BASE, 3);

            // Read ADC Value.
            ADCSequenceDataGet(ADC0_BASE, 3, ulADC0_Value);

            // Display the AIN0 (PE7) digital value on the console.
            unsigned short val = ulADC0_Value[0];

            UARTCharPut(UART0_BASE,(char)(val&0x00FF));
            UARTCharPut(UART0_BASE,(char)((val>>8)&0x00FF));
            if (i==200){
            	GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0);
            	i=0;
            }
        }
        // This function provides a means of generating a constant length
        // delay.  The function delay (in cycles) = 3 * parameter.  Delay
        // 250ms arbitrarily.
        SysCtlDelay(SysCtlClockGet() / 250);
    }
}
Ejemplo n.º 17
0
//*****************************************************************************
//
// Private function to manage UART received bytes.
//
// This function maintains the current state of the UART packet reception. It
// tracks start of frame, length expected, length recieved and the frame check
// sequence. Each new byte is captured and stored into the buffer. Status is
// updated and when a message is fully received and in the buffer the callback
// is called if present.
//
// \return None.
//
//*****************************************************************************
static void
RemoTIUARTRxHandler(void)
{
    static uint_fast8_t ui8SOFFlag;
    static uint_fast16_t ui16Length;
    static uint_fast16_t ui16Counter;
    static uint8_t ui8FrameCheck;
    static uint8_t ui8Command0;
    uint8_t ui8RxByte;

    //
    //Get the character from the hardware uart
    //
    ui8RxByte = UARTCharGetNonBlocking(g_ui32UARTBase);

    //
    // Check if this is a start of frame character
    //
    if(ui8RxByte == RPC_UART_SOF)
    {
        //
        // check for error condition that all of prev msg was not captured.
        // send callback if present
        //
        if(ui16Length != ui16Counter)
        {
            if(g_pfnErrCallback)
            {
                g_pfnErrCallback(REMOTI_UART_UNEXPECTED_SOF_ERR);
            }
        }
        else
        {
            //
            // this is a start of frame so set the flag and clear all the other
            // state indicators.
            //
            ui8SOFFlag = 1;
            ui16Length = 0;
            ui16Counter = 0;
            ui8FrameCheck = 0;
            ui8Command0 = 0;
        }
    }
    else
    {
        //
        // This is not a SOF char. if it is the char immediate after a SOF
        // then it is a length char and needs special handling.
        //
        if(ui8SOFFlag == 1)
        {
            //
            // record the length in terms of total bytes in the UART frame.
            // RemoTI just sends number of bytes in the data payload
            // we want Number of general bytes + SOF byte + Length byte +
            // two command bytes + frame check byte.
            //
            ui16Length = ui8RxByte + 5;

            //
            // Clear the SOF flag
            //
            ui8SOFFlag = 0;
        }
    }

    //
    // load the new byte in to the ring buffer for later use. unless we are
    // receiving past the end of an expected message's length.
    //
    if(ui16Counter <= ui16Length)
    {
        RingBufWriteOne(&g_rbRemoTIRxRingBuf, ui8RxByte);
        //
        // increment the counter to track how many bytes are in this msg.
        //
        ui16Counter++;

        if(ui16Counter == 3)
        {
            ui8Command0 = ui8RxByte;
        }
    }
    else if(g_pfnErrCallback)
    {
        //
        // Alert to the user code that RX Msg Lenght was greater than expected
        //
        g_pfnErrCallback(REMOTI_UART_RX_LENGTH_ERR);
    }

    //
    // Check if this is the end of the message and manage callbacks
    //
    if(ui16Length == ui16Counter)
    {
        //
        // compare the current Frame Check to the recieved frame check
        // if not equal then call error callback if present.
        //
        if(ui8FrameCheck != ui8RxByte)
        {
            //
            // Advance read index which effectively dumps the erroneous msg.
            //
            RingBufAdvanceRead(&g_rbRemoTIRxRingBuf, ui16Counter);

            //
            // If a callback is registered, call it.
            //
            if(g_pfnErrCallback)
            {
                //
                // Alert the user that the Frame check sequence failed.
                //
                g_pfnErrCallback(REMOTI_UART_RX_FCS_ERR);
            }
        }
        else
        {
            //
            // Message was successfully recieved and copied to local buffers.
            // Frame check was valid.  Increment the message counter and call
            // the receive callback.
            //
            g_ui16RxMsgCount += 1;
            if(g_pfnRxCallback)
            {
                g_pfnRxCallback(ui8Command0);
            }
        }
    }
    else if(!ui8SOFFlag)
    {
        //
        // calculate the frame check as we go.
        //
        ui8FrameCheck ^= ui8RxByte;
    }
}
Ejemplo n.º 18
0
uint8_t Uart::readByte(void)
{
    int32_t byte;
    byte = UARTCharGetNonBlocking(config_.base);
    return (uint8_t)(byte & 0xFF);
}
Ejemplo n.º 19
0
int main(void) {

    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);
		//
	    // Enable the GPIO port that is used for the on-board LED.
	    //
	    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

	    //
	    // Enable the GPIO pins for the LED (PF2).
	    //
	    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);
	    ConfigureUART();
	    GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_2);


	  //COnfigure gps fro NMEA GPRMC protocol
	    GPSConfigMsg(NMEA_GPRMCmsgConfig, 16 );
	 //CONFIGURE GPS TO OUTPUT IN NMEA FORMAT NOT UBX
	    GPSConfigMsg(NMEAoutConfig, 28);




	   while(1)
	   {
		   if(GPSrxFlag)
		   {
			   //GRab data from Uart3 while it is available
			   while(UARTCharsAvail(UART3_BASE))
			   {

				  //UARTCharPutNonBlocking(UART0_BASE,UARTCharGetNonBlocking(UART3_BASE));
				  GPS_Data_String[gCharcnt] = UARTCharGetNonBlocking(UART3_BASE);
				  gCharcnt++;
				  GPSrxFlag = false;
			   }
		   }
		   //Check for end of the String
		   if(GPS_Data_String[gCharcnt-1] == '\n')
		   {

			   int i = 0;
			   // Print String to console
			   for (i = 0; i < BUF_SIZE; i ++)
			   {
				   UARTprintf("%c", GPS_Data_String[i]);

			   }
			   UARTprintf("%d\n", gCharcnt);

			   //Reset GPS DATA STring
			   for (i = 0; i < BUF_SIZE; i ++)
			   {
				   GPS_Data_String[i] = 0;
			   }

			   gCharcnt = 0;
		   }
	   }

}
Ejemplo n.º 20
0
void UARTIntHandler(void)
{
	uint32_t ui32Status;
	ui32Status = UARTIntStatus(UART0_BASE, true); //get interrupt status
	UARTIntClear(UART0_BASE, ui32Status); //clear the asserted interrupts
	while(UARTCharsAvail(UART0_BASE)) //loop while there are chars
	{
		unsigned char s_detector = UARTCharGetNonBlocking(UART0_BASE);
		if(mode==0){
			if(s_detector == 'S' || s_detector == 's'){
				mode = 1;
				GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0);
				UARTCharPut(UART0_BASE, 'E');
				UARTCharPut(UART0_BASE, 'n');
				UARTCharPut(UART0_BASE, 't');
				UARTCharPut(UART0_BASE, 'e');
				UARTCharPut(UART0_BASE, 'r');
				UARTCharPut(UART0_BASE, ':');
				UARTCharPut(UART0_BASE, ' ');
			}
		}
		else{
			//UARTCharPut(UART0_BASE, 'a');
			int ss = s_detector;
			if(ss == 13){
				//UARTCharPut(UART0_BASE, 'b');
				set_temp = curr_temp;
				curr_temp = 0;
				UARTCharPut(UART0_BASE, '\r');
				UARTCharPut(UART0_BASE, '\n');

				UARTCharPut(UART0_BASE, 'S');
				UARTCharPut(UART0_BASE, 'e');
				UARTCharPut(UART0_BASE, 't');
				UARTCharPut(UART0_BASE, ' ');
				UARTCharPut(UART0_BASE, 't');
				UARTCharPut(UART0_BASE, 'e');
				UARTCharPut(UART0_BASE, 'm');
				UARTCharPut(UART0_BASE, 'p');
				UARTCharPut(UART0_BASE, ' ');
				UARTCharPut(UART0_BASE, 'u');
				UARTCharPut(UART0_BASE, 'p');
				UARTCharPut(UART0_BASE, 'd');
				UARTCharPut(UART0_BASE, 'a');
				UARTCharPut(UART0_BASE, 't');
				UARTCharPut(UART0_BASE, 'e');
				UARTCharPut(UART0_BASE, 'd');
				UARTCharPut(UART0_BASE, ' ');
				UARTCharPut(UART0_BASE, 't');
				UARTCharPut(UART0_BASE, 'o');
				UARTCharPut(UART0_BASE, ':');
				UARTCharPut(UART0_BASE, ' ');
				uint32_t yo = set_temp;
				int div = 1;
				while(yo!=0){
					yo = yo/10;
					div = div*10;
				}
				yo = set_temp;
				div = div/10;
				while(div!=0){
					uint32_t remain = yo/div;
					unsigned char xyz = remain+'0';
					UARTCharPut(UART0_BASE, xyz);
					yo = yo - remain*div;
					div = div/10;
				}

				UARTCharPut(UART0_BASE, ' ');
				unsigned char xyz = 167;
				UARTCharPut(UART0_BASE, xyz);
				UARTCharPut(UART0_BASE, 'C');


				UARTCharPut(UART0_BASE, '\r');
				UARTCharPut(UART0_BASE, '\n');
				//Set Temp updated to XX ºC

				mode = 0;
			}
			else{
				//UARTCharPut(UART0_BASE, 'c');
				UARTCharPut(UART0_BASE, s_detector);
				if(ss == 127) curr_temp = curr_temp/10;
				else curr_temp = curr_temp*10 + (s_detector - '0');
			}
		}
		//UARTCharPut(UART0_BASE, UARTCharGetNonBlocking(UART0_BASE)); //echo character
		//UARTCharPut(UART0_BASE, 'r');
		//GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2); //blink LED
		//SysCtlDelay(SysCtlClockGet() / (1000 * 3)); //delay ~1 msec
		//GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0); //turn off LED
	}
}
Ejemplo n.º 21
0
/**
 * UART 3 - for wifi
 */
void uart3InturruptHandle(void) {
	unsigned long ulStatus;
	unsigned char ble[15];
	ble[14] = '\0';
	unsigned long val;
	bool msg = false;

//
// Get the interrrupt 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 (UARTCharsAvail(UART3_BASE)) {
		//
		// Read the next character from the UART and write it back to the UART.
		//
		val = UARTCharGetNonBlocking(UART3_BASE);
		ble[i] = val;
		if (val == '\n' || val == '\r' || i == 13) {
			i = -1;
			msg = true;
		}

//		UARTCharPutNonBlocking(UART3_BASE, val);
		i++;
	}
	if (msg) {
		if (strncmp((char*) ble, "gps", 3) == 0) {// && (strncmp((char*) ble, "accl", 4) == 0)
//					UARTCharPutNonBlocking(UART3_BASE, 'p');
			sendGPSData();
			msg = false;
//
		} else if (strncmp((char*) ble, "accl", 4) == 0) {
			sendAcclData();
			msg = false;
		} else if (strncmp((char*) ble, "mag", 3) == 0) {
			//sendMagnetoData();
			sendHeading();
			msg = false;
		} else if (strncmp((char*) ble, "ser", 3) == 0) {
			if (ble[3] == '+') {
				servoSet(servo, 1800);
			} else if (ble[3] == '-') {
				servoSet(servo, 1388);
			} else {
				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);

				servoSet(servo, 1500);
			}

		}
		msg = false;
	}

}
Ejemplo n.º 22
0
void UARTIsr()
{
    //static unsigned int length = sizeof(txArray);
    //static unsigned int count = 0;
    char rxData = 0;
    unsigned int int_id = 0;
    static char *inBufferPtr = inBuffer;
    static char traceBuf[2] = {'\0', '\0'};

    do {
    /* This determines the cause of UART2 interrupt.*/
    int_id = UARTIntStatus(SOC_UART_2_REGS);

#ifdef _TMS320C6X
    // Clear UART2 system interrupt in DSPINTC
    IntEventClear(SYS_INT_UART2_INT);
#else
    /* Clears the system interupt status of UART2 in AINTC. */
    IntSystemStatusClear(SYS_INT_UARTINT2);
#endif

#if 0
    /* Checked if the cause is transmitter empty condition.*/
    if(UART_INTID_TX_EMPTY == int_id)
    {
        if(0 < length)
        {
            /* Write a byte into the THR if THR is free. */
            UARTCharPutNonBlocking(SOC_UART_2_REGS, txArray[count]);
            length--;
            count++;
        }
        if(0 == length)
        {
            /* Disable the Transmitter interrupt in UART.*/
            UARTIntDisable(SOC_UART_2_REGS, UART_INT_TX_EMPTY);
        }
     }
#endif

    /* Check if the cause is receiver data condition.*/
    if(UART_INTID_RX_DATA == int_id)
    {
			rxData = UARTCharGetNonBlocking(SOC_UART_2_REGS);
			if (uartNewString == 0) {
				if (rxData == '\r') {
					*inBufferPtr = '\0';
					uartNewString = 1;
					inBufferPtr = inBuffer;
					/* Disable the Receiver interrupt in UART.*/
					//UARTIntDisable(SOC_UART_2_REGS, UART_INT_RXDATA_CTI);

				} else {
					*inBufferPtr = rxData;
					inBufferPtr++;
					if (inBufferPtr >= (inBuffer + inBufferSize))
						inBufferPtr--;
					else {
						*traceBuf = rxData;
						trace(traceBuf);
					}
				}
			}
			//UARTCharPutNonBlocking(SOC_UART_2_REGS, rxData);
    }


    /* Check if the cause is receiver line error condition.*/
    if(UART_INTID_RX_LINE_STAT == int_id)
    {
        while(UARTRxErrorGet(SOC_UART_2_REGS))
        {
            /* Read a byte from the RBR if RBR has data.*/
            UARTCharGetNonBlocking(SOC_UART_2_REGS);
        }
    }

    } while (int_id);

    return;
}
Ejemplo n.º 23
0
void BluetoothIntHandler(void)
{
	uint32_t ulStatus;
	static uint8_t count = 0;

	ulStatus = UARTIntStatus(UART_Bluetooth.PortName, true);
	ROM_UARTIntClear(UART_Bluetooth.PortName, ulStatus);
	while(UARTCharsAvail(UART_Bluetooth.PortName))
	{
#ifdef SET_PID
		ControlFlag = 1;
		*p_UARTBuf++ = (uint8_t)(UARTCharGetNonBlocking(UART_Bluetooth.PortName));
		if (p_UARTBuf[-1] == '\n')
		{
			p_UARTBuf = &UARTBuf[0];
			set = 0;
			count = 0;
		}
		else if (p_UARTBuf[-1] == '\r')
		{
			switch (count)
			{
#ifdef PID_SPEED
				case 0:
					avrSpeed = set / 10000;
					PIDVerLeft.SetPoint = avrSpeed;
//					PIDPosLeft.SetPoint = set / 10000;
					break;
				case 1:
					PIDVerLeft.Kp = (float)set / 10000;
					break;
				case 2:
					PIDVerLeft.Ki = (float)set / 10000;
					break;
				case 3:
					PIDVerLeft.Kd = (float)set / 10000;
					break;
#endif
#ifdef PID_POSITION
				case 0:
					PIDPosLeft.SetPoint = set / 10000;
					break;
				case 1:
					PIDPosLeft.Kp = (float)set / 10000;
					PIDPosRight.Kp = (float)set / 10000;
					break;
				case 2:
					PIDPosLeft.Ki = (float)set / 10000;
					PIDPosRight.Ki = (float)set / 10000;
					break;
				case 3:
					PIDPosLeft.Kd = (float)set / 10000;
					PIDPosRight.Kd = (float)set / 10000;
					break;
#endif
#ifdef PID_WALL
//				case 1:
//					DeltaEnc = (float)set / 10000;
//					break;

				case 1:
					PIDWallRight.Kp = (float)set / 10000;
					break;
				case 2:
					PIDWallRight.Ki = (float)set / 10000;
					break;
				case 3:
					PIDWallRight.Kd = (float)set / 10000;
					break;
#endif
			}

			set = 0;
			count++;
		}
		else
		{
			set = set * 10 + (p_UARTBuf[-1] - 48);
		}
#else
		return;
#endif
	}
}
Ejemplo n.º 24
0
/*
 * Function Name: UARTIntHandler
 * Input: none
 * Output: none
 * Description: Interrupt handler for UART Int
 * Example Call: UARTIntHandler();
 */
void UARTIntHandler(void) {
	uint32_t ui32Status;
	ui32Status = UARTIntStatus(UART0_BASE, true); //get interrupt status
	UARTIntClear(UART0_BASE, ui32Status); //clear the asserted interrupts
	while (UARTCharsAvail(UART0_BASE)) //loop while there are chars
	{
		unsigned char a = UARTCharGetNonBlocking(UART0_BASE);

		if (a == 'S') {
			mode = 1;
			clearscreen();
			UARTCharPut(UART0_BASE, '\r');
			UARTCharPut(UART0_BASE, 'E');
			UARTCharPut(UART0_BASE, 'n');
			UARTCharPut(UART0_BASE, 't');
			UARTCharPut(UART0_BASE, 'e');
			UARTCharPut(UART0_BASE, 'r');
			UARTCharPut(UART0_BASE, ' ');
			UARTCharPut(UART0_BASE, 't');
			UARTCharPut(UART0_BASE, 'h');
			UARTCharPut(UART0_BASE, 'e');
			UARTCharPut(UART0_BASE, ' ');
			UARTCharPut(UART0_BASE, 't');
			UARTCharPut(UART0_BASE, 'e');
			UARTCharPut(UART0_BASE, 'm');
			UARTCharPut(UART0_BASE, 'p');
			UARTCharPut(UART0_BASE, ':');
			UARTCharPut(UART0_BASE, ' ');
			unsigned char x = UARTCharGet(UART0_BASE);
			UARTCharPut(UART0_BASE, x);
			unsigned char y = UARTCharGet(UART0_BASE);
			UARTCharPut(UART0_BASE, y);
			ui32SetTempValueC = (x - '0') * 10 + (y - '0');
			UARTCharPut(UART0_BASE, ' ');
			UARTCharPut(UART0_BASE, 'T');
			UARTCharPut(UART0_BASE, 'e');
			UARTCharPut(UART0_BASE, 'm');
			UARTCharPut(UART0_BASE, 'p');
			UARTCharPut(UART0_BASE, 'e');
			UARTCharPut(UART0_BASE, 'r');
			UARTCharPut(UART0_BASE, 'a');
			UARTCharPut(UART0_BASE, 't');
			UARTCharPut(UART0_BASE, 'u');
			UARTCharPut(UART0_BASE, 'r');
			UARTCharPut(UART0_BASE, 'e');
			UARTCharPut(UART0_BASE, ' ');
			UARTCharPut(UART0_BASE, 'u');
			UARTCharPut(UART0_BASE, 'p');
			UARTCharPut(UART0_BASE, 'd');
			UARTCharPut(UART0_BASE, 'a');
			UARTCharPut(UART0_BASE, 't');
			UARTCharPut(UART0_BASE, 'e');
			UARTCharPut(UART0_BASE, 'd');
			UARTCharPut(UART0_BASE, ' ');
			UARTCharPut(UART0_BASE, 't');
			UARTCharPut(UART0_BASE, 'o');
			UARTCharPut(UART0_BASE, ':');
			UARTCharPut(UART0_BASE, ' ');
			UARTCharPut(UART0_BASE, x);
			UARTCharPut(UART0_BASE, y);
			UARTCharPut(UART0_BASE, '\r');
			SysCtlDelay(SysCtlClockGet()); //delay 1 sec
			mode = 0;
		} else {
			UARTCharPutNonBlocking(UART0_BASE, a); //echo character
		}
		GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2); //blink LED
		SysCtlDelay(SysCtlClockGet() / (1000 * 3)); //delay ~1 msec
		GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0); //turn off LED
	}
}
Ejemplo n.º 25
0
char  UartGetChar()
{
    return UARTCharGetNonBlocking(UART1_BASE);
}
Ejemplo n.º 26
0
//*****************************************************************************
//
// This function is called when a receive interrupt is generated by the UART.
//
//*****************************************************************************
void
UARTIntHandler(void)
{
    //
    // Clear the interrupt cause.
    //
    UARTIntClear(UART0_BASE, UARTIntStatus(UART0_BASE, true));

    //
    // Loop while there are characters available in the UART receive FIFO.
    //
    while(UARTCharsAvail(UART0_BASE))
    {
        //
        // Determine the current UART handler state.
        //
        switch(g_ulUARTState)
        {
            //
            // The UART handler is waiting for the start of a packet.
            //
            case UART_STATE_IDLE:
            {
                //
                // The next character is the packet size.
                //
                g_ulUpdateSize = UARTCharGetNonBlocking(UART0_BASE) - 2;

                //
                // If the packet size is not zero, then go to the wait for
                // checksum state.
                //
                if(g_ulUpdateSize != 0)
                {
                    g_ulUARTState = UART_STATE_HAVE_SIZE;
                }

                //
                // This character has been read.
                //
                break;
            }

            //
            // The UART handler is waiting for the packet checksum.
            //
            case UART_STATE_HAVE_SIZE:
            {
                //
                // The next charcter is the packet checksum.
                //
                g_ulUpdateCheckSum = UARTCharGetNonBlocking(UART0_BASE);

                //
                // Set the index into the packet buffer to zero.
                //
                g_ulUpdateIdx = 3;

                //
                // Go to the wait for data state.
                //
                g_ulUARTState = UART_STATE_HAVE_CKSUM;

                //
                // This character has been read.
                //
                break;
            }

            //
            // The UART handler is waiting for the packet data.
            //
            case UART_STATE_HAVE_CKSUM:
            {
                //
                // The next character is part of the packet data.
                //
                g_pucUpdateData[g_ulUpdateIdx++] =
                    UARTCharGetNonBlocking(UART0_BASE);

                //
                // See if this was the last byte of the packet data.
                //
                if(g_ulUpdateIdx == (g_ulUpdateSize + 3))
                {
                    //
                    // Process this packet.
                    //
                    ProcessPacket();

                    //
                    // If the handler state hasn't changed (for example, as a
                    // result of packet being output), then go to the wait for
                    // packet state.
                    //
                    if(g_ulUARTState == UART_STATE_HAVE_CKSUM)
                    {
                        g_ulUARTState = UART_STATE_IDLE;
                    }
                }

                //
                // This character has been read.
                //
                break;
            }

            //
            // The UART handler is waiting for an ACK or NAK packet.
            //
            case UART_STATE_ACK_NAK:
            {
                //
                // Read the next byte.
                //
                g_ulUpdateIdx = UARTCharGetNonBlocking(UART0_BASE);

                //
                // Go to the wait for packet state if this is an ACK or NAK.
                //
                if((g_ulUpdateIdx == COMMAND_ACK) ||
                   (g_ulUpdateIdx == COMMAND_NAK))
                {
                    g_ulUARTState = UART_STATE_IDLE;
                }

                //
                // This character has been read.
                //
                break;
            }
        }
    }
}
Ejemplo n.º 27
0
// A regular command returns OK when good, ERROR when failed
bool processRegularCommand(char* atCommand, char* waitForString, unsigned retryLimit, char* response, unsigned maxLen)
{
	const unsigned rxBufLen = 200;
    char rxBuf[200] = {0};
    int counter = 0;
    int index = 0;
    unsigned retryCounter = 0;


    // Take control of the stdio UART
    // The wifi chip is connected to UART1
    UARTStdioConfig(1, 115200, 16000000);
    // Can we even talk to the device?
    while(1<2)
    {
    	// First time, and every time counter is reset, we try again
    	if( counter == 0)
    	{
    		// Send command
    		if( !(atCommand[0] == '\0') )
    		{
		    	UARTprintf("%s\r\n", atCommand);
		    }

		    // If they didn't set a limit, we try forever
		   	if( retryLimit && (retryCounter >= retryLimit) )
		    {
		    	UARTStdioConfig(0, 115200, 16000000);
		    	return false;
		    }
			
			// Clean out the buffer
            memset(rxBuf, 0x00, rxBufLen);

			index = 0;  //resending the command, so reset the index
		    retryCounter++;

		    // THis is for debug
		    counter++;
    	}

        // Check if data exists on uart1 (non usb uart)
        if( UARTCharsAvail(UART1_BASE) )
        {
            rxBuf[index] = (char)UARTCharGetNonBlocking(UART1_BASE);
            index++;

            if( strstr(rxBuf, waitForString) )
            {
            	UARTStdioConfig(0, 115200, 16000000);
                
                // Copy data back to user if they passed in a valid buffer and length
                if( (response!=0) && (maxLen != 0) )
                {
                    memcpy(response, rxBuf, maxLen);
                }
                return true;
            }
            else if( strstr(rxBuf, "ERROR") )
            {
            	UARTStdioConfig(0, 115200, 16000000);
            	return false;
            }
            else if( strstr(rxBuf, "no change") )
            {
            	UARTStdioConfig(0, 115200, 16000000);
            	return true;
            }
            else if( strstr(rxBuf, "\r\n") )
            {
            	// So the data we received so far was useless. 
            	// Go back to zero
            	memset(rxBuf, 0x00, rxBufLen);
            	index = 0;
            }
			
			/*
            UARTStdioConfig(0, 115200, 16000000);
            
            for(i=0;i<strlen(response);i++)
            {
            	UARTprintf("response[%d]: %c = %d\n", i, response[i], response[i]);
            }
            
            
            //UARTprintf("wifi chip gave us: %s\n", rxBuf);

            UARTStdioConfig(1, 115200, 16000000);
            */
        }
        /*
        else
        {
        	//SysCtlDelay(SysCtlClockGet() / 3);
        	counter++;

        	// Reset counter
        	if(counter>15)
        	{
        		//counter = 0;
        	}
        }
        counter++;
        */
    }
}
Ejemplo n.º 28
0
static void UARTIsr(void)
{
    unsigned int rxErrorType = 0;
    unsigned char rxByte = 0;
    unsigned int intId = 0;
    unsigned int idx = 0;

    /* Checking ths source of UART interrupt. */
    intId = UARTIntIdentityGet(SOC_UART_0_REGS);

    switch(intId)
    {
        case UART_INTID_TX_THRES_REACH:

            /*
            ** Checking if the entire transmisssion is complete. If this
            ** condition fails, then the entire transmission has been completed.
            */
            if(currNumTxBytes < (sizeof(txArray) - 1))
            {
                txEmptyFlag = TRUE;
            }

            /*
            ** Disable the THR interrupt. This has to be done even if the
            ** transmission is not complete so as to prevent the Transmit
            ** empty interrupt to be continuously generated.
            */
            UARTIntDisable(SOC_UART_0_REGS, UART_INT_THR);

        break;

        case UART_INTID_RX_THRES_REACH:
            rxByte = UARTCharGetNonBlocking(SOC_UART_0_REGS);
            UARTCharPutNonBlocking(SOC_UART_0_REGS, rxByte);
        break;

        case UART_INTID_RX_LINE_STAT_ERROR:

            rxErrorType = UARTRxErrorGet(SOC_UART_0_REGS);

            /* Check if Overrun Error has occured. */
            if(rxErrorType & UART_LSR_RX_OE)
            {
                ConsoleUtilsPrintf("\r\nUART Overrun Error occured."
                              " Reading and Echoing all data in RX FIFO.\r\n");

                /* Read the entire RX FIFO and the data in RX Shift register. */
                for(idx = 0; idx < (RX_FIFO_SIZE + 1); idx++)
                {
                    rxByte = UARTFIFOCharGet(SOC_UART_0_REGS);
                    UARTFIFOCharPut(SOC_UART_0_REGS, rxByte);
                }

                break;
            }

            /* Check if Break Condition has occured. */
            else if(rxErrorType & UART_LSR_RX_BI)
            {
                ConsoleUtilsPrintf("\r\nUART Break Condition occured.");
            }

            /* Check if Framing Error has occured. */
            else if(rxErrorType & UART_LSR_RX_FE)
            {
                ConsoleUtilsPrintf("\r\nUART Framing Error occured.");
            }

            /* Check if Parity Error has occured. */
            else if(rxErrorType & UART_LSR_RX_PE)
            {
                ConsoleUtilsPrintf("\r\nUART Parity Error occured.");
            }

            ConsoleUtilsPrintf(" Data at the top of RX FIFO is: ");
            rxByte = UARTFIFOCharGet(SOC_UART_0_REGS);
            UARTFIFOCharPut(SOC_UART_0_REGS, rxByte);

        break;
    
        case UART_INTID_CHAR_TIMEOUT:

            ConsoleUtilsPrintf("\r\nUART Character Timeout Interrupt occured."
                              " Reading and Echoing all data in RX FIFO.\r\n");

            /* Read all the data in RX FIFO. */
            while(TRUE == UARTCharsAvail(SOC_UART_0_REGS))
            {
                rxByte = UARTFIFOCharGet(SOC_UART_0_REGS);
                UARTFIFOCharPut(SOC_UART_0_REGS, rxByte);
            }

        break;

        default:
        break;    
    }

}
//*****************************************************************************
//
// Read as many characters from the UART FIFO as we can and move them into
// the CDC transmit buffer.
//
// \return Returns UART error flags read during data reception.
//
//*****************************************************************************
static uint32_t
ReadUARTData(void)
{
    int32_t i32Char;
    int8_t ui8Char;
    uint32_t ui32Space, ui32Errors;

    //
    // Clear our error indicator.
    //
    ui32Errors = 0;

    //
    // How much space do we have in the buffer?
    //
    ui32Space = USBBufferSpaceAvailable((tUSBBuffer *)&g_sTxBuffer);

    //
    // Read data from the UART FIFO until there is none left or we run
    // out of space in our receive buffer.
    //
    while(ui32Space && UARTCharsAvail(UART0_BASE))
    {
        //
        // Read a character from the UART FIFO into the ring buffer if no
        // errors are reported.
        //
        i32Char = UARTCharGetNonBlocking(UART0_BASE);

        //
        // If the character did not contain any error notifications,
        // copy it to the output buffer.
        //
        if(!(i32Char & ~0xFF))
        {
            ui8Char = (unsigned char)(i32Char & 0xFF);
            USBBufferWrite((tUSBBuffer *)&g_sTxBuffer,
                           (unsigned char *)&ui8Char, 1);

            //
            // Decrement the number of bytes we know the buffer can accept.
            //
            ui32Space--;
        }
        else
        {
#ifdef DEBUG
            //
            // Increment our receive error counter.
            //
            g_ui32UARTRxErrors++;
#endif
            //
            // Update our error accumulator.
            //
            ui32Errors |= i32Char;
        }

        //
        // Update our count of bytes received via the UART.
        //
        g_ui32UARTRxCount++;
    }

    //
    // Pass back the accumulated error indicators.
    //
    return(ui32Errors);
}
void UART_0_ISR(void)
{
    unsigned int rxErrorType = 0;
    unsigned char rxByte = 0;
    unsigned int intId = 0;
    unsigned int idx = 0;

    /* Checking ths source of UART interrupt. */
    intId = UARTIntIdentityGet(SOC_UART_0_REGS);

    switch(intId)
    {
        case UART_INTID_RX_THRES_REACH:
            rxByte = UARTCharGetNonBlocking(SOC_UART_0_REGS);
            UART_AddToRXBuffer(rxByte);
            break;

        case UART_INTID_RX_LINE_STAT_ERROR:
            rxErrorType = UARTRxErrorGet(SOC_UART_0_REGS);

            /* Check if Overrun Error has occured. */
            if(rxErrorType & UART_LSR_RX_OE)
            {
                /* Read the entire RX FIFO and the data in RX Shift register. */
                for(idx = 0; idx < (RX_FIFO_SIZE + 1); idx++)
                {
                    rxByte = UARTFIFOCharGet(SOC_UART_0_REGS);
                    UART_AddToRXBuffer(rxByte);
                }

                break;
            }
            rxByte = UARTFIFOCharGet(SOC_UART_0_REGS);
            break;

        case UART_INTID_CHAR_TIMEOUT:
            /* Read all the data in RX FIFO. */
            while(TRUE == UARTCharsAvail(SOC_UART_0_REGS))
            {
                rxByte = UARTFIFOCharGet(SOC_UART_0_REGS);
                UART_AddToRXBuffer(rxByte);
            }

            break;

        case (UART_INTID_TX_THRES_REACH):
			/* UART transfer register and FIFO is empty */
			if(UART_TX_remove != UART_TX_add)
			{
				while(UARTTxFIFOFullStatusGet(SOC_UART_0_REGS) == UART_TX_FIFO_NOT_FULL)
				{
					if(UART_TX_remove == UART_TX_add)
					{
						break;
					}
					UARTFIFOCharPut(SOC_UART_0_REGS, UART_TX_buffer[UART_TX_remove]);
					UART_TX_remove = (UART_TX_remove + 1UL) % UART_TX_SIZE;
				}
			}
			else
			{
				/* Disabling required TX Interrupts. */
				UARTIntDisable(SOC_UART_0_REGS, UART_INT_THR);
			}
			break;

        default:
        	break;
    }
}