Presentation is loading. Please wait.

Presentation is loading. Please wait.

USB A RCHITECTURE P97922006 彭治民. O UTLINE Introduction Electronic specification Protocol Linux’s driver.

Similar presentations


Presentation on theme: "USB A RCHITECTURE P97922006 彭治民. O UTLINE Introduction Electronic specification Protocol Linux’s driver."— Presentation transcript:

1 USB A RCHITECTURE P97922006 彭治民

2 O UTLINE Introduction Electronic specification Protocol Linux’s driver

3 I NTRODUCTION USB 由 2004 年釋出,採用主從架構方式與周邊裝置 溝通,初期速度 12Mbit/s(USB 1.1) ,目前速度最高 為 480Mbit/s(USB 2.0) 。 通常有一個主機端 (Host)& 伺服器端 (Slave) 。 USB 採用星狀拓墣方式與各個周邊裝置連接。 特點是,隨插即用,可以快速與周邊建立連接通道, 進而控制 USB 周邊裝置。 傳輸線距離約 1.2 Meter 。 Total device <127

4 E LECTRONIC SPECIFICATION - C ONNECTOR A Type B TypeMini-B

5 E LECTRONIC SPECIFICATION - USB D ETECT ItemSpeedDetectingVersion LOW SPEED1.5Mbit/SecR1 pull upUSB 1.0/1.1 FULL SPEED12Mbit /SecR2 pull lowUSB 1.0/1.1 HIGH SPEED480Mbit/SecAuto detectUSB 2.0 PC USB Device D- D+ R R R R R1R1 R1R1 R2R2 R2R2 VBUS

6 E LECTRONIC SPECIFICATION - T RANSMISSION

7 E LECTRONIC SPECIFICATION - H UB TOPOLOGY Max Level => 7

8 P ROTOCOL - P ACKET DESCRIPTOR Packet Identifier(PID) Field SYNC PID TypeSubTypeDescriptor TokenOUT,IN,SOF,SETUPControl DataDATA0,DATA1,DATA2..Send Data HandshakeACK,NACK,STALL,NYE T Respond SpecialPRE,ERR,SPLIT,PING

9 P ROTOCOL - P ACKET DESCRIPTOR 16 bit - CRC DATA <=1024 Endpoint 0~15 Address 0~127

10 P ROTOCOL - T OKEN P ACKET SubTyp e PID Descriptor OUT0001BAddress + endpoint number in host-to- function transaction IN1001BAddress + endpoint number in function-to- host transaction SOF0101BStart-of-Frame marker and frame number SETUP1101BAddress + endpoint number in host-to- function transaction for SETUP to a control pipe

11 P ROTOCOL - D ATA P ACKET SubTyp e PID Descriptor DATA10011BData packet PID even DATA21011BData packet PID odd DATA30111BData packet PID high-speed, high bandwidth isochronous transaction in a microframe MDATA1111BData packet PID high-speed for split and high bandwidth isochronous transactions

12 P ROTOCOL - H ANDSHAKE P ACKET SubTyp e PID Descriptor PRE1100B(Token) Host-issued preamble. Enables downstream bus traffic to low-speed devices. ERR1100B(Handshake) Split Transaction Error Handshake (reuses PRE value) SPLIT1000B(Token) High-speed Split Transaction Token PING0100B(Token) High-speed flow control probe for a bulk/control endpoint

13 P ROTOCOL - F OUR T YPES T RANSMISSION CONTROL BULK INTERRUPT ISOCHRONOUS

14 P ROTOCOL - C ONTROL /B ULK

15 P ROTOCOL - I NTERRUPT

16 P ROTOCOL - I SOCHRONOUS

17 P ROTOCOL - F ORMAT OF S ETUP D ATA (1/2)

18 P ROTOCOL - F ORMAT OF S ETUP D ATA (2/2)

19 P ROTOCOL - G ET D ESCRIPTOR (1/2)

20 P ROTOCOL - G ET D ESCRIPTOR (2/2)

21 P ROTOCOL - G ET Q UALIFIER

22 P ROTOCOL -S TANDARD C ONFIGURATION D ESCRIPTOR

23

24 P ROTOCOL -S TANDARD I NTERFACE D ESCRIPTOR (1/3)

25 P ROTOCOL -S TANDARD I NTERFACE D ESCRIPTOR (2/3)

26 P ROTOCOL -S TANDARD I NTERFACE D ESCRIPTOR (3/3)

27 P ROTOCOL -S TANDARD E NDPOINT D ESCRIPTOR (1/4)

28 P ROTOCOL -S TANDARD E NDPOINT D ESCRIPTOR (2/4)

29 P ROTOCOL -S TANDARD E NDPOINT D ESCRIPTOR (3/4)

30 P ROTOCOL -S TANDARD E NDPOINT D ESCRIPTOR (4/4)

31 USB control flow P ROTOCOL - USB H OST C ONTROL FLOW USB HOST USB Hub Addr 0Assign Addr 1 USB Device1USB Device2 Addr 0 Assign Addr 2 Assign Addr 3

32 USB control flow USB HOST USB Hub USB Controller USB Dev 127 USB Device.. USB Device 1 USB Device 0 HID Class Custom Device Descriptor Configure interface VID,PID 0 subdrivers VID,PID 0 Class ID subdrivers P ROTOCOL - USB H OST C ONTROL FLOW

33 L INUX ’ S D RIVER - MODULE E XAMPLE static int __init rt2870_init(void){ int result; result = usb_register (&rt2870_driver); if(result) return result; return 0; } static void __exit rt2870_exit(void){ usb_deregister (&rt2870_driver); } module_init(rt2870_init); module_exit(rt2870_exit); MODULE_LICENSE("GPL"); static struct usb_driver rt2870_driver= {.name = “USBdriver”,.probe =rt2870_probe,.disconnect=rt2870_disconnect,.id_table =rt2870_table, //PID,VID.supports_autosuspend=0, };

34 L INUX ’ S D RIVER - MODULE E XAMPLE static struct usb_class_driver rt2870_class = {.name = " rt2870usb%d ",.fops =&rt2870_fops, }; static struct file_operations rt2870_fops = {.owner =THIS_MODULE,.read =rt2870_read,.write =rt2870_write,.open =rt2870_open,.ioctl = rt2870_ioctl,.release= rt2870_release, };

35 static int rt2870_probe(struct usb_interface * interface, const struct usb_device_id *id) { struct rt2870_dev *dev; struct usb_host_interface *iface_desc; struct usb_endpoint_descriptor *endpoint; dev = kzalloc(sizeof(*dev), GFP_KERNEL); usb_set_intfdata(interface, dev); // set private parameter iface_desc = interface- >cur_altsetting; //Current USB status,Endpoint.. ret = usb_register_dev(interface, &rt2870_class); dev->udev = usb_get_dev(interface_to_usbdev(i nterface )); return ret; } L INUX ’ S D RIVER - MODULE E XAMPLE

36 static int rt2870_open(struct inode *node, struct file *file) { struct usb_interface *interface; struct rt2870_dev *dev; interface = usb_find_interface(&rt2870_driver, iminor(node)); if(!interface) return -ENODEV; dev = usb_get_intfdata(interface); file->private_data = dev; return 0; }

37 L INUX ’ S D RIVER - MODULE E XAMPLE static int rt2870_release(struct inode *node, struct file *file) { struct rt2870_dev *dev; dev = (struct rt2870_dev*)(file->private_data); //free memeoty… return 0; } static ssize_t rt2870_read(struct file *file, char __user *buf, size_t len, loff_t *loff){ size_t size; struct rt2870_dev *dev = file->private_data; … //Get Data from queue. return size; }

38 L INUX ’ S D RIVER - MODULE E XAMPLE static ssize_t rt2870_write(struct file *file, const char __user *buf, size_t len, loff_t *loff) { size_t size; struct rt2870_dev *dev = file->private_data; … Setting Data for send... … usb_control_msg(dev->udev); //Send Data return size; }

39 L INUX ’ S D RIVER - MODULE E XAMPLE C ONTROL D ATA S END ret = int usb_control_msg(usb_dev_handle *dev, int requesttype, int request, int value, int index, char *bytes, int size, int timeout); Blocking access *dev :usb handle Requestype : Setup packet Value : Setup packet Index : Setup packet Bytes : Return data size : Number of buf size ret = usb_submit_urb(dev->pUrbIn, GFP_ATOMIC);

40 L INUX ’ S D RIVER - MODULE E XAMPLE B ULK D ATA S END AND R ECEIVER int usb_bulk_msg (struct usb_device * usb_dev, struct urb *purb, unsigned int pipe,void * data,int len,,void *function,void *context); usb_dev: usb handle purb : urb pipe : endpoint data : Data in or out len :data size *function :complete call back function. * context :private data Int usb_submit_urb(dev->pUrb, GFP_ATOMIC); dev->pUrb =usb_alloc_urb(0,GFP_ATOMIC); //Build Urb for usb packet

41 L INUX ’ S D RIVER - MODULE E XAMPLE S END C OMPLIETE void BulkComplete(struct urb *pUrb, struct pt_regs *regs) { struct rt2870_dev *dev; dev=(struct rt2870_dev *)pUrb->context; pUrb->actual_length; //Num of data sent Call Next one }


Download ppt "USB A RCHITECTURE P97922006 彭治民. O UTLINE Introduction Electronic specification Protocol Linux’s driver."

Similar presentations


Ads by Google