📄 evmdm642_eeprom.c
字号:
/*
* Copyright 2003 by Spectrum Digital Incorporated.
* All rights reserved. Property of Spectrum Digital Incorporated.
*/
/*
* ======== evmdm642_eeprom.c ========
* I2C EEPROM module implementation for DM642 EVM
*/
#include <std.h>
#include <csl.h>
#include <csl_i2c.h>
#include "evmdm642_i2c.h"
#include "evmdm642_eeprom_i2c.h"
I2C_Config myeepromRcvCfg = {
0x0000007f, /* I2COAR - Not used if master */
0x00000008, /* I2CIER - Disable interrupts, use polling */
0x0000001b, /* I2CCLKL - Low period for 100KHz operation */
0x0000001b, /* I2CCLKH - High period for 100KHz operation */
0x00000002, /* I2CCNT - Data words per transmission */
0x00000050, /* I2CSAR - Slave address */
0x000064a0, /* I2CMDR - Mode */
0x00000019 /* I2CPSC - Prescale 300MHz to 12MHz */
};
I2C_Config myeepromXmtCfg = {
0x0000007f, /* I2COAR - Not used if master */
0x00000010, /* I2CIER - Disable interrupts, use polling */
0x0000001b, /* I2CCLKL - Low period for 100KHz operation */
0x0000001b, /* I2CCLKH - High period for 100KHz operation */
0x00000002, /* I2CCNT - Data words per transmission */
0x00000050, /* I2CSAR - Slave address */
0x00004680, /* I2CMDR - Mode */
0x00000019 /* I2CPSC - Prescale 300MHz to 12MHz */
};
static I2C_Config eepromRcvCfg = {
0x0000007f, /* I2COAR - Not used if master */
0x00000000, /* I2CIER - Disable interrupts, use polling */
0x0000001b, /* I2CCLKL - Low period for 100KHz operation */
0x0000001b, /* I2CCLKH - High period for 100KHz operation */
0x00000002, /* I2CCNT - Data words per transmission */
0x00000050, /* I2CSAR - Slave address */
0x000044a0, /* I2CMDR - Mode */
0x00000019 /* I2CPSC - Prescale 300MHz to 12MHz */
};
static I2C_Config eepromXmtCfg = {
0x0000007f, /* I2COAR - Not used if master */
0x00000000, /* I2CIER - Disable interrupts, use polling */
0x0000001b, /* I2CCLKL - Low period for 100KHz operation */
0x0000001b, /* I2CCLKH - High period for 100KHz operation */
0x00000002, /* I2CCNT - Data words per transmission */
0x00000050, /* I2CSAR - Slave address */
0x000046a0, /* I2CMDR - Mode */
0x00000019 /* I2CPSC - Prescale 300MHz to 12MHz */
};
interrupt void I2C_Int()
{
Uint8 aa;
//send the address in the eeprom
if(op<2)
{
I2C_writeByte(I2C_hI2C, addr[op]);
op++;
}
else
{
if(op==2)
{
I2C_config(I2C_hI2C, &myeepromRcvCfg);
op++;
}
else
{
bufferR[index]= I2C_readByte(I2C_hI2C);
index++;
if(index>=length)
{
I2C_sendStop(I2C_hI2C);
index=0;
op=0;
loop=0;
waitusec(10000);
I2C_config(I2C_hI2C, &myeepromXmtCfg);
}
}
}
aa=0;
}
/*
* ======== EVMDM642_eeprom_read ========
* Read data from an I2C EEPROM
*/
void EEPROM_read(Uint32 src, Uint32 dst, Uint32 length)
{
Uint8 *pdst;
Uint32 i;
I2C_Config prevI2CCfg;
/* Establish destination pointer */
pdst = (Uint8 *)dst;
/* Wait until bus is free */
while (I2C_bb(I2C_hI2C));
/* Save old settings */
I2C_getConfig(I2C_hI2C, &prevI2CCfg);
/* Set address using dummy write */
EEPROM_write(0, src, 0);
/* Configure for receive */
I2C_config(I2C_hI2C, &eepromRcvCfg);
waitusec(1);
/* Generate start condition */
I2C_start(I2C_hI2C);
/* Receive the data */
for (i = 0; i < length; i++)
{
while(!I2C_rrdy(I2C_hI2C));
*pdst++ = I2C_readByte(I2C_hI2C);
}
/* Generate stop condition */
I2C_sendStop(I2C_hI2C);
/* Need to wait at least 10ms */
waitusec(10000);
/* Wait until bus is free */
while (I2C_bb(I2C_hI2C));
/* Reconfigure I2C with old settings */
I2C_config(I2C_hI2C, &prevI2CCfg);
}
/*
* ======== EVMDM642_eeprom_write ========
* Write data to an I2C EEPROM
*/
void EEPROM_write(Uint32 src, Uint32 dst, Uint32 length)
{
Uint8 *psrc;
Uint32 i;
I2C_Config prevI2CCfg;
/* Establish source pointer */
psrc = (Uint8 *)src;
/* Wait until bus is free */
while (I2C_bb(I2C_hI2C));
/* Clear bus busy */
I2C_FSETH(I2C_hI2C, I2CSTR, BB, 1);
/* Save old settings */
I2C_getConfig(I2C_hI2C, &prevI2CCfg);
/* Configure for transmit */
I2C_config(I2C_hI2C, &eepromXmtCfg);
waitusec(1);
/* Submit the high address byte */
I2C_writeByte(I2C_hI2C, (dst & 0xff00) >> 8);
/* Generate start condition */
I2C_start(I2C_hI2C);
while(!I2C_xrdy(I2C_hI2C));
/* Submit the low address byte */
I2C_writeByte(I2C_hI2C, dst & 0xff);
while(!I2C_xrdy(I2C_hI2C));
/* Transmit the data */
for (i = 0; i < length; i++)
{
I2C_writeByte(I2C_hI2C, *psrc++);
while(!I2C_xrdy(I2C_hI2C));
}
/* Generate stop condition */
I2C_sendStop(I2C_hI2C);
/* Need to wait at least 10ms */
waitusec(10000);
/* Wait until bus is free */
while (I2C_bb(I2C_hI2C));
/* Reconfigure I2C with old settings */
I2C_config(I2C_hI2C, &prevI2CCfg);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -