/*
 * FreeRTOS Kernel V10.3.1
 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * http://www.FreeRTOS.org
 * http://aws.amazon.com/freertos
 *
 * 1 tab == 4 spaces!
 */

#ifndef SERIAL_COMMS_H
#define SERIAL_COMMS_H
#include "cirq_buffer.h"
#include "log.h"
//#include "uart.h"
//#include "uart_cfg.h"
/*--------------------------------------------------------------------
 * uart
 *--------------------------------------------------------------------*/
#define DS_UART0				0/* peri0_uart1 */
#define DS_UART1				1/* peri1_uart0 */
#define DS_UART2				3/* peri1_uart2 */
#define EVB_UART0				1/* peri1_uart0 */
#define EVB_UART1				2/* peri1_uart1 */
#define EVB_UART2				3/* peri1_uart2 */
#define UART_SEL				EVB_UART1
#define SAF_TRUE		1u
#define SAF_FALSE	0u

#define PERI_BASE				0xE9400000
#define PERI_END				0xE9500000
#if 0
typedef enum
{
	serCOM1,
	serCOM2,
	serCOM3,
	serCOM4,
	serCOM5,
	serCOM6,
	serCOM7,
	serCOM8
} eCOMPort;
#endif
typedef enum
{
	serNO_PARITY,
	serODD_PARITY,
	serEVEN_PARITY,
	serMARK_PARITY,
	serSPACE_PARITY
} eParity;

typedef enum
{
	serSTOP_1,
	serSTOP_2
} eStopBits;

typedef enum
{
	serBITS_5,
	serBITS_6,
	serBITS_7,
	serBITS_8
} eDataBits;

typedef enum
{
	ser50,
	ser75,
	ser110,
	ser134,
	ser150,
	ser200,
	ser300,
	ser600,
	ser1200,
	ser1800,
	ser2400,
	ser4800,
	ser9600,
	ser19200,
	ser38400,
	ser57600,
	ser115200
} eBaud;
typedef struct
{
	//struct LINFlexD_tag * pUART;
	CirqBufferType TxCycBuffer;
	CirqBufferType RxCycBuffer;	
	uint32_t RxTrigger;						/*Rx Trigger Count*/
  	uint8_t TxProgress;       		/*Tx in progress*/
  	uint32_t RxDroped;						/*record uart droped bytes*/
  	uint32_t TxDroped;
} ST_UART_CHAN_DATA;

typedef void * xComPortHandle;

xComPortHandle xSerialPortInitMinimal(unsigned long ulWantedBaud, base_t uxQueueLength );
//xComPortHandle xSerialPortInit(eCOMPort ePort, eBaud eWantedBaud, eParity eWantedParity, eDataBits eWantedDataBits, eStopBits eWantedStopBits, unsigned base_t uxBufferLength);
void vSerialPutString( uint8_t ch,xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength );
base_t xSerialGetChar(uint8_t com,xComPortHandle pxPort, signed char *pcRxedChar, TickType_t xBlockTime);
extern void Lpuart_Uart_Ip_GetData(const uint8 Instance);


//base_t xSerialPutChar(Uart_Peri_Channel_e ch, xComPortHandle pxPort, signed char cOutChar, tickType xBlockTime );
//base_t xSerialWaitForSemaphore(xComPortHandle xPort);
//void vSerialClose(xComPortHandle xPort);

//void PeriUart_PinsInit(eCOMPort com);
//void PeriUart_ClkInit(eCOMPort com);
//void PeriUart_ComInit(eCOMPort com);
//void PeriUart_Baudrate(eCOMPort com, unsigned long baudrate);
//void PeriUart_RecvIntrEnable(Uart_Peri_Channel_e com);
//uint32_t ulPeriUartIntrStatus(Uart_Peri_Channel_e ch);
//uint8_t ucPeriUartInitStatus(Uart_Peri_Channel_e com);
//void PeriUart_Init(eCOMPort com, unsigned long baudrate);
//uint8_t PeriUart_Init();
//uint8_t PeriUart_Getc(Uart_Peri_Channel_e com);
//void PeriUart_Putc(Uart_Peri_Channel_e ch, uint8_t c);
//extern uint8_t ucUartChSelect; 
//extern uint8_t ucUartChType;
//extern Uart_Peri_ChCfg_t xUart_Peri_ChCfg[UART_PERI_MAX];
#endif

