⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test.c

📁 Linux 2.6.24通过SMBUS总线(也类似于i2c总线)读写内存上的SPD信息。里面包含驱动和测试程序。再PC机上反复测试过
💻 C
字号:
/*  This file is subject to the terms and conditions of the GNU General Public * License.  See the file "COPYING" in the main directory of this archive * for more details. * * Copyright (C) 2007, 2010 fengGuojin(fgjnew@163.com) */#include	<sys/types.h>#include	<unistd.h>#include	<fcntl.h>#include	<linux/rtc.h>#include	<linux/ioctl.h>#include	<stdio.h>#include	<stdlib.h>#define		COUNT  (100)int main(void){	int fd;	int i,result;	unsigned char buf[COUNT];	for(i=0;i<COUNT;i++)		buf[i] = 0x00;  	fd=open("/dev/spd",O_RDWR);  	if(fd==-1)  	{		perror("  #### i2c test device open failed #### \n");     	return -1;  	} 	//printf("  open /dev/spd successfully\n");/*	while(chr != '9'){		chr = getchar();		if(chr != 10)			printf("%x ",chr);	}	getchar();*/	result = read(fd,&buf,COUNT);	if(result < 0)	{		perror("   #### read data form smbus failed #### \n");		goto out;	}	for(i=0; i<COUNT;i++)	{		printf("   buf[%d]=%2x",i,buf[i]);		if(i%5 == 0)  printf("\n");	}	printf("\n");out:	close(fd);	return result;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -