久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费
標(biāo)題:
exynos4412 I2C EEPROM測試程序
[打印本頁]
作者:
mercsun
時間:
2017-3-15 11:32
標(biāo)題:
exynos4412 I2C EEPROM測試程序
這是的exynos4412 I2C EEPROM測試程序。
/***************************************************************************
copyright : (C) by 2003-2004 Stefano Barbato
email : [url=mailto:stefano@codesink.org]stefano@codesink.org[/url]
$Id: 24cXX.c,v 1.5 02/29 11:05:28 tat Exp $
***************************************************************************/
/***************************************************************************
* *
* 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 <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <linux/fs.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <assert.h>
#include <string.h>
#include <linux/i2c-dev.h>
#include <linux/i2c.h>
static inline __s32 i2c_smbus_access(int file, char read_write, __u8 command,
int size, union i2c_smbus_data *data)
{
struct i2c_smbus_ioctl_data args;
args.read_write = read_write;
args.command = command;
args.size = size;
args.data = data;
return ioctl(file,I2C_SMBUS,&args);
}
static inline __s32 i2c_smbus_write_quick(int file, __u8 value)
{
return i2c_smbus_access(file,value,0,I2C_SMBUS_QUICK,NULL);
}
static inline __s32 i2c_smbus_read_byte(int file)
{
union i2c_smbus_data data;
if (i2c_smbus_access(file,I2C_SMBUS_READ,0,I2C_SMBUS_BYTE,&data))
return -1;
else
return 0x0FF & data.byte;
}
static inline __s32 i2c_smbus_write_byte(int file, __u8 value)
{
return i2c_smbus_access(file,I2C_SMBUS_WRITE,value,
I2C_SMBUS_BYTE,NULL);
}
static inline __s32 i2c_smbus_read_byte_data(int file, __u8 command)
{
union i2c_smbus_data data;
if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
I2C_SMBUS_BYTE_DATA,&data))
return -1;
else
return 0x0FF & data.byte;
}
static inline __s32 i2c_smbus_write_byte_data(int file, __u8 command,
__u8 value)
{
union i2c_smbus_data data;
data.byte = value;
return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
I2C_SMBUS_BYTE_DATA, &data);
}
static inline __s32 i2c_smbus_read_word_data(int file, __u8 command)
{
union i2c_smbus_data data;
if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
I2C_SMBUS_WORD_DATA,&data))
return -1;
else
return 0x0FFFF & data.word;
}
static inline __s32 i2c_smbus_write_word_data(int file, __u8 command,
__u16 value)
{
union i2c_smbus_data data;
data.word = value;
return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
I2C_SMBUS_WORD_DATA, &data);
}
static inline __s32 i2c_smbus_process_call(int file, __u8 command, __u16 value)
{
union i2c_smbus_data data;
data.word = value;
if (i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
I2C_SMBUS_PROC_CALL,&data))
return -1;
else
return 0x0FFFF & data.word;
}
/* Returns the number of read bytes */
static inline __s32 i2c_smbus_read_block_data(int file, __u8 command,
__u8 *values)
{
union i2c_smbus_data data;
int i;
if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
I2C_SMBUS_BLOCK_DATA,&data))
return -1;
else {
for (i = 1; i <= data.block[0]; i++)
values[i-1] = data.block[i];
return data.block[0];
}
}
static inline __s32 i2c_smbus_write_block_data(int file, __u8 command,
__u8 length, __u8 *values)
{
union i2c_smbus_data data;
int i;
if (length > 32)
length = 32;
for (i = 1; i <= length; i++)
data.block[i] = values[i-1];
data.block[0] = length;
return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
I2C_SMBUS_BLOCK_DATA, &data);
}
/* Returns the number of read bytes */
static inline __s32 i2c_smbus_read_i2c_block_data(int file, __u8 command,
__u8 *values)
{
union i2c_smbus_data data;
int i;
if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
I2C_SMBUS_I2C_BLOCK_DATA,&data))
return -1;
else {
for (i = 1; i <= data.block[0]; i++)
values[i-1] = data.block[i];
return data.block[0];
}
}
static inline __s32 i2c_smbus_write_i2c_block_data(int file, __u8 command,
__u8 length, __u8 *values)
{
union i2c_smbus_data data;
int i;
if (length > 32)
length = 32;
for (i = 1; i <= length; i++)
data.block[i] = values[i-1];
data.block[0] = length;
return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
I2C_SMBUS_I2C_BLOCK_DATA, &data);
}
/* Returns the number of read bytes */
static inline __s32 i2c_smbus_block_process_call(int file, __u8 command,
__u8 length, __u8 *values)
{
union i2c_smbus_data data;
int i;
if (length > 32)
length = 32;
for (i = 1; i <= length; i++)
data.block[i] = values[i-1];
data.block[0] = length;
if (i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
I2C_SMBUS_BLOCK_PROC_CALL,&data))
return -1;
else {
for (i = 1; i <= data.block[0]; i++)
values[i-1] = data.block[i];
return data.block[0];
}
}
#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 main(int argc, char** argv)
{
int funcs, fd, r;
//int addr = 0x68;
int addr = 0x50;
fd = 0;
__u8 buf[2];
__u8 dat[2];
fd = open("/dev/i2c/0", O_RDWR);
if(fd <= 0)
{
fprintf(stderr, "Error sensor_open: %s\n", strerror(errno));
return -1;
}
if((r = ioctl(fd, I2C_FUNCS, &funcs) < 0))
{
fprintf(stderr, "Error sensor_open: %s\n", strerror(errno));
return -1;
}
// 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)
{
fprintf(stderr, "Error sensor_open: %s\n", strerror(errno));
return -1;
}
#if 0
buf[0] = 0x1A;
buf[1] = 0x07;
i2c_write_2b(fd, buf);
i2c_write_1b(fd, 0x41);
dat[1] = i2c_smbus_read_byte(fd);
i2c_write_1b(fd, 0x42);
dat[0] = i2c_smbus_read_byte(fd);
#endif
printf("begin to test...\n");
buf[0] = 0x01;
buf[1] = 0x6c;
r = i2c_smbus_write_byte_data(fd, buf[0], buf[1]);
if(r < 0){printf(" current smbus_wirte_byte_data error.\n");};
printf("write data ok.\n");
usleep(1000);
fflush(stdout);
r = i2c_smbus_read_byte_data(fd, 0x01);
if(r < 0){
printf("current smbus_wirte_byte error1.\n");
}else{
printf("set high address ok.\n");
}
…………余下代碼請下載附件…………
}
復(fù)制代碼
下載:
exynos4412 I2C EEPROM測試程序.rar
(1.8 KB, 下載次數(shù): 5)
2017-3-15 22:48 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
歡迎光臨 (http://www.zg4o1577.cn/bbs/)
Powered by Discuz! X3.1
主站蜘蛛池模板:
国产在线视频在线观看
|
日韩2020狼一二三
|
成人午夜免费在线视频
|
一级黄色播放
|
男人天堂久久
|
a久久久久久
|
成人午夜免费在线视频
|
97伦理
|
久久9热
|
精品一区二区三区在线观看国产
|
www日韩
|
japan25hdxxxx日本 做a的各种视频
|
国产成人精品久久二区二区91
|
91精品国产自产精品男人的天堂
|
99福利网
|
日韩日韩日韩日韩日韩日韩日韩
|
狠狠色综合久久婷婷
|
国产精品久久国产精品99
|
亚洲第一网站
|
欧美性大战xxxxx久久久
|
国产精品日日摸夜夜添夜夜av
|
在线观看 亚洲
|
欧美日韩在线成人
|
久久久久精
|
日本一区高清
|
日韩欧美在线一区
|
久久久九九
|
欧美成人h版在线观看
|
美女久久视频
|
国产大片一区
|
亚洲最大的黄色网址
|
欧美一区二区三区在线观看
|
岛国视频
|
亚洲人成人一区二区在线观看
|
亚洲 欧美 日韩在线
|
国产福利91精品一区二区三区
|
香蕉久久久
|
99精品国产一区二区三区
|
日韩电影中文字幕
|
人人干人人玩
|
精品国产一区二区三区久久
|