USBHOST : introduce USBHOST_OTHER (USBHost on USB IP not OHCI).

pull/3432/head
Michel Jaouen 2016-12-05 15:44:10 +01:00
parent 48434cfd64
commit 54db0a4143
5 changed files with 83 additions and 15 deletions

View File

@ -17,7 +17,7 @@
#include "dbg.h"
#include "USBEndpoint.h"
#if !defined(USBHOST_OTHER)
void USBEndpoint::init(HCED * hced_, ENDPOINT_TYPE type_, ENDPOINT_DIRECTION dir_, uint32_t size, uint8_t ep_number, HCTD* td_list_[2])
{
hced = hced_;
@ -76,6 +76,7 @@ void USBEndpoint::setSpeed(uint8_t speed)
hced->control &= ~(1 << 13);
hced->control |= (speed << 13);
}
#endif
//Only for control Eps
void USBEndpoint::setNextToken(uint32_t token)
@ -95,7 +96,6 @@ void USBEndpoint::setNextToken(uint32_t token)
break;
}
}
struct {
USB_TYPE type;
const char * str;
@ -120,18 +120,17 @@ struct {
{USB_TYPE_PROCESSING, "USB_TYPE_PROCESSING"},
{USB_TYPE_ERROR, "USB_TYPE_ERROR"}
};
const char * USBEndpoint::getStateString() {
return type_string[state].str;
}
#if !defined(USBHOST_OTHER)
void USBEndpoint::setState(uint8_t st) {
if (st > 18)
return;
state = type_string[st].type;
}
const char * USBEndpoint::getStateString() {
return type_string[state].str;
}
USB_TYPE USBEndpoint::queueTransfer()
{
transfer_len = (uint32_t)td_current->bufEnd - (uint32_t)td_current->currBufPtr + 1;
@ -161,3 +160,4 @@ void USBEndpoint::queueEndpoint(USBEndpoint * ed)
nextEp = ed;
hced->nextED = (ed == NULL) ? 0 : (hcEd*)(ed->getHCED());
}
#endif

View File

@ -47,6 +47,7 @@ public:
* @param ep_number endpoint number
* @param td_list array of two allocated transfer descriptors
*/
void init(HCED * hced, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint32_t size, uint8_t ep_number, HCTD* td_list[2]);
/**
@ -123,12 +124,17 @@ public:
const char * getStateString();
inline USB_TYPE getState() { return state; }
inline ENDPOINT_TYPE getType() { return type; };
#ifdef USBHOST_OTHER
inline uint8_t getDeviceAddress() { return device_address; };
inline uint32_t getSize() { return size; };
#else
inline uint8_t getDeviceAddress() { return hced->control & 0x7f; };
inline uint32_t getSize() { return (hced->control >> 16) & 0x3ff; };
inline volatile HCTD * getHeadTD() { return (volatile HCTD*) ((uint32_t)hced->headTD & ~0xF); };
#endif
inline int getLengthTransferred() { return transferred; }
inline uint8_t * getBufStart() { return buf_start; }
inline uint8_t getAddress(){ return address; };
inline uint32_t getSize() { return (hced->control >> 16) & 0x3ff; };
inline volatile HCTD * getHeadTD() { return (volatile HCTD*) ((uint32_t)hced->headTD & ~0xF); };
inline volatile HCTD** getTDList() { return td_list; };
inline volatile HCED * getHCED() { return hced; };
inline ENDPOINT_DIRECTION getDir() { return dir; }
@ -146,6 +152,12 @@ private:
ENDPOINT_TYPE type;
volatile USB_TYPE state;
ENDPOINT_DIRECTION dir;
#ifdef USBHOST_OTHER
uint32_t size;
uint32_t ep_number;
uint32_t speed;
uint8_t device_address;
#endif
bool setup;
uint8_t address;

View File

@ -249,13 +249,14 @@ void USBHost::usb_process() {
USBHost::USBHost() : usbThread(osPriorityNormal, USB_THREAD_STACK)
{
#ifndef USBHOST_OTHER
headControlEndpoint = NULL;
headBulkEndpoint = NULL;
headInterruptEndpoint = NULL;
tailControlEndpoint = NULL;
tailBulkEndpoint = NULL;
tailInterruptEndpoint = NULL;
#endif
lenReportDescr = 0;
controlEndpointAllocated = false;
@ -312,6 +313,12 @@ void USBHost::transferCompleted(volatile uint32_t addr)
if (td->ep != NULL) {
USBEndpoint * ep = (USBEndpoint *)(td->ep);
#ifdef USBHOST_OTHER
state = ((HCTD *)td)->state;
if (state == USB_TYPE_IDLE)
ep->setLengthTransferred((uint32_t)td->currBufPtr - (uint32_t)ep->getBufStart());
#else
if (((HCTD *)td)->control >> 28) {
state = ((HCTD *)td)->control >> 28;
} else {
@ -319,6 +326,9 @@ void USBHost::transferCompleted(volatile uint32_t addr)
ep->setLengthTransferred((uint32_t)td->currBufPtr - (uint32_t)ep->getBufStart());
state = 16 /*USB_TYPE_IDLE*/;
}
#endif
if (state == USB_TYPE_IDLE)
ep->setLengthTransferred((uint32_t)td->currBufPtr - (uint32_t)ep->getBufStart());
ep->unqueueTransfer(td);
@ -428,8 +438,10 @@ void USBHost::freeDevice(USBDeviceConnected * dev)
USB_DBG("FREE INTF %d on dev: %p, %p, nb_endpot: %d, %s", j, (void *)dev->getInterface(j), dev, dev->getInterface(j)->nb_endpoint, dev->getName(j));
for (int i = 0; i < dev->getInterface(j)->nb_endpoint; i++) {
if ((ep = dev->getEndpoint(j, i)) != NULL) {
#ifndef USBHOST_OTHER
ed = (HCED *)ep->getHCED();
ed->control |= (1 << 14); //sKip bit
#endif
unqueueEndpoint(ep);
freeTD((volatile uint8_t*)ep->getTDList()[0]);
@ -450,6 +462,9 @@ void USBHost::freeDevice(USBDeviceConnected * dev)
void USBHost::unqueueEndpoint(USBEndpoint * ep)
{
#ifdef USBHOST_OTHER
ep->setState(USB_TYPE_FREE);
#else
USBEndpoint * prec = NULL;
USBEndpoint * current = NULL;
@ -499,6 +514,7 @@ void USBHost::unqueueEndpoint(USBEndpoint * ep)
current = current->nextEndpoint();
}
}
#endif
}
@ -563,8 +579,10 @@ bool USBHost::addEndpoint(USBDeviceConnected * dev, uint8_t intf_nb, USBEndpoint
return false;
}
#ifndef USBHOST_OTHER
HCED * prevEd;
#endif
// set device address in the USBEndpoint descriptor
if (dev == NULL) {
ep->setDeviceAddress(0);
@ -578,6 +596,7 @@ bool USBHost::addEndpoint(USBDeviceConnected * dev, uint8_t intf_nb, USBEndpoint
ep->setIntfNb(intf_nb);
#ifndef USBHOST_OTHER
// queue the new USBEndpoint on the ED list
switch (ep->getType()) {
@ -625,6 +644,7 @@ bool USBHost::addEndpoint(USBDeviceConnected * dev, uint8_t intf_nb, USBEndpoint
return false;
}
#endif
ep->dev = dev;
dev->addEndpoint(intf_nb, ep);
@ -659,7 +679,7 @@ int USBHost::findDevice(uint8_t hub, uint8_t port, USBHostHub * hub_parent)
void USBHost::printList(ENDPOINT_TYPE type)
{
#if DEBUG_EP_STATE
#if defined(DEBUG_EP_STATE) && !defined(USBHOST_OTHER)
volatile HCED * hced;
switch(type) {
case CONTROL_ENDPOINT:
@ -708,6 +728,7 @@ USB_TYPE USBHost::addTransfer(USBEndpoint * ed, uint8_t * buf, uint32_t len)
return USB_TYPE_ERROR;
}
#ifndef USBHOST_OTHER
uint32_t token = (ed->isSetup() ? TD_SETUP : ( (ed->getDir() == IN) ? TD_IN : TD_OUT ));
uint32_t td_toggle;
@ -732,6 +753,12 @@ USB_TYPE USBHost::addTransfer(USBEndpoint * ed, uint8_t * buf, uint32_t len)
ed->queueTransfer();
printList(type);
enableList(type);
#else
/* call method specific for endpoint */
td->currBufPtr = buf;
td->size = len;
ret = ed->queueTransfer();
#endif
td_mutex.unlock();

View File

@ -16,7 +16,9 @@
#ifndef USBHOST_H
#define USBHOST_H
#ifdef TARGET_STM
#include "mbed.h"
#endif
#include "USBHALHost.h"
#include "USBDeviceConnected.h"
#include "IUSBEnumerator.h"

View File

@ -67,6 +67,7 @@ enum ENDPOINT_TYPE {
#define HUB_CLASS 0x09
#define SERIAL_CLASS 0x0A
#if !defined(USBHOST_OTHER)
// ------------------ HcControl Register ---------------------
#define OR_CONTROL_PLE 0x00000004
#define OR_CONTROL_CLE 0x00000010
@ -114,6 +115,13 @@ enum ENDPOINT_TYPE {
#define TD_TOGGLE_1 (uint32_t)(0x03000000) // Toggle 1
#define TD_CC (uint32_t)(0xF0000000) // Completion Code
#else
#define TD_SETUP (uint32_t)(0) // Direction of Setup Packet
#define TD_IN (uint32_t)(0x00100000) // Direction In
#define TD_OUT (uint32_t)(0x00080000) // Direction Out
#endif
#define DEVICE_DESCRIPTOR (1)
#define CONFIGURATION_DESCRIPTOR (2)
#define INTERFACE_DESCRIPTOR (4)
@ -140,6 +148,27 @@ enum ENDPOINT_TYPE {
#define DEVICE_DESCRIPTOR_LENGTH 0x12
#define CONFIGURATION_DESCRIPTOR_LENGTH 0x09
// ------------ HostController Transfer Descriptor ------------
#if defined(USBHOST_OTHER)
typedef struct hcTd {
__IO uint32_t state;
__IO uint8_t * currBufPtr; // Physical address of current buffer pointer
__IO hcTd * nextTD; // Physical pointer to next Transfer Descriptor
__IO uint32_t size; // size of buffer
void * ep; // ep address where a td is linked in
} PACKED HCTD;
// ----------- HostController EndPoint Descriptor -------------
typedef struct hcEd {
uint8_t ch_num;
void *hhcd;
} PACKED HCED;
// ----------- Host Controller Communication Area ------------
#define HCCA void
#else
// -------------OHCI register --------------------------------
// ------------ HostController Transfer Descriptor ------------
typedef struct hcTd {
__IO uint32_t control; // Transfer descriptor control
@ -149,7 +178,6 @@ typedef struct hcTd {
void * ep; // ep address where a td is linked in
uint32_t dummy[3]; // padding
} PACKED HCTD;
// ----------- HostController EndPoint Descriptor -------------
typedef struct hcEd {
__IO uint32_t control; // Endpoint descriptor control
@ -157,8 +185,6 @@ typedef struct hcEd {
__IO HCTD * headTD; // Physcial address of head in Transfer descriptor list
__IO hcEd * nextED; // Physical address of next Endpoint descriptor
} PACKED HCED;
// ----------- Host Controller Communication Area ------------
typedef struct hcca {
__IO uint32_t IntTable[32]; // Interrupt Table
@ -167,6 +193,7 @@ typedef struct hcca {
volatile uint8_t Reserved[116]; // Reserved for future use
volatile uint8_t Unknown[4]; // Unused
} PACKED HCCA;
#endif
typedef struct {
uint8_t bLength;