资源简介
i2cdetect :检测i2c芯片是否存在
i2cdump :检测i2c寄存器
i2cget :从i2c芯片寄存器种读取数据
i2cset :设置i2c寄存器
isadump:监测isa寄存器
代码片段和文件信息
/***************************************************************************
copyright : (C) by 2002-2003 Stefano Barbato
email : stefano@codesink.org
$Id: 24cXX.c 4230 2006-11-10 09:22:12Z khali $
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License or *
* (at your option) any later version. *
* *
***************************************************************************/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include “24cXX.h“
static int i2c_write_1b(struct eeprom *e __u8 buf)
{
int r;
// we must simulate a plain I2C byte write with SMBus functions
r = i2c_smbus_write_byte(e->fd buf);
if(r < 0)
fprintf(stderr “Error i2c_write_1b: %s\n“ strerror(errno));
usleep(10);
return r;
}
static int i2c_write_2b(struct eeprom *e __u8 buf[2])
{
int r;
// we must simulate a plain I2C byte write with SMBus functions
r = i2c_smbus_write_byte_data(e->fd buf[0] buf[1]);
if(r < 0)
fprintf(stderr “Error i2c_write_2b: %s\n“ strerror(errno));
usleep(10);
return r;
}
static int i2c_write_3b(struct eeprom *e __u8 buf[3])
{
int r;
// we must simulate a plain I2C byte write with SMBus functions
// the __u16 data field will be byte swapped by the SMBus protocol
r = i2c_smbus_write_word_data(e->fd buf[0] buf[2] << 8 | buf[1]);
if(r < 0)
fprintf(stderr “Error i2c_write_3b: %s\n“ strerror(errno));
usleep(10);
return r;
}
#define CHECK_I2C_FUNC( var label ) \
do { if(0 == (var & label)) { \
fprintf(stderr “\nError: “ \
#label “ function is required. Program halted.\n\n“); \
exit(1); } \
} while(0);
int eeprom_open(char *dev_fqn int addr int type struct eeprom* e)
{
int fd r;
unsigned long funcs;
e->fd = e->addr = 0;
e->dev = 0;
fd = open(dev_fqn O_RDWR);
if(fd <= 0)
return -1;
// get funcs list
if((r = ioctl(fd I2C_FUNCS &funcs) < 0))
return r;
// check for req funcs
CHECK_I2C_FUNC( funcs I2C_FUNC_SMBUS_READ_BYTE );
CHECK_I2C_FUNC( funcs I2C_FUNC_SMBUS_WRITE_BYTE );
CHECK_I2C_FUNC( funcs I2C_FUNC_SMBUS_READ_BYTE_DATA );
CHECK_I2C_FUNC( funcs I2C_FUNC_SMBUS_WRITE_BYTE_DATA );
CHECK_I2C_FUNC( funcs I2C_FUNC_SMBUS_READ_WORD_DATA );
CHECK_I2C_FUNC( funcs I2C_FUNC_SMBUS_WRITE_WORD_DATA );
// set working device
if( ( r = ioctl(fd I2C_SLAVE addr)) < 0)
return r;
e->fd =
相关资源
- uboot到linux logo显示不间断 补丁
- UNIX/LINUX编程实践教程的源码
- Linux任务管理器
- linux应用层的华容道游戏源代码
- ubuntu9.10 可加载内核模块和字符设备驱
- MP3文件ID3v2ID3v2APEv2标签读取
- 操作系统实验——虚存管理实验
- linux下的发包工具sendip
- 尚观培训linux许巍关于c 的笔记和讲义
- 尚观培训linux董亮老师关于数据结构的
- linux 线程池源码 c 版
- linux C 电梯程序练习
- linux下用多进程同步方法解决生产者
- Linux 操作系统实验(全)
- Linux From Scratch 中文手册
- linux 网络实验 ftp程序
- Linux命令大全离线版&在线版
- 操作系统共享内存实验
- dos 下运行Linux 命令--gnu_utils
- linux 0.12内核源代码
- linux简易shell C实现
- linux实验报告及心得体会
- 基于GTK的Linux环境下的简易任务管理器
- linux扫雷游戏代码
- CAN Linux驱动代码
- Linux系统教材
- intel 82579LM 网卡驱动Linux系统版 v1.9.
- SA1110处理器掌上电脑液晶显示器设计
- 基于Linux的串口服务器设计
- Windows下访问LINUX的利器-SSH
评论
共有 条评论