#include "p33fxxxx.h"
#include <uart.h>
#include "Vejlupek_Car4_HIL_PIDSpeed.h"
#include "Vejlupek_Car4_HIL_PIDSpeed_private.h"

uint8_T send232Buff_Uart1(int16_T valeur, uint8_T cannal)
{                                      /*  0U -- 63U */
  uint8_T Tmp;
  uint8_T Tmp2;
  Tmp = ~(TxPtrHaut_Uart1 - TxPtrBas_Uart1);/* Tmp = 7 - (Haut - Bas) modulo 32	*/
  Tmp = Tmp & (Tx_BUFF_SIZE_Uart1-1);
  Tmp2 = (cannal & 0x03)+2;            /*	 Nbr bits a envoye */
  if (Tmp >= Tmp2) {                   /*  Si on a la place ds le buffer d'envoye */
    TxTab_Uart1[TxPtrHaut_Uart1] = ((cannal << 2) & 0xFC) | 1;

    /* envoie 6 derniers bits du canal et bit 1=0 ; bit 0=1 */
    /* signature octet controle en poids faible	*/
    TxPtrHaut_Uart1 = (TxPtrHaut_Uart1 + 1) & (Tx_BUFF_SIZE_Uart1-1);
    for (Tmp=1; Tmp < Tmp2 ; Tmp++) {
      TxTab_Uart1[TxPtrHaut_Uart1] = valeur & 0xFF;
      valeur = valeur >> 8;
      TxPtrHaut_Uart1 = (TxPtrHaut_Uart1 + 1) & (Tx_BUFF_SIZE_Uart1-1);
    }

    Tmp = 0;                           /* bufferisation reussit	*/
    _U1TXIF = 1;
    _U1TXIE = 1;
  } else
    Tmp = 1;
  return Tmp;
}
