一区二区三区日韩精品-日韩经典一区二区三区-五月激情综合丁香婷婷-欧美精品中文字幕专区

分享

linux下PC與AT91SAM9X35 USB通訊

 quasiceo 2015-07-04
最近在做PC和開(kāi)發(fā)板的USB通訊,借鑒了內(nèi)核中的代碼zero.c和usb-skeieton.c,實(shí)現(xiàn)了linux環(huán)境下USB的通訊,在此做點(diǎn)記錄,如有疑問(wèn),請(qǐng)發(fā)郵箱:lutao614@126.com
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include  
#include  
#include
#include
#include
#include "g_zero.h"
#include "gadget_chips.h"
#include "composite.c"
#include "usbstring.c"
#include "config.c"
#include "epautoconf.c"
#include "f_sink.c"  ////自己添加的

#define DRIVER_VERSION "Gestton 2013"
static const char longname[] = "Gestton USB Device";
unsigned buflen = 4096;
static int loopdefault = 0;
#define DRIVER_VENDOR_NUM 0x03EB
#define DRIVER_PRODUCT_NUM 0x6119
#define DEFAULT_AUTORESUME 0
unsigned autoresume = DEFAULT_AUTORESUME;
static struct usb_device_descriptor device_desc = {
.bLength = sizeof device_desc,
.bDescriptorType = USB_DT_DEVICE,
.bcdUSB = cpu_to_le16(0x0200),
.bDeviceClass = USB_CLASS_VENDOR_SPEC,
.idVendor = cpu_to_le16(DRIVER_VENDOR_NUM),
.idProduct = cpu_to_le16(DRIVER_PRODUCT_NUM),
.bNumConfigurations = 2,
};
#define STRING_MANUFACTURER_IDX 0
#define STRING_PRODUCT_IDX 1
#define STRING_SERIAL_IDX 2
static char manufacturer[50];
static char serial[] = "0123456789.0123456789.0123456789";
static struct usb_string strings_dev[] = {
[STRING_MANUFACTURER_IDX].s = manufacturer,
[STRING_PRODUCT_IDX].s = longname,
[STRING_SERIAL_IDX].s = serial,
{  }
};

static struct usb_gadget_strings stringtab_dev = {
.language = 0x0409,  
.strings = strings_dev,
};

static struct usb_gadget_strings *dev_strings[] = {
&stringtab_dev,
NULL,
};

struct usb_request *alloc_ep_req(struct usb_ep *ep)
{
struct usb_request *req;
req = usb_ep_alloc_request(ep, GFP_ATOMIC);
if (req) {
req->length = buflen;
req->buf = kmalloc(buflen, GFP_ATOMIC);
if (!req->buf) {
usb_ep_free_request(ep, req);
req = NULL;
}
}
return req;
}

void free_ep_req(struct usb_ep *ep, struct usb_request *req)
{
kfree(req->buf);
usb_ep_free_request(ep, req);
}

static void disable_ep(struct usb_composite_dev *cdev, struct usb_ep *ep)
{
int value;
if (ep->driver_data) {
value = usb_ep_disable(ep);
if (value < 0)
DBG(cdev, "disable %s --> %d\n",ep->name, value);
ep->driver_data = NULL;
}
}

void disable_endpoints(struct usb_composite_dev *cdev,struct usb_ep *in, struct usb_ep *out)
{
disable_ep(cdev, in);
disable_ep(cdev, out);
}

static struct timer_list autoresume_timer;
static void zero_autoresume(unsigned long _c)
{
struct usb_composite_dev *cdev = (void *)_c;
struct usb_gadget *g = cdev->gadget;
if (!cdev->config)
return;
if (g->speed != USB_SPEED_UNKNOWN) {
int status = usb_gadget_wakeup(g);
INFO(cdev, "%s --> %d\n", __func__, status);
}
}

static void zero_suspend(struct usb_composite_dev *cdev)
{
if (cdev->gadget->speed == USB_SPEED_UNKNOWN)
return;
if (autoresume) {
mod_timer(&autoresume_timer, jiffies + (HZ * autoresume));
DBG(cdev, "suspend, wakeup in %d seconds\n", autoresume);
} else
DBG(cdev, "%s\n", __func__);
}

static void zero_resume(struct usb_composite_dev *cdev)
{
DBG(cdev, "%s\n", __func__);
del_timer(&autoresume_timer);
}

static int __init zero_bind(struct usb_composite_dev *cdev)
{
int gcnum;
struct usb_gadget *gadget = cdev->gadget;
int id;

id = usb_string_id(cdev);
if (id < 0)
return id;
strings_dev[STRING_MANUFACTURER_IDX].id = id;
device_desc.iManufacturer = id;

id = usb_string_id(cdev);
if (id < 0)
return id;
strings_dev[STRING_PRODUCT_IDX].id = id;
device_desc.iProduct = id;

id = usb_string_id(cdev);
if (id < 0)
return id;
strings_dev[STRING_SERIAL_IDX].id = id;
device_desc.iSerialNumber = id;
setup_timer(&autoresume_timer, zero_autoresume, (unsigned long) cdev);

if (loopdefault) {
loopback_add(cdev, autoresume != 0);
sourcesink_add(cdev, autoresume != 0);
} else {
                sourcesink_add(cdev, 1);
}

gcnum = usb_gadget_controller_number(gadget);//獲得控制器代號(hào)
if (gcnum >= 0)
device_desc.bcdDevice = cpu_to_le16(0x0200 + gcnum);
else {
pr_warning("%s: controller '%s' not recognized\n",
longname, gadget->name);
device_desc.bcdDevice = cpu_to_le16(0x9999);
}

INFO(cdev, "%s, version: " DRIVER_VERSION "\n", longname);
snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
init_utsname()->sysname, init_utsname()->release,
gadget->name);

return 0;
}

static int zero_unbind(struct usb_composite_dev *cdev)
{
del_timer_sync(&autoresume_timer);
return 0;
}

static struct usb_composite_driver zero_driver = {
.name = "zero",
.dev = &device_desc,
.strings = dev_strings,
.unbind = zero_unbind,
.suspend = zero_suspend,
.resume = zero_resume,
};


static int __init init(void)
{
return usb_composite_probe(&zero_driver, zero_bind);
}
static void __exit cleanup(void)
{
usb_composite_unregister(&zero_driver);
}
module_init(init);
module_exit(cleanup);
MODULE_AUTHOR("LUTAO");
MODULE_LICENSE("GPL");

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類(lèi)似文章 更多

    日韩精品人妻少妇一区二区| 久久久免费精品人妻一区二区三区 | 初尝人妻少妇中文字幕在线| 日本人妻中出在线观看| 高中女厕偷拍一区二区三区| 国产成人综合亚洲欧美日韩| 爽到高潮嗷嗷叫之在现观看| 黑人粗大一区二区三区| 99少妇偷拍视频在线| 91精品日本在线视频| 国产精品九九九一区二区| 国产中文字幕一区二区| 国产精品一区二区不卡中文| 欧美性高清一区二区三区视频| 欧美色欧美亚洲日在线| 人妻乱近亲奸中文字幕| 一区二区三区人妻在线| 亚洲欧美日韩国产综合在线| 婷婷色网视频在线播放| 日韩一区二区三区在线日| 国产美女精品人人做人人爽| 在线免费国产一区二区三区| 好东西一起分享老鸭窝| 午夜视频成人在线观看| 好吊色免费在线观看视频| 日韩少妇人妻中文字幕| 精品日韩国产高清毛片| 日韩精品视频香蕉视频| 欧美国产日产综合精品| 欧美熟妇一区二区在线| 免费精品一区二区三区| 亚洲欧美日韩在线看片| 91老熟妇嗷嗷叫太91| 国产一区二区不卡在线视频| 加勒比东京热拍拍一区二区| 真实偷拍一区二区免费视频| 亚洲综合天堂一二三区| 好吊色免费在线观看视频| 99精品国产自在现线观看| 日韩国产亚洲欧美激情| 韩国激情野战视频在线播放|