#### File: D:\bobes\0 skola\_car4\my matlab\HIL - PID speed\firmware\Vejlupek_Car4_HIL_PIDSpeed_dspic\sources\dsPIC_UART2_Interrupt.c
        1   #include "p33fxxxx.h"
        2   #include "Vejlupek_Car4_HIL_PIDSpeed.h"
        3   #include "Vejlupek_Car4_HIL_PIDSpeed_private.h"
        4
        5   /* Tx Variables */
        6   #define Tx_BUFF_SIZE_Uart2             32
        7
        8   volatile uint8_T TxTab_Uart2[Tx_BUFF_SIZE_Uart2];
        9   volatile uint8_T TxPtrHaut_Uart2 = 0;
       10   volatile uint8_T TxPtrBas_Uart2 = 0;
       11
       12   /* Rx Variables */
       13   #define Rx_BUFF_SIZE_Uart2             32
       14
       15   volatile uint8_T RxTab_Uart2[Rx_BUFF_SIZE_Uart2];
       16   volatile uint8_T RxPtrHaut_Uart2 = 0;
       17   volatile uint8_T RxPtrBas_Uart2 = 0;
       18   void __attribute__((__interrupt__)) _U2TXInterrupt(void)
       19   {
       20     _U2TXIF = 0;
       21     while ((U2STAbits.UTXBF == 0) && (TxPtrHaut_Uart2 != TxPtrBas_Uart2) ) {/* while UxTXREG buffer is not full */
       22       U2TXREG = TxTab_Uart2[TxPtrBas_Uart2];
       23       TxPtrBas_Uart2 = (TxPtrBas_Uart2 + 1) & (Tx_BUFF_SIZE_Uart2-1);
       24     }
       25
       26     if (TxPtrHaut_Uart2 == TxPtrBas_Uart2)
       27       _U2TXIE = 0;                       /* remove interrupt  */
       28   }
       29
       30   void __attribute__((__interrupt__)) _U2RXInterrupt(void)
       31   {
       32     uint8_T Tmp;
       33     Tmp = ~(RxPtrHaut_Uart2 - RxPtrBas_Uart2);/* Tmp = 7 - (Haut - Bas) modulo buffersize	*/
       34     Tmp = Tmp & (Rx_BUFF_SIZE_Uart2-1);
       35     _U2RXIF = 0;
       36     while ((Tmp--) && (U2STAbits.URXDA == 1)) {
       37       RxTab_Uart2[RxPtrHaut_Uart2++] = (uint8_T) U2RXREG;
       38       RxPtrHaut_Uart2 &= (Rx_BUFF_SIZE_Uart2-1);
       39     }
       40
       41     if (U2STAbits.OERR == 1)
       42       U2STAbits.OERR = 0;                /* Buffer Overflow cleared */
       43   }