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