/*
* osx_pl2303.cpp Prolific PL2303 USB to serial adaptor driver for OS X
*
* Copyright (c) 2006 BJA Electronics, Jeroen Arnoldus (opensource@bja-electronics.nl)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Driver is inspired by the following projects:
* - Linux kernel PL2303.c Copyright (C) 2001-2004 Greg Kroah-Hartman (greg@kroah.com)
* Copyright (C) 2003 IBM Corp.
* - Apple16x50Serial Copyright (c) 1997-2003 Apple Computer, Inc. All rights reserved.
* Copyright (c) 1994-1996 NeXT Software, Inc. All rights reserved.
* - AppleRS232Serial Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
* - AppleUSBIrda Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
*
*
*
* Tests:
* - Driver only tested with ATEN UC-RS232A, but should support other PL2303 based USB to RS232 converters
* - Handshake signals
*
* Todo:
* - Implementation Powermanagement
* - Fix USBF: Could not open device: Strange error message
*
*
*
* http://www.usb.org/developers/devclass_docs/usbcdc11.pdf
*/
#include <IOKit/IOLib.h>
#include <IOKit/IOTypes.h>
#include <IOKit/IOMessage.h>
#include "osx_pl2303.h"
#include <IOKit/serial/IOSerialKeys.h>
#include <IOKit/usb/IOUSBInterface.h>
#include <IOKit/usb/IOUSBLog.h>
#include <UserNotification/KUNCUserNotifications.h>
extern "C" {
#include <pexpert/pexpert.h>
}
//To enable logging remove comments from #define DEBUG and #define DATALOG
//Use USB Prober to monitor the logs.
//#define DEBUG
//#define DATALOG
#ifdef DEBUG
#define DEBUG_IOLog(args...) USBLog (args)
#else
#define DEBUG_IOLog(args...)
#endif
#ifdef DATALOG
#define DATA_IOLog(args...) USBLog (args)
#else
#define DATA_IOLog(args...)
#endif
#define super IOSerialDriverSync
OSDefineMetaClassAndStructors(nl_bjaelectronics_driver_PL2303, IOSerialDriverSync)
/****************************************************************************************************/
//
// Function: Asciify
//
// Inputs: i - the nibble
//
// Outputs: return byte - ascii byte
//
// Desc: Converts to ascii.
//
/****************************************************************************************************/
static UInt8 Asciify(UInt8 i)
{
i &= 0xF;
if ( i < 10 )
return( '0' + i );
else return( 55 + i );
}/* end Asciify */
bool nl_bjaelectronics_driver_PL2303::init(OSDictionary *dict)
{
bool res = super::init(dict);
DEBUG_IOLog(4,"%s(%p)::Initializing\n", getName(), this);
return res;
}
void nl_bjaelectronics_driver_PL2303::free(void)
{
DEBUG_IOLog(4,"%s(%p)::Freeing\n", getName(), this);
super::free();
}
IOService *nl_bjaelectronics_driver_PL2303::probe(IOService *provider, SInt32 *score)
{
IOUSBDevice *Provider;
DEBUG_IOLog(4,",%s(%p)::Probe\n", getName(), this);
Provider = OSDynamicCast(IOUSBDevice, provider);
if (!Provider) {
IOLog("%s(%p)::Probe Attached to non-IOUSBDevice provider! Failing probe()\n", getName(), this);
return NULL;
}
IOService *res = super::probe(provider, score);
DEBUG_IOLog(5,"%s(%p)::Probe successful\n", getName(), this);
return res;
}
bool nl_bjaelectronics_driver_PL2303::start(IOService *provider)
{
enum pl2303_type type = type_1;
fTerminate = false; // Make sure we don't think we're being terminated
fPort = NULL;
fNub = NULL;
fpInterface = NULL;
fpinterruptPipeBuffer = NULL;
fPipeInBuffer = NULL;
fPipeOutBuffer = NULL;
fpDevice = NULL;
fpInPipe = NULL;
fpOutPipe = NULL;
fpInterruptPipe = NULL;
fUSBStarted = false; // set to true when start finishes up ok
fSessions = 0;
fReadActive = false;
fWriteActive = false;
DEBUG_IOLog(4,"%s(%p)::start PL2303 Driver\n", getName(), this);
if( !super::start( provider ) )
{
IOLog("%s(%p)::start - super failed\n", getName(), this);
goto Fail;
}
fpDevice = OSDynamicCast(IOUSBDevice, provider);
if(!fpDevice)
{
IOLog("%s(%p)::start - Provider isn't a USB device!!!\n", getName(), this);
goto Fail;
}
if (fpDevice->GetNumConfigurations() < 1)
{
IOLog("%s(%p)::start - no composite configurations\n", getName(), this);
goto Fail;
}
// make our nub (and fPort) now
if( !createNub() ) goto Fail;
// Now configure it (leaves device suspended)
if( !configureDevice( fpDevice->GetNumConfigurations() ) ) goto Fail;
// Finally create the bsd tty (serial stream) and leave it there until usb stop
if( !createSerialStream() ) goto Fail;
fWorkLoop = getWorkLoop();
if (!fWorkLoop)
{
IOLog("%s(%p)::start - getWorkLoop failed\n", getName(), this);
goto Fail;
}
fWorkLoop->retain();
fCommandGate = IOCommandGate::commandGate(this);
if (!fCommandGate)
{
IOLog("%s(%p)::start - create commandGate failed\n", getName(), this);
goto Fail;
}
if (fWorkLoop->addEventSource(fCommandGate) != kIOReturnSuccess)
{
IOLog("%s(%p)::start - addEventSource fCommandGate to WorkLoop failed\n", getName(), this);
goto Fail;
}
fCommandGate->enable();
OSNumber * release = (OSNumber *) fpDevice->getProperty(kUSBDeviceReleaseNumber);
DEBUG_IOLog(1,"%s(%p)::start - Get device version: %p \n", getName(), this, release->unsigned16BitValue() );
if (release->unsigned16BitValue()==PROLIFIC_REV_H) {
DEBUG_IOLog(1,"%s(%p)::start - Chip type: H \n" );
type = type_1; // was rev_H
} else if ( release->unsigned16BitValue()==PROLIFIC_REV_X ) {
DEBUG_IOLog(1,"%s(%p)::start - Chip type: X \n" );
type = rev_HX; // was rev_X
} else if ( release->unsigned16BitValue()==PROLIFIC_REV_HX_CHIP_D ) {
DEBUG_IOLog(1,"%s(%p)::start - Chip type: HX \n" );
type = rev_HX;
} else if ( release->unsigned16BitValue()==PROLIFIC_REV_1 ) {
DEBUG_IOLog(1,"%s(%p)::start - Chip type: 1 \n" );
type = type_1;
} else {
DEBUG_IOLog(1,"%s(%p)::start - Chip type: unkwown \n" );
type = unknown;
}
fPort->type = type;
fUSBStarted = true;
DEBUG_IOLog(3,"%s(%p)::start - Allocate resources \n", getName(), this);
return true;
Fail:
if (fNub)
{
destroyNub();
}
if (fCommandGate)
{
fCommandGate->release();
fCommandGate = NULL;
}
if (fWorkLoop)
{
fWorkLoop->release();
fWorkLoop = NULL;
}
DEBUG_IOLog(1,"%s(%p)::start - failed\n", getName(), this);
stop( provider );
return false;
}
/****************************************************************************************************/
//
// Method: nl_bjaelectronics_driver_PL2303::stop
//
// Inputs: provider - my provider
//
// Outputs: None
//
// Desc: Stops
//
/****************************************************************************************************/
void nl_bjaelectronics_driver_PL2303::stop( IOService *provider )
{
fUSBStarted = false; // reset usb start/stop flag for CheckSerialState
CheckSerialState(); // turn serial off, release resources
DEBUG_IOLog(5,"%s(%p)::stop CheckSerialState succeed\n", getName(), this);
if (fCommandGate)
{
fCommandGate->release();
fComm
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
osx-pl2303-code-41.zip (64个子文件)
osx-pl2303-code-41
tags
release-0.3.0
osx-pl2303.xcodeproj
project.pbxproj 17KB
load.sh 247B
distribution
osx-pl2303-10.3.9.pmproj 3KB
osx-pl2303.pmproj 3KB
welcome.rtf 993B
license.rtf 15KB
osx_pl2303.h 17KB
osx_pl2303.cpp 132KB
release-osx-10.3.x-Info.plist 715B
English.lproj
InfoPlist.strings 198B
Info.plist 16KB
COPYING 18KB
release-0.2.1
osx-pl2303.xcodeproj
project.pbxproj 17KB
load.sh 230B
distribution
osx-pl2303-10.3.9.pmproj 2KB
osx-pl2303.pmproj 2KB
welcome.rtf 1KB
license.rtf 15KB
osx_pl2303.h 16KB
osx_pl2303.cpp 131KB
release-osx-10.3.x-Info.plist 715B
English.lproj
InfoPlist.strings 198B
Info.plist 15KB
COPYING 18KB
release-0.1
osx-pl2303.xcodeproj
Jeroen.pbxuser 19KB
project.pbxproj 9KB
osx_pl2303.h 14KB
osx_pl2303.cpp 111KB
English.lproj
InfoPlist.strings 198B
Info.plist 2KB
COPYING 18KB
release-0.2.2
osx-pl2303.xcodeproj
project.pbxproj 17KB
load.sh 247B
distribution
osx-pl2303-10.3.9.pmproj 2KB
osx-pl2303.pmproj 2KB
welcome.rtf 1KB
license.rtf 15KB
osx_pl2303.h 16KB
osx_pl2303.cpp 131KB
release-osx-10.3.x-Info.plist 715B
English.lproj
InfoPlist.strings 198B
Info.plist 15KB
COPYING 18KB
release-0.2
osx-pl2303.xcodeproj
project.pbxproj 9KB
distribution
osx-pl2303.pmproj 2KB
welcome.rtf 1KB
license.rtf 15KB
osx_pl2303.h 16KB
osx_pl2303.cpp 129KB
English.lproj
InfoPlist.strings 198B
Info.plist 15KB
COPYING 18KB
trunk
osx-pl2303.xcodeproj
project.pbxproj 17KB
load.sh 247B
distribution
osx-pl2303-10.3.9.pmproj 3KB
osx-pl2303.pmproj 3KB
welcome.rtf 993B
license.rtf 15KB
osx_pl2303.h 17KB
osx_pl2303.cpp 132KB
release-osx-10.3.x-Info.plist 715B
English.lproj
InfoPlist.strings 198B
Info.plist 18KB
COPYING 18KB
共 64 条
- 1
资源评论
nyp860624
- 粉丝: 1
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功