/*----------------------------------------------------------------------
* FILE:  uart_functions.h
*-----------------------------------------------------------------------
*             (C) Copyright 2001 Metrowerks Corp.
*                 ALL RIGHTS RESERVED .
*
*   THIS IS  CONFIDENTIAL  PROPRIETARY SOURCE CODE OF METROWERKS CORP.
*
*          The copyright notice above does not evidence any
*         actual or intended publication of such source code.
*-----------------------------------------------------------------------
*
* DESCRIPTION: UARTs loopback test on the TORTOLA (i.mx31) board
*              Common UARTs function defines/macro
*
* REFERENCES: 
*      1) TORTOLA spec
*
* HISTORY:
*
* 01 Feb  2005 zeldal	Created
*
*--------------------------------------------------------------------------*/

#ifndef UART_FUNCTIONS_H__
#define UART_FUNCTIONS_H__  /* Prevent multiple inclusions */
#include "verif_common.h"    /* Common functions of verification environment */

// ========================================================================= //
// -- Definitions to define the access width for UART registers ------------ //
// ========================================================================= //
#define RDY_TIMEOUT 0xf0000
#define IDLE_TIMEOUT 0xf00000
// Assumed size of a register, must match the following two definitions
#define  UART_REGSIZE unsigned short //UINT16

// Operation to perform register reads, must match above register size
#define  UART_READ_OP reg16read

// Operation to perform register writes, must match above register size
#define  UART_WRITE_OP reg16write

// Operation to request register comparisons for CheckTest
#define  UART_COMPARE_OP PutCheck16


// The higher order bits (15:8) of this register contain status information;
//  these bits are set to 0x80xx when the retrieved data is valid (with the
//  exception of the 32nd character in the RxFIFO, here use the macro below.
#define uart_compare_data_valid(byte) \
   uart_compare(URXD, (0x8000|(byte)));
// For the last character in the RxFIFO the OVERRUN and ERR bits are set also.
#define uart_compare_lastdata_valid(byte) \
   uart_compare(URXD, (0xE000|(byte)));
// ========================================================================= //
// -- Shortcuts for the most common accesses, use register names ----------- //
// ========================================================================= //

#define  uart_read(name) \
         UART_READ_OP((UART_REG_##name))

#define  uart_write(name,newvalue) \
         UART_WRITE_OP((UART_REG_##name),(newvalue))

#define  uart_compare(name,expected) \
         UART_COMPARE_OP((UART_REG_##name),(expected))

#define  uart_setbit(name,bitpos) \
         UART_WRITE_OP((UART_REG_##name), \
                       (UART_READ_OP(UART_REG_##name) | (1<<(bitpos))))

#define  uart_clrbit(name,bitpos) \
         UART_WRITE_OP((UART_REG_##name), \
                       (UART_READ_OP(UART_REG_##name) & (0xFFFF ^ (1<<(bitpos)))))

#define  uart_checkbit_set(name, bitpos) \
         CheckValue((UART_READ_OP((UART_REG_##name))&(1<<(bitpos))), \
                    (1<<(bitpos)))

#define  uart_checkbit_clr(name, bitpos) \
         CheckValue((UART_READ_OP((UART_REG_##name))&(1<<(bitpos))), 0)

#define UART_ENABLE uart_setbit(UCR1, UART_UCR1_UARTEN_BP)

int UART_RESET( int Enable );
int UART_WAIT_FOR_RRDY_SET(void);
void HIGHEST_BAUDRATE( void );
void BAUDRATE_1875Kbps( void );
void BAUDRATE_1152Kbps( void );
void BAUDRATE_920Kbps( void );
void BAUDRATE_812_5Kbps( void );
void BAUDRATE_460Kbps( void );
void BAUDRATE_230Kbps( void );
void BAUDRATE_115_2Kbps( void );
void BAUDRATE_57_6Kbps( void );
void BAUDRATE_28_8Kbps( void );
void BAUDRATE_19_2Kbps( void );
void BAUDRATE_14_4Kbps( void );
void BAUDRATE_9600bps( void );
void BAUDRATE_4800bps( void );
void BAUDRATE_2400bps( void );
void BAUDRATE_1200bps( void );
void BAUDRATE_600bps( void );
//void WAIT_FOR_SET( unsigned long Addr, UART_REGSIZE ExpectedMask );
//void WAIT_FOR_CLR( unsigned long Addr, UART_REGSIZE ExpectedMask );
void UART_WAIT_FOR_TXDC_SET( void );
int UART_WAIT_FOR_RDR_SET( void );
int UART_WAIT_FOR_IDLE_SET( void );
void uart_setup_iomux( void );
void uart_setup_ccm( void );
int UART_SWRESET( void );
UINT08 UART_READ_BYTE( void );
void UART_WRITE_BYTE( UINT08 WriteValue );
void WAIT_FOR_SET( unsigned long Addr, UART_REGSIZE ExpectedMask );
void WAIT_FOR_CLR( unsigned long Addr, UART_REGSIZE ExpectedMask );

#endif  /* #ifndef UART_FUNCTIONS_H__ */

