Example #1
0
/******************************************************************************
*																			  *
* \brief  UART error handler.\n                                               *
*                                                                             *
* \param none.\n       				                                          *
*																		      *
* \return none.                                                               *
*                                                                             *
******************************************************************************/
void UARTHandleError(void)
{
    while((UARTRxErrorGet(USB_UART_BASE)))
    {
        /* Read a byte from the RBR if RBR has data.*/
       UARTCharGetNonBlocking(USB_UART_BASE);       
    }
}
Example #2
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;
}
/*
** Interrupt Service Routine for UART.
*/
static void UARTIsr(void)
{
    unsigned int rxErrorType = 0;
    unsigned char rxByte = 0;
    unsigned int intId = 0;
    unsigned int idx = 0;
    unsigned int i=0;

    unsigned short rx_array[22];

    //unsigned int rx_integer=0,rx_integer1=0;

    /* Checking ths syource of UART interrupt. */
    intId = UARTIntIdentityGet(SOC_UART_0_REGS);
    //printf("intId=0x%x\n\r",intId);
    switch(intId)
    {
        case UART_INTID_TX_THRES_REACH:
        	printf("UART_INTID_TX_THRES_REACH\n\r");
            /*
            ** 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:
        	/*Берём один байт из UART */

        	//printf("UART_INTID_RX_THRES_REACH");
        	rx_array[0]=UARTCharGetTimeout(SOC_UART_0_REGS, 100);
        	rx_array[1]=UARTCharGetTimeout(SOC_UART_0_REGS, 100);
        	rx_array[2]=UARTCharGetTimeout(SOC_UART_0_REGS, 100);
        	rx_array[3]=UARTCharGetTimeout(SOC_UART_0_REGS, 100);
        	rx_array[4]=UARTCharGetTimeout(SOC_UART_0_REGS, 100);
        	rx_array[5]=UARTCharGetTimeout(SOC_UART_0_REGS, 100);
        	rx_array[6]=UARTCharGetTimeout(SOC_UART_0_REGS, 100);
        	rx_array[7]=UARTCharGetTimeout(SOC_UART_0_REGS, 100);
        	rx_array[8]=UARTCharGetTimeout(SOC_UART_0_REGS, 100);
        	rx_array[9]=UARTCharGetTimeout(SOC_UART_0_REGS, 100);
        	rx_array[10]=UARTCharGetTimeout(SOC_UART_0_REGS, 100);
        	rx_array[11]=UARTCharGetTimeout(SOC_UART_0_REGS, 100);
        	rx_array[12]=UARTCharGetTimeout(SOC_UART_0_REGS, 100);
        	rx_array[13]=UARTCharGetTimeout(SOC_UART_0_REGS, 100);
        	rx_array[14]=UARTCharGetTimeout(SOC_UART_0_REGS, 100);
        	rx_array[15]=UARTCharGetTimeout(SOC_UART_0_REGS, 100);
        	rx_array[16]=UARTCharGetTimeout(SOC_UART_0_REGS, 100);
        	rx_array[17]=UARTCharGetTimeout(SOC_UART_0_REGS, 100);
        	rx_array[18]=UARTCharGetTimeout(SOC_UART_0_REGS, 100);
        	rx_array[19]=UARTCharGetTimeout(SOC_UART_0_REGS, 100);
        	rx_array[20]=UARTCharGetTimeout(SOC_UART_0_REGS, 100);
        	rx_array[21]=UARTCharGetTimeout(SOC_UART_0_REGS, 100);



            for(i=0;i<22;i++)
            {
            	printf("rx_byte=%X\n\r",rx_array[i]);

            }

        	//rxByte = UARTCharGetNonBlocking(SOC_UART_0_REGS);
        	//printf("rx_byte=%c\n\r",rxByte);
        //	printf("rx_byte=%x,rx_byte1=%x\n\r",rx_integer,rx_integer1);

        	//UARTCharPutNonBlocking(SOC_UART_0_REGS, rxByte);
        break;


        case UART_INTID_RX_LINE_STAT_ERROR:
        	printf("UART_INTID_RX_LINE_STAT_ERROR\n\r");
            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:
        	printf("UART_INTID_CHAR_TIMEOUT\n\r");
            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:
        printf("default\n\r");
        break;    
    }

}
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;
    }
}
Example #5
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;    
    }

}