/***************************************************************************************************
  Filename:       hal_uart_ti.h
  Revised:        $Date: $
  Revision:       $Revision: $

  Description:    Low Level UART intfc

 **************************************************************************************************/


#ifndef HAL_UART_TI_H
#define HAL_UART_TI_H

#include <stdint.h>
#include <stdbool.h>
#include "ComTypeDefs.h"

/**************************************************************************************************
 *                                          CONSTANTS
 **************************************************************************************************/



/**************************************************************************************************
 *                                      TYPEDEFS / STRUCTS
 **************************************************************************************************/

typedef enum 
{
    HAL_UART_STATUS_SUCCESS = 0,
    HAL_UART_STATUS_BAD_PORT,  
    HAL_UART_STATUS_BAD_BAUD,
    HAL_UART_STATUS_QUEUE_EMPTY,  
    HAL_UART_STATUS_QUEUE_FULL,
    HAL_UART_STATUS_BUS_CONTENTION,
    HAL_UART_STATUS_TX_ACTIVE,
    HAL_UART_STATUS_ERROR = 0xFF
} uartStatus_t;

typedef enum 
{
    HAL_UART_BR_1200   = 1200,
    HAL_UART_BR_2400   = 2400,
    HAL_UART_BR_4800   = 4800,
    HAL_UART_BR_9600   = 9600,
    HAL_UART_BR_19200  = 19200,
    HAL_UART_BR_38400  = 38400,
    HAL_UART_BR_57600  = 57600,
    HAL_UART_BR_115200 = 115200
} uartBaudRate_t;


typedef enum 
{
//#ifdef HAL_UART_ENABLE_PORT_0
    HAL_UART_PORT_0 = 0,
//#endif
//#ifdef HAL_UART_ENABLE_PORT_1
    HAL_UART_PORT_1,
//#endif  
    HAL_UART_PORT_MAX  
} uartPorts_t;

typedef void (*halUARTCBack_t) (uartPorts_t port, uint8_t unused);

_Pragma("pack(1)") 
typedef struct
{
    uint16_t maxBufSize;
} halUARTBufControl_t;

typedef struct
{
    bool                configured;   // unused
    uartBaudRate_t      baudRate;
    bool                flowControl;  // unused
    uint16_t              flowControlThreshold;  // unused
    uint8_t               idleTimeout;  // unused
    halUARTBufControl_t rx;
    halUARTBufControl_t tx;
    bool                intEnable;    // unused
    uint32_t              rxChRvdTime;  // unused
    halUARTCBack_t      callBackFunc;
} halUARTCfg_t;
_Pragma("pack()") 

extern halUARTCBack_t halUartRxCallback;

/**************************************************************************************************
 *                                        FUNCTIONS - PUBLIC API
 **************************************************************************************************/

//extern void HalUARTInit( void );
extern uartStatus_t HalUARTOpen ( uartPorts_t port, halUARTCfg_t *config, void *rxBuffer, void *txBuffer );
extern uint16_t HalUARTRead( uartPorts_t port, uint8_t *dest, uint16_t length );
extern uint16_t HalUARTWrite( uartPorts_t port, uint8_t *src, uint16_t length );
extern void HalUARTPoll( void );
extern bool HalUARTRxEmpty( uartPorts_t port );
extern void HalUARTRxFlush( uartPorts_t port );
extern bool HalUARTTxEmpty( uartPorts_t port );
extern uint16_t HalUARTTxBytesAvailable( uartPorts_t port );
extern void HalUARTTxForcedZero( uartPorts_t port );
extern uartStatus_t HalUARTTxStartTransmit( uartPorts_t port );

#endif //HAL_UART_TI_H
