/**
 * \file   plat_i2c.h
 *
 *  \brief 
 *
*/
/*
 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
 */

#ifndef _PLAT_I2C_H
#define _PLAT_I2C_H
/* ========================================================================== */
/*                             Include Files                                  */
/* ========================================================================== */
#include "plat_utils.h"
/* ========================================================================== */
/*                           Macros & Typedefs                                */
/* ========================================================================== */
#define I2_INSTANCE_0           0
#define I2_INSTANCE_1           1

#define I2C_TIMEOUT             1000
#define I2C_DELAY_MILLI_SEC     1
#define I2C_DELAY_CYCLES	    100


typedef void (*I2CDELAY_FN)(unsigned int delay);
/* ========================================================================== */
/*                         Structures and Enums                               */
/* ========================================================================== */

/* ========================================================================== */
/*                            Global Variables Declarations                   */
/* ========================================================================== */

/* ========================================================================== */
/*                          Function Declarations                             */
/* ========================================================================== */
/**
 * \brief   Routine to register sleep function.
 *     Setting an OS provided sleep function (For ex - Task_sleep)  as the delay
 *     function enables i2c APIs to sleep in between i2c operations ( instead of 
 *     going to a tight loop ).
 *     Note that, on sysbios, from main, no i2c APIs shall be called after 
 *     this call as calling Task_sleep is not allowed from main.
 *    
 *
 * \param   fn  Pointer to sleep fucntion    
 *
 *
 * \return  None.
 *
 **/
void I2CSetDelayFn(I2CDELAY_FN fn);
/**
 * \brief   Intilializes the I2C instance module. If this is called multiple times
 *          from an application, initialization will be done only once.
 *
 * \param   i2c_instance        i2c instance number 
 *
 *
 * \return  SUCCESS or FAIL.
 *
 **/
short I2CInit(unsigned char i2c_instance);
/**
 * \brief   De initializes i2c module
 *
 * \param   instance    i2c instance number
 *
 *
 * \return  SUCCESS or FAIL.
 *
 **/
short I2CDeInit( unsigned char instance);
/**
 * \brief   Renitializes i2c instance even it is already intitalized.
 *
 * \param   instance    i2c instance number
 *
 *
 * \return  SUCCESS or FAIL.
 *
 **/
short I2CReInit( unsigned char instance);

/**
 * \brief   Rotuine to power up the i2c module
 *
 * \param   i2c_instance    i2c instance number
 *
 *
 * \return  None.
 *
 **/
void I2CPowerup(unsigned char i2c_instance);
/**
 * \brief   Initialize i2c - Deprecated function
 *
 * \param   i2c_instance    i2c instance number
 * \param   slaveAdd    slave address
 *
 *
 * \return  None.
 *
 **/
void SetupI2C(unsigned char i2c_instance,unsigned int slaveAdd);
/**
 * \brief   Transmit data on i2c - Deprecated function 
 *
 * \param   i2c_instance    i2c instance number
 * \param   data        data to be transmitted
 * \param   output      output 
 *
 *
 * \return  None.
 *
 **/
void SetupI2CTransmitMan(unsigned char i2c_instance,unsigned char data,unsigned char output);
/**
 * \brief   Clear all interrupts
 *
 * \param   i2c_instance    i2c instance number
 *
 *
 * \return  None.
 *
 **/
void CleanUpInterrupts(unsigned char i2c_instance);
/**
 * \brief   Recieve data on i2c -  Deprecated function
 *
 * \param   i2c_instance   i2c instance number
 * \param   buff           Buffer to hold data read from i2c
 * \param   dcount         Number of bytes to be written
 *
 * \return  None.
 *
 **/
int SetupI2CReception(unsigned char i2c_instance,unsigned char* buff,unsigned int dcount);

/**
 * \brief    Write data on i2c bus
 *
 * \param   instance    i2c instance number
 * \param   slaveAdd    i2c Slave address
 * \param   buffer      Buffer having data to be written
 * \param   bufLen      number of bytes to be written
 * \param   dataWritten Data originally written 
 *
 *
 * \return  SUCCESS or FAIL.
 *
 **/
short I2CWrite(unsigned char   instance,
               unsigned short  slaveAdd,
               unsigned char   *buffer,
               unsigned char   bufLen,
               unsigned char   *dataWritten );

 /** 
 * \brief Routine to read data from slave device the I2C - 0
 *
 * This routine initializes the I2C controller for reading from the slave
 * peripheral connected to the bus. This function takes the slave address
 * as a parameter along with the read buffer pointer and the length of buffer.
 * This function returns the number of bytes read into the output length pointer.
 *
 * \param   busNum 		[IN]		I2C Bus number
 * \param   slaveAddr 	[IN]		I2C Slave address to read from
 * \param   buffer		[OUT]		Buffer pointer to copy data into
 * \param   bufLen 		[IN]		Length of the input buffer pointer
 * \param   pDataRead	[OUT]		Place holder to return read number of bytes
 *
 * \return
 * \n      return SUCCESS for success  - Description
 * \n      return FAIL for error   - Description
 */
short I2CRead( unsigned char	busNum,
                unsigned short	slaveAddr,
                unsigned char	*buffer,
                unsigned char	bufLen,
                unsigned char	*pDataRead); 
                
                
/**
 * \brief   Routine to impose delay between i2c transactions. 
 *
 * \param   delay   delay amount    
 *
 *
 * \return  None.
 *
 **/
void I2CDelay(unsigned int delay);                
#endif //_PLAT_I2C_H


