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
LPC4088-USBHost/USBHost/USBEndpoint.cpp@0:11152e69fc05, 2014-04-22 (annotated)
- Committer:
- va009039
- Date:
- Tue Apr 22 10:54:52 2014 +0000
- Revision:
- 0:11152e69fc05
first commit,sync rev.25.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 0:11152e69fc05 | 1 | /* mbed USBHost Library |
va009039 | 0:11152e69fc05 | 2 | * Copyright (c) 2006-2013 ARM Limited |
va009039 | 0:11152e69fc05 | 3 | * |
va009039 | 0:11152e69fc05 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
va009039 | 0:11152e69fc05 | 5 | * you may not use this file except in compliance with the License. |
va009039 | 0:11152e69fc05 | 6 | * You may obtain a copy of the License at |
va009039 | 0:11152e69fc05 | 7 | * |
va009039 | 0:11152e69fc05 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
va009039 | 0:11152e69fc05 | 9 | * |
va009039 | 0:11152e69fc05 | 10 | * Unless required by applicable law or agreed to in writing, software |
va009039 | 0:11152e69fc05 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
va009039 | 0:11152e69fc05 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
va009039 | 0:11152e69fc05 | 13 | * See the License for the specific language governing permissions and |
va009039 | 0:11152e69fc05 | 14 | * limitations under the License. |
va009039 | 0:11152e69fc05 | 15 | */ |
va009039 | 0:11152e69fc05 | 16 | |
va009039 | 0:11152e69fc05 | 17 | #include "USBHost.h" |
va009039 | 0:11152e69fc05 | 18 | #include "BaseUsbHostDebug.h" |
va009039 | 0:11152e69fc05 | 19 | #include "USBEndpoint.h" |
va009039 | 0:11152e69fc05 | 20 | #include "BaseUsbHostTest.h" |
va009039 | 0:11152e69fc05 | 21 | |
va009039 | 0:11152e69fc05 | 22 | USBEndpoint::USBEndpoint(int addr, uint8_t ep, uint16_t size, int lowSpeed) |
va009039 | 0:11152e69fc05 | 23 | :m_td_queue_count(0) { |
va009039 | 0:11152e69fc05 | 24 | dev = NULL; |
va009039 | 0:11152e69fc05 | 25 | host = USBHost::getHostInst(); |
va009039 | 0:11152e69fc05 | 26 | setNextEndpoint(NULL); |
va009039 | 0:11152e69fc05 | 27 | DBG("%p FA=%d EN=%02x MPS=%d S=%d\n", this, addr, ep, size, lowSpeed); |
va009039 | 0:11152e69fc05 | 28 | TEST_ASSERT(size >= 8 && size <= 1023); |
va009039 | 0:11152e69fc05 | 29 | TEST_ASSERT(lowSpeed == 0 || lowSpeed == 1); |
va009039 | 0:11152e69fc05 | 30 | m_pED = new HCED(addr, ep, size, lowSpeed); |
va009039 | 0:11152e69fc05 | 31 | TEST_ASSERT(m_pED); |
va009039 | 0:11152e69fc05 | 32 | } |
va009039 | 0:11152e69fc05 | 33 | |
va009039 | 0:11152e69fc05 | 34 | int USBEndpoint::GetAddr() { |
va009039 | 0:11152e69fc05 | 35 | USB_TEST_ASSERT(m_pED); |
va009039 | 0:11152e69fc05 | 36 | if (m_pED) { |
va009039 | 0:11152e69fc05 | 37 | return m_pED->FunctionAddress(); |
va009039 | 0:11152e69fc05 | 38 | } |
va009039 | 0:11152e69fc05 | 39 | return 0; |
va009039 | 0:11152e69fc05 | 40 | } |
va009039 | 0:11152e69fc05 | 41 | |
va009039 | 0:11152e69fc05 | 42 | int USBEndpoint::GetLowSpeed() |
va009039 | 0:11152e69fc05 | 43 | { |
va009039 | 0:11152e69fc05 | 44 | TEST_ASSERT(m_pED); |
va009039 | 0:11152e69fc05 | 45 | if (m_pED) { |
va009039 | 0:11152e69fc05 | 46 | return m_pED->Speed(); |
va009039 | 0:11152e69fc05 | 47 | } |
va009039 | 0:11152e69fc05 | 48 | return 0; |
va009039 | 0:11152e69fc05 | 49 | } |
va009039 | 0:11152e69fc05 | 50 | |
va009039 | 0:11152e69fc05 | 51 | void USBEndpoint::update_FunctionAddress(int addr) |
va009039 | 0:11152e69fc05 | 52 | { |
va009039 | 0:11152e69fc05 | 53 | TEST_ASSERT(addr >= 0 && addr <= 127); |
va009039 | 0:11152e69fc05 | 54 | TEST_ASSERT(m_pED); |
va009039 | 0:11152e69fc05 | 55 | if (m_pED) { |
va009039 | 0:11152e69fc05 | 56 | m_pED->setFunctionAddress(addr); |
va009039 | 0:11152e69fc05 | 57 | } |
va009039 | 0:11152e69fc05 | 58 | } |
va009039 | 0:11152e69fc05 | 59 | |
va009039 | 0:11152e69fc05 | 60 | void USBEndpoint::update_MaxPacketSize(uint16_t size) |
va009039 | 0:11152e69fc05 | 61 | { |
va009039 | 0:11152e69fc05 | 62 | TEST_ASSERT(size >= 8 && size <= 1023); |
va009039 | 0:11152e69fc05 | 63 | TEST_ASSERT(m_pED); |
va009039 | 0:11152e69fc05 | 64 | if (m_pED) { |
va009039 | 0:11152e69fc05 | 65 | m_pED->setMaxPacketSize(size); |
va009039 | 0:11152e69fc05 | 66 | } |
va009039 | 0:11152e69fc05 | 67 | } |
va009039 | 0:11152e69fc05 | 68 | |
va009039 | 0:11152e69fc05 | 69 | HCTD* USBEndpoint::get_queue_HCTD(uint32_t millisec) |
va009039 | 0:11152e69fc05 | 70 | { |
va009039 | 0:11152e69fc05 | 71 | for(int i = 0; i < 16; i++) { |
va009039 | 0:11152e69fc05 | 72 | osEvent evt = m_queue.get(millisec); |
va009039 | 0:11152e69fc05 | 73 | if (evt.status == osEventMessage) { |
va009039 | 0:11152e69fc05 | 74 | HCTD* td = reinterpret_cast<HCTD*>(evt.value.p); |
va009039 | 0:11152e69fc05 | 75 | TEST_ASSERT(td); |
va009039 | 0:11152e69fc05 | 76 | uint8_t cc = td->ConditionCode(); |
va009039 | 0:11152e69fc05 | 77 | if (cc != 0) { |
va009039 | 0:11152e69fc05 | 78 | m_ConditionCode = cc; |
va009039 | 0:11152e69fc05 | 79 | DBG_TD(td); |
va009039 | 0:11152e69fc05 | 80 | } |
va009039 | 0:11152e69fc05 | 81 | return td; |
va009039 | 0:11152e69fc05 | 82 | } else if (evt.status == osOK) { |
va009039 | 0:11152e69fc05 | 83 | continue; |
va009039 | 0:11152e69fc05 | 84 | } else if (evt.status == osEventTimeout) { |
va009039 | 0:11152e69fc05 | 85 | return NULL; |
va009039 | 0:11152e69fc05 | 86 | } else { |
va009039 | 0:11152e69fc05 | 87 | DBG("evt.status: %02x\n", evt.status); |
va009039 | 0:11152e69fc05 | 88 | TEST_ASSERT(evt.status == osEventMessage); |
va009039 | 0:11152e69fc05 | 89 | } |
va009039 | 0:11152e69fc05 | 90 | } |
va009039 | 0:11152e69fc05 | 91 | return NULL; |
va009039 | 0:11152e69fc05 | 92 | } |
va009039 | 0:11152e69fc05 | 93 | |
va009039 | 0:11152e69fc05 | 94 | InterruptEp::InterruptEp(int addr, uint8_t ep, uint16_t size, int lowSpeed) |
va009039 | 0:11152e69fc05 | 95 | :USBEndpoint(addr, ep, size, lowSpeed) { |
va009039 | 0:11152e69fc05 | 96 | setType(INTERRUPT_ENDPOINT); |
va009039 | 0:11152e69fc05 | 97 | } |
va009039 | 0:11152e69fc05 | 98 | |
va009039 | 0:11152e69fc05 | 99 | BulkEp::BulkEp(int addr, uint8_t ep, uint16_t size): USBEndpoint(addr, ep, size) { |
va009039 | 0:11152e69fc05 | 100 | setType(BULK_ENDPOINT); |
va009039 | 0:11152e69fc05 | 101 | } |
va009039 | 0:11152e69fc05 | 102 | |
va009039 | 0:11152e69fc05 | 103 |