/* ------------------------------------------------------------------------------------------------ */
/* FILE :		avr32_uart.h																		*/
/*																									*/
/* CONTENTS :																						*/
/*				Driver for the AVR32 chip familly from Atmel (Micriochip)							*/
/*																									*/
/*																									*/
/* Copyright (c) 2017, Code-Time Technologies Inc. All rights reserved.								*/
/*																									*/
/* Redistribution and use in source and binary forms, with or without								*/
/* modification, are permitted provided that the following conditions are met:						*/
/*																									*/
/* 1. Redistributions of source code must retain the above copyright notice, this					*/
/*    list of conditions and the following disclaimer.												*/
/* 2. Redistributions in binary form must reproduce the above copyright notice,						*/
/*    this list of conditions and the following disclaimer in the documentation						*/
/*    and/or other materials provided with the distribution.										*/
/*																									*/
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND					*/
/* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED					*/
/* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE							*/
/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR					*/
/* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES					*/
/* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;						*/
/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND						*/
/* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT						*/
/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS					*/
/* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.										*/
/*																									*/
/*																									*/
/*	$Revision: 1.8 $																				*/
/*	$Date: 2013/10/03 15:55:16 $																	*/
/*																									*/
/* ------------------------------------------------------------------------------------------------ */

#ifndef __AVR32_UART_H
#define __AVR32_UART_H

#ifdef __cplusplus
 extern "C" {
#endif

/* ------------------------------------------------------------------------------------------------ */

#ifndef OS_PLATFORM
  #define OS_PLATFORM 0x003C1766					/* Default platform is Olimex LPC1766-STK		*/
#endif

/* ------------------------------------------------------------------------------------------------ */

#if defined(UART_MAX_DEVICES) && defined(UART_LIST_DEVICE)
  #error "Define one of the two: UART_MAX_DEVICES or UART_LIST_DEVICE"
  #error "Do not define both as there could be conflicting info"
#endif

#if !defined(UART_MAX_DEVICES) && !defined(UART_LIST_DEVICE)
  #if (((OS_PLATFORM) & 0x00FFF000) == 0x00AEA000)
	#define UART_MAX_DEVICES	4

  #else
	#define UART_MAX_DEVICES	1
  #endif
#endif

#ifndef UART_LIST_DEVICE
  #define UART_LIST_DEVICE	((1U<<(UART_MAX_DEVICES))-1U)
#endif

/* ------------------------------------------------------------------------------------------------ */
/* Input & output character filter control masks													*/

#define UART_FILT_IN_CR_CRLF	(1U<<0)				/* Replace input  CR by CR LF					*/
#define UART_FILT_IN_CR_LF		(1U<<1)				/* Replace input  CR by LF						*/
#define UART_FILT_IN_CR_DROP	(1U<<2)				/* Remove all CR received						*/
#define UART_FILT_IN_LF_CRLF	(1U<<3)				/* Replace input  LF by CR LF					*/
#define UART_FILT_IN_LF_CR		(1U<<4)				/* Replace input  LF by CR						*/
#define UART_FILT_IN_LF_DROP	(1U<<5)				/* Remove all LF received						*/
#define UART_FILT_OUT_CR_CRLF	(1U<<6)				/* Replace output CR by CR LF					*/
#define UART_FILT_OUT_CR_LF		(1U<<7)				/* Replace output CR by LF						*/
#define UART_FILT_OUT_CR_DROP	(1U<<8)				/* Remove all CR to output						*/
#define UART_FILT_OUT_LF_CRLF	(1U<<9)				/* Replace output LF by CR LF					*/
#define UART_FILT_OUT_LF_CR		(1U<<10)			/* Replace output LF by CR						*/
#define UART_FILT_OUT_LF_DROP	(1U<<11)			/* Remove all LF to output						*/
#define UART_ECHO				(1U<<12)			/* Echo input to output							*/
#define UART_ECHO_BS_EXPAND		(1U<<13)			/* When echoing, do <BS><SPACE><BS>				*/

/* ------------------------------------------------------------------------------------------------ */

int uart_init(int Dev, int Baud, int Nbits, int Parity, int Stop, int RXsize, int TXsize,int Filter);
int uart_recv(int Dev, char *Buff, int Len);
int uart_send(int Dev, const char *Buff, int Len);

/* ------------------------------------------------------------------------------------------------ */

#if (((UART_LIST_DEVICE) & 0x001) != 0)
  extern void UARTintHndl_0(void);
#endif
#if (((UART_LIST_DEVICE) & 0x002) != 0)
  extern void UARTintHndl_1(void);
#endif
#if (((UART_LIST_DEVICE) & 0x004) != 0)
  extern void UARTintHndl_2(void);
#endif
#if (((UART_LIST_DEVICE) & 0x008) != 0)
  extern void UARTintHndl_3(void);
#endif
#if (((UART_LIST_DEVICE) & 0x010) != 0)
  extern void UARTintHndl_4(void);
#endif
#if (((UART_LIST_DEVICE) & 0x020) != 0)
  extern void UARTintHndl_5(void);
#endif
#if (((UART_LIST_DEVICE) & 0x040) != 0)
  extern void UARTintHndl_6(void);
#endif
#if (((UART_LIST_DEVICE) & 0x080) != 0)
  extern void UARTintHndl_7(void);
#endif
#if (((UART_LIST_DEVICE) & 0x100) != 0)
  extern void UARTintHndl_8(void);
#endif
#if (((UART_LIST_DEVICE) & 0x200) != 0)
  extern void UARTintHndl_9(void);
#endif

/* ------------------------------------------------------------------------------------------------ */

#ifdef __cplusplus
}
#endif

#endif

/* EOF */
