Simple USBHost MSD(USB flash drive) for EA LPC4088 QSB test program
Dependencies: LPC4088-USBHost mbed
EA LPC4088をUSBホストにしてUSBフラッシュメモリ(USB flash drive)を読み書きするテストプログラムです。
https://bitbucket.org/va009039/lpc4088_usbhost
Diff: LPC4088-USBHost/USBHost/USBEndpoint.cpp
- Revision:
- 0:11152e69fc05
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LPC4088-USBHost/USBHost/USBEndpoint.cpp Tue Apr 22 10:54:52 2014 +0000 @@ -0,0 +1,103 @@ +/* mbed USBHost Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "USBHost.h" +#include "BaseUsbHostDebug.h" +#include "USBEndpoint.h" +#include "BaseUsbHostTest.h" + +USBEndpoint::USBEndpoint(int addr, uint8_t ep, uint16_t size, int lowSpeed) + :m_td_queue_count(0) { + dev = NULL; + host = USBHost::getHostInst(); + setNextEndpoint(NULL); + DBG("%p FA=%d EN=%02x MPS=%d S=%d\n", this, addr, ep, size, lowSpeed); + TEST_ASSERT(size >= 8 && size <= 1023); + TEST_ASSERT(lowSpeed == 0 || lowSpeed == 1); + m_pED = new HCED(addr, ep, size, lowSpeed); + TEST_ASSERT(m_pED); +} + +int USBEndpoint::GetAddr() { + USB_TEST_ASSERT(m_pED); + if (m_pED) { + return m_pED->FunctionAddress(); + } + return 0; +} + +int USBEndpoint::GetLowSpeed() +{ + TEST_ASSERT(m_pED); + if (m_pED) { + return m_pED->Speed(); + } + return 0; +} + +void USBEndpoint::update_FunctionAddress(int addr) +{ + TEST_ASSERT(addr >= 0 && addr <= 127); + TEST_ASSERT(m_pED); + if (m_pED) { + m_pED->setFunctionAddress(addr); + } +} + +void USBEndpoint::update_MaxPacketSize(uint16_t size) +{ + TEST_ASSERT(size >= 8 && size <= 1023); + TEST_ASSERT(m_pED); + if (m_pED) { + m_pED->setMaxPacketSize(size); + } +} + +HCTD* USBEndpoint::get_queue_HCTD(uint32_t millisec) +{ + for(int i = 0; i < 16; i++) { + osEvent evt = m_queue.get(millisec); + if (evt.status == osEventMessage) { + HCTD* td = reinterpret_cast<HCTD*>(evt.value.p); + TEST_ASSERT(td); + uint8_t cc = td->ConditionCode(); + if (cc != 0) { + m_ConditionCode = cc; + DBG_TD(td); + } + return td; + } else if (evt.status == osOK) { + continue; + } else if (evt.status == osEventTimeout) { + return NULL; + } else { + DBG("evt.status: %02x\n", evt.status); + TEST_ASSERT(evt.status == osEventMessage); + } + } + return NULL; +} + +InterruptEp::InterruptEp(int addr, uint8_t ep, uint16_t size, int lowSpeed) + :USBEndpoint(addr, ep, size, lowSpeed) { + setType(INTERRUPT_ENDPOINT); +} + +BulkEp::BulkEp(int addr, uint8_t ep, uint16_t size): USBEndpoint(addr, ep, size) { + setType(BULK_ENDPOINT); +} + +