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