fixed compiling error, RT_Device_Class_I2C is not defined in rtdef.h
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2173 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
9d53578c54
commit
6e7f8a36ff
|
@ -609,7 +609,7 @@ rt_err_t rt_hw_iic_register(
|
||||||
RT_ASSERT(0);
|
RT_ASSERT(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
device->type = RT_Device_Class_I2C;
|
device->type = RT_Device_Class_Unknown;
|
||||||
device->rx_indicate = RT_NULL;
|
device->rx_indicate = RT_NULL;
|
||||||
device->tx_complete = RT_NULL;
|
device->tx_complete = RT_NULL;
|
||||||
device->init = rt_iic_init;
|
device->init = rt_iic_init;
|
||||||
|
|
|
@ -30,24 +30,14 @@
|
||||||
|
|
||||||
static struct rt_device ee_dev;
|
static struct rt_device ee_dev;
|
||||||
|
|
||||||
uint32_t EE_ReadBuffer(void* pBuffer, rt_off_t ReadAddr, rt_size_t NumByteToRead)
|
uint32_t EE_ReadBuffer(void *pBuffer, rt_off_t ReadAddr, rt_size_t NumByteToRead)
|
||||||
{
|
{
|
||||||
return I2C_IORW(I2C1, (uint8_t*)pBuffer, (uint16_t)NumByteToRead, (uint16_t)ReadAddr, EE_Address | 0x01, I2C_MEM_1Byte );
|
return I2C_IORW(I2C1, (uint8_t *)pBuffer, (uint16_t)NumByteToRead, (uint16_t)ReadAddr, EE_Address | 0x01, I2C_MEM_1Byte );
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t EE_WritePage(void* pBuffer, uint16_t WriteAddr)
|
uint32_t EE_WritePage(void *pBuffer, uint16_t WriteAddr)
|
||||||
{
|
{
|
||||||
I2C_IORW(I2C1, (uint8_t*)pBuffer, EE_PageSize , WriteAddr, EE_Address , EE_ADDR_SIZE );
|
I2C_IORW(I2C1, (uint8_t *)pBuffer, EE_PageSize , WriteAddr, EE_Address , EE_ADDR_SIZE );
|
||||||
|
|
||||||
/*if( I2C_AcknowledgePolling(I2C1 , EE_Address) == Error )
|
|
||||||
rt_kprintf("EE ACK failed\n");*/
|
|
||||||
rt_thread_delay(50);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
uint32_t EE_WriteByte(void* pBuffer, uint16_t WriteAddr)
|
|
||||||
{
|
|
||||||
I2C_IORW(I2C1, (uint8_t*)pBuffer, 1 , WriteAddr, EE_Address, EE_ADDR_SIZE );
|
|
||||||
|
|
||||||
/*if( I2C_AcknowledgePolling(I2C1 , EE_Address) == Error )
|
/*if( I2C_AcknowledgePolling(I2C1 , EE_Address) == Error )
|
||||||
rt_kprintf("EE ACK failed\n");*/
|
rt_kprintf("EE ACK failed\n");*/
|
||||||
|
@ -56,20 +46,31 @@ uint32_t EE_WriteByte(void* pBuffer, uint16_t WriteAddr)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Status EE_WriteBuffer(const void* pBuffer, rt_off_t WriteAddr, rt_size_t NumByteToWrite)
|
uint32_t EE_WriteByte(void *pBuffer, uint16_t WriteAddr)
|
||||||
|
{
|
||||||
|
I2C_IORW(I2C1, (uint8_t *)pBuffer, 1 , WriteAddr, EE_Address, EE_ADDR_SIZE );
|
||||||
|
|
||||||
|
/*if( I2C_AcknowledgePolling(I2C1 , EE_Address) == Error )
|
||||||
|
rt_kprintf("EE ACK failed\n");*/
|
||||||
|
rt_thread_delay(50);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Status EE_WriteBuffer(const void *pBuffer, rt_off_t WriteAddr, rt_size_t NumByteToWrite)
|
||||||
{
|
{
|
||||||
uint8_t NumOfPage = 0, NumOfSingle = 0;
|
uint8_t NumOfPage = 0, NumOfSingle = 0;
|
||||||
uint16_t Addr = 0,count = 0;
|
uint16_t Addr = 0,count = 0;
|
||||||
uint8_t* ptr = (uint8_t*)pBuffer;
|
uint8_t *ptr = (uint8_t *)pBuffer;
|
||||||
|
|
||||||
Addr = (uint16_t)(WriteAddr&0xFFFF);
|
Addr = (uint16_t)(WriteAddr&0xFFFF);
|
||||||
|
|
||||||
count = (uint16_t)(NumByteToWrite&0xFFFF);
|
count = (uint16_t)(NumByteToWrite&0xFFFF);
|
||||||
|
|
||||||
if( (WriteAddr + NumByteToWrite ) > EE_MEM_SIZE )
|
if ((WriteAddr + NumByteToWrite) > EE_MEM_SIZE)
|
||||||
return Error;
|
return Error;
|
||||||
|
|
||||||
while( count >= EE_PageSize )
|
while (count >= EE_PageSize)
|
||||||
{
|
{
|
||||||
EE_WritePage(ptr, Addr);
|
EE_WritePage(ptr, Addr);
|
||||||
Addr += EE_PageSize;
|
Addr += EE_PageSize;
|
||||||
|
@ -77,31 +78,31 @@ Status EE_WriteBuffer(const void* pBuffer, rt_off_t WriteAddr, rt_size_t NumByte
|
||||||
ptr += EE_PageSize;
|
ptr += EE_PageSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
while( count )
|
while (count)
|
||||||
{
|
{
|
||||||
EE_WriteByte( ptr++, Addr++ );
|
EE_WriteByte(ptr++, Addr++);
|
||||||
count--;
|
count--;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Success;
|
return Success;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static rt_err_t ee24LCxx_init (rt_device_t dev)
|
static rt_err_t ee24LCxx_init(rt_device_t dev)
|
||||||
{
|
{
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
static rt_size_t ee24LCxx_read( rt_device_t dev, rt_off_t pos, void *buf, rt_size_t size )
|
|
||||||
|
static rt_size_t ee24LCxx_read(rt_device_t dev, rt_off_t pos, void *buf, rt_size_t size)
|
||||||
{
|
{
|
||||||
if( EE_ReadBuffer(buf, pos, size) == Success )
|
if (EE_ReadBuffer(buf, pos, size) == Success)
|
||||||
return size;
|
return size;
|
||||||
else
|
else
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static rt_size_t ee24LCxx_write( rt_device_t dev, rt_off_t pos, const void *buf, rt_size_t size )
|
static rt_size_t ee24LCxx_write(rt_device_t dev, rt_off_t pos, const void *buf, rt_size_t size)
|
||||||
{
|
{
|
||||||
if( EE_WriteBuffer(buf, pos, size) == Success )
|
if (EE_WriteBuffer(buf, pos, size) == Success)
|
||||||
return size;
|
return size;
|
||||||
else
|
else
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -117,20 +118,20 @@ static rt_err_t ee24LCxx_close(rt_device_t dev)
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static rt_err_t ee24LCxx_control (rt_device_t dev, rt_uint8_t cmd, void *args)
|
static rt_err_t ee24LCxx_control(rt_device_t dev, rt_uint8_t cmd, void *args)
|
||||||
{
|
{
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ee24LCxx_hw_init()
|
void ee24LCxx_hw_init(void)
|
||||||
{
|
{
|
||||||
uint32_t delay, i;
|
uint32_t delay, i;
|
||||||
I2C1_INIT();
|
I2C1_INIT();
|
||||||
|
|
||||||
for( i =0; i < 4; i++ )
|
for (i =0; i < 4; i++)
|
||||||
{
|
{
|
||||||
delay = 0xFFFFF;
|
delay = 0xFFFFF;
|
||||||
while(delay--);
|
while (delay--);
|
||||||
}
|
}
|
||||||
|
|
||||||
ee_dev.init = ee24LCxx_init;
|
ee_dev.init = ee24LCxx_init;
|
||||||
|
@ -139,13 +140,12 @@ void ee24LCxx_hw_init()
|
||||||
ee_dev.read = ee24LCxx_read;
|
ee_dev.read = ee24LCxx_read;
|
||||||
ee_dev.write = ee24LCxx_write;
|
ee_dev.write = ee24LCxx_write;
|
||||||
ee_dev.control = ee24LCxx_control;
|
ee_dev.control = ee24LCxx_control;
|
||||||
ee_dev.type = RT_Device_Class_I2C;
|
ee_dev.type = RT_Device_Class_Unknown;
|
||||||
|
|
||||||
|
|
||||||
rt_device_register(&ee_dev, "eeprom", RT_DEVICE_FLAG_RDWR);
|
rt_device_register(&ee_dev, "eeprom", RT_DEVICE_FLAG_RDWR);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dump_ee()
|
void dump_ee(void)
|
||||||
{
|
{
|
||||||
rt_device_t dev;
|
rt_device_t dev;
|
||||||
char buf[EE_MEM_SIZE];
|
char buf[EE_MEM_SIZE];
|
||||||
|
@ -154,40 +154,39 @@ void dump_ee()
|
||||||
dev = rt_device_find("eeprom");
|
dev = rt_device_find("eeprom");
|
||||||
rt_device_read(dev, 0, buf, EE_MEM_SIZE );
|
rt_device_read(dev, 0, buf, EE_MEM_SIZE );
|
||||||
|
|
||||||
for( i = 0; i < 16; i++ )
|
for (i = 0; i < 16; i++)
|
||||||
{
|
{
|
||||||
for( j = 0; j < 16; j++ )
|
for (j = 0; j < 16; j++)
|
||||||
{
|
{
|
||||||
rt_kprintf("0x%02X ", buf[ i*16+ j]);
|
rt_kprintf("0x%02X ", buf[ i*16+ j]);
|
||||||
|
|
||||||
}
|
}
|
||||||
rt_kprintf("\n");
|
rt_kprintf("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ee_reset()
|
void ee_reset(void)
|
||||||
{
|
{
|
||||||
char buf[EE_MEM_SIZE], read[EE_MEM_SIZE];
|
char buf[EE_MEM_SIZE], read[EE_MEM_SIZE];
|
||||||
int i;
|
int i;
|
||||||
rt_device_t dev = rt_device_find("eeprom");
|
rt_device_t dev = rt_device_find("eeprom");
|
||||||
|
|
||||||
for(i = 0; i < EE_MEM_SIZE; i++ )
|
for (i = 0; i < EE_MEM_SIZE; i++)
|
||||||
{
|
{
|
||||||
buf[i] = 0xFF;
|
buf[i] = 0xFF;
|
||||||
read[i] = 0;
|
read[i] = 0;
|
||||||
}
|
}
|
||||||
if( rt_device_write(dev, 0, buf, EE_MEM_SIZE ) == EE_MEM_SIZE )
|
if (rt_device_write(dev, 0, buf, EE_MEM_SIZE ) == EE_MEM_SIZE)
|
||||||
rt_kprintf("Write Success\n");
|
rt_kprintf("Write Success\n");
|
||||||
|
|
||||||
rt_device_read(dev, 0, read, EE_MEM_SIZE );
|
rt_device_read(dev, 0, read, EE_MEM_SIZE );
|
||||||
|
|
||||||
for(i = 0; i < EE_MEM_SIZE; i++ )
|
for (i = 0; i < EE_MEM_SIZE; i++)
|
||||||
{
|
{
|
||||||
if( buf[i] != read[i] )
|
if (buf[i] != read[i])
|
||||||
rt_kprintf("EE Failed %X != %X at %d\n", buf[i], read[i], i);
|
rt_kprintf("EE Failed %X != %X at %d\n", buf[i], read[i], i);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef RT_USING_FINSH
|
#ifdef RT_USING_FINSH
|
||||||
#include <finsh.h>
|
#include <finsh.h>
|
||||||
FINSH_FUNCTION_EXPORT(ee_reset, test system);
|
FINSH_FUNCTION_EXPORT(ee_reset, test system);
|
||||||
|
|
Loading…
Reference in New Issue