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
usb/UsbEndpoint2.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 | /* |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 2 | Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 3 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 5 | of this software and associated documentation files (the "Software"), to deal |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 6 | in the Software without restriction, including without limitation the rights |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 8 | copies of the Software, and to permit persons to whom the Software is |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 9 | furnished to do so, subject to the following conditions: |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 10 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 11 | The above copyright notice and this permission notice shall be included in |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 12 | all copies or substantial portions of the Software. |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 13 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 20 | THE SOFTWARE. |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 21 | */ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 22 | #include "UsbEndpoint.h" |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 23 | #include "UsbDevice.h" |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 24 | #include "usb_mem.h" |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 25 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 26 | //#define __DEBUG |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 27 | //#define __DEBUG3 |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 28 | //#include "dbg/dbg.h" |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 29 | #include "mydbg.h" |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 30 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 31 | void UsbEndpoint::UsbEndpoint_iso(UsbDevice* pDevice, uint8_t ep, bool dir, UsbEndpointType type, uint16_t size, int addr) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 32 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 33 | m_itdActive = 0; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 34 | m_pEd = (volatile HCED*)usb_get_ed(); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 35 | DBG_ASSERT(m_pEd); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 36 | memset((void*)m_pEd, 0, sizeof(HCED)); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 37 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 38 | m_pTdHead = NULL; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 39 | m_pTdTail = NULL; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 40 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 41 | volatile HCTD* itd = (volatile HCTD*)usb_get_itd((uint32_t)this); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 42 | DBG_ASSERT(itd); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 43 | memset((void*)itd, 0, sizeof(HCITD)); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 44 | DBG3("m_pEd =%p\n", m_pEd); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 45 | DBG3("itd =%p\n", itd); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 46 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 47 | if(addr == -1) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 48 | addr = pDevice->m_addr; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 49 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 50 | //Setup Ed |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 51 | //printf("\r\n--Ep Setup--\r\n"); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 52 | m_pEd->Control = addr | /* USB address */ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 53 | ((ep & 0x7F) << 7) | /* Endpoint address */ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 54 | ((dir?2:1) << 11) | /* direction : Out = 1, 2 = In */ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 55 | (1 << 15) | /* F Format */ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 56 | (size << 16); /* MaxPkt Size */ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 57 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 58 | DBG3("m_pEd->Control=%08X\n", m_pEd->Control); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 59 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 60 | m_dir = dir; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 61 | m_setup = false; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 62 | m_type = type; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 63 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 64 | m_pEd->TailTd = m_pEd->HeadTd = (uint32_t)itd; //Empty TD list |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 65 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 66 | DBG("Before link\n"); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 67 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 68 | //printf("\r\n--Ep Reg--\r\n"); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 69 | //Append Ed to Ed list |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 70 | HCCA* hcca = (HCCA*)usb_get_hcca(); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 71 | for(int i = 0; i < 32; i++) { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 72 | if (hcca->IntTable[i] == 0) { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 73 | hcca->IntTable[i] = (uint32_t)m_pEd; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 74 | } else { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 75 | volatile HCED* nextEd = (volatile HCED*)hcca->IntTable[i]; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 76 | while(nextEd->Next && nextEd->Next != (uint32_t)m_pEd) { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 77 | nextEd = (volatile HCED*)nextEd->Next; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 78 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 79 | nextEd->Next = (uint32_t)m_pEd; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 80 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 81 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 82 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 83 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 84 | // for isochronous |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 85 | UsbErr UsbEndpoint::transfer(uint16_t frame, int count, volatile uint8_t* buf, int len) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 86 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 87 | DBG_ASSERT(count >= 1 && count <= 8); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 88 | DBG_ASSERT(buf); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 89 | DBG_ASSERT((len % count) == 0); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 90 | HCITD *itd = (HCITD*)m_pEd->TailTd; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 91 | DBG_ASSERT(itd); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 92 | HCITD *new_itd = (HCITD*)usb_get_itd((uint32_t)this); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 93 | DBG_ASSERT(new_itd); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 94 | if (itd == NULL) { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 95 | return USBERR_ERROR; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 96 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 97 | DBG("itd=%p\n", itd); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 98 | DBG2("new_itd=%p\n", new_itd); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 99 | int di = 0; //DelayInterrupt |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 100 | itd->Control = 0xe0000000 | // CC ConditionCode NOT ACCESSED |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 101 | ((count-1) << 24) | // FC FrameCount |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 102 | TD_DELAY_INT(di) | // DI DelayInterrupt |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 103 | frame; // SF StartingFrame |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 104 | itd->BufferPage0 = (uint32_t)buf; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 105 | itd->BufferEnd = (uint32_t)buf+len-1; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 106 | itd->Next = (uint32_t)new_itd; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 107 | uint16_t offset[8]; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 108 | for(int i = 0; i < 8; i++) { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 109 | uint32_t addr = (uint32_t)buf + i*(len/count); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 110 | offset[i] = addr & 0x0fff; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 111 | if ((addr&0xfffff000) == (itd->BufferEnd&0xfffff000)) { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 112 | offset[i] |= 0x1000; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 113 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 114 | offset[i] |= 0xe000; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 115 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 116 | itd->OffsetPSW10 = (offset[1]<<16) | offset[0]; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 117 | itd->OffsetPSW32 = (offset[3]<<16) | offset[2]; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 118 | itd->OffsetPSW54 = (offset[5]<<16) | offset[4]; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 119 | itd->OffsetPSW76 = (offset[7]<<16) | offset[6]; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 120 | m_itdActive++; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 121 | DBG2("itd->Control =%08X\n", itd->Control); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 122 | DBG2("itd->BufferPage0=%08X\n", itd->BufferPage0); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 123 | DBG2("itd->Next =%08X\n", itd->Next); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 124 | DBG2("itd->BufferEnd =%08X\n", itd->BufferEnd); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 125 | DBG2("itd->OffsetPSW10=%08X\n", itd->OffsetPSW10); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 126 | DBG2("itd->OffsetPSW32=%08X\n", itd->OffsetPSW32); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 127 | DBG2("itd->OffsetPSW54=%08X\n", itd->OffsetPSW54); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 128 | DBG2("itd->OffsetPSW76=%08X\n", itd->OffsetPSW76); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 129 | m_pEd->TailTd = (uint32_t)new_itd; // start!!! |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 130 | LPC_USB->HcControl |= OR_CONTROL_PLE; //Enable Periodic |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 131 | return USBERR_PROCESSING; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 132 | } |