USB Architecture

Report
USB ARCHITECTURE
P97922006
彭治民
OUTLINE
Introduction
 Electronic specification
 Protocol
 Linux’s driver

INTRODUCTION
USB 由2004年釋出,採用主從架構方式與周邊裝置溝
通,初期速度12Mbit/s(USB 1.1),目前速度最高為
480Mbit/s(USB 2.0)。
 通常有一個主機端(Host)&伺服器端(Slave)。
 USB採用星狀拓墣方式與各個周邊裝置連接。
 特點是,隨插即用,可以快速與周邊建立連接通道,
進而控制USB周邊裝置。
 傳輸線距離約 1.2 Meter。
 Total device <127

ELECTRONIC SPECIFICATIONCONNECTOR
A Type
B Type
Mini-B
ELECTRONIC SPECIFICATIONUSB DETECT
Item
Speed
Detecting
Version
LOW SPEED
1.5Mbit/Sec
R1 pull up
USB 1.0/1.1
FULL SPEED
12Mbit /Sec
R2 pull low USB 1.0/1.1
HIGH SPEED
480Mbit/Sec
Auto detect USB 2.0
VBUS
DPC
D+
R R
R R
1 2
USB
Device
ELECTRONIC SPECIFICATIONTRANSMISSION
ELECTRONIC SPECIFICATIONHUB TOPOLOGY
Max Level => 7
PROTOCOL- PACKET DESCRIPTOR
 SYNC
 Packet Identifier(PID) Field
PID Type
SubType
Descriptor
Token
OUT,IN,SOF,SETUP
Control
Data
DATA0,DATA1,DATA2..
Send Data
Handshake
ACK,NACK,STALL,NYE
T
Respond
Special
PRE,ERR,SPLIT,PING
PROTOCOL- PACKET DESCRIPTOR
 Address
0~127
 Endpoint
0~15
 DATA
<=1024
16 bit CRC
PROTOCOL- TOKEN PACKET
SubTyp
e
PID<3:0
>
Descriptor
OUT
0001B
Address + endpoint number in host-tofunction transaction
IN
1001B
Address + endpoint number in function-tohost transaction
SOF
0101B
Start-of-Frame marker and frame number
SETUP
1101B
Address + endpoint number in host-tofunction transaction for SETUP to a control
pipe
PROTOCOL- DATA PACKET
SubTyp
e
PID<3:0
>
Descriptor
DATA1
0011B
Data packet PID even
DATA2
1011B
Data packet PID odd
DATA3
0111B
Data packet PID high-speed, high bandwidth
isochronous transaction in a microframe
MDATA
1111B
Data packet PID high-speed for split and
high bandwidth isochronous transactions
PROTOCOL- HANDSHAKE PACKET
SubTyp
e
PID<3:0
>
Descriptor
PRE
1100B
(Token) Host-issued preamble. Enables
downstream bus traffic to low-speed devices.
ERR
1100B
(Handshake) Split Transaction Error
Handshake (reuses PRE value)
SPLIT
1000B
(Token) High-speed Split Transaction Token
PING
0100B
(Token) High-speed flow control probe for a
bulk/control endpoint
PROTOCOLFOUR TYPES TRANSMISSION
CONTROL
 BULK
 INTERRUPT
 ISOCHRONOUS

PROTOCOL- CONTROL/BULK
PROTOCOL- INTERRUPT
PROTOCOL- ISOCHRONOUS
PROTOCOL- FORMAT OF SETUP DATA(1/2)
PROTOCOL- FORMAT OF SETUP DATA(2/2)
PROTOCOL- GET DESCRIPTOR(1/2)
PROTOCOL- GET DESCRIPTOR(2/2)
PROTOCOL- GET QUALIFIER
PROTOCOL-STANDARD CONFIGURATION
DESCRIPTOR
PROTOCOL-STANDARD CONFIGURATION
DESCRIPTOR
PROTOCOL-STANDARD INTERFACE
DESCRIPTOR(1/3)
PROTOCOL-STANDARD INTERFACE
DESCRIPTOR(2/3)
PROTOCOL-STANDARD INTERFACE
DESCRIPTOR(3/3)
PROTOCOL-STANDARD ENDPOINT
DESCRIPTOR(1/4)
PROTOCOL-STANDARD ENDPOINT
DESCRIPTOR(2/4)
PROTOCOL-STANDARD ENDPOINT
DESCRIPTOR(3/4)
PROTOCOL-STANDARD ENDPOINT
DESCRIPTOR(4/4)
PROTOCOL-USB
USB Hcontrol
OST CONTROL
FLOW
flow
USB HOST
Assign Addr 1
Addr 0
USB Hub
Assign
Addr 2
Addr 0
Addr 0
USB Device1
Assign
Addr 3
USB Device2
PROTOCOL-USB
USB Hcontrol
OST CONTROL
FLOW
flow
USB HOST
Descriptor
Configure
USB Controller
interface
Custom
Device
HID Class
USB Hub
USB Dev
USB Device
USB Device 127
USB Device
..
1
0
VID,PID 0
VID,PID 0
VID,PID
0 0
VID,PID
subdrivers
VID,PID 0
VID,PID
Class
ID 0
subdrivers
LINUX’S DRIVER- MODULE EXAMPLE
static struct usb_driver rt2870_driver= {
.name =
“USBdriver”,
.probe = rt2870_probe,
.disconnect=
rt2870_disconnect,
.id_table =
rt2870_table, //PID ,VID
.supports_autosuspend=0,
};
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");
LINUX’S DRIVER- MODULE EXAMPLE
static struct file_operations rt2870_fops = {
.owner =THIS_MODULE,
.read =rt2870_read,
.write =rt2870_write,
.open =rt2870_open,
.ioctl = rt2870_ioctl,
.release= rt2870_release,
};
static struct usb_class_driver rt2870_class = {
.name = "rt2870usb%d",
.fops = &rt2870_fops,
};
LINUX’S DRIVER- MODULE EXAMPLE
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(interface));
return ret;
}
LINUX’S DRIVER- MODULE EXAMPLE
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;
}
LINUX’S DRIVER- MODULE EXAMPLE
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;
}
LINUX’S DRIVER- MODULE EXAMPLE
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;
}
LINUX’S DRIVER- MODULE EXAMPLE
CONTROL DATA SEND
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
size
: Return data
: Number of buf size
ret = usb_submit_urb(dev->pUrbIn, GFP_ATOMIC);
LINUX’S DRIVER- MODULE EXAMPLE
BULK DATA SEND AND RECEIVER
dev->pUrb =usb_alloc_urb(0,GFP_ATOMIC); //Build Urb for usb packet
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);
LINUX’S DRIVER- MODULE EXAMPLE
SEND COMPLIETE
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
}

similar documents