CẤU HÌNH THIÊT BỊ 48-

Một phần của tài liệu đồ án công nghệ thông tin USB driver trên hệ điều hành Linux Red Hat (Trang 48 - 54)

Mỗi khi thiết bị (device) được gắn vào hệ thống thì nó được đánh số và các thông tin description được đọc. Description là các thông tin mô tả về thiết bị và các thuộc tính của nó

+ Device Descriptor chứa thông tin về device. Một device thì có một Descriptor

+ Configuration Descriptor xác định các thông tin cấu hình, môt device thì có một hay nhiều configuration descriptors.

+ Interface Descriptor mô tả giao diện đối với một configuration descriptor + Endpoint Descriptor chứa các thông tin được yêu cầu bởi host để lấy được băng thông của mỗi điểm truy cập cuối.

+ String Descriptors cung cấp thêm các thồn tin có thê đọc được dưới ở Unicode format.

Một USB device được đăng ký và gỡ bỏ khỏi host như một hệ thống con. Mỗi USB device driver cần đăng ký một file, một số chính (đối với USB luôn luôn la 180) và một số phụ từ 0 đến 15.

+ Cấu trúc dữ liệu lưu các thông tin về USB driver

struct usb_driver { const char *name;

void * (*probe)(struct usb_device *, unsigned int, const struct usb_device_id *id_table);

void (*disconnect)(struct usb_device *, void *); struct list_head driver_list;

struct file_operations *fops; int minor;

struct semaphore serialize;

int (*ioctl) (struct usb_device *dev, unsigned int code, void *buf);

const struct usb_device_id *id_table; };

Trong đó

- name: thường là tên module

- probe: điểm truy cập của probe function.

- disconnect: điểm truy cập của disconnect function.

- driver list: cho sử dụng bên trong driver - khởi tạo là NULL,NULL - fops: các thao tác đối với a driver

- minor: so phụ được gán cho device này device - serialize:

- ioctl: - id table:

+ 2 điểm truy cập các hàm chức năng

probe được gọi khi một device được kết gắn vào hệ thống disconnect được gọi khi một device được tháo ra khỏi hệ thống

void *probe(struct usb_device *dev, unsigned int interface, const struct usb_device_id *id_table)

{

struct driver_context *context;

if (dev->descriptor.idVendor == 0x0547 && dev->descriptor.idProduct == 0x2131 && interface == 1 ) { context=allocate_driver_resources(); return context; } return NULL;

}

static void dabusb_disconnect (struct usb_device *usbdev, void *drv_context)

{

struct driver_context *s = drv_context; s->remove_pending = 1; wake_up (&s->wait); sleep_on (&s->remove_ok); free_driver_resources(s); } + Các hàm hỗ trợ từ host (adsbygoogle = window.adsbygoogle || []).push({});

- int usb register(struct usb driver *drv);

dùng để dăng ký một USB device driver mới như một hệ thống con của host

- void usb deregister(struct usb driver *drv);

dùng để gỡ bỏ một USB device driver ra khỏi host host

- void usb driver claim interface(struct usb driver *driver, struct usb interface *iface, void *drv context);

dùng để đăng ky USB sử dụng nhiều giao diện khác nhau - int usb interface claimed(struct usb interface *iface);

dung để kiểm tra xem device driver khác đã sử dụng giao dien này chưa

- void usb driver release interface(struct usb driver *driver, struct usb interface *iface);

giải phóng tất cả các giao diện đã được đăng ký trong hàm probe

- const struct usb device id *usb match id( struct usb device *dev, struct usb interface *interface, const struct usb device id *id);

+ Cấu hình Descriptor cho device:

Mỗi device có một cấu trúc phân cấp các thông tin về device và thuộc tính của nó

struct usb_device{ ...

struct usb_config_descriptor *actconfig;/* the active configuration */

...

struct usb_device_descriptor descriptor;/* Descriptor */ struct usb_config_descriptor *config; /* All of the configs */ }

usb_device là gốc truy cập của tất cả các descriptor

+ Truy cập tất cả các descriptor

for (i = 0; i < dev->descriptor.bNumConfigurations; i++) { struct usb_config_descriptor *cfg = &dev->config[i]; ...

}

+ Truy cập tất cả các interface của một Configuration

for (j = 0; j < cfg->bNumInterfaces; j++) {

struct usb_interface *ifp = &cfg->interface[j]; ...

}

+ Truy cập tất cả các interface thay thế của một Configuration

for (k = 0; k < ifp->num_altsetting; k++) {

struct usb_interface_descriptor *as = &ifp->altsetting[k]; ...

}

+ Truy cập tất cả các endpoint descriptors của một interface

for(l = 0; l < as->bNumEndpoints; l++) { (adsbygoogle = window.adsbygoogle || []).push({});

struct usb_endpoint_descriptor *ep=&as->endpoint[k]; ...

}

+ Các hàm thiết lập, gỡ bỏ Desctiptor, Interface, Configuration

- int usb set_configuration(struct usb device *dev, int configuration); thiết lập một configuration

- int usb set_interface(struct usb device *dev, int interface, int alternate);

thiết lập một interface thay thế

- int usb_ get_ device descriptor(struct usb device *dev); lấy các thông tin về usb device

- int usb get descriptor(struct usb device *dev, unsigned char desctype, unsigned char descindex, void *buf, int size);

lấy các thông tin về descriptors

- int usb get string(struct usb device *dev, unsigned short langid, unsigned char index,

void *buf, int size);

lấy các string đã được đánh chỉ mục cho một device, configuration hay interface

- int usb string(struct usb device *dev, int index, char *buf, size t size);

lấy các string đã được đánh chỉ mục cho một device,

configuration hay interface nhưng chuyển đổi từ Unicode sang ASCII

- int usb get status(struct usb device *dev, int type, int target, void *data)

lấy trạng thái của device

+Một số hàm khác

- int usb clear halt(struct usb device *dev, int pipe); - int usb get protocol(struct usb device *dev, int ifnum); - int usb set protocol(struct usb device *dev, int protocol, - int usb get report(struct usb device *dev, unsigned char type, unsigned char id,

int ifnum, void *buf, int size);

- int usb set idle(struct usb device *dev, int ifnum, int duration, int report id);

Một phần của tài liệu đồ án công nghệ thông tin USB driver trên hệ điều hành Linux Red Hat (Trang 48 - 54)