/*
 *  Copyright 2007 by Texas Instruments Incorporated.
 *  All rights reserved. Property of Texas Instruments Incorporated.
 *  Restricted rights to use, duplicate or disclose this code are
 *  granted through contract.
 *
 *  @(#) TCP/IP_Network_Developers_Kit 1.92.00.22 01-10-2007 (ndk-b22)
 */
/*
 *  Copyright 2005 by Spectrum Digital Incorporated.
 *  All rights reserved. Property of Spectrum Digital Incorporated.
 */

/*
 *  ======== dsk6455.h ========
 *
 *  This file contains DSK6455 board initialization and CPLD register access
 *  functions.
 */

/*
 *  BSL Version #3.20
 */

#ifndef DSK6455_
#define DSK6455_

#ifdef __cplusplus
extern "C" {
#endif

#include <stdio.h>
#include <std.h>
#include <sys.h>

/*
 *  Note:  Bit definitions for each register field
 *         needs to be supplied here for the CPLD
 *         and other board periperals.
 */

/* Initialize all board APIs */
void DSK6455_init();

/* Spin in a delay loop for delay iterations */
void DSK6455_wait(Uint32 delay);

/* Spin in a delay loop for delay microseconds */
void DSK6455_waitusec(Uint32 delay);

/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  I2C Controller                                                          *
 *                                                                          *
 * ------------------------------------------------------------------------ */
#define I2C_BASE            0x02B04000
#define I2C_OAR             *( volatile Uint32* )( I2C_BASE + 0x00 )
#define I2C_ICIMR           *( volatile Uint32* )( I2C_BASE + 0x04 )
#define I2C_ICSTR           *( volatile Uint32* )( I2C_BASE + 0x08 )
#define I2C_ICCLKL          *( volatile Uint32* )( I2C_BASE + 0x0C )
#define I2C_ICCLKH          *( volatile Uint32* )( I2C_BASE + 0x10 )
#define I2C_ICCNT           *( volatile Uint32* )( I2C_BASE + 0x14 )
#define I2C_ICDRR           *( volatile Uint32* )( I2C_BASE + 0x18 )
#define I2C_ICSAR           *( volatile Uint32* )( I2C_BASE + 0x1C )
#define I2C_ICDXR           *( volatile Uint32* )( I2C_BASE + 0x20 )
#define I2C_ICMDR           *( volatile Uint32* )( I2C_BASE + 0x24 )
#define I2C_ICIVR           *( volatile Uint32* )( I2C_BASE + 0x28 )
#define I2C_ICEMDR          *( volatile Uint32* )( I2C_BASE + 0x2C )
#define I2C_ICPSC           *( volatile Uint32* )( I2C_BASE + 0x30 )
#define I2C_ICPFUNC         *( volatile Uint32* )( I2C_BASE + 0x48 )
#define I2C_ICPDIR          *( volatile Uint32* )( I2C_BASE + 0x4C )
#define I2C_ICPDIN          *( volatile Uint32* )( I2C_BASE + 0x50 )
#define I2C_ICPDOUT         *( volatile Uint32* )( I2C_BASE + 0x54 )
#define I2C_ICPDSET         *( volatile Uint32* )( I2C_BASE + 0x58 )
#define I2C_ICPDCLR         *( volatile Uint32* )( I2C_BASE + 0x5C )

/* I2C Field Definitions */
#define ICOAR_MASK_7        0x007F
#define ICOAR_MASK_10       0x03FF
#define ICSAR_MASK_7        0x007F
#define ICSAR_MASK_10       0x03FF
#define ICOAR_OADDR         0x007f
#define ICSAR_SADDR         0x0050

#define ICSTR_BB            0x1000
#define ICSTR_RSFULL        0x0800
#define ICSTR_XSMT          0x0400
#define ICSTR_AAS           0x0200
#define ICSTR_AD0           0x0100
#define ICSTR_ICXRDY        0x0010
#define ICSTR_ICRRDY        0x0008
#define ICSTR_ARDY          0x0004
#define ICSTR_NACK          0x0002
#define ICSTR_AL            0x0001

#define ICMDR_FREE          0x4000
#define ICMDR_STT           0x2000
#define ICMDR_IDLEEN        0x1000
#define ICMDR_STP           0x0800
#define ICMDR_MST           0x0400
#define ICMDR_TRX           0x0200
#define ICMDR_XA            0x0100
#define ICMDR_RM            0x0080
#define ICMDR_DLB           0x0040
#define ICMDR_IRS           0x0020
#define ICMDR_STB           0x0010
#define ICMDR_FDF           0x0008
#define ICMDR_BC_MASK       0x0007

/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  I2C Prototypes                                                          *
 *                                                                          *
 * ------------------------------------------------------------------------ */
Int16 DSK6455_I2C_init ( );
Int16 DSK6455_I2C_write( Uint16 slaveaddr, Uint8* data, Uint16 len );
Int16 DSK6455_I2C_read ( Uint16 slaveaddr, Uint8* data, Uint16 len );


/* I2C Address */
#define EEPROM_I2C_ADDR             0x50

/* EEPROM specific settings */
#define EEPROM_PAGE_SIZE            64
#define EEPROM_PAGE_SIZE_POW2       6
#define EEPROM_MAX_BURST_LEN        EEPROM_PAGE_SIZE

/* ------------------------------------------------------------------------ *
 *  EEPROM Prototypes                                                       *
 * ------------------------------------------------------------------------ */
Int16 DSK6455_EEPROM_read ( Uint32 src, Uint32 dst, Uint32 length );

#ifdef __cplusplus
}
#endif

#endif
