The beta version of the Vodafone K3770 dongle driver
This library is deprecated. Please use the newest production branch of the library from https://mbed.org/users/mbed_official/code/VodafoneUSBModem/
USBHostWANDongleLib/USBHost/USBHALHost.h@1:4b33ffe61bfa, 2012-11-01 (annotated)
- Committer:
- donatien
- Date:
- Thu Nov 01 10:03:50 2012 +0000
- Revision:
- 1:4b33ffe61bfa
- Parent:
- 0:0ac66acdfdc0
Deprecating library, pointing out at new one
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
donatien | 0:0ac66acdfdc0 | 1 | /* Copyright (c) 2010-2011 mbed.org, MIT License |
donatien | 0:0ac66acdfdc0 | 2 | * |
donatien | 0:0ac66acdfdc0 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
donatien | 0:0ac66acdfdc0 | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
donatien | 0:0ac66acdfdc0 | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
donatien | 0:0ac66acdfdc0 | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
donatien | 0:0ac66acdfdc0 | 7 | * Software is furnished to do so, subject to the following conditions: |
donatien | 0:0ac66acdfdc0 | 8 | * |
donatien | 0:0ac66acdfdc0 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
donatien | 0:0ac66acdfdc0 | 10 | * substantial portions of the Software. |
donatien | 0:0ac66acdfdc0 | 11 | * |
donatien | 0:0ac66acdfdc0 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
donatien | 0:0ac66acdfdc0 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
donatien | 0:0ac66acdfdc0 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
donatien | 0:0ac66acdfdc0 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
donatien | 0:0ac66acdfdc0 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
donatien | 0:0ac66acdfdc0 | 17 | */ |
donatien | 0:0ac66acdfdc0 | 18 | |
donatien | 0:0ac66acdfdc0 | 19 | #ifndef USBHALHOST_H |
donatien | 0:0ac66acdfdc0 | 20 | #define USBHALHOST_H |
donatien | 0:0ac66acdfdc0 | 21 | |
donatien | 0:0ac66acdfdc0 | 22 | #include "rtos.h" |
donatien | 0:0ac66acdfdc0 | 23 | |
donatien | 0:0ac66acdfdc0 | 24 | #include "USBHostTypes.h" |
donatien | 0:0ac66acdfdc0 | 25 | |
donatien | 0:0ac66acdfdc0 | 26 | #define MAX_ENDPOINT 6 |
donatien | 0:0ac66acdfdc0 | 27 | #define MAX_TD (MAX_ENDPOINT*2) |
donatien | 0:0ac66acdfdc0 | 28 | |
donatien | 0:0ac66acdfdc0 | 29 | #define USBHALHOST_SIG_INIT 0x01 |
donatien | 0:0ac66acdfdc0 | 30 | #define USBHALHOST_SIG_IRQ 0x02 |
donatien | 0:0ac66acdfdc0 | 31 | |
donatien | 0:0ac66acdfdc0 | 32 | class USBHALHost { |
donatien | 0:0ac66acdfdc0 | 33 | public: |
donatien | 0:0ac66acdfdc0 | 34 | |
donatien | 0:0ac66acdfdc0 | 35 | /* |
donatien | 0:0ac66acdfdc0 | 36 | * Constructor |
donatien | 0:0ac66acdfdc0 | 37 | * init variables and memory where will be stored HCCA, ED and TD |
donatien | 0:0ac66acdfdc0 | 38 | */ |
donatien | 0:0ac66acdfdc0 | 39 | USBHALHost(); |
donatien | 0:0ac66acdfdc0 | 40 | |
donatien | 0:0ac66acdfdc0 | 41 | /* |
donatien | 0:0ac66acdfdc0 | 42 | * Initialize host controller. Enable USB interrupts. This part is not in the constructor because, |
donatien | 0:0ac66acdfdc0 | 43 | * this function calls a virtual method if a device is already connected |
donatien | 0:0ac66acdfdc0 | 44 | */ |
donatien | 0:0ac66acdfdc0 | 45 | void init(); |
donatien | 0:0ac66acdfdc0 | 46 | |
donatien | 0:0ac66acdfdc0 | 47 | /* |
donatien | 0:0ac66acdfdc0 | 48 | * reset a port of a specific hub |
donatien | 0:0ac66acdfdc0 | 49 | * TODO: support hub |
donatien | 0:0ac66acdfdc0 | 50 | */ |
donatien | 0:0ac66acdfdc0 | 51 | void resetPort(int hub, int port); |
donatien | 0:0ac66acdfdc0 | 52 | |
donatien | 0:0ac66acdfdc0 | 53 | /* |
donatien | 0:0ac66acdfdc0 | 54 | * return the value contained in the control HEAD ED register |
donatien | 0:0ac66acdfdc0 | 55 | * |
donatien | 0:0ac66acdfdc0 | 56 | * @returns address of the control Head ED |
donatien | 0:0ac66acdfdc0 | 57 | */ |
donatien | 0:0ac66acdfdc0 | 58 | uint32_t controlHeadED(); |
donatien | 0:0ac66acdfdc0 | 59 | |
donatien | 0:0ac66acdfdc0 | 60 | /* |
donatien | 0:0ac66acdfdc0 | 61 | * return the value contained in the bulk HEAD ED register |
donatien | 0:0ac66acdfdc0 | 62 | * |
donatien | 0:0ac66acdfdc0 | 63 | * @returns address of the bulk head ED |
donatien | 0:0ac66acdfdc0 | 64 | */ |
donatien | 0:0ac66acdfdc0 | 65 | uint32_t bulkHeadED(); |
donatien | 0:0ac66acdfdc0 | 66 | |
donatien | 0:0ac66acdfdc0 | 67 | /* |
donatien | 0:0ac66acdfdc0 | 68 | * return the value of the head interrupt ED contained in the HCCA |
donatien | 0:0ac66acdfdc0 | 69 | * |
donatien | 0:0ac66acdfdc0 | 70 | * @returns address of the head interrupt ED contained in the HCCA |
donatien | 0:0ac66acdfdc0 | 71 | */ |
donatien | 0:0ac66acdfdc0 | 72 | uint32_t interruptHeadED(); |
donatien | 0:0ac66acdfdc0 | 73 | |
donatien | 0:0ac66acdfdc0 | 74 | |
donatien | 0:0ac66acdfdc0 | 75 | /* |
donatien | 0:0ac66acdfdc0 | 76 | * Update the head ED for control transfers |
donatien | 0:0ac66acdfdc0 | 77 | */ |
donatien | 0:0ac66acdfdc0 | 78 | void updateControlHeadED(uint32_t addr); |
donatien | 0:0ac66acdfdc0 | 79 | |
donatien | 0:0ac66acdfdc0 | 80 | /* |
donatien | 0:0ac66acdfdc0 | 81 | * Update the head ED for bulk transfers |
donatien | 0:0ac66acdfdc0 | 82 | */ |
donatien | 0:0ac66acdfdc0 | 83 | void updateBulkHeadED(uint32_t addr); |
donatien | 0:0ac66acdfdc0 | 84 | |
donatien | 0:0ac66acdfdc0 | 85 | /* |
donatien | 0:0ac66acdfdc0 | 86 | * Update the head ED for interrupt transfers |
donatien | 0:0ac66acdfdc0 | 87 | */ |
donatien | 0:0ac66acdfdc0 | 88 | void updateInterruptHeadED(uint32_t addr); |
donatien | 0:0ac66acdfdc0 | 89 | |
donatien | 0:0ac66acdfdc0 | 90 | /* |
donatien | 0:0ac66acdfdc0 | 91 | * Enable control list ED |
donatien | 0:0ac66acdfdc0 | 92 | */ |
donatien | 0:0ac66acdfdc0 | 93 | void enableControlList(); |
donatien | 0:0ac66acdfdc0 | 94 | |
donatien | 0:0ac66acdfdc0 | 95 | /* |
donatien | 0:0ac66acdfdc0 | 96 | * Enable bulk list ED |
donatien | 0:0ac66acdfdc0 | 97 | */ |
donatien | 0:0ac66acdfdc0 | 98 | void enableBulkList(); |
donatien | 0:0ac66acdfdc0 | 99 | |
donatien | 0:0ac66acdfdc0 | 100 | /* |
donatien | 0:0ac66acdfdc0 | 101 | * Enable Interrupt list ED |
donatien | 0:0ac66acdfdc0 | 102 | */ |
donatien | 0:0ac66acdfdc0 | 103 | void enableInterruptList(); |
donatien | 0:0ac66acdfdc0 | 104 | |
donatien | 0:0ac66acdfdc0 | 105 | /* |
donatien | 0:0ac66acdfdc0 | 106 | * Disable control list ED |
donatien | 0:0ac66acdfdc0 | 107 | */ |
donatien | 0:0ac66acdfdc0 | 108 | bool disableControlList(); |
donatien | 0:0ac66acdfdc0 | 109 | |
donatien | 0:0ac66acdfdc0 | 110 | /* |
donatien | 0:0ac66acdfdc0 | 111 | * Disable bulk list ED |
donatien | 0:0ac66acdfdc0 | 112 | */ |
donatien | 0:0ac66acdfdc0 | 113 | bool disableBulkList(); |
donatien | 0:0ac66acdfdc0 | 114 | |
donatien | 0:0ac66acdfdc0 | 115 | /* |
donatien | 0:0ac66acdfdc0 | 116 | * Disable Interrupt list ED |
donatien | 0:0ac66acdfdc0 | 117 | */ |
donatien | 0:0ac66acdfdc0 | 118 | bool disableInterruptList(); |
donatien | 0:0ac66acdfdc0 | 119 | |
donatien | 0:0ac66acdfdc0 | 120 | //Lock processing |
donatien | 0:0ac66acdfdc0 | 121 | void lock(); |
donatien | 0:0ac66acdfdc0 | 122 | |
donatien | 0:0ac66acdfdc0 | 123 | void unlock(); |
donatien | 0:0ac66acdfdc0 | 124 | |
donatien | 0:0ac66acdfdc0 | 125 | |
donatien | 0:0ac66acdfdc0 | 126 | protected: |
donatien | 0:0ac66acdfdc0 | 127 | /* |
donatien | 0:0ac66acdfdc0 | 128 | * Virtual method called when a device has been connected |
donatien | 0:0ac66acdfdc0 | 129 | * |
donatien | 0:0ac66acdfdc0 | 130 | * @param hub hub number of the device |
donatien | 0:0ac66acdfdc0 | 131 | * @param port port number of the device |
donatien | 0:0ac66acdfdc0 | 132 | * @param lowSpeed 1 if low speed, 0 otherwise |
donatien | 0:0ac66acdfdc0 | 133 | */ |
donatien | 0:0ac66acdfdc0 | 134 | virtual void deviceConnected(int hub, int port, bool lowSpeed) {}; |
donatien | 0:0ac66acdfdc0 | 135 | |
donatien | 0:0ac66acdfdc0 | 136 | /* |
donatien | 0:0ac66acdfdc0 | 137 | * Virtuel method called when a device has been disconnected |
donatien | 0:0ac66acdfdc0 | 138 | * |
donatien | 0:0ac66acdfdc0 | 139 | * @param hub hub number of the device |
donatien | 0:0ac66acdfdc0 | 140 | * @param port port number of the device |
donatien | 0:0ac66acdfdc0 | 141 | * @param addr list of the TDs which have been completed to dequeue freed TDs |
donatien | 0:0ac66acdfdc0 | 142 | */ |
donatien | 0:0ac66acdfdc0 | 143 | virtual void deviceDisconnected(int hub, int port, volatile uint32_t addr) {}; |
donatien | 0:0ac66acdfdc0 | 144 | |
donatien | 0:0ac66acdfdc0 | 145 | /* |
donatien | 0:0ac66acdfdc0 | 146 | * Virtual method called when a transfer has been completed |
donatien | 0:0ac66acdfdc0 | 147 | * |
donatien | 0:0ac66acdfdc0 | 148 | * @param addr list of the TDs which have been completed |
donatien | 0:0ac66acdfdc0 | 149 | */ |
donatien | 0:0ac66acdfdc0 | 150 | virtual void transferCompleted(volatile uint32_t addr){}; |
donatien | 0:0ac66acdfdc0 | 151 | |
donatien | 0:0ac66acdfdc0 | 152 | /* |
donatien | 0:0ac66acdfdc0 | 153 | * Find a memory section for a new ED |
donatien | 0:0ac66acdfdc0 | 154 | * |
donatien | 0:0ac66acdfdc0 | 155 | * @returns the address of this section |
donatien | 0:0ac66acdfdc0 | 156 | */ |
donatien | 0:0ac66acdfdc0 | 157 | volatile uint8_t * getED(); |
donatien | 0:0ac66acdfdc0 | 158 | |
donatien | 0:0ac66acdfdc0 | 159 | /* |
donatien | 0:0ac66acdfdc0 | 160 | * Find a memory section for a new TD |
donatien | 0:0ac66acdfdc0 | 161 | * |
donatien | 0:0ac66acdfdc0 | 162 | * @returns the address of this section |
donatien | 0:0ac66acdfdc0 | 163 | */ |
donatien | 0:0ac66acdfdc0 | 164 | volatile uint8_t * getTD(); |
donatien | 0:0ac66acdfdc0 | 165 | |
donatien | 0:0ac66acdfdc0 | 166 | /* |
donatien | 0:0ac66acdfdc0 | 167 | * Release a previous memory section reserved for an ED |
donatien | 0:0ac66acdfdc0 | 168 | * |
donatien | 0:0ac66acdfdc0 | 169 | * @param ed address of the ED |
donatien | 0:0ac66acdfdc0 | 170 | */ |
donatien | 0:0ac66acdfdc0 | 171 | void freeED(volatile uint8_t * ed); |
donatien | 0:0ac66acdfdc0 | 172 | |
donatien | 0:0ac66acdfdc0 | 173 | /* |
donatien | 0:0ac66acdfdc0 | 174 | * Release a previous memory section reserved for an TD |
donatien | 0:0ac66acdfdc0 | 175 | * |
donatien | 0:0ac66acdfdc0 | 176 | * @param ed address of the TD |
donatien | 0:0ac66acdfdc0 | 177 | */ |
donatien | 0:0ac66acdfdc0 | 178 | void freeTD(volatile uint8_t * td); |
donatien | 0:0ac66acdfdc0 | 179 | |
donatien | 0:0ac66acdfdc0 | 180 | |
donatien | 0:0ac66acdfdc0 | 181 | private: |
donatien | 0:0ac66acdfdc0 | 182 | static void _usbisr(void); |
donatien | 0:0ac66acdfdc0 | 183 | void UsbIrqhandler(); |
donatien | 0:0ac66acdfdc0 | 184 | |
donatien | 0:0ac66acdfdc0 | 185 | void memInit(); |
donatien | 0:0ac66acdfdc0 | 186 | |
donatien | 0:0ac66acdfdc0 | 187 | void process(); |
donatien | 0:0ac66acdfdc0 | 188 | |
donatien | 0:0ac66acdfdc0 | 189 | static void staticCb(void const* p); |
donatien | 0:0ac66acdfdc0 | 190 | |
donatien | 0:0ac66acdfdc0 | 191 | HCCA volatile * usb_hcca; //256 bytes aligned! |
donatien | 0:0ac66acdfdc0 | 192 | uint8_t volatile * usb_edBuf; //4 bytes aligned! |
donatien | 0:0ac66acdfdc0 | 193 | uint8_t volatile * usb_tdBuf; //4 bytes aligned! |
donatien | 0:0ac66acdfdc0 | 194 | |
donatien | 0:0ac66acdfdc0 | 195 | static USBHALHost * instHost; |
donatien | 0:0ac66acdfdc0 | 196 | |
donatien | 0:0ac66acdfdc0 | 197 | bool volatile edBufAlloc[MAX_ENDPOINT]; |
donatien | 0:0ac66acdfdc0 | 198 | bool volatile tdBufAlloc[MAX_TD]; |
donatien | 0:0ac66acdfdc0 | 199 | |
donatien | 0:0ac66acdfdc0 | 200 | //RTOS impl |
donatien | 0:0ac66acdfdc0 | 201 | Thread thread; |
donatien | 0:0ac66acdfdc0 | 202 | Mutex mtx; |
donatien | 0:0ac66acdfdc0 | 203 | |
donatien | 0:0ac66acdfdc0 | 204 | }; |
donatien | 0:0ac66acdfdc0 | 205 | |
donatien | 0:0ac66acdfdc0 | 206 | #endif |