mirror of https://github.com/ARMmbed/mbed-os.git
USBHOST : introduce USBHOST_OTHER (USBHost on USB IP not OHCI).
parent
48434cfd64
commit
54db0a4143
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
#include "dbg.h"
|
#include "dbg.h"
|
||||||
#include "USBEndpoint.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])
|
void USBEndpoint::init(HCED * hced_, ENDPOINT_TYPE type_, ENDPOINT_DIRECTION dir_, uint32_t size, uint8_t ep_number, HCTD* td_list_[2])
|
||||||
{
|
{
|
||||||
hced = hced_;
|
hced = hced_;
|
||||||
|
@ -76,6 +76,7 @@ void USBEndpoint::setSpeed(uint8_t speed)
|
||||||
hced->control &= ~(1 << 13);
|
hced->control &= ~(1 << 13);
|
||||||
hced->control |= (speed << 13);
|
hced->control |= (speed << 13);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
//Only for control Eps
|
//Only for control Eps
|
||||||
void USBEndpoint::setNextToken(uint32_t token)
|
void USBEndpoint::setNextToken(uint32_t token)
|
||||||
|
@ -95,7 +96,6 @@ void USBEndpoint::setNextToken(uint32_t token)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
USB_TYPE type;
|
USB_TYPE type;
|
||||||
const char * str;
|
const char * str;
|
||||||
|
@ -120,18 +120,17 @@ struct {
|
||||||
{USB_TYPE_PROCESSING, "USB_TYPE_PROCESSING"},
|
{USB_TYPE_PROCESSING, "USB_TYPE_PROCESSING"},
|
||||||
{USB_TYPE_ERROR, "USB_TYPE_ERROR"}
|
{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) {
|
void USBEndpoint::setState(uint8_t st) {
|
||||||
if (st > 18)
|
if (st > 18)
|
||||||
return;
|
return;
|
||||||
state = type_string[st].type;
|
state = type_string[st].type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char * USBEndpoint::getStateString() {
|
|
||||||
return type_string[state].str;
|
|
||||||
}
|
|
||||||
|
|
||||||
USB_TYPE USBEndpoint::queueTransfer()
|
USB_TYPE USBEndpoint::queueTransfer()
|
||||||
{
|
{
|
||||||
transfer_len = (uint32_t)td_current->bufEnd - (uint32_t)td_current->currBufPtr + 1;
|
transfer_len = (uint32_t)td_current->bufEnd - (uint32_t)td_current->currBufPtr + 1;
|
||||||
|
@ -161,3 +160,4 @@ void USBEndpoint::queueEndpoint(USBEndpoint * ed)
|
||||||
nextEp = ed;
|
nextEp = ed;
|
||||||
hced->nextED = (ed == NULL) ? 0 : (hcEd*)(ed->getHCED());
|
hced->nextED = (ed == NULL) ? 0 : (hcEd*)(ed->getHCED());
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -47,6 +47,7 @@ public:
|
||||||
* @param ep_number endpoint number
|
* @param ep_number endpoint number
|
||||||
* @param td_list array of two allocated transfer descriptors
|
* @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]);
|
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();
|
const char * getStateString();
|
||||||
inline USB_TYPE getState() { return state; }
|
inline USB_TYPE getState() { return state; }
|
||||||
inline ENDPOINT_TYPE getType() { return type; };
|
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 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 int getLengthTransferred() { return transferred; }
|
||||||
inline uint8_t * getBufStart() { return buf_start; }
|
inline uint8_t * getBufStart() { return buf_start; }
|
||||||
inline uint8_t getAddress(){ return address; };
|
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 HCTD** getTDList() { return td_list; };
|
||||||
inline volatile HCED * getHCED() { return hced; };
|
inline volatile HCED * getHCED() { return hced; };
|
||||||
inline ENDPOINT_DIRECTION getDir() { return dir; }
|
inline ENDPOINT_DIRECTION getDir() { return dir; }
|
||||||
|
@ -146,6 +152,12 @@ private:
|
||||||
ENDPOINT_TYPE type;
|
ENDPOINT_TYPE type;
|
||||||
volatile USB_TYPE state;
|
volatile USB_TYPE state;
|
||||||
ENDPOINT_DIRECTION dir;
|
ENDPOINT_DIRECTION dir;
|
||||||
|
#ifdef USBHOST_OTHER
|
||||||
|
uint32_t size;
|
||||||
|
uint32_t ep_number;
|
||||||
|
uint32_t speed;
|
||||||
|
uint8_t device_address;
|
||||||
|
#endif
|
||||||
bool setup;
|
bool setup;
|
||||||
|
|
||||||
uint8_t address;
|
uint8_t address;
|
||||||
|
|
|
@ -249,13 +249,14 @@ void USBHost::usb_process() {
|
||||||
|
|
||||||
USBHost::USBHost() : usbThread(osPriorityNormal, USB_THREAD_STACK)
|
USBHost::USBHost() : usbThread(osPriorityNormal, USB_THREAD_STACK)
|
||||||
{
|
{
|
||||||
|
#ifndef USBHOST_OTHER
|
||||||
headControlEndpoint = NULL;
|
headControlEndpoint = NULL;
|
||||||
headBulkEndpoint = NULL;
|
headBulkEndpoint = NULL;
|
||||||
headInterruptEndpoint = NULL;
|
headInterruptEndpoint = NULL;
|
||||||
tailControlEndpoint = NULL;
|
tailControlEndpoint = NULL;
|
||||||
tailBulkEndpoint = NULL;
|
tailBulkEndpoint = NULL;
|
||||||
tailInterruptEndpoint = NULL;
|
tailInterruptEndpoint = NULL;
|
||||||
|
#endif
|
||||||
lenReportDescr = 0;
|
lenReportDescr = 0;
|
||||||
|
|
||||||
controlEndpointAllocated = false;
|
controlEndpointAllocated = false;
|
||||||
|
@ -312,6 +313,12 @@ void USBHost::transferCompleted(volatile uint32_t addr)
|
||||||
if (td->ep != NULL) {
|
if (td->ep != NULL) {
|
||||||
USBEndpoint * ep = (USBEndpoint *)(td->ep);
|
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) {
|
if (((HCTD *)td)->control >> 28) {
|
||||||
state = ((HCTD *)td)->control >> 28;
|
state = ((HCTD *)td)->control >> 28;
|
||||||
} else {
|
} else {
|
||||||
|
@ -319,6 +326,9 @@ void USBHost::transferCompleted(volatile uint32_t addr)
|
||||||
ep->setLengthTransferred((uint32_t)td->currBufPtr - (uint32_t)ep->getBufStart());
|
ep->setLengthTransferred((uint32_t)td->currBufPtr - (uint32_t)ep->getBufStart());
|
||||||
state = 16 /*USB_TYPE_IDLE*/;
|
state = 16 /*USB_TYPE_IDLE*/;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
if (state == USB_TYPE_IDLE)
|
||||||
|
ep->setLengthTransferred((uint32_t)td->currBufPtr - (uint32_t)ep->getBufStart());
|
||||||
|
|
||||||
ep->unqueueTransfer(td);
|
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));
|
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++) {
|
for (int i = 0; i < dev->getInterface(j)->nb_endpoint; i++) {
|
||||||
if ((ep = dev->getEndpoint(j, i)) != NULL) {
|
if ((ep = dev->getEndpoint(j, i)) != NULL) {
|
||||||
|
#ifndef USBHOST_OTHER
|
||||||
ed = (HCED *)ep->getHCED();
|
ed = (HCED *)ep->getHCED();
|
||||||
ed->control |= (1 << 14); //sKip bit
|
ed->control |= (1 << 14); //sKip bit
|
||||||
|
#endif
|
||||||
unqueueEndpoint(ep);
|
unqueueEndpoint(ep);
|
||||||
|
|
||||||
freeTD((volatile uint8_t*)ep->getTDList()[0]);
|
freeTD((volatile uint8_t*)ep->getTDList()[0]);
|
||||||
|
@ -450,6 +462,9 @@ void USBHost::freeDevice(USBDeviceConnected * dev)
|
||||||
|
|
||||||
void USBHost::unqueueEndpoint(USBEndpoint * ep)
|
void USBHost::unqueueEndpoint(USBEndpoint * ep)
|
||||||
{
|
{
|
||||||
|
#ifdef USBHOST_OTHER
|
||||||
|
ep->setState(USB_TYPE_FREE);
|
||||||
|
#else
|
||||||
USBEndpoint * prec = NULL;
|
USBEndpoint * prec = NULL;
|
||||||
USBEndpoint * current = NULL;
|
USBEndpoint * current = NULL;
|
||||||
|
|
||||||
|
@ -499,6 +514,7 @@ void USBHost::unqueueEndpoint(USBEndpoint * ep)
|
||||||
current = current->nextEndpoint();
|
current = current->nextEndpoint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -563,8 +579,10 @@ bool USBHost::addEndpoint(USBDeviceConnected * dev, uint8_t intf_nb, USBEndpoint
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef USBHOST_OTHER
|
||||||
HCED * prevEd;
|
HCED * prevEd;
|
||||||
|
|
||||||
|
#endif
|
||||||
// set device address in the USBEndpoint descriptor
|
// set device address in the USBEndpoint descriptor
|
||||||
if (dev == NULL) {
|
if (dev == NULL) {
|
||||||
ep->setDeviceAddress(0);
|
ep->setDeviceAddress(0);
|
||||||
|
@ -578,6 +596,7 @@ bool USBHost::addEndpoint(USBDeviceConnected * dev, uint8_t intf_nb, USBEndpoint
|
||||||
|
|
||||||
ep->setIntfNb(intf_nb);
|
ep->setIntfNb(intf_nb);
|
||||||
|
|
||||||
|
#ifndef USBHOST_OTHER
|
||||||
// queue the new USBEndpoint on the ED list
|
// queue the new USBEndpoint on the ED list
|
||||||
switch (ep->getType()) {
|
switch (ep->getType()) {
|
||||||
|
|
||||||
|
@ -625,6 +644,7 @@ bool USBHost::addEndpoint(USBDeviceConnected * dev, uint8_t intf_nb, USBEndpoint
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
ep->dev = dev;
|
ep->dev = dev;
|
||||||
dev->addEndpoint(intf_nb, ep);
|
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)
|
void USBHost::printList(ENDPOINT_TYPE type)
|
||||||
{
|
{
|
||||||
#if DEBUG_EP_STATE
|
#if defined(DEBUG_EP_STATE) && !defined(USBHOST_OTHER)
|
||||||
volatile HCED * hced;
|
volatile HCED * hced;
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case CONTROL_ENDPOINT:
|
case CONTROL_ENDPOINT:
|
||||||
|
@ -708,6 +728,7 @@ USB_TYPE USBHost::addTransfer(USBEndpoint * ed, uint8_t * buf, uint32_t len)
|
||||||
return USB_TYPE_ERROR;
|
return USB_TYPE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef USBHOST_OTHER
|
||||||
uint32_t token = (ed->isSetup() ? TD_SETUP : ( (ed->getDir() == IN) ? TD_IN : TD_OUT ));
|
uint32_t token = (ed->isSetup() ? TD_SETUP : ( (ed->getDir() == IN) ? TD_IN : TD_OUT ));
|
||||||
|
|
||||||
uint32_t td_toggle;
|
uint32_t td_toggle;
|
||||||
|
@ -732,6 +753,12 @@ USB_TYPE USBHost::addTransfer(USBEndpoint * ed, uint8_t * buf, uint32_t len)
|
||||||
ed->queueTransfer();
|
ed->queueTransfer();
|
||||||
printList(type);
|
printList(type);
|
||||||
enableList(type);
|
enableList(type);
|
||||||
|
#else
|
||||||
|
/* call method specific for endpoint */
|
||||||
|
td->currBufPtr = buf;
|
||||||
|
td->size = len;
|
||||||
|
ret = ed->queueTransfer();
|
||||||
|
#endif
|
||||||
|
|
||||||
td_mutex.unlock();
|
td_mutex.unlock();
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,9 @@
|
||||||
|
|
||||||
#ifndef USBHOST_H
|
#ifndef USBHOST_H
|
||||||
#define USBHOST_H
|
#define USBHOST_H
|
||||||
|
#ifdef TARGET_STM
|
||||||
|
#include "mbed.h"
|
||||||
|
#endif
|
||||||
#include "USBHALHost.h"
|
#include "USBHALHost.h"
|
||||||
#include "USBDeviceConnected.h"
|
#include "USBDeviceConnected.h"
|
||||||
#include "IUSBEnumerator.h"
|
#include "IUSBEnumerator.h"
|
||||||
|
|
|
@ -67,6 +67,7 @@ enum ENDPOINT_TYPE {
|
||||||
#define HUB_CLASS 0x09
|
#define HUB_CLASS 0x09
|
||||||
#define SERIAL_CLASS 0x0A
|
#define SERIAL_CLASS 0x0A
|
||||||
|
|
||||||
|
#if !defined(USBHOST_OTHER)
|
||||||
// ------------------ HcControl Register ---------------------
|
// ------------------ HcControl Register ---------------------
|
||||||
#define OR_CONTROL_PLE 0x00000004
|
#define OR_CONTROL_PLE 0x00000004
|
||||||
#define OR_CONTROL_CLE 0x00000010
|
#define OR_CONTROL_CLE 0x00000010
|
||||||
|
@ -114,6 +115,13 @@ enum ENDPOINT_TYPE {
|
||||||
#define TD_TOGGLE_1 (uint32_t)(0x03000000) // Toggle 1
|
#define TD_TOGGLE_1 (uint32_t)(0x03000000) // Toggle 1
|
||||||
#define TD_CC (uint32_t)(0xF0000000) // Completion Code
|
#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 DEVICE_DESCRIPTOR (1)
|
||||||
#define CONFIGURATION_DESCRIPTOR (2)
|
#define CONFIGURATION_DESCRIPTOR (2)
|
||||||
#define INTERFACE_DESCRIPTOR (4)
|
#define INTERFACE_DESCRIPTOR (4)
|
||||||
|
@ -140,6 +148,27 @@ enum ENDPOINT_TYPE {
|
||||||
#define DEVICE_DESCRIPTOR_LENGTH 0x12
|
#define DEVICE_DESCRIPTOR_LENGTH 0x12
|
||||||
#define CONFIGURATION_DESCRIPTOR_LENGTH 0x09
|
#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 ------------
|
// ------------ HostController Transfer Descriptor ------------
|
||||||
typedef struct hcTd {
|
typedef struct hcTd {
|
||||||
__IO uint32_t control; // Transfer descriptor control
|
__IO uint32_t control; // Transfer descriptor control
|
||||||
|
@ -149,7 +178,6 @@ typedef struct hcTd {
|
||||||
void * ep; // ep address where a td is linked in
|
void * ep; // ep address where a td is linked in
|
||||||
uint32_t dummy[3]; // padding
|
uint32_t dummy[3]; // padding
|
||||||
} PACKED HCTD;
|
} PACKED HCTD;
|
||||||
|
|
||||||
// ----------- HostController EndPoint Descriptor -------------
|
// ----------- HostController EndPoint Descriptor -------------
|
||||||
typedef struct hcEd {
|
typedef struct hcEd {
|
||||||
__IO uint32_t control; // Endpoint descriptor control
|
__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 HCTD * headTD; // Physcial address of head in Transfer descriptor list
|
||||||
__IO hcEd * nextED; // Physical address of next Endpoint descriptor
|
__IO hcEd * nextED; // Physical address of next Endpoint descriptor
|
||||||
} PACKED HCED;
|
} PACKED HCED;
|
||||||
|
|
||||||
|
|
||||||
// ----------- Host Controller Communication Area ------------
|
// ----------- Host Controller Communication Area ------------
|
||||||
typedef struct hcca {
|
typedef struct hcca {
|
||||||
__IO uint32_t IntTable[32]; // Interrupt Table
|
__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 Reserved[116]; // Reserved for future use
|
||||||
volatile uint8_t Unknown[4]; // Unused
|
volatile uint8_t Unknown[4]; // Unused
|
||||||
} PACKED HCCA;
|
} PACKED HCCA;
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t bLength;
|
uint8_t bLength;
|
||||||
|
|
Loading…
Reference in New Issue