Skip to content

Commit 54db0a4

Browse files
committed
USBHOST : introduce USBHOST_OTHER (USBHost on USB IP not OHCI).
1 parent 48434cf commit 54db0a4

File tree

5 files changed

+83
-15
lines changed

5 files changed

+83
-15
lines changed

features/unsupported/USBHost/USBHost/USBEndpoint.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#include "dbg.h"
1919
#include "USBEndpoint.h"
20-
20+
#if !defined(USBHOST_OTHER)
2121
void USBEndpoint::init(HCED * hced_, ENDPOINT_TYPE type_, ENDPOINT_DIRECTION dir_, uint32_t size, uint8_t ep_number, HCTD* td_list_[2])
2222
{
2323
hced = hced_;
@@ -76,6 +76,7 @@ void USBEndpoint::setSpeed(uint8_t speed)
7676
hced->control &= ~(1 << 13);
7777
hced->control |= (speed << 13);
7878
}
79+
#endif
7980

8081
//Only for control Eps
8182
void USBEndpoint::setNextToken(uint32_t token)
@@ -95,7 +96,6 @@ void USBEndpoint::setNextToken(uint32_t token)
9596
break;
9697
}
9798
}
98-
9999
struct {
100100
USB_TYPE type;
101101
const char * str;
@@ -120,18 +120,17 @@ struct {
120120
{USB_TYPE_PROCESSING, "USB_TYPE_PROCESSING"},
121121
{USB_TYPE_ERROR, "USB_TYPE_ERROR"}
122122
};
123+
const char * USBEndpoint::getStateString() {
124+
return type_string[state].str;
125+
}
123126

127+
#if !defined(USBHOST_OTHER)
124128
void USBEndpoint::setState(uint8_t st) {
125129
if (st > 18)
126130
return;
127131
state = type_string[st].type;
128132
}
129133

130-
131-
const char * USBEndpoint::getStateString() {
132-
return type_string[state].str;
133-
}
134-
135134
USB_TYPE USBEndpoint::queueTransfer()
136135
{
137136
transfer_len = (uint32_t)td_current->bufEnd - (uint32_t)td_current->currBufPtr + 1;
@@ -161,3 +160,4 @@ void USBEndpoint::queueEndpoint(USBEndpoint * ed)
161160
nextEp = ed;
162161
hced->nextED = (ed == NULL) ? 0 : (hcEd*)(ed->getHCED());
163162
}
163+
#endif

features/unsupported/USBHost/USBHost/USBEndpoint.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class USBEndpoint
4747
* @param ep_number endpoint number
4848
* @param td_list array of two allocated transfer descriptors
4949
*/
50+
5051
void init(HCED * hced, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint32_t size, uint8_t ep_number, HCTD* td_list[2]);
5152

5253
/**
@@ -123,12 +124,17 @@ class USBEndpoint
123124
const char * getStateString();
124125
inline USB_TYPE getState() { return state; }
125126
inline ENDPOINT_TYPE getType() { return type; };
127+
#ifdef USBHOST_OTHER
128+
inline uint8_t getDeviceAddress() { return device_address; };
129+
inline uint32_t getSize() { return size; };
130+
#else
126131
inline uint8_t getDeviceAddress() { return hced->control & 0x7f; };
132+
inline uint32_t getSize() { return (hced->control >> 16) & 0x3ff; };
133+
inline volatile HCTD * getHeadTD() { return (volatile HCTD*) ((uint32_t)hced->headTD & ~0xF); };
134+
#endif
127135
inline int getLengthTransferred() { return transferred; }
128136
inline uint8_t * getBufStart() { return buf_start; }
129137
inline uint8_t getAddress(){ return address; };
130-
inline uint32_t getSize() { return (hced->control >> 16) & 0x3ff; };
131-
inline volatile HCTD * getHeadTD() { return (volatile HCTD*) ((uint32_t)hced->headTD & ~0xF); };
132138
inline volatile HCTD** getTDList() { return td_list; };
133139
inline volatile HCED * getHCED() { return hced; };
134140
inline ENDPOINT_DIRECTION getDir() { return dir; }
@@ -146,6 +152,12 @@ class USBEndpoint
146152
ENDPOINT_TYPE type;
147153
volatile USB_TYPE state;
148154
ENDPOINT_DIRECTION dir;
155+
#ifdef USBHOST_OTHER
156+
uint32_t size;
157+
uint32_t ep_number;
158+
uint32_t speed;
159+
uint8_t device_address;
160+
#endif
149161
bool setup;
150162

151163
uint8_t address;

features/unsupported/USBHost/USBHost/USBHost.cpp

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,14 @@ void USBHost::usb_process() {
249249

250250
USBHost::USBHost() : usbThread(osPriorityNormal, USB_THREAD_STACK)
251251
{
252+
#ifndef USBHOST_OTHER
252253
headControlEndpoint = NULL;
253254
headBulkEndpoint = NULL;
254255
headInterruptEndpoint = NULL;
255256
tailControlEndpoint = NULL;
256257
tailBulkEndpoint = NULL;
257258
tailInterruptEndpoint = NULL;
258-
259+
#endif
259260
lenReportDescr = 0;
260261

261262
controlEndpointAllocated = false;
@@ -312,13 +313,22 @@ void USBHost::transferCompleted(volatile uint32_t addr)
312313
if (td->ep != NULL) {
313314
USBEndpoint * ep = (USBEndpoint *)(td->ep);
314315

316+
#ifdef USBHOST_OTHER
317+
state = ((HCTD *)td)->state;
318+
if (state == USB_TYPE_IDLE)
319+
ep->setLengthTransferred((uint32_t)td->currBufPtr - (uint32_t)ep->getBufStart());
320+
321+
#else
315322
if (((HCTD *)td)->control >> 28) {
316323
state = ((HCTD *)td)->control >> 28;
317324
} else {
318325
if (td->currBufPtr)
319326
ep->setLengthTransferred((uint32_t)td->currBufPtr - (uint32_t)ep->getBufStart());
320327
state = 16 /*USB_TYPE_IDLE*/;
321328
}
329+
#endif
330+
if (state == USB_TYPE_IDLE)
331+
ep->setLengthTransferred((uint32_t)td->currBufPtr - (uint32_t)ep->getBufStart());
322332

323333
ep->unqueueTransfer(td);
324334

@@ -428,8 +438,10 @@ void USBHost::freeDevice(USBDeviceConnected * dev)
428438
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));
429439
for (int i = 0; i < dev->getInterface(j)->nb_endpoint; i++) {
430440
if ((ep = dev->getEndpoint(j, i)) != NULL) {
441+
#ifndef USBHOST_OTHER
431442
ed = (HCED *)ep->getHCED();
432443
ed->control |= (1 << 14); //sKip bit
444+
#endif
433445
unqueueEndpoint(ep);
434446

435447
freeTD((volatile uint8_t*)ep->getTDList()[0]);
@@ -450,6 +462,9 @@ void USBHost::freeDevice(USBDeviceConnected * dev)
450462

451463
void USBHost::unqueueEndpoint(USBEndpoint * ep)
452464
{
465+
#ifdef USBHOST_OTHER
466+
ep->setState(USB_TYPE_FREE);
467+
#else
453468
USBEndpoint * prec = NULL;
454469
USBEndpoint * current = NULL;
455470

@@ -499,6 +514,7 @@ void USBHost::unqueueEndpoint(USBEndpoint * ep)
499514
current = current->nextEndpoint();
500515
}
501516
}
517+
#endif
502518
}
503519

504520

@@ -563,8 +579,10 @@ bool USBHost::addEndpoint(USBDeviceConnected * dev, uint8_t intf_nb, USBEndpoint
563579
return false;
564580
}
565581

582+
#ifndef USBHOST_OTHER
566583
HCED * prevEd;
567584

585+
#endif
568586
// set device address in the USBEndpoint descriptor
569587
if (dev == NULL) {
570588
ep->setDeviceAddress(0);
@@ -578,6 +596,7 @@ bool USBHost::addEndpoint(USBDeviceConnected * dev, uint8_t intf_nb, USBEndpoint
578596

579597
ep->setIntfNb(intf_nb);
580598

599+
#ifndef USBHOST_OTHER
581600
// queue the new USBEndpoint on the ED list
582601
switch (ep->getType()) {
583602

@@ -625,6 +644,7 @@ bool USBHost::addEndpoint(USBDeviceConnected * dev, uint8_t intf_nb, USBEndpoint
625644
return false;
626645
}
627646

647+
#endif
628648
ep->dev = dev;
629649
dev->addEndpoint(intf_nb, ep);
630650

@@ -659,7 +679,7 @@ int USBHost::findDevice(uint8_t hub, uint8_t port, USBHostHub * hub_parent)
659679

660680
void USBHost::printList(ENDPOINT_TYPE type)
661681
{
662-
#if DEBUG_EP_STATE
682+
#if defined(DEBUG_EP_STATE) && !defined(USBHOST_OTHER)
663683
volatile HCED * hced;
664684
switch(type) {
665685
case CONTROL_ENDPOINT:
@@ -708,6 +728,7 @@ USB_TYPE USBHost::addTransfer(USBEndpoint * ed, uint8_t * buf, uint32_t len)
708728
return USB_TYPE_ERROR;
709729
}
710730

731+
#ifndef USBHOST_OTHER
711732
uint32_t token = (ed->isSetup() ? TD_SETUP : ( (ed->getDir() == IN) ? TD_IN : TD_OUT ));
712733

713734
uint32_t td_toggle;
@@ -732,6 +753,12 @@ USB_TYPE USBHost::addTransfer(USBEndpoint * ed, uint8_t * buf, uint32_t len)
732753
ed->queueTransfer();
733754
printList(type);
734755
enableList(type);
756+
#else
757+
/* call method specific for endpoint */
758+
td->currBufPtr = buf;
759+
td->size = len;
760+
ret = ed->queueTransfer();
761+
#endif
735762

736763
td_mutex.unlock();
737764

features/unsupported/USBHost/USBHost/USBHost.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616

1717
#ifndef USBHOST_H
1818
#define USBHOST_H
19-
19+
#ifdef TARGET_STM
20+
#include "mbed.h"
21+
#endif
2022
#include "USBHALHost.h"
2123
#include "USBDeviceConnected.h"
2224
#include "IUSBEnumerator.h"

features/unsupported/USBHost/USBHost/USBHostTypes.h

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ enum ENDPOINT_TYPE {
6767
#define HUB_CLASS 0x09
6868
#define SERIAL_CLASS 0x0A
6969

70+
#if !defined(USBHOST_OTHER)
7071
// ------------------ HcControl Register ---------------------
7172
#define OR_CONTROL_PLE 0x00000004
7273
#define OR_CONTROL_CLE 0x00000010
@@ -114,6 +115,13 @@ enum ENDPOINT_TYPE {
114115
#define TD_TOGGLE_1 (uint32_t)(0x03000000) // Toggle 1
115116
#define TD_CC (uint32_t)(0xF0000000) // Completion Code
116117

118+
#else
119+
120+
#define TD_SETUP (uint32_t)(0) // Direction of Setup Packet
121+
#define TD_IN (uint32_t)(0x00100000) // Direction In
122+
#define TD_OUT (uint32_t)(0x00080000) // Direction Out
123+
124+
#endif
117125
#define DEVICE_DESCRIPTOR (1)
118126
#define CONFIGURATION_DESCRIPTOR (2)
119127
#define INTERFACE_DESCRIPTOR (4)
@@ -140,6 +148,27 @@ enum ENDPOINT_TYPE {
140148
#define DEVICE_DESCRIPTOR_LENGTH 0x12
141149
#define CONFIGURATION_DESCRIPTOR_LENGTH 0x09
142150

151+
// ------------ HostController Transfer Descriptor ------------
152+
#if defined(USBHOST_OTHER)
153+
154+
typedef struct hcTd {
155+
__IO uint32_t state;
156+
__IO uint8_t * currBufPtr; // Physical address of current buffer pointer
157+
__IO hcTd * nextTD; // Physical pointer to next Transfer Descriptor
158+
__IO uint32_t size; // size of buffer
159+
void * ep; // ep address where a td is linked in
160+
} PACKED HCTD;
161+
// ----------- HostController EndPoint Descriptor -------------
162+
typedef struct hcEd {
163+
uint8_t ch_num;
164+
void *hhcd;
165+
} PACKED HCED;
166+
// ----------- Host Controller Communication Area ------------
167+
#define HCCA void
168+
169+
170+
#else
171+
// -------------OHCI register --------------------------------
143172
// ------------ HostController Transfer Descriptor ------------
144173
typedef struct hcTd {
145174
__IO uint32_t control; // Transfer descriptor control
@@ -149,16 +178,13 @@ typedef struct hcTd {
149178
void * ep; // ep address where a td is linked in
150179
uint32_t dummy[3]; // padding
151180
} PACKED HCTD;
152-
153181
// ----------- HostController EndPoint Descriptor -------------
154182
typedef struct hcEd {
155183
__IO uint32_t control; // Endpoint descriptor control
156184
__IO HCTD * tailTD; // Physical address of tail in Transfer descriptor list
157185
__IO HCTD * headTD; // Physcial address of head in Transfer descriptor list
158186
__IO hcEd * nextED; // Physical address of next Endpoint descriptor
159187
} PACKED HCED;
160-
161-
162188
// ----------- Host Controller Communication Area ------------
163189
typedef struct hcca {
164190
__IO uint32_t IntTable[32]; // Interrupt Table
@@ -167,6 +193,7 @@ typedef struct hcca {
167193
volatile uint8_t Reserved[116]; // Reserved for future use
168194
volatile uint8_t Unknown[4]; // Unused
169195
} PACKED HCCA;
196+
#endif
170197

171198
typedef struct {
172199
uint8_t bLength;

0 commit comments

Comments
 (0)