USB host library, support isochronous,bulk,interrupt and control.

Dependents:   BaseUsbHost_example BaseJpegDecode_example SimpleJpegDecode_example

Import programBaseUsbHost_example

BaseUsbHost example program

Committer:
va009039
Date:
Tue Dec 11 15:26:54 2012 +0000
Revision:
2:fe1e62051d88
Parent:
1:3b7bc4f87a61
Child:
3:ae77d63a1eda
bug fix

Who changed what in which revision?

UserRevisionLine numberNew contents of line
va009039 2:fe1e62051d88 1 // BaseUsbHostIntEp.cpp 2012/12/11
va009039 0:b7d6879637a8 2 #include "mbed.h"
va009039 0:b7d6879637a8 3 #include "rtos.h"
va009039 0:b7d6879637a8 4 #include "BaseUsbHost.h"
va009039 0:b7d6879637a8 5 #define DEBUG
va009039 0:b7d6879637a8 6 #include "BaseUsbHostDebug.h"
va009039 0:b7d6879637a8 7 #define TEST
va009039 0:b7d6879637a8 8 #include "BaseUsbHostTest.h"
va009039 0:b7d6879637a8 9
va009039 0:b7d6879637a8 10 InterruptEp::InterruptEp(int addr, uint8_t ep, uint16_t size, int lowSpeed)
va009039 0:b7d6879637a8 11 :BaseEp(addr, ep, size, lowSpeed)
va009039 0:b7d6879637a8 12 {
va009039 0:b7d6879637a8 13 HCTD* td = new_HCTD();
va009039 0:b7d6879637a8 14 m_pED->TailTd = td;
va009039 0:b7d6879637a8 15 m_pED->HeadTd = td;
va009039 2:fe1e62051d88 16 TEST_ASSERT(td);
va009039 2:fe1e62051d88 17 if (td == NULL) {
va009039 2:fe1e62051d88 18 return;
va009039 2:fe1e62051d88 19 }
va009039 0:b7d6879637a8 20 HCCA* pHcca = reinterpret_cast<HCCA*>(LPC_USB->HcHCCA);
va009039 0:b7d6879637a8 21 TEST_ASSERT(pHcca);
va009039 2:fe1e62051d88 22 if (pHcca == NULL) {
va009039 2:fe1e62051d88 23 return;
va009039 2:fe1e62051d88 24 }
va009039 0:b7d6879637a8 25 int n = 0;
va009039 0:b7d6879637a8 26 m_pED->Next = pHcca->InterruptTable[n];
va009039 0:b7d6879637a8 27 pHcca->InterruptTable[n] = reinterpret_cast<uint32_t>(m_pED);
va009039 0:b7d6879637a8 28 LPC_USB->HcControl |= OR_CONTROL_PLE;
va009039 0:b7d6879637a8 29 }
va009039 0:b7d6879637a8 30
va009039 1:3b7bc4f87a61 31 int InterruptEp::interruptReceive(uint8_t* buf, int len, int millisec)
va009039 0:b7d6879637a8 32 {
va009039 0:b7d6879637a8 33 if (m_td_queue_count == 0) {
va009039 0:b7d6879637a8 34 HCTD* data_td = m_pED->TailTd;
va009039 0:b7d6879637a8 35 TEST_ASSERT(data_td);
va009039 2:fe1e62051d88 36 if (data_td == NULL) {
va009039 2:fe1e62051d88 37 return USB_ERROR;
va009039 2:fe1e62051d88 38 }
va009039 0:b7d6879637a8 39 data_td->Control |= TD_IN;
va009039 0:b7d6879637a8 40 data_td->CurrBufPtr = buf;
va009039 0:b7d6879637a8 41 data_td->BufEnd = const_cast<uint8_t*>(buf)+len-1;
va009039 0:b7d6879637a8 42 HCTD* blank_td = new_HCTD();
va009039 0:b7d6879637a8 43 TEST_ASSERT(blank_td);
va009039 2:fe1e62051d88 44 if (blank_td == NULL) {
va009039 2:fe1e62051d88 45 return USB_ERROR_MEMORY;
va009039 2:fe1e62051d88 46 }
va009039 0:b7d6879637a8 47 data_td->Next = reinterpret_cast<uint32_t>(blank_td);
va009039 0:b7d6879637a8 48 m_pED->TailTd = blank_td;
va009039 0:b7d6879637a8 49 m_td_queue_count++;
va009039 0:b7d6879637a8 50 DBG_ED(m_pED);
va009039 0:b7d6879637a8 51 LPC_USB->HcControl |= OR_CONTROL_PLE; // Enable Periodic
va009039 0:b7d6879637a8 52 }
va009039 0:b7d6879637a8 53
va009039 0:b7d6879637a8 54 HCTD* td = get_queue_HCTD(millisec);
va009039 2:fe1e62051d88 55 if (td == NULL) {
va009039 2:fe1e62051d88 56 return USB_PROCESSING;
va009039 0:b7d6879637a8 57 }
va009039 2:fe1e62051d88 58 DBG_TD(td);
va009039 2:fe1e62051d88 59 int ret = len;
va009039 2:fe1e62051d88 60 if (td->CurrBufPtr) {
va009039 2:fe1e62051d88 61 ret = td->CurrBufPtr - buf;
va009039 2:fe1e62051d88 62 }
va009039 2:fe1e62051d88 63 delete_HCTD(td);
va009039 2:fe1e62051d88 64 m_td_queue_count--;
va009039 2:fe1e62051d88 65 return ret;
va009039 0:b7d6879637a8 66 }