- change KLSI init the way it's done by the linux driver

- do not count usb headers as part of count returned by write(), else we might end up writing more than the passed amount :)


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25939 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
François Revol 2008-06-12 13:44:49 +00:00
parent 1a5c921404
commit 12f3292615
11 changed files with 70 additions and 39 deletions

View File

@ -114,7 +114,7 @@ ACMDevice::SetControlLineState(uint16 state)
void
ACMDevice::OnWrite(const char *buffer, size_t *numBytes)
ACMDevice::OnWrite(const char *buffer, size_t *numBytes, size_t *packetBytes)
{
memcpy(WriteBuffer(), buffer, *numBytes);
}

View File

@ -30,7 +30,8 @@ virtual status_t AddDevice(const usb_configuration_info *config);
virtual status_t SetLineCoding(usb_serial_line_coding *coding);
virtual status_t SetControlLineState(uint16 state);
virtual void OnWrite(const char *buffer, size_t *numBytes);
virtual void OnWrite(const char *buffer, size_t *numBytes,
size_t *packetBytes);
};
#endif //_USB_ACM_H_

View File

@ -11,8 +11,13 @@
#include <OS.h>
#include <KernelExport.h>
#include <Drivers.h>
#include <string.h>
#ifdef __HAIKU__
#include <lock.h>
#else
#include "BeOSCompatibility.h"
#endif
#include "kernel_cpp.h"
#include "Tracing.h"
#include "USB3.h"

View File

@ -212,16 +212,16 @@ FTDIDevice::OnRead(char **buffer, size_t *numBytes)
void
FTDIDevice::OnWrite(const char *buffer, size_t *numBytes)
FTDIDevice::OnWrite(const char *buffer, size_t *numBytes, size_t *packetBytes)
{
char *writeBuffer = WriteBuffer();
if (fHeaderLength > 0) {
if (*numBytes >= WriteBufferSize() - fHeaderLength)
*numBytes = WriteBufferSize() - fHeaderLength;
*numBytes = *packetBytes = WriteBufferSize() - fHeaderLength;
*writeBuffer = FTDI_OUT_TAG(*numBytes, FTDI_PIT_DEFAULT);
}
memcpy(writeBuffer + fHeaderLength, buffer, *numBytes);
*numBytes += fHeaderLength;
memcpy(writeBuffer + fHeaderLength, buffer, *packetBytes);
*packetBytes += fHeaderLength;
}

View File

@ -31,7 +31,8 @@ virtual status_t SetLineCoding(usb_serial_line_coding *coding);
virtual status_t SetControlLineState(uint16 state);
virtual void OnRead(char **buffer, size_t *numBytes);
virtual void OnWrite(const char *buffer, size_t *numBytes);
virtual void OnWrite(const char *buffer, size_t *numBytes,
size_t *packetBytes);
private:
size_t fHeaderLength;

View File

@ -2,6 +2,11 @@ SubDir HAIKU_TOP src add-ons kernel drivers ports usb_serial ;
SetSubDirSupportedPlatformsBeOSCompatible ;
if $(TARGET_PLATFORM_HAIKU_COMPATIBLE) {
UsePrivateKernelHeaders ;
UseHeaders [ FDirName $(HAIKU_TOP) headers os drivers tty ] : true ;
}
SubDirC++Flags -fno-rtti ;
KernelAddon usb_serial :

View File

@ -29,15 +29,18 @@ KLSIDevice::AddDevice(const usb_configuration_info *config)
if (endpoint->descr->attributes == USB_EP_ATTR_INTERRUPT) {
if (endpoint->descr->endpoint_address & USB_EP_ADDR_DIR_IN) {
SetControlPipe(endpoint->handle);
SetInterruptBufferSize(endpoint->descr->max_packet_size);
if (++pipesSet >= 3)
break;
}
} else if (endpoint->descr->attributes == USB_EP_ATTR_BULK) {
if (endpoint->descr->endpoint_address & USB_EP_ADDR_DIR_IN) {
SetReadBufferSize(ROUNDUP(endpoint->descr->max_packet_size, 16));
SetReadPipe(endpoint->handle);
if (++pipesSet >= 3)
break;
} else {
SetWriteBufferSize(ROUNDUP(endpoint->descr->max_packet_size, 16));
SetWritePipe(endpoint->handle);
if (++pipesSet >= 3)
break;
@ -60,10 +63,25 @@ KLSIDevice::ResetDevice()
TRACE_FUNCALLS("> KLSIDevice::ResetDevice(%08x)\n", this);
size_t length = 0;
status_t status = gUSBModule->send_request(Device(),
USB_REQTYPE_VENDOR | USB_REQTYPE_INTERFACE_OUT,
status_t status;
usb_serial_line_coding linecoding = { 9600, 1, 0, 8 };
uint8 linestate[2];
status = SetLineCoding(&linecoding);
status = gUSBModule->send_request(Device(),
USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT,
KLSI_CONF_REQUEST,
KLSI_CONF_REQUEST_READ_ON, 0, 0, NULL, &length);
TRACE("= KLSIDevice::ResetDevice(): set conf read_on returns: 0x%08x\n",
status);
linestate[0] = 0xff;
linestate[1] = 0xff;
length = 0;
status = gUSBModule->send_request(Device(),
USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_IN,
KLSI_POLL_REQUEST,
0, 0, 2, linestate, &length);
TRACE_FUNCRET("< KLSIDevice::ResetDevice() returns: 0x%08x\n", status);
return status;
@ -106,7 +124,7 @@ KLSIDevice::SetLineCoding(usb_serial_line_coding *lineCoding)
size_t length = 0;
status_t status = gUSBModule->send_request(Device(),
USB_REQTYPE_VENDOR | USB_REQTYPE_INTERFACE_OUT,
USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT,
KLSI_SET_REQUEST, 0, 0,
sizeof(codingPacket), codingPacket, &length);
@ -133,15 +151,15 @@ KLSIDevice::OnRead(char **buffer, size_t *numBytes)
void
KLSIDevice::OnWrite(const char *buffer, size_t *numBytes)
KLSIDevice::OnWrite(const char *buffer, size_t *numBytes, size_t *packetBytes)
{
if (*numBytes >= WriteBufferSize() - 2)
*numBytes = WriteBufferSize() - 2;
*numBytes = *packetBytes = WriteBufferSize() - 2;
char *writeBuffer = WriteBuffer();
*((uint16 *)writeBuffer) = B_HOST_TO_LENDIAN_INT16(*numBytes);
memcpy(writeBuffer + 2, buffer, *numBytes);
*numBytes += 2;
memcpy(writeBuffer + 2, buffer, *packetBytes);
*packetBytes += 2;
}

View File

@ -53,7 +53,8 @@ virtual status_t ResetDevice();
virtual status_t SetLineCoding(usb_serial_line_coding *coding);
virtual void OnRead(char **buffer, size_t *numBytes);
virtual void OnWrite(const char *buffer, size_t *numBytes);
virtual void OnWrite(const char *buffer, size_t *numBytes,
size_t *packetBytes);
virtual void OnClose();
};

View File

@ -26,11 +26,11 @@ SerialDevice::SerialDevice(usb_device device, uint16 vendorID,
fWritePipe(0),
fBufferArea(-1),
fReadBuffer(NULL),
fReadBufferSize(0),
fReadBufferSize(ROUNDUP(DEF_BUFFER_SIZE, 16)),
fWriteBuffer(NULL),
fWriteBufferSize(0),
fWriteBufferSize(ROUNDUP(DEF_BUFFER_SIZE, 16)),
fInterruptBuffer(NULL),
fInterruptBufferSize(0),
fInterruptBufferSize(16),
fDoneRead(-1),
fDoneWrite(-1),
fControlOut(0),
@ -68,9 +68,6 @@ SerialDevice::Init()
mutex_init(&fReadLock, "usb_serial:read_lock");
mutex_init(&fWriteLock, "usb_serial:write_lock");
fReadBufferSize = fWriteBufferSize = ROUNDUP(DEF_BUFFER_SIZE, 16);
fInterruptBufferSize = 16;
size_t totalBuffers = fReadBufferSize + fWriteBufferSize + fInterruptBufferSize;
fBufferArea = create_area("usb_serial:buffers_area", (void **)&fReadBuffer,
B_ANY_KERNEL_ADDRESS, ROUNDUP(totalBuffers, B_PAGE_SIZE), B_CONTIGUOUS,
@ -342,10 +339,11 @@ SerialDevice::Write(const char *buffer, size_t *numBytes)
while (bytesLeft > 0) {
size_t length = MIN(bytesLeft, fWriteBufferSize);
OnWrite(buffer, &length);
size_t packetLength = length;
OnWrite(buffer, &length, &packetLength);
status = gUSBModule->queue_bulk(fWritePipe, fWriteBuffer,
length, WriteCallbackFunction, this);
packetLength, WriteCallbackFunction, this);
if (status < B_OK) {
TRACE_ALWAYS("write: queueing failed with status 0x%08x\n", status);
break;
@ -369,9 +367,9 @@ SerialDevice::Write(const char *buffer, size_t *numBytes)
continue;
}
buffer += fActualLengthWrite;
*numBytes += fActualLengthWrite;
bytesLeft -= fActualLengthWrite;
buffer += length;
*numBytes += length;
bytesLeft -= length;
}
mutex_unlock(&fWriteLock);
@ -528,7 +526,7 @@ SerialDevice::OnRead(char **buffer, size_t *numBytes)
void
SerialDevice::OnWrite(const char *buffer, size_t *numBytes)
SerialDevice::OnWrite(const char *buffer, size_t *numBytes, size_t *packetBytes)
{
// default implementation - does nothing
}

View File

@ -68,9 +68,14 @@ virtual status_t SetLineCoding(usb_serial_line_coding *coding);
virtual status_t SetControlLineState(uint16 state);
virtual void OnRead(char **buffer, size_t *numBytes);
virtual void OnWrite(const char *buffer, size_t *numBytes);
virtual void OnWrite(const char *buffer, size_t *numBytes,
size_t *packetBytes);
virtual void OnClose();
protected:
void SetReadBufferSize(size_t size) { fReadBufferSize = size; };
void SetWriteBufferSize(size_t size) { fWriteBufferSize = size; };
void SetInterruptBufferSize(size_t size) { fInterruptBufferSize = size; };
private:
static int32 DeviceThread(void *data);

View File

@ -9,10 +9,6 @@
#include "Driver.h"
#include "USB3.h"
extern "C" {
#include <ttylayer.h>
}
#include <stdio.h> //sprintf
#include <unistd.h> //posix file i/o - create, write, close
#include <Drivers.h>
@ -121,14 +117,15 @@ trace_termios(struct termios *tios)
"\tc_cflag: 0x%08x\n"
"\tc_lflag: 0x%08x\n"
"\tc_line: 0x%08x\n"
"\tc_ixxxxx: 0x%08x\n"
"\tc_oxxxxx: 0x%08x\n"
// "\tc_ixxxxx: 0x%08x\n"
// "\tc_oxxxxx: 0x%08x\n"
"\tc_cc[0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x]\n",
tios->c_iflag, tios->c_oflag, tios->c_cflag, tios->c_lflag,
tios->c_line, tios->c_ixxxxx, tios->c_oxxxxx, tios->c_cc[0],
tios->c_cc[1], tios->c_cc[2], tios->c_cc[3], tios->c_cc[4],
tios->c_cc[5], tios->c_cc[6], tios->c_cc[7], tios->c_cc[8],
tios->c_cc[9], tios->c_cc[10]);
tios->c_iflag, tios->c_oflag, tios->c_cflag, tios->c_lflag,
tios->c_line,
// tios->c_ixxxxx, tios->c_oxxxxx,
tios->c_cc[0], tios->c_cc[1], tios->c_cc[2], tios->c_cc[3],
tios->c_cc[4], tios->c_cc[5], tios->c_cc[6], tios->c_cc[7],
tios->c_cc[8], tios->c_cc[9], tios->c_cc[10]);
}