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/usb_mem.c@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 | /* |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 3 | Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 4 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 6 | of this software and associated documentation files (the "Software"), to deal |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 7 | in the Software without restriction, including without limitation the rights |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 9 | copies of the Software, and to permit persons to whom the Software is |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 10 | furnished to do so, subject to the following conditions: |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 11 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 12 | The above copyright notice and this permission notice shall be included in |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 13 | all copies or substantial portions of the Software. |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 14 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 21 | THE SOFTWARE. |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 22 | */ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 23 | #include "mbed.h" |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 24 | //#define __DEBUG |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 25 | #include "mydbg.h" |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 26 | #include "usb_mem.h" |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 27 | #include "string.h" //For memcpy, memmove, memset |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 28 | //#include "netCfg.h" |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 29 | #include "UsbInc.h" |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 30 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 31 | //#if NET_USB |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 32 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 33 | #define EDS_COUNT 16 |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 34 | #define TDS_COUNT 0 |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 35 | #define ITDS_COUNT 0 |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 36 | #define UTDS_COUNT 32 |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 37 | #define BPS_COUNT 8 |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 38 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 39 | #define HCCA_SIZE 0x100 |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 40 | #define ED_SIZE 0x10 |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 41 | #define TD_SIZE 0x10 |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 42 | #define ITD_SIZE 0x20 |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 43 | #define UTD_SIZE (32+16) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 44 | #define BP_SIZE (128*8) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 45 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 46 | #define TOTAL_SIZE (HCCA_SIZE + (EDS_COUNT*ED_SIZE) + (TDS_COUNT*TD_SIZE) + (ITDS_COUNT*ITD_SIZE)) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 47 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 48 | static volatile __align(256) byte usb_buf[TOTAL_SIZE] __attribute((section("AHBSRAM0"),aligned)); //256 bytes aligned! |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 49 | static volatile __align(32) uint8_t usb_utdBuf[UTDS_COUNT*UTD_SIZE] __attribute((section("AHBSRAM0"),aligned)); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 50 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 51 | static volatile byte* usb_hcca; //256 bytes aligned! |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 52 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 53 | static volatile byte* usb_edBuf; //4 bytes aligned! |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 54 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 55 | static byte usb_edBufAlloc[EDS_COUNT] __attribute((section("AHBSRAM0"),aligned)); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 56 | static uint8_t usb_utdBufAlloc[UTDS_COUNT] __attribute((section("AHBSRAM0"),aligned)); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 57 | static uint8_t usb_bpBufAlloc[BPS_COUNT] __attribute((section("AHBSRAM0"),aligned)); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 58 | static uint8_t usb_bpBuf[BP_SIZE*BPS_COUNT] __attribute((section("AHBSRAM0"),aligned)); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 59 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 60 | static void utd_init() |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 61 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 62 | DBG_ASSERT(sizeof(HCTD) == 16); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 63 | DBG_ASSERT(sizeof(HCITD) == 32); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 64 | DBG_ASSERT(sizeof(HCUTD) == 48); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 65 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 66 | DBG_ASSERT(((uint32_t)usb_utdBuf % 16) == 0); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 67 | DBG_ASSERT(((uint32_t)usb_utdBuf % 32) == 0); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 68 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 69 | DBG_ASSERT((uint32_t)usb_utdBufAlloc >= 0x2007c000); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 70 | DBG_ASSERT((uint32_t)&usb_utdBufAlloc[UTDS_COUNT] <= 0x2007ffff); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 71 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 72 | DBG_ASSERT((uint32_t)usb_utdBuf >= 0x2007c000); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 73 | DBG_ASSERT((uint32_t)&usb_utdBuf[UTD_SIZE*UTDS_COUNT] <= 0x2007cfff); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 74 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 75 | memset(usb_utdBufAlloc, 0x00, UTDS_COUNT); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 76 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 77 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 78 | static void pb_init() |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 79 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 80 | memset(usb_bpBufAlloc, 0x00, BPS_COUNT); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 81 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 82 | DBG_ASSERT((uint32_t)usb_bpBufAlloc >= 0x2007c000); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 83 | DBG_ASSERT((uint32_t)&usb_bpBufAlloc[BPS_COUNT] <= 0x2007ffff); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 84 | DBG_ASSERT((uint32_t)usb_bpBuf >= 0x2007c000); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 85 | DBG_ASSERT((uint32_t)(&usb_bpBuf[BP_SIZE*BPS_COUNT]) <= 0x2007ffff); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 86 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 87 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 88 | void usb_mem_init() |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 89 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 90 | usb_hcca = usb_buf; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 91 | usb_edBuf = usb_buf + HCCA_SIZE; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 92 | memset(usb_edBufAlloc, 0, EDS_COUNT); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 93 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 94 | utd_init(); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 95 | pb_init(); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 96 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 97 | DBG("--- Memory Map --- \n"); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 98 | DBG("usb_hcca =%p\n", usb_hcca); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 99 | DBG("usb_edBuf =%p\n", usb_edBuf); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 100 | DBG("usb_utdBuf =%p\n", usb_utdBuf); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 101 | DBG("usb_edBufAlloc =%p\n", usb_edBufAlloc); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 102 | DBG("usb_utdBufAlloc=%p\n", usb_utdBufAlloc); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 103 | DBG("usb_bpBufAlloc =%p\n", usb_bpBufAlloc); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 104 | DBG("usb_bpBuf =%p\n", usb_bpBuf); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 105 | DBG(" =%p\n", &usb_bpBuf[BP_SIZE*BPS_COUNT]); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 106 | DBG_ASSERT(((uint32_t)usb_hcca % 256) == 0); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 107 | DBG_ASSERT(((uint32_t)usb_edBuf % 16) == 0); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 108 | DBG_ASSERT(((uint32_t)usb_utdBuf % 32) == 0); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 109 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 110 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 111 | volatile byte* usb_get_hcca() |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 112 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 113 | return usb_hcca; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 114 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 115 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 116 | volatile byte* usb_get_ed() |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 117 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 118 | int i; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 119 | for(i = 0; i < EDS_COUNT; i++) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 120 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 121 | if( !usb_edBufAlloc[i] ) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 122 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 123 | usb_edBufAlloc[i] = 1; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 124 | return usb_edBuf + i*ED_SIZE; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 125 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 126 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 127 | return NULL; //Could not alloc ED |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 128 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 129 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 130 | static uint8_t* usb_get_utd(int al) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 131 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 132 | DBG_ASSERT(al == 16 || al == 32); // GTD or ITD |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 133 | if (al == 16) { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 134 | for(int i = 1; i < UTDS_COUNT; i += 2) { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 135 | if (usb_utdBufAlloc[i] == 0) { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 136 | uint32_t p = (uint32_t)usb_utdBuf + i * UTD_SIZE; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 137 | if ((p % al) == 0) { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 138 | usb_utdBufAlloc[i] = 1; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 139 | DBG_ASSERT((p % al) == 0); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 140 | return (uint8_t*)p; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 141 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 142 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 143 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 144 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 145 | for(int i = 0; i < UTDS_COUNT; i++) { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 146 | if (usb_utdBufAlloc[i] == 0) { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 147 | uint32_t p = (uint32_t)usb_utdBuf + i * UTD_SIZE; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 148 | if ((p % al) == 0) { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 149 | usb_utdBufAlloc[i] = 1; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 150 | DBG_ASSERT((p % al) == 0); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 151 | return (uint8_t*)p; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 152 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 153 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 154 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 155 | return NULL; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 156 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 157 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 158 | volatile byte* usb_get_td(uint32_t endpoint) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 159 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 160 | DBG_ASSERT(endpoint); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 161 | uint8_t* td = usb_get_utd(16); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 162 | if (td) { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 163 | HCUTD* utd = (HCUTD*)td; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 164 | memset(utd, 0x00, sizeof(HCTD)); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 165 | utd->type = 1; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 166 | utd->UsbEndpoint = endpoint; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 167 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 168 | return td; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 169 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 170 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 171 | volatile byte* usb_get_itd(uint32_t endpoint) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 172 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 173 | DBG_ASSERT(endpoint); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 174 | uint8_t* itd = usb_get_utd(32); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 175 | if (itd) { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 176 | HCUTD* utd = (HCUTD*)itd; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 177 | memset(utd, 0x00, sizeof(HCITD)); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 178 | utd->type = 2; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 179 | utd->UsbEndpoint = endpoint; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 180 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 181 | return itd; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 182 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 183 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 184 | volatile byte* usb_get_bp(int size) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 185 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 186 | DBG_ASSERT(size >= 128 && size <= BP_SIZE); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 187 | if (size > BP_SIZE) { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 188 | return NULL; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 189 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 190 | for(int i = 0; i < BPS_COUNT; i++) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 191 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 192 | if( !usb_bpBufAlloc[i] ) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 193 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 194 | usb_bpBufAlloc[i] = 1; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 195 | return usb_bpBuf + i*BP_SIZE; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 196 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 197 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 198 | return NULL; //Could not alloc Buffer Page |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 199 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 200 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 201 | int usb_bp_size() |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 202 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 203 | return BP_SIZE; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 204 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 205 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 206 | void usb_free_ed(volatile byte* ed) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 207 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 208 | int i; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 209 | i = (ed - usb_edBuf) / ED_SIZE; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 210 | usb_edBufAlloc[i] = 0; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 211 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 212 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 213 | static void usb_free_utd(volatile uint8_t* utd) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 214 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 215 | DBG_ASSERT(utd >= usb_utdBuf); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 216 | DBG_ASSERT(utd <= (usb_utdBuf+UTD_SIZE*(UTDS_COUNT-1))); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 217 | DBG_ASSERT(((uint32_t)utd % 16) == 0); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 218 | int i = (utd - usb_utdBuf) / UTD_SIZE; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 219 | DBG_ASSERT(usb_utdBufAlloc[i] == 1); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 220 | usb_utdBufAlloc[i] = 0; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 221 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 222 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 223 | void usb_free_td(volatile byte* td) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 224 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 225 | usb_free_utd(td); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 226 | return; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 227 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 228 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 229 | void usb_free_itd(volatile byte* itd) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 230 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 231 | usb_free_utd(itd); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 232 | return; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 233 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 234 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 235 | void usb_free_bp(volatile byte* bp) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 236 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 237 | DBG_ASSERT(bp >= usb_bpBuf); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 238 | int i; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 239 | i = (bp - usb_bpBuf) / BP_SIZE; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 240 | DBG_ASSERT(usb_bpBufAlloc[i] == 1); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 241 | usb_bpBufAlloc[i] = 0; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 242 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 243 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 244 | bool usb_is_td(volatile byte* td) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 245 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 246 | DBG_ASSERT(td); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 247 | HCUTD* utd = (HCUTD*)td; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 248 | DBG_ASSERT(utd->type != 0); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 249 | return utd->type == 1; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 250 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 251 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 252 | bool usb_is_itd(volatile byte* itd) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 253 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 254 | DBG_ASSERT(itd); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 255 | HCUTD* utd = (HCUTD*)itd; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 256 | DBG_ASSERT(utd->type != 0); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 257 | return utd->type == 2; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 258 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 259 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 260 | //#endif |