USB串口驱动Word文档下载推荐.docx
- 文档编号:17215915
- 上传时间:2022-11-29
- 格式:DOCX
- 页数:37
- 大小:25.02KB
USB串口驱动Word文档下载推荐.docx
《USB串口驱动Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《USB串口驱动Word文档下载推荐.docx(37页珍藏版)》请在冰豆网上搜索。
linux/usb/serial.h>
#include"
pl2303.h"
*VersionInformation
#defineDRIVER_AUTHOR"
GregKroah-Hartman,greg@,
#defineDRIVER_DESC"
USBSerialDrivercore"
staticvoidport_free(structusb_serial_port*port);
/*DriverstructureweregisterwiththeUSBcore*/
staticstructusb_driverusb_serial_driver={
.name="
usbserial"
.probe=usb_serial_probe,
.disconnect=usb_serial_disconnect,
.suspend=usb_serial_suspend,
.resume=usb_serial_resume,
.no_dynamic_id=1,
};
/*ThereisnoMODULE_DEVICE_TABLEforusbserial.c.Instead
theMODULE_DEVICE_TABLEdeclarationsineachserialdriver
causethe"
hotplug"
programtopullinwhatevermoduleisnecessary
viamodprobe,andmodprobewillloadusbserialbecausetheserial
driversdependonit.
*/
staticintdebug;
/*initiallyallNULL*/
staticstructusb_serial*serial_table[SERIAL_TTY_MINORS];
staticDEFINE_MUTEX(table_lock);
staticLIST_HEAD(usb_serial_driver_list);
structusb_serial*usb_serial_get_by_index(unsignedindex)
{
structusb_serial*serial;
mutex_lock(&
table_lock);
serial=serial_table[index];
if(serial)
kref_get(&
serial->
kref);
mutex_unlock(&
returnserial;
}
staticstructusb_serial*get_free_serial(structusb_serial*serial,
intnum_ports,unsignedint*minor)
unsignedinti,j;
intgood_spot;
dbg("
%s%d"
__func__,num_ports);
*minor=0;
for(i=0;
i<
SERIAL_TTY_MINORS;
++i){
if(serial_table[i])
continue;
good_spot=1;
for(j=1;
j<
=num_ports-1;
++j)
if((i+j>
=SERIAL_TTY_MINORS)||(serial_table[i+j])){
good_spot=0;
i+=j;
break;
}
if(good_spot==0)
*minor=i;
j=0;
dbg("
%s-minorbase=%d"
__func__,*minor);
for(i=*minor;
(i<
(*minor+num_ports))&
&
SERIAL_TTY_MINORS);
serial_table[i]=serial;
serial->
port[j++]->
number=i;
}
mutex_unlock(&
returnserial;
}
returnNULL;
staticvoidreturn_serial(structusb_serial*serial)
inti;
%s"
__func__);
serial->
num_ports;
++i)
serial_table[serial->
minor+i]=NULL;
staticvoiddestroy_serial(structkref*kref)
structusb_serial_port*port;
serial=to_usb_serial(kref);
%s-%s"
__func__,serial->
type->
description);
/*returntheminorrangethatthisdevicehad*/
if(serial->
minor!
=SERIAL_TTY_NO_MINOR)
return_serial(serial);
release(serial);
port=serial->
port[i];
if(port)
put_device(&
port->
dev);
/*Ifthisisa"
fake"
port,wehavetocleanituphere,asitwill
*notgetcleanedupinport_release()asitwasneverregisteredwith
*thedrivercore*/
num_ports<
num_port_pointers){
for(i=serial->
i<
num_port_pointers;
port=serial->
if(port)
port_free(port);
usb_put_dev(serial->
/*freeupanymemorythatweallocated*/
kfree(serial);
voidusb_serial_put(structusb_serial*serial)
kref_put(&
kref,destroy_serial);
/*****************************************************************************
*Driverttyinterfacefunctions
*****************************************************************************/
staticintserial_open(structtty_struct*tty,structfile*filp)
unsignedintportNumber;
intretval=0;
/*gettheserialobjectassociatedwiththisttypointer*/
serial=usb_serial_get_by_index(tty->
index);
if(!
serial){
tty->
driver_data=NULL;
return-ENODEV;
disc_mutex);
portNumber=tty->
index-serial->
minor;
port=serial->
port[portNumber];
port||serial->
disconnected)
retval=-ENODEV;
else
get_device(&
/*
*Note:
Ourlockingorderrequirementdoesnotallowport->
mutex
*tobeacquiredwhileserial->
disc_mutexisheld.
if(retval)
gotobailout_serial_put;
if(mutex_lock_interruptible(&
mutex)){
retval=-ERESTARTSYS;
gotobailout_port_put;
++port->
port.count;
/*setupourportstructuremakingthettydriver
*rememberourportobject,andusit*/
tty->
driver_data=port;
tty_port_tty_set(&
port,tty);
if(port->
port.count==1){
/*lockthismodulebeforewecallit
*thismayfail,whichmeanswemustbailout,
*safebecausewearecalledwithBKLheld*/
if(!
try_module_get(serial->
driver.owner)){
retval=-ENODEV;
gotobailout_mutex_unlock;
mutex_lock(&
if(serial->
else
retval=usb_autopm_get_interface(serial->
interface);
if(retval)
gotobailout_module_put;
/*onlycallthedevicespecificopenifthis
*isthefirsttimetheportisopened*/
retval=serial->
open(tty,port,filp);
gotobailout_interface_put;
mutex);
return0;
bailout_interface_put:
usb_autopm_put_interface(serial->
bailout_module_put:
module_put(serial->
driver.owner);
bailout_mutex_unlock:
port->
port.count=0;
port,NULL);
bailout_port_put:
put_device(&
bailout_serial_put:
usb_serial_put(serial);
returnretval;
staticvoidserial_close(structtty_struct*tty,structfile*filp)
structusb_serial_port*port=tty->
driver_data;
structmodule*owner;
intcount;
port)
return;
%s-port%d"
__func__,port->
number);
serial=port->
serial;
owner=serial->
driver.owner;
port.count==0){
port.count==1)
/*onlycallthedevicespecificcloseifthis
*portisbeingclosedbythelastowner.Ensurewedo
*thisbeforewedroptheportcount.Thecallisprotected
*bytheportmutex
*/
serial->
close(tty,port,filp);
port.count==(port->
console?
2:
1)){
structtty_struct*tty=tty_port_tty_get(&
port);
if(tty){
/*Wemustdothisbeforewedroptheportcountto
zero.*/
if(tty->
driver_data)
tty->
tty_port_tty_set(&
tty_kref_put(tty);
--port->
count=port->
/*Mustn'
tdereferenceportanymore*/
if(count==0){
usb_autopm_put_interface(serial->
tdereferenceserialanymore*/
if(count==0)
module_put(owner);
staticintserial_write(structtty_struct*tty,constunsignedchar*buf,
intcount)
intretval=-ENODEV;
dev->
state==USB_STATE_NOTATTACHED)
gotoexit;
%s-port%d,%dbyte(s)"
number,count);
/*countismanagedunderthemutexlockforthettysocannot
droptozerountilafterthelastclosecompletes*/
WARN_ON(!
port.count);
/*passontothedriverspecificversionofthisfunction*/
retval=port->
write(tty,port,buf,count);
exit:
staticintserial_write_room(structtty_struct*tty)
returnport->
write_room(tty);
staticintserial_chars_in_buffer(structtty_struct*tty)
%s=port%d"
/*ifthedevicewasunpluggedthenanyremainingcharacters
felloutoftheconnector;
)*/
return0;
chars_in_buffer(tty);
staticvoidserial_throttle(structtty_struct*tty)
th
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- USB 串口 驱动
![提示](https://static.bdocx.com/images/bang_tan.gif)