Chinaunix首页 | 论坛 | 博客
  • 博客访问: 938625
  • 博文数量: 192
  • 博客积分: 3070
  • 博客等级: 中校
  • 技术积分: 1861
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-27 23:44
个人简介

Start Linux Leave Linux a while Back to Linux

文章分类

全部博文(192)

文章存档

2023年(18)

2022年(11)

2021年(8)

2020年(14)

2019年(7)

2018年(13)

2017年(16)

2016年(4)

2012年(2)

2011年(13)

2010年(26)

2009年(13)

2008年(27)

2007年(20)

我的朋友

分类: LINUX

2008-08-11 23:02:23

u-boot提供了I2C的接口,驱动程序在 ./cpu/arm920t/s3c24x0/i2c.c 中,在 smdk2440.h 中加入
 
#define CONFIG_DRIVER_S3C24X0_I2C    1    /* we use the buildin I2C controller */
#define CONFIG_HARD_I2C    1        /* I2C with hardware support */
 
#define CFG_I2C_SPEED        100000    /* I2C speed and slave address */
#define CFG_I2C_SLAVE        0x50
#define CFG_I2C_EEPROM_ADDR_LEN     1    /* Bytes of address        */
/* mask of address bits that overflow into the "EEPROM chip address"    */
#define CFG_I2C_EEPROM_ADDR_OVERFLOW    0x07
 
在board.c 文件中加入 write_info2eeprom() 将u-boot 生成的日期写入 24c16的 0x50位置中。
 

static void write_info2eeprom()
{
    memset(uboot_info,0,sizeof(uboot_info);
    strcpy(uboot_info, __DATE__);
    i2c_init(CFG_I2C_SPEED, CFG_I2C_SLAVE);
    i2c_write(CFG_I2C_SLAVE, 0x50, 1, uboot_info, 6);
    memset(uboot_info,0,sizeof(uboot_info);
    i2c_read(CFG_I2C_SLAVE, 0x50, 1, uboot_info, 6);
    printf("read back: %s\n", uboot_info);
}

 

其中读/写这2个函数的说明

/*
 * Read/Write interface:
 *   chip:    I2C chip address, range 0..127
 *   addr:    Memory (register) address within the chip
 *   alen:    Number of bytes to use for addr (typically 1, 2 for larger
 *              memories, 0 for register type devices with only one
 *              register)
 *   buffer:  Where to read/write the data
 *   len:     How many bytes to read/write
 *
 *   Returns: 0 on success, not 0 on failure
 */
int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len);
int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len);

其中alen 为1,说明chip是8bit的, 为2则是 16bit的。

 

 

阅读(5612) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

andytan2008-09-07 11:23:55

ri