Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FatFileSystem TB6612FNG2 mbed
uvc/usb_itd.cpp@0:de03cbbcd0ff, 2015-11-30 (annotated)
- Committer:
- mbed_Cookbook_SE
- Date:
- Mon Nov 30 09:32:15 2015 +0000
- Revision:
- 0:de03cbbcd0ff
??
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 1 | #include "mbed.h" |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 2 | #include "usb_itd.h" |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 3 | #define __DEBUG |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 4 | #include "mydbg.h" |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 5 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 6 | usb_itd::usb_itd(HCITD* itd) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 7 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 8 | DBG_ASSERT(itd); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 9 | m_itd = itd; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 10 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 11 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 12 | bool usb_itd::Done() |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 13 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 14 | int cc = (m_itd->Control >> 28); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 15 | if (cc == 0xe || cc == 0xf) { // not accessed? |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 16 | return false; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 17 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 18 | if (m_itd->Next) { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 19 | return false; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 20 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 21 | return true; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 22 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 23 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 24 | int usb_itd::ConditionCode() |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 25 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 26 | int cc = (m_itd->Control >> 28); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 27 | return cc; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 28 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 29 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 30 | uint16_t usb_itd::get_psw(int n) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 31 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 32 | DBG_ASSERT(n >= 0 && n <= 7); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 33 | DBG_ASSERT(m_itd); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 34 | uint16_t psw = 0; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 35 | switch(n) { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 36 | case 0: psw = m_itd->OffsetPSW10; break; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 37 | case 1: psw = m_itd->OffsetPSW10 >> 16; break; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 38 | case 2: psw = m_itd->OffsetPSW32; break; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 39 | case 3: psw = m_itd->OffsetPSW32 >> 16; break; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 40 | case 4: psw = m_itd->OffsetPSW54; break; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 41 | case 5: psw = m_itd->OffsetPSW54 >> 16; break; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 42 | case 6: psw = m_itd->OffsetPSW76; break; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 43 | case 7: psw = m_itd->OffsetPSW76 >> 16; break; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 44 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 45 | return psw; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 46 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 47 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 48 | uint16_t usb_itd::StartingFrame() |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 49 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 50 | return (m_itd->Control & ITD_SF); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 51 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 52 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 53 | int usb_itd::FrameCount() |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 54 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 55 | DBG_ASSERT(m_itd); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 56 | int fc = ((m_itd->Control & ITD_FC) >> 24) + 1; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 57 | DBG_ASSERT(fc >= 1 && fc <= 8); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 58 | return fc; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 59 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 60 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 61 | int usb_itd::PacketStatus(int n) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 62 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 63 | DBG_ASSERT(n >=0 && n <= 7); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 64 | uint16_t psw = get_psw(n); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 65 | int cc = (psw >> 12) & 0xf; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 66 | return cc; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 67 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 68 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 69 | int usb_itd::Length(int n) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 70 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 71 | DBG_ASSERT(n >=0 && n <= 7); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 72 | uint16_t psw = get_psw(n); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 73 | int size = psw & 0x7ff; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 74 | int cc = (psw >> 12) & 0xf; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 75 | if (cc == 0xe || cc == 0xf) { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 76 | return -1; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 77 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 78 | if (cc == 0 || cc == 9) { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 79 | return size; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 80 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 81 | debug(); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 82 | return -1; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 83 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 84 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 85 | uint8_t* usb_itd::BufferPage(int n, int size) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 86 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 87 | DBG_ASSERT(n >=0 && n <= 7); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 88 | DBG_ASSERT(size >= 128 && size <= 956); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 89 | uint8_t* buf = (uint8_t*)m_itd->BufferPage0 + n * size; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 90 | DBG_ASSERT((uint32_t)(buf+size-1) <= m_itd->BufferEnd); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 91 | return buf; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 92 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 93 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 94 | void usb_itd::free() |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 95 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 96 | DBG_ASSERT(m_itd); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 97 | if (m_itd) { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 98 | uint8_t* buf = (uint8_t*)m_itd->BufferPage0; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 99 | DBG_ASSERT(buf); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 100 | usb_free_bp(buf); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 101 | usb_free_itd((byte*)m_itd); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 102 | m_itd = NULL; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 103 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 104 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 105 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 106 | void usb_itd::debug() |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 107 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 108 | DBG("itd =%08X\n", m_itd); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 109 | DBG("itd->Control =%08X\n", m_itd->Control); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 110 | DBG("itd->BufferPage0=%08X\n", m_itd->BufferPage0); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 111 | DBG("itd->Next =%08X\n", m_itd->Next); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 112 | DBG("itd->BufferEnd =%08X\n", m_itd->BufferEnd); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 113 | DBG("itd->OffsetPSW10=%08X\n", m_itd->OffsetPSW10); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 114 | DBG("itd->OffsetPSW32=%08X\n", m_itd->OffsetPSW32); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 115 | DBG("itd->OffsetPSW54=%08X\n", m_itd->OffsetPSW54); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 116 | DBG("itd->OffsetPSW76=%08X\n", m_itd->OffsetPSW76); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 117 | } |