#### File: D:\bobes\0 skola\_car4\my matlab\HIL - PID speed\firmware\Vejlupek_Car4_HIL_PIDSpeed_dspic\sources\dsPIC_UART1_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_Uart1             32
        7
        8   volatile uint8_T TxTab_Uart1[Tx_BUFF_SIZE_Uart1];
        9   volatile uint8_T TxPtrHaut_Uart1 = 0;
       10   volatile uint8_T TxPtrBas_Uart1 = 0;
       11
       12   /* Rx Variables */
       13   #define Rx_BUFF_SIZE_Uart1             32
       14
       15   volatile uint8_T RxTab_Uart1[Rx_BUFF_SIZE_Uart1];
       16   volatile uint8_T RxPtrHaut_Uart1 = 0;
       17   volatile uint8_T RxPtrBas_Uart1 = 0;
       18   void __attribute__((__interrupt__)) _U1TXInterrupt(void)
       19   {
       20     _U1TXIF = 0;
       21     while ((U1STAbits.UTXBF == 0) && (TxPtrHaut_Uart1 != TxPtrBas_Uart1) ) {/* while UxTXREG buffer is not full */
       22       U1TXREG = TxTab_Uart1[TxPtrBas_Uart1];
       23       TxPtrBas_Uart1 = (TxPtrBas_Uart1 + 1) & (Tx_BUFF_SIZE_Uart1-1);
       24     }
       25
       26     if (TxPtrHaut_Uart1 == TxPtrBas_Uart1)
       27       _U1TXIE = 0;                       /* remove interrupt  */
       28   }
       29
       30   void __attribute__((__interrupt__)) _U1RXInterrupt(void)
       31   {
       32     uint8_T Tmp;
       33     Tmp = ~(RxPtrHaut_Uart1 - RxPtrBas_Uart1);/* Tmp = 7 - (Haut - Bas) modulo buffersize	*/
       34     Tmp = Tmp & (Rx_BUFF_SIZE_Uart1-1);
       35     _U1RXIF = 0;
       36     while ((Tmp--) && (U1STAbits.URXDA == 1)) {
       37       RxTab_Uart1[RxPtrHaut_Uart1++] = (uint8_T) U1RXREG;
       38       RxPtrHaut_Uart1 &= (Rx_BUFF_SIZE_Uart1-1);
       39     }
       40
       41     if (U1STAbits.OERR == 1)
       42       U1STAbits.OERR = 0;                /* Buffer Overflow cleared */
       43   }