Linux I2CºËÐÄ¡¢×ÜÏßÓëÉ豸Çý¶¯
Linux I2CºËÐÄ¡¢×ÜÏßÓëÉ豸Çý¶¯
×¢:
ÔÚlinux2.6.32°æ±¾ÖÐÓÐÕâÑùµÄ´úÂëÓë×¢ÊÍ:
struct i2c_driver {
unsigned int class;
/* Notifies the driver that a new bus has appeared or is about to be
* removed. You should avoid using this if you can, it will probably
* be removed in a near future.
*/
int (*attach_adapter)(struct i2c_adapter *);
int (*detach_adapter)(struct i2c_adapter *);
/* Standard driver model interfaces */
int (*probe)(struct i2c_client *, const struct i2c_device_id *);
int (*remove)(struct i2c_client *);
...
}
ÎÒµÄÀí½âÊÇ.а汾ÖÐÓÃprobeºÍremove´úÌæÁËÔÀ´µÄattach_adapterºÍdetach_adapter.
I2C×ÜÏß½ö½öʹÓÃSCL¡¢SDAÁ½¸ùÐźÅÏß¾ÍʵÏÖÁËÉ豸֮¼äµÄÊý¾Ý½»»¥£¬¼«´óµØ¼ò»¯¶ÔÓ²¼þ×ÊÔ´ºÍPCB°å²¼Ï߿ռäµÄÕ¼Óá£Òò´Ë£¬I2C×ÜÏß±»·Ç³£¹ã·ºµØÓ¦ÓÃÔÚEEPROM¡¢ÊµÊ±ÖÓ¡¢Ð¡ÐÍLCDµÈÉ豸ÓëCPUµÄ½Ó¿ÚÖС£
Linux¶¨ÒåÁËϵͳµÄI2CÇý¶¯Ìåϵ½á¹¹£¬ÔÚLinuxϵͳÖУ¬I2CÇý¶¯ÓÉ3²¿·Ö×é³É£¬¼´I2CºËÐÄ¡¢I2C×ÜÏßÇý¶¯ºÍI2CÉ豸Çý¶¯¡£Õâ3²¿·ÖÏ໥Ð×÷£¬ÐγÉÁ˷dz£Í¨ÓᢿÉÊÊÓ¦ÐÔºÜÇ¿µÄI2C¿ò¼Ü¡£
±¾ÕµÚ1½Ú½«¶ÔLinux I2CÌåϵ½á¹¹½øÐзÖÎö£¬½²Ã÷3¸ö×é³É²¿·Ö¸÷×ԵŦÄܼ°Ï໥ÁªÏµ¡£
µÚ2½Ú½«¶ÔLinux I2CºËÐĽøÐзÖÎö£¬½âÊÍi2c-core.cÎļþµÄ¹¦ÄܺÍÖ÷Òªº¯ÊýµÄʵÏÖ¡£
µÚ3¡¢4½Ú½«·Ö±ðÏêϸ½éÉÜI2C×ÜÏßÇý¶¯ºÍI2CÉ豸Çý¶¯µÄ±àд·½·¨£¬¸ø³ö¿É¹©²Î¿¼µÄÉè¼ÆÄ£°å¡£
µÚ5¡¢6½Ú½«ÒÔµÚ3¡¢4½Ú¸ø³öµÄÉè¼ÆÄ£°åΪ»ù´¡£¬½²½âS3C2410 ARM´¦ÀíÆ÷I2C×ÜÏßÇý¶¯¼°¹Ò½ÓÔÚÉϵÄSAA7113HÊÓÆµÄ£Äâ/Êý×Öת»»Ð¾Æ¬É豸Çý¶¯µÄ±àд·½·¨¡£
15.1 Linux I2CÌåϵ½á¹¹
LinuxµÄI2CÌåϵ½á¹¹·ÖΪ3¸ö×é³É²¿·Ö£º
1 I2CºËÐÄ
I2C
ºËÐÄÌṩÁËI2C×ÜÏßÇý¶¯ºÍÉ豸Çý¶¯µÄ×¢²á¡¢×¢Ïú·½·¨£¬I2CͨÐÅ·½·¨£¨¼´“algorithm”£¬±ÊÕßÈÏΪֱÒëΪ“ÔËËã·½·¨”²¢²»ºÏÊÊ£¬ÎªÃâÒýÆðÎó½â£¬
ÏÂÎĽ«Ö±½ÓʹÓÓalgorithm”£©ÉϲãµÄ¡¢Óë¾ßÌåÊÊÅäÆ÷Î޹صĴúÂëÒÔ¼°Ì½²âÉ豸¡¢¼ì²âÉ豸µØÖ·µÄÉϲã´úÂëµÈ¡£
2 I2C×ÜÏßÇý¶¯
I2C×ÜÏßÇý¶¯ÊǶÔI2CÓ²¼þÌåϵ½á¹¹ÖÐÊÊÅäÆ÷¶ËµÄʵÏÖ£¬ÊÊÅäÆ÷¿ÉÓÉCPU¿ØÖÆ£¬ÉõÖÁÖ±½Ó¼¯³ÉÔÚ
Ïà¹ØÎĵµ£º
Ò»£®Ç°ÑÔ
¡¡¡¡LinuxÓµÓзḻ¸÷ÖÖÔ´´úÂë×ÊÔ´,µ«ÊǴ󲿷ִúÂëÔÚWindowsƽ̨Çé¿öÊÇÎÞ·¨Õý³£±àÒëµÄ¡£Windowsƽ̨¸ù±¾ÎÞ·¨Ö±½ÓÀûÓÃÕâЩԴ´úÂë×ÊÔ´¡£Èç¹ûÏëҪʹÓÃÍêÕûµÄ´úÂ룬¾ÍÒª×öÒÆÖ²¹¤×÷¡£ÒòΪC/C++ LibraryµÄ²»Í¬ºÍÆäËûµÄһЩÔÒò£¬ÒÆÖ²C/C++´úÂëÊÇÒ»ÏîÀ§ÄѵŤ×÷¡£±¾ÎĽ«ÒÔÒ»¸öʵ¼ÊµÄÀý×Ó£¨Tar£©À´ËµÃ÷ÈçºÎ°ÑLinux´úÂëÒÆÖ² ......
WindowsÓëLinuxÖеĻ»ÐÐÊDz»Ò»ÑùµÄ£¬ÒѾÓöµ½¹ýºÃ¼¸´ÎÎÊÌâÁË¡«ÅúÁ¿Ð½¨Óû§µÄʱºò£¬ÐÂÓû§²»ÄܵǼ£¬ÒòΪÎÒµÄÎı¾ÊÇÔÚWindowsÏÂÉú³ÉµÄ£¬»»ÐÐÊÇWindows¸ñʽ£¬¶øLinuxÖÐʹÓÃnewusersÃüÁîµ¼Èëµ½passwdÎļþ£¬ÊÇÖ±½Ó¸´ÖƹýÈ¥µÄ¡«²»ÄÜÒ»ÐÐÒ»Ðеĸİ¡¡«ºÇºÇ£¬¸Õ¸Õѧµ½ÁËÒ»ÕС£
×Ö·ûÎļþÔÚÁ½¸öϵͳ֮¼ä¿½±´Ö®ºó£¬¿ÉÒÔʹÓÃdos2unix» ......
2010-3-8
Ò»¡¢gccµ÷ÊÔ£º
Èç¹û±àÒëʱ£¬Ê¹ÓÃÏÂÃæµÄÖ¸Áî(Ôö¼ÓÁ˲ÎÊý-g)£¬¾Í»áÉú³É´øÔ´´úÂëµ÷ÊÔ·ûºÅµÄ¿ÉÖ´ÐÐÎļþ¡£±àÒëÐγɵĿÉÖ´ÐÐÎļþÓÐ7KB¡£Ö®ËùÒÔÔö¼ÓÁË2KB£¬¾ÍÊÇÒòΪÔö¼ÓµÄµ÷ÊÔ·ûºÅ¡£
gcc -o calc calcutlator.c -g
½øÒ»²½µØ£¬¾Í¿ÉÒÔÖ´ÐÐÏÂÃæµÄÖ¸ÁîÆô¶¯µ÷ÊÔ¹¤¾ß½øÈëµ÷ÊÔ»·¾³¶Ô³ÌÐò½øÐе÷ÊÔÁË¡£
gdb calc
ÔÚµ÷ÊÔ»·¾³Ï ......
CÊý×éµÄСÎÊÌâ
ÕâÀï˵µÄ¶¯Ì¬Êý×éÊÇ¿ÉÒÔ¸ù¾ÝÐèÒª¶¯Ì¬Ôö³¤Õ¼ÓÃÄÚ´æµÄÊý×飬±ÈÈç³ÌÐò³õʼ·ÖÅäÁË100¸öÔªËØ£¬¿ÉÊÇÔËÐÐÁËÒ»¶Îʱ¼äºóÇøÇø100¸ö¿Õ¼ä²»ÄÜÂú×ãÁË£¬ÏÖÔÚÐèÒª400¸ö£¬Ôõô°ìÄØ£»Äǿ϶¨ÐèÒªÔÙ¶îÍâ·ÖÅä300¸ö¡£
CÓïÑÔÓÐrealloc()º¯ÊýÀ´½â¾ö¿Õ¼äÀ©³äµÄÎÊÌ⣬µ«ÊDz»ÒªÍ ......
#include <stdio.h>
int main ()
{
FILE *fp1;
fp1=fopen("test0.txt","rt");
if(fp1==NULL)
{
printf("can not open test0.txt\n");return 0;
&n ......