#include "common.h" /* include peripheral declarations */
#define printf print_str
#include "i2c.h"
#include "i2c_cfg.h"

void i2c_general_call(void);
void run_test(void);

void i2c_master_gencall_int_tx(unsigned char mst_addr, unsigned char slv_addr);
void i2c_slave_gencall_int_rx(unsigned char addr);

void i2c_master_gencall_int_tx(unsigned char mst_addr, unsigned char slv_addr)
{
	uint8 i;
	printf("***Mini I2C int master TX Test***\r\n");	
    i2c_tx_buffer.tx_index = 0;
    i2c_tx_buffer.rx_index = 0;
    i2c_tx_buffer.data_present = TRUE;
    i2c_tx_buffer.length = 64;
    i2c_tx_buffer.buf[0] = (uint8)(slv_addr&0x0FF);
	
	for(i=1;i<64;i++)
	{
		i2c_tx_buffer.buf[i] = i;
	}
	
	i2c_init(0, mst_addr, 50000);
	i2c_master(0, I2C_TX, 0); // general call	
}

void i2c_slave_gencall_int_rx(unsigned char addr)
{
	printf("***Mini I2C int slave RX Test***\r\n");
	i2c_init(0, addr, 50000);
	I2C_C2(0) |= 0x80; //enable general call	
}


void i2c_general_call(void) 
{
	SIM_SCGC1 |= 0xF0; // enable I2C clock gate 
	INTC_CIMR = 26; // I2C0
//	INTC_CIMR = 27; // I2C2
//	INTC_CIMR = 30; // I2C1
//	INTC_CIMR = 31; // I2C3
//	i2c_master_gencall_int_tx(I2C_MASTER_ADDR, I2C_SLAVE_ADDR);
	i2c_slave_gencall_int_rx(I2C_SLAVE_ADDR);	
}

void run_test(void)
{
	/* This function will call the testcase function */
	i2c_general_call();
}

