// UART 2 interrupt handler
// it is set at priority level 2
void __ISR(_UART2_VECTOR, ipl2) IntUart2Handler(void)
{
	// Is this an RX interrupt?
	if(INTGetFlag(INT_SOURCE_UART_RX(UART2)))
	{
		unsigned char databyte;

		// Clear the RX interrupt Flag
	    INTClearFlag(INT_SOURCE_UART_RX(UART2));

		// Code to be executed on RX interrupt:
		databyte = UARTGetDataByte(UART2);
		databyte++;
		
		// Echo what we just received.
		PutCharacter(databyte);
	}

	// We don't care about TX interrupt
	if ( INTGetFlag(INT_SOURCE_UART_TX(UART2)) )
	{
		// Clear the TX interrupt Flag
		INTClearFlag(INT_SOURCE_UART_TX(UART2));

		// Code to be executed on TX interrupt:

		
	}
}
// *****************************************************************************
// UINT32 GetDataBuffer(char *buffer, UINT32 max_size)
// *****************************************************************************
UINT32 GetDataBuffer(char *buffer, UINT32 max_size)
{
    UINT32 num_char;

    num_char = 0;

    while(num_char < max_size)
    {
        UINT8 character;

        while(!UARTReceivedDataIsAvailable(UART2))
            ;

        character = UARTGetDataByte(UART2);

        if(character == '\r')
            break;

        *buffer = character;

        buffer++;
        num_char++;
    }

    return num_char;
}
/*******************************************************************************
 * FUNCTION: vUART2FlushRxBuffer
 *
 * PARAMETERS:
 * ~ void
 *
 * RETURN:
 * ~ void
 *
 * DESCRIPTIONS:
 * Flush all the data in the Rx buffer.
 *
 *******************************************************************************/
void vUART2FlushRxBuffer(void)
{
    unsigned char ucReceivedData;

    unsigned int iStatus = INTDisableInterrupts();
    
    prv_xRx.uiDataCount = 0;
    prv_xRx.uiReadPt = 0;
    prv_xRx.uiWritePt = 0;
    
    // Discard all data available in the UART receive buffer.
    while (UARTReceivedDataIsAvailable(UART2)) {
        // Read the received data.
        ucReceivedData = UARTGetDataByte(UART2);
    }

    // Clear the overrun flag.
    if (UARTGetLineStatus(UART2) & UART_OVERRUN_ERROR) {
        U2STAbits.OERR = 0;
    }

    // Clear the semaphore.
    xSemaphoreTake(xBluetoothRxSemaphore, 0);

    INTRestoreInterrupts(iStatus);
}
void __ISR(_UART2_VECTOR, ipl2) IntUart2Handler(void)
{
	// Is this an RX interrupt?
	if(INTGetFlag(INT_SOURCE_UART_RX(UART2)))
	{

		// Clear the RX interrupt Flag
	    INTClearFlag(INT_SOURCE_UART_RX(UART2));

		// Code to be executed on RX interrupt:
		COMMAND = UARTGetDataByte(UART2);
		
		// Echo what we just received.
		PutCharacter(COMMAND);
	}

	// We don't care about TX interrupt
	if ( INTGetFlag(INT_SOURCE_UART_TX(UART2)) )
	{
		// Clear the TX interrupt Flag
		INTClearFlag(INT_SOURCE_UART_TX(UART2));

		// Code to be executed on TX interrupt:
			//none
	}
}
Exemple #5
0
void ReadUART3(char *message, int max) {
    char data;
    int complete = 0, num_bytes = 0;
    // loop until you get a '\r' or '\n'
    while (!complete) {
        if (UARTReceivedDataIsAvailable(UART3)) {
            data = UARTGetDataByte(UART3);
            if ((data == '\n') || (data == '\r')) {
                complete = 1;
            } else {
                message[num_bytes] = data;
                num_bytes++;
                // roll over if the array is too small
                if (num_bytes >= max) {
                    num_bytes = 0;
                }
            }
        }
    }
    // clear the remaining elements in the array
    int i;
    for (i = num_bytes; i < max; i++) {
        message[i] = '\0';
    }
}
// UART 2 interrupt handler
// it is set at priority level 2
void __ISR(_UART2_VECTOR, ipl2) IntUart2Handler(void)
{
	// Is this an RX interrupt?
	if(INTGetFlag(INT_SOURCE_UART_RX(UART2)))
	{
		// Clear the RX interrupt Flag
	    INTClearFlag(INT_SOURCE_UART_RX(UART2));

	// Code to be executed on RX interrupt:

		// Echo what we just received.
		PutCharacter(UARTGetDataByte(UART2));
		// Toggle LED to indicate UART activity
		mPORTAToggleBits(BIT_7);

	}

	// We don't care about TX interrupt
	if ( INTGetFlag(INT_SOURCE_UART_TX(UART2)) )
	{
		// Clear the TX interrupt Flag
		INTClearFlag(INT_SOURCE_UART_TX(UART2));

	// Code to be executed on TX interrupt:

		
	}
}
// *****************************************************************************
// UINT32 GetMenuChoice(void)
// *****************************************************************************
UINT32 GetMenuChoice(void)
{
    UINT8  menu_item;

    while(!UARTReceivedDataIsAvailable(UARTTEST));
    menu_item = UARTGetDataByte(UARTTEST);


    return (UINT32)menu_item;
}
// read byte if one is ready.
// if exists, return true and byte
// if return false, byte = 0 is none avail, else
// byte != 0 means error
bool UARTReadByte(uint8_t * byte)
    {
    if (UARTReceivedDataIsAvailable(UART1))
    {
        *byte = UARTGetDataByte(UART1);
        return true;
    }
    *byte = 0;
    return false;
    } // UARTReadByte
// *****************************************************************************
// Wait for a new character to arrive on the Console serial port
// *****************************************************************************
char getConsole(void)
{
    char character;

    while(!UARTReceivedDataIsAvailable(UART_CONSOLE));

    character = UARTGetDataByte(UART_CONSOLE);

    return character;		// read the character from the receive buffer
}
Exemple #10
0
		int rx(void *dst, size_t n) {
			size_t ui;
			for (ui = 0; ui < n; ++ui) {
				if (!UARTReceivedDataIsAvailable(module)) {
					return -1;
				}
				WDT::clear();
				((uint8_t *)dst)[ui] = UARTGetDataByte(module);
			}
			return 0;
		}
Exemple #11
0
void serial_handling(void){
    static int step = 0;
    static uint8_t msg[MESS_SIZE];

    if(UARTReceivedDataIsAvailable(UART2))
    {
       PutCharInFifo ( &descrFifoRX, UARTGetDataByte(UART2));
    }

    if(GetReadSize(&descrFifoRX) < 1){
        // Il n'y a rien à faire
        return ;
    }

    GetCharFromFifo(&descrFifoRX, &msg[step]);

    switch(step){
        case 0:
            // Recherche du caractère '!'
            if(msg[0] == '!'){
                step++;
            }
            break;
        case 1:
        case 2:
            step++;
            break;
        case 3:
            // Message complet
            msg_processing(msg);
            step = 0;
        default:
            step = 0;
            break;

    }


    if (GetReadSize(&descrFifoTX) > 0)
    {
        // Autorise int émission
        INTEnable(INT_U2TX, INT_ENABLED);
    }

}
void handleUartInterrupt(UART_MODULE uart, Buffer* buffer) {
    // Is this an RX interrupt?
    if (INTGetFlag(INT_SOURCE_UART_RX(uart))) {
        if (UARTReceivedDataIsAvailable(uart)) {
            unsigned char c = UARTGetDataByte(uart);
            // BUG2018, BUG2019 (255 / 254 value) when Motor Power is too strong
            if (c != 'ÿ' && c != 'þ') {
                bufferWriteChar(buffer, c);
            }
            // Clear the RX interrupt Flag
            INTClearFlag(INT_SOURCE_UART_RX(uart));
        }
    }
    // We don't care about TX interrupt
    if ( INTGetFlag(INT_SOURCE_UART_TX(uart)) ) {
        INTClearFlag(INT_SOURCE_UART_TX(uart));
    }
}
Exemple #13
0
void __ISR(_UART1_VECTOR, IPL2SOFT) IntUart1Handler(void)
{
     if(INTGetFlag(INT_SOURCE_UART_RX(UART1)))
     {
         INTClearFlag(INT_SOURCE_UART_RX(UART1));
         if (uart_rx_count<sizeof(uart_rx_buff)-1)
             uart_rx_count++;
         else
             uart_rx_count=0; // overflow
         
         uart_rx_buff[uart_rx_count]=UARTGetDataByte(UART1);
     }

    if(INTGetFlag(INT_SOURCE_UART_TX(UART1)))
   {
       INTClearFlag(INT_SOURCE_UART_TX(UART1));
    }
}
void __ISR(_UART_4_VECTOR, ipl1) IntUart4Handler(void)
{
    // Is this an RX interrupt?
    if(INTGetFlag(INT_SOURCE_UART_RX(UART_WIFI_MODULE_ID)))
    {
        const char rchar = UARTGetDataByte(UART_WIFI_MODULE_ID);

        PutcToWifiReceivedBuffer(rchar, &DefaultWifiService);

        // Clear the RX interrupt Flag
        INTClearFlag(INT_SOURCE_UART_RX(UART_WIFI_MODULE_ID));
    }

    // We don't care about TX interrupt
    if ( INTGetFlag(INT_SOURCE_UART_TX(UART_WIFI_MODULE_ID)) )
    {
        INTClearFlag(INT_SOURCE_UART_TX(UART_WIFI_MODULE_ID));
    }
}
// UART interrupt handler, set at priority level 2
void __ISR(_UART_2_VECTOR, ipl2) IntUart2Handler(void)
{
    // Is this an RX interrupt?
    if(INTGetFlag(INT_SOURCE_UART_RX(UART_CMD_MODULE_ID)))
    {
        char rchar = UARTGetDataByte(UART_CMD_MODULE_ID);

        AddKeystroke(&CurrentCommandEngine, rchar);

        // Clear the RX interrupt Flag
        INTClearFlag(INT_SOURCE_UART_RX(UART_CMD_MODULE_ID));
    }

    // We don't care about TX interrupt
    if ( INTGetFlag(INT_SOURCE_UART_TX(UART_CMD_MODULE_ID)) )
    {
        INTClearFlag(INT_SOURCE_UART_TX(UART_CMD_MODULE_ID));
    }
}
Exemple #16
0
//******************************************************************************
//Interrupt Request Routines
//******************************************************************************
void __ISR(_UART_1_VECTOR, IPL5AUTO) __UART1Interrupt(void)
{
    UINT8 rxByte = 0;
    UINT8 txByte = 0;
    int rslt = 0;

    if (INTGetFlag(INT_U1RX))
    {
        //Add received byte
        rxByte = UARTGetDataByte(UART1);
        FIFOUART1_pushRxQueue(&rxByte, 1);

        INTClearFlag(INT_U1RX);
    }
    if (INTGetFlag(INT_U1TX))
    {
        rslt = FIFOUART1_popTxQueue(&txByte);

        switch (rslt)
        {
            case 2: //Success, non-empty buffer
                UARTSendDataByte(UART1, txByte);
                break;

            case 1: //Success, empty buffer
                UARTSendDataByte(UART1, txByte);
                INTEnable(INT_U1TX, INT_DISABLED);
                break;

            case -1: //Queue is Overflowing
                //Reset the indexs
                FIFOUART1_TxBuffer_TxIndex = 0;
                FIFOUART1_TxBuffer_Index = 0;
            case -2: //Queue is Empty
            default: //unknown result
                INTEnable(INT_U1TX, INT_DISABLED);
                break;
        }

        INTClearFlag(INT_U1TX);
    }
}
Exemple #17
0
void __ISR(_UART_2_VECTOR, ipl2) IntUart2Handler(void)
{
	// Is this an RX interrupt?
	if(INTGetFlag(INT_SOURCE_UART_RX(UART_MODULE_ID2)))
	{
            #ifdef DEBUG

                 PutCharacterXbee(UARTGetDataByte(UART_MODULE_ID2));
                
            #endif

            INTClearFlag(INT_SOURCE_UART_RX(UART_MODULE_ID2));
            
	}

	// We don't care about TX interrupt
	if (INTGetFlag(INT_SOURCE_UART_TX(UART_MODULE_ID2)))
	{
            INTClearFlag(INT_SOURCE_UART_TX(UART_MODULE_ID2));
	}

}
Exemple #18
0
// XC32 Manual page 138
void __ISR(_UART_1_VECTOR, IPL5AUTO) uart_handler(void)
{
    static int count = 0;
    
    unsigned char byte;
    static int length_lsb = 0, length_msb = 0;
    static int length = 0;
    static int selected_sensor = 0;
    //IFS0CLR = (1 << 28) |( 1 << 27)  ; // TX, RX, clear interrupt flags atomically.
    INTClearFlag(INT_U1TX);
    INTClearFlag(INT_U1RX);
    byte = UARTGetDataByte(UART1);
    switch (state)
    {
        case START:
        {
            
            if (byte == XBEE_FRAME_START)
            {
                state = START_FRAME_RECEIVED;
            }

            count = 0;
            length_lsb = 0;
            length_msb = 0;
            length = 0;
            selected_sensor = 0;
        }
            break;
        case START_FRAME_RECEIVED:
        {
            if (count == 0)
            {
                length_msb = byte;
                ++count;
                //state = state;
            }
            else if (count == 1)
            {
                length_lsb = byte;
                state = CHECK_FRAME_TYPE;
                length = ((int) length_lsb) | (((int) length_msb) << 8);
                count = 0;
            }
        }
            break;
        case CHECK_FRAME_TYPE:
        {
            if (byte == XBEE_RX_SAMPLE)
            {
                state = GET_ADDRESS;
                count = 0;
            }
            else
            {
                state = START; // not the correct frame type
                count = 0;
            }

        }
            break;
        case GET_ADDRESS:
        {
            if (count < 1)
            {
                ++count;
            }
            else
            {
                selected_sensor = byte - 2;
                count = 0;
                state = SKIP_FIVE;
            }
        }
            break;
        case SKIP_FIVE:
        {
            if (count < 4)
                count = count + 1;
            else
            {
                state = GET_TEMP;
                count = 0;
            }
        }
            break;
        case GET_TEMP:
        {
            if (count < 1)
            {
                remote_temperatures[selected_sensor] = ((int) byte) << 8; // msb
                ++count;
            }
            else
            {
               
                remote_temperatures[selected_sensor] = remote_temperatures[selected_sensor] | (((int) byte) & 0xFF); // lsb
                state = START;
                temp_one_final =  ((((float)remote_temperatures[selected_sensor]) * (3300.0f/1024.0f)) - 500.0f) / 10.0f;
                count = 0;
            }
        }
            break;
        default:
            break;

    }



    //if(UARTTransmitterIsReady(UART1))
    //{
    //    UARTSendDataByte(UART1, 0x55);
   // }

    // should only be one byte ever here, due to the interupt mode, but just in case.
   /* if( U1STA & RXDA_MASK )
    {
        g_uart_rx_buf = U1RXREG;
        g_received_char = 1;

    }

        // if transmit shift reg empty and we're signaled to start, then begin transmission.
    if( ((TRMT_MASK & U1STA) ) && g_start_transmit)
    {
        U1TXREG = g_uart_rx_buf;
    }
    */
}
Exemple #19
0
/*******************************************************************************
  Function:
    void ConsoleUartIntHandler(void)

  Remarks:
 UART 1 interrupt handler is set at priority level 2 with software context saving
 */
void ConsoleUartIntHandler(void)
{
    unsigned char byteReceived;

    // Is this an RX interrupt?
    if (INTGetFlag(INT_SOURCE_UART_RX(UART_CONSOLE)))
    {
        while (UARTReceivedDataIsAvailable(UART_CONSOLE) != 0)
        {
            byteReceived = UARTGetDataByte(UART_CONSOLE);
            //Console Interrupt - In Self Test Mode
            if(self_TESTMode == TRUE)
            {
                ConsoleMsgCallback_selfTest();
            }
            //Console Interrupt - RN1723 Command Mode
            else if(RN_UartCmdMode == 1)
            {
                //Exit console mode if 'ESC'
                if(byteReceived == ESC)
                {
                    RN_UartCmdMode = FALSE;
                    RN_DATA_MODE();
                    memset(consoleMsg, '\0', sizeof(consoleMsg));
                }
                else
                {
                    while(!UARTTransmitterIsReady(UART_WIFLY));
                    UARTSendDataByte(UART_WIFLY, byteReceived);
                }

            }
            else
            {
                PIC32_ConsoleMode = TRUE;
                putConsole(byteReceived);
                if(byteReceived == CR)
                {
                    PrintConsoleMenu();
                }
                else if(byteReceived == LF)
                {
                    //Ignore Line Feed
                }
                else if(byteReceived == BACKSPACE)
                {
                    consoleMsg[(strlen(consoleMsg)-1)] = '\0';
                }
                else if(byteReceived == ESC)
                {
                    PIC32_ConsoleMode = FALSE;
                    memset(consoleMsg, '\0', sizeof(consoleMsg));

                }
                else
                {
                    consoleMsg[strlen(consoleMsg)] = byteReceived;
                }

            }

        }

        // Clear the RX interrupt Flag
        INTClearFlag(INT_SOURCE_UART_RX(UART_CONSOLE));
    }

    // We don't care about the TX interrupt
    if (INTGetFlag(INT_SOURCE_UART_TX(UART_CONSOLE)) )
    {
        INTClearFlag(INT_SOURCE_UART_TX(UART_CONSOLE));
    }
}
/*******************************************************************************
 * ISR: UART 2 Interrupt.
 *
 * DESCRIPTIONS:
 * Interrupt vector for UART 2.
 *
 *******************************************************************************/
void __ISR(_UART_2_VECTOR, IPL7AUTO) UART2Interrupt(void)
{
    unsigned char ucReceivedData;

    xSystemState.bBluetoothBusy = 1;


    // Rx interrupt.
    if (INTGetEnable(INT_U2RX) && INTGetFlag(INT_U2RX)) {
        INTClearFlag(INT_U2RX);

        // Read out all data available.
        while (UARTReceivedDataIsAvailable(UART2)) {
            // Read the received data.
            ucReceivedData = UARTGetDataByte(UART2);

            // Make sure there is empty space in the buffer.
            if ((prv_xRx.uiBufferSize - prv_xRx.uiDataCount) > 0) {

                // Copy the data to the buffer.
                prv_xRx.pucBuffer[prv_xRx.uiWritePt] = ucReceivedData;

                // Increase the write pointer and data count.
                prv_vIncPointer(&prv_xRx.uiWritePt, prv_xRx.uiBufferSize);
                prv_xRx.uiDataCount++;

                portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
                xSemaphoreGiveFromISR(xBluetoothRxSemaphore, &xHigherPriorityTaskWoken);
            }
            else {
                xSystemError.bBluetoothError = 1;
            }
        }
    }



    // Tx interrupt.
    if (INTGetEnable(INT_U2TX) && INTGetFlag(INT_U2TX)) {
        // Loop until the Tx buffer is fully filled.
        while (UARTTransmitterIsReady(UART2)) {
            // If there is data to transmit...
            if (prv_xTx.uiDataCount > 0) {
                // Shift in the data to the transmit buffer.
                UARTSendDataByte(UART2, prv_xTx.pucBuffer[prv_xTx.uiReadPt]);

                // Increase the read pointer and decrease the data count.
                prv_vIncPointer(&prv_xTx.uiReadPt, prv_xTx.uiBufferSize);
                prv_xTx.uiDataCount--;
            }

            // Else, disable the transmit interrupt.
            else {
                INTEnable(INT_U2TX, INT_DISABLED);
                break;
            }
        }
    }



    // Error Interrupt.
    if (INTGetEnable(INT_U2E) && INTGetFlag(INT_U2E)) {
        INTClearFlag(INT_U2E);

        // Discard all data available.
        while (UARTReceivedDataIsAvailable(UART2)) {
            // Read the received data.
            ucReceivedData = UARTGetDataByte(UART2);
        }

        // Clear the overrun flag.
        if (UARTGetLineStatus(UART2) & UART_OVERRUN_ERROR) {
            U2STAbits.OERR = 0;
        }

        xSystemError.bBluetoothError = 1;
    }

}
Exemple #21
0
// UART3 interrupt handler, priority level 2
void __ISR(_UART_3_VECTOR, ipl2) IntUart3Handler(void) {
  // Is this an RX interrupt?
  if(INTGetFlag(INT_SOURCE_UART_RX(UART3))){
    char data = UARTGetDataByte(UART3);

    LED1 = !LED1;

	if(data =='x') {
		//Stop program, both magnets ON
		start = 0;
		EMAG1 = EMAG2 = 1;
	}
	
    if(data =='e') {
       // Magnet 1 ON
       EMAG1 = 1;
    }

    if(data =='f') {
       // Magnet 1 OFF
       EMAG1 = 0;
    }

    if(data =='g') {
       // Magnet 2 ON
       EMAG2 = 1;
    }

    if(data =='h') {
       // Magnet 2 OFF
       EMAG2 = 0;
    }

	if(data =='s') {
		// start motion program
		start = 1;
		LED0=0;
	}
    if(data =='o') {
        delay1 = delay1+1;
	}
	if(data =='p') {
        delay1 = delay1-1;
	}
	if(data =='k') {
        delay2 = delay2+1;
	}
	if(data =='l') {
        delay2 = delay2-1;
	}
	if(data =='n') {
        delay3 = delay3+1;
	}
	if(data =='m') {
        delay3 = delay3-1;
	}


    // Clear the RX interrupt Flag
    INTClearFlag(INT_SOURCE_UART_RX(UART3)); 
  }

  // We don't care about TX interrupt
  if(INTGetFlag(INT_SOURCE_UART_TX(UART3))) {
    INTClearFlag(INT_SOURCE_UART_TX(UART3));
  }
}
Exemple #22
0
void hal_uart_interrupt_handler(hal_uart_port port) {
    UART_MODULE uart = logic_uart2phy_uart(port);
    assert(port >= HAL_UART_PORT_1 && port <= HAL_UART_NUMBER_OF_PORTS );
    /* get the txbuffer to send */
    struct txbuffer_struct *buffer = get_tx_buffer(port);
    /* If the source of interrupt is the TXInterrupt, start
     * transmitting the data in output queue. */
    if (INTGetFlag(INT_SOURCE_UART_TX(uart))) {
        /* Clear interrupt to prevent reentry */
        INTClearFlag(INT_SOURCE_UART_TX(uart));
        /* if queue is not empty, send tx data to uart while available. */
        while (buffer->nbytes > 0) {
            if (UARTTransmitterIsReady(uart)) {
                UARTSendDataByte(uart, buffer->buffer[buffer->counter++]);
                /* decrement buffer count after byte was transmitted */
                buffer->nbytes --;
            } else {
                break;
            }
        }
        /* if queue is empty, disable tx interrupt. */
        if (buffer->nbytes <= 0) {
            INTEnable(INT_SOURCE_UART_TX(uart), INT_DISABLED);
            if(on_data_sent[port]!=NULL)
                on_data_sent[port](port);
        }
    }

    /* detect uart rx errors */
    if(INTGetFlag(INT_SOURCE_UART_ERROR(uart))){
        uint8_t in_byte = 0x00;
        hal_uart_error error = HAL_UART_ERR_NONE;
        volatile UART_LINE_STATUS  lineStatus = UARTGetLineStatus(uart);
        /* detect framming error. (break)*/
        /* Framing error are only valid if data is available in buffer. */
        if(UART_FRAMING_ERROR & lineStatus){
            /* trigger an on_data_received_callback */
            error = HAL_UART_ERR_FRAMMING;
        }
        /* detect uart overrun errors. */
        if(UART_OVERRUN_ERROR & lineStatus)
        {
            error = HAL_UART_ERR_OVERRUN;
            /* TODO: Not sure what to do if buffer overruns (it means data
             * arrives faster than we are able to process. So just
             * clear error and continue with our lives as nothing happened.
             */
            UARTClearOverrunError(uart);
        }
        if(UART_PARITY_ERROR & lineStatus){
            error = HAL_UART_ERR_PARITY;
        }
        if(UARTReceivedDataIsAvailable(uart)){
            in_byte = UARTGetDataByte(uart);
        }
        if(on_data_received[port]!=NULL)
            on_data_received[port](port,in_byte,error);
        /* clear the error flag. */
        INTClearFlag(INT_SOURCE_UART_ERROR(uart));
    }
    
    /* If receive interrupt was triggered, feed user apps with data. */
    if (INTGetFlag(INT_SOURCE_UART_RX(uart))) {
        /* Clear interrupt to prevent reentry */
        INTClearFlag(INT_SOURCE_UART_RX(uart));
        /* Copy the received data into input buffer */
        while (UARTReceivedDataIsAvailable(uart)) {
            uint8_t c = UARTGetDataByte(uart);
            if(on_data_received[port]!=NULL)
                on_data_received[port](port, c,HAL_UART_ERR_NONE);
        }
    }
}
Exemple #23
0
BYTE UARTReceiveByte(UART_MODULE uart)
{
      return UARTGetDataByte(uart); //This function is only called when receive data is ready, therefore no check is needed
}
Exemple #24
0
void __ISR(_UART_6_VECTOR, U6_INTERRUPT_PRIORITY) Uart6InterruptHandler(void)
{
  UINT8  i
        ,iMax   // Read/write max 8 bytes/interrupt
        ,data   // used in UartFifoWrite/Read functions
        ;

  if ( INTGetFlag ( INT_SOURCE_UART_ERROR(UART6)) )
  {
    LED_ERROR_ON;
    INTClearFlag(INT_SOURCE_UART_ERROR(UART6));
  }
  
	// TX interrupt handling
  //===========================================================
  if ( INTGetEnable ( INT_SOURCE_UART_TX(UART6) ) )               // If TX interrupts enabled
  {
    if ( INTGetFlag ( INT_SOURCE_UART_TX(UART6) ) )               // If TX interrupt occured
    {
      if ( UARTTransmitterIsReady(UART6) && !Uart.Var.uartTxFifo[UART6].bufEmpty )  // If TX buffer is ready to receive data and the user's TX buffer is not empty
      {
        if (Uart.Var.uartTxFifo[UART6].lineBuffer.length < 8)     // Write max 8 bytes/interrupt
        {
          iMax = Uart.Var.uartTxFifo[UART6].lineBuffer.length;
        }
        else
        {
          iMax = 8;
        }

        for (i = 0; i < iMax; i++)
        {
          UartFifoRead((void *) &Uart.Var.uartTxFifo[UART6], &data);  // Copy from user
          U6TXREG = data;                                         // Put data in PIC32's TX buffer
        }
      }

      if (Uart.Var.uartTxFifo[UART6].bufEmpty)                    // If User's TX buffer is empty
      {
        Uart.DisableTxInterrupts(UART6);                          // Disable TX interrupts
      }

      INTClearFlag(INT_SOURCE_UART_TX(UART6));                    // Clear the TX interrupt Flag
    }
  }
  //===========================================================
  

	// RX interrupt handling
  //===========================================================
  if ( INTGetEnable ( INT_SOURCE_UART_RX(UART6) ) )               // If RX interrupts enabled
  {
    if ( INTGetFlag ( INT_SOURCE_UART_RX(UART6) ) )               // If RX interrupt occured
    {
      i = 0;
      iMax = 8;                                                   // Read max 8 bytes/interrupt
      while (   UARTReceivedDataIsAvailable(UART6)                // While RX data available
            && !Uart.Var.uartRxFifo[UART6].bufFull                // and user's RX buffer not full
            && (i < iMax)                                         // and under 8 bytes read
            )
      { // while ^
        data = UARTGetDataByte(UART6);                            // Get data for PIC32's RX FIFO buffer and copy it to user (next line)
        if ( UartFifoWrite((void *) &Uart.Var.uartRxFifo[UART6], &data) < 0 ) // If copy to user did not work
        {
          break;                                                  // Exit while loop
        }
        i++;
      } // end while

      if (!Uart.Var.uartRxFifo[UART6].bufEmpty)                   // If there is data in the user's RX buffer
      {
        Uart.Var.oIsRxDataAvailable[UART6] = 1;                   // Set according flag
      }

      INTClearFlag (INT_SOURCE_UART_RX(UART6) );                  // Clear the RX interrupt Flag

    }
	}
  //===========================================================
}
Exemple #25
0
int GetCharacter(UART_MODULE id) {
    while (!UARTReceivedDataIsAvailable(id));
        return UARTGetDataByte(id);
}
Exemple #26
0
void __ISR(_UART_2_VECTOR, IPL5SOFT) UART2_isr(void)
{
   uint8_t ErrFiFoFull = 0;
   uint8_t freeSize, TXsize;
   int8_t c;
   uint8_t i_cts = 0;
   BOOL  TxPossible;

   UART_LINE_STATUS lineStatus;



    // Is this an RX interrupt ?
    if ( INTGetFlag(INT_U2RX) && INTGetEnable(INT_U2RX) ) {


        // oui Test si erreur comm
        lineStatus = UARTGetLineStatus(UART2);

        if ( (lineStatus & (UART_PARITY_ERROR | UART_FRAMING_ERROR |
                            UART_OVERRUN_ERROR)) == 0) {
             // transfert dans le fifo de tous les caractères recu
             while (UARTReceivedDataIsAvailable(UART2))
             {
                 c = UARTGetDataByte(UART2);
                 PutCharInFifo ( &descrFifoRX, c);
             }
             INTClearFlag(INT_U2RX); // buffer is empty, clear interrupt flag

        } else {
             UART2ClearAllErrors();   // Macro C32
        }

         freeSize = GetWriteSpace ( &descrFifoRX);
         if (freeSize <= 6 )        // a cause d'un int pour 6 char
         {
            // Demande de ne plus émettre
            //RS232_RTS = 1;

            if (freeSize == 0) {
                 ErrFiFoFull = 1;    // pour debugging si probème ctrl flux
            }
        }
    } // end if RX

    // Is this an TX interrupt ?
    if(INTGetFlag(INT_U2TX) && INTGetEnable(INT_U2TX)  ) {


         TXsize = GetReadSize (&descrFifoTX);
         // i_cts = input(RS232_CTS);
         // On vérifie 3 conditions :
         //    Si CTS = 0 (autorisation d'émettre)
         //    Si il y a un caratères à émettre
         //    Si le txreg est bien disponible

         //i_cts = RS232_CTS;

         TxPossible = UARTTransmitterIsReady(UART2);
         //if ( (i_cts == 0) && ( TXsize > 0 ) && TxPossible )  {
         if (  ( TXsize > 0 ) && TxPossible )  {
             do {
                 GetCharFromFifo(&descrFifoTX, &c);

                 UARTSendDataByte(UART2, c);
                 //i_cts = RS232_CTS;
                 TXsize = GetReadSize (&descrFifoTX);
                 TxPossible = UARTTransmitterIsReady(UART2);

             //} while ( (i_cts == 0) && ( TXsize > 0 ) && TxPossible  );
             } while (  ( TXsize > 0 ) && TxPossible  );
            // Clear the TX interrupt Flag (Seulement aprés TX)
            INTClearFlag(INT_U2TX);
        } else {
           // disable TX interrupt
           INTEnable(INT_U2TX, INT_DISABLED);
        }
    }
} // UART_isr