LinuxÄÚºËÉ豸ģÐÍ(3)
ÒëÕߣº¹ùÉÙ±¯
2009/12/01
ÔÎÄ£ºlinux-2.6/Documentation/driver-model/bus.txt
×ÜÏßÀàÐÍ
¶¨Òå
~~~~
struct bus_type {
char * name;
struct subsystem subsys;
struct kset drivers;
struct kset devices;
struct bus_attribute * bus_attrs;
struct device_attribute * dev_attrs;
struct driver_attribute * drv_attrs;
int (*match)(struct device * dev, struct device_driver * drv);
int (*hotplug) (struct device *dev, char **envp,
int num_envp, char *buffer, int buffer_size);
int (*suspend)(struct device * dev, pm_message_t state);
int (*resume)(struct device * dev);
};
int bus_register(struct bus_type * bus);
ÉùÃ÷
~~~~
ÄÚºËÀïµÄÿһ¸ö×ÜÏßÀàÐÍ£¨PCI£¬USB£¬µÈ£©Ó¦µ±ÉùÃ÷Ò»¸ö¾²Ì¬µÄ¶ÔÏó¡£ËüÃDZØÐë³õʼ
»¯nameÓò£¬ÓÐʱҲ³õʼ»¯match()»Øµ÷º¯Êý¡£
struct bus_type pci_bus_type = {
.name = "pci",
.match = pci_bus_match,
};
¸ÃÊý¾Ý½á¹¹Ó¦µ±±»°üº¬ÔÚÒ»¸öÍ·ÎļþÀÏòÏà¹ØµÄÇý¶¯µ¼³ö:
extern struct bus_type pci_bus_type;
×¢²á
~~~~~
×ÜÏßÇý¶¯ÔÚ³õʼ»¯µÄʱºò£¬»áµ÷ÓÃbus_register()¡£Ëü³õʼ»¯×ÜÏß¶ÔÏóµÄÆäÓàµÄÓò£¬
²¢½«×ÜÏß¶ÔÏó²åÈëµ½×ÜÏßÀàÐ͵ÄÈ«¾ÖÁ´±íÀï¡£Ò»µ©×ÜÏß¶ÔÏó±»×¢²á£¬
ËüµÄÿ¸öÓò¶ÔÓÚ×ÜÏßÇý¶¯¶¼ÊÇ¿ÉÓõġ£
»Øµ÷º¯Êý
~~~~~~~~
match():¹ØÁªÇý¶¯µ½É豸
~~~~~~~~~~~~~~~~~~~~~~
É豸µÄIDÊý¾Ý½á¹¹µÄ¸ñʽºÍ±È½ÏÓï·¨ÓÉÆä×ÜÏß×Ô¼º¹æ¶¨¡£Çý¶
Ïà¹ØÎĵµ£º
1. HCI²ãÐÒé¸ÅÊö£º
HCIÌṩһÌ×ͳһµÄ·½·¨À´·ÃÎÊBluetoothµ×²ã¡£ÈçͼËùʾ£º
´ÓͼÉÏ¿ÉÒÔ¿´³ö£¬Host Controller Interface(HCI) ¾ÍÊÇÓÃÀ´¹µÍ¨HostºÍModule¡£Hostͨ³£¾ÍÊÇPC£¬ ModuleÔòÊÇÒÔ¸÷ÖÖÎïÀíÁ¬½ÓÐÎʽ£¨USB,serial,pc-cardµÈ£©Á¬½Óµ½PCÉϵÄbluetooth Dongle¡£
ÔÚHostÕâÒ»¶Ë£ºapplication,SDP,L2capµÈÐÒé ......
ÀýÒ»£º·¢ËÍSignaling Packet£º
Signaling CommandÊÇ2¸öBluetoothʵÌåÖ®¼äµÄL2CAP²ãÃüÁî´«Êä¡£ËùÒÔµÃSignaling CommandʹÓÃCID 0x0001.
¶à¸öCommand¿ÉÒÔÔÚÒ»¸öC-frame£¨control frame£©Öз¢ËÍ¡£
Èç¹ûÒªÖ±½Ó·¢ËÍSignaling Command.ÐèÒª½¨Á¢SOCK_RAWÀàÐ͵ÄL2CAPÁ¬½ÓSocket¡£ÕâÑù²ÅÓлú»á×Ô¼ºÌî³äCommand Code£¬Identi ......
1. ѧ»áд¼òµ¥µÄmakefile
2. ±àһЩӦÓÃ
³ÌÐò
£¬¿ÉÒÔÓÃmakefileÅÜÆðÀ´
3. ѧ»áдÇý¶¯
µÄmakefile
4. дһ¼òµ¥charÇý¶¯£¬makefile±àÒëͨ¹ý£¬¿ÉÒÔinsmod£¬ lsmod£¬ rmmod. ÔÚÇý¶¯µÄinitº¯ÊýÀï´òÓ¡hello world£¬insmodºóÓ¦¸ÃÄܹ»Í¨¹ýdmesg¿´µ½Êä³ö
¡£
5. дһÍêÕûÇý¶¯£¬ ¼ÓÉÏread£¬ write£¬ ioctl£¬ pollingµÈ¸ ......
˫ϵͳ°²×°Ê±£¬Linux´ÓÓ²ÅÌÆô¶¯£º
°²×°windows¾Í²»ÔÙ½²ÁË¡£
ÏÂÔØLinuxϵͳ¾µÏñ£¬ÎÒÏÂÔØµÄÊÇCentOS5.3¡£½«Linux¾µÏñ½âѹµ½Ò»¸öfat32·ÖÇøÄ¿Â¼£¨ÎÒµÄÊÇFÅÌ£©¡£
²¢½«¾µÏñÖÐisolinuxĿ¼ÏµÄvmlinuxzºÍinitrd.imgÁ½¸öÎļþcopyµ½FÅÌ£¨ÎÒµÄÊÇFÅÌ£©¡£ÏÂÔØwingrub£¬Ë«»÷°²×°¡£°²×°ºó´ò¿ªwingrub³öÀ´Ò»½çÃæchoose driverÈÃÄãÑ¡ÔñÅÌ ......
Ò»¡¢ioctl
´ó²¿·ÖÉ豸³ýÁ˶ÁдÄÜÁ¦£¬»¹¿É½øÐг¬³ö¼òµ¥µÄÊý¾Ý´«ÊäÖ®ÍâµÄ²Ù×÷£¬ËùÒÔÉ豸Çý¶¯Ò²±ØÐë¾ß±¸½øÐи÷ÖÖÓ²¼þ¿ØÖƲÙ×÷µÄÄÜÁ¦. ÕâЩ²Ù×÷³£³£Í¨¹ý ioctl ·½·¨À´Ö§³Ö£¬ËüÓкÍÓû§¿Õ¼ä°æ±¾²»Í¬µÄÔÐÍ:
int (*ioctl) (struct inode *inode, struct file *filp,
&n ......