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.
USBHALHost.h
00001 /* Copyright (c) 2010-2011 mbed.org, MIT License 00002 * 00003 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00004 * and associated documentation files (the "Software"), to deal in the Software without 00005 * restriction, including without limitation the rights to use, copy, modify, merge, publish, 00006 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the 00007 * Software is furnished to do so, subject to the following conditions: 00008 * 00009 * The above copyright notice and this permission notice shall be included in all copies or 00010 * substantial portions of the Software. 00011 * 00012 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00013 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00014 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00015 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00016 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00017 */ 00018 00019 #ifndef USBHALHOST_H 00020 #define USBHALHOST_H 00021 00022 #include "rtos.h" 00023 00024 #include "USBHostTypes.h" 00025 00026 #define MAX_ENDPOINT 6 00027 #define MAX_TD (MAX_ENDPOINT*2) 00028 00029 #define USBHALHOST_SIG_INIT 0x01 00030 #define USBHALHOST_SIG_IRQ 0x02 00031 00032 class USBHALHost { 00033 public: 00034 00035 /* 00036 * Constructor 00037 * init variables and memory where will be stored HCCA, ED and TD 00038 */ 00039 USBHALHost(); 00040 00041 /* 00042 * Initialize host controller. Enable USB interrupts. This part is not in the constructor because, 00043 * this function calls a virtual method if a device is already connected 00044 */ 00045 void init(); 00046 00047 /* 00048 * reset a port of a specific hub 00049 * TODO: support hub 00050 */ 00051 void resetPort(int hub, int port); 00052 00053 /* 00054 * return the value contained in the control HEAD ED register 00055 * 00056 * @returns address of the control Head ED 00057 */ 00058 uint32_t controlHeadED(); 00059 00060 /* 00061 * return the value contained in the bulk HEAD ED register 00062 * 00063 * @returns address of the bulk head ED 00064 */ 00065 uint32_t bulkHeadED(); 00066 00067 /* 00068 * return the value of the head interrupt ED contained in the HCCA 00069 * 00070 * @returns address of the head interrupt ED contained in the HCCA 00071 */ 00072 uint32_t interruptHeadED(); 00073 00074 00075 /* 00076 * Update the head ED for control transfers 00077 */ 00078 void updateControlHeadED(uint32_t addr); 00079 00080 /* 00081 * Update the head ED for bulk transfers 00082 */ 00083 void updateBulkHeadED(uint32_t addr); 00084 00085 /* 00086 * Update the head ED for interrupt transfers 00087 */ 00088 void updateInterruptHeadED(uint32_t addr); 00089 00090 /* 00091 * Enable control list ED 00092 */ 00093 void enableControlList(); 00094 00095 /* 00096 * Enable bulk list ED 00097 */ 00098 void enableBulkList(); 00099 00100 /* 00101 * Enable Interrupt list ED 00102 */ 00103 void enableInterruptList(); 00104 00105 /* 00106 * Disable control list ED 00107 */ 00108 bool disableControlList(); 00109 00110 /* 00111 * Disable bulk list ED 00112 */ 00113 bool disableBulkList(); 00114 00115 /* 00116 * Disable Interrupt list ED 00117 */ 00118 bool disableInterruptList(); 00119 00120 //Lock processing 00121 void lock(); 00122 00123 void unlock(); 00124 00125 00126 protected: 00127 /* 00128 * Virtual method called when a device has been connected 00129 * 00130 * @param hub hub number of the device 00131 * @param port port number of the device 00132 * @param lowSpeed 1 if low speed, 0 otherwise 00133 */ 00134 virtual void deviceConnected(int hub, int port, bool lowSpeed) {}; 00135 00136 /* 00137 * Virtuel method called when a device has been disconnected 00138 * 00139 * @param hub hub number of the device 00140 * @param port port number of the device 00141 * @param addr list of the TDs which have been completed to dequeue freed TDs 00142 */ 00143 virtual void deviceDisconnected(int hub, int port, volatile uint32_t addr) {}; 00144 00145 /* 00146 * Virtual method called when a transfer has been completed 00147 * 00148 * @param addr list of the TDs which have been completed 00149 */ 00150 virtual void transferCompleted(volatile uint32_t addr){}; 00151 00152 /* 00153 * Find a memory section for a new ED 00154 * 00155 * @returns the address of this section 00156 */ 00157 volatile uint8_t * getED(); 00158 00159 /* 00160 * Find a memory section for a new TD 00161 * 00162 * @returns the address of this section 00163 */ 00164 volatile uint8_t * getTD(); 00165 00166 /* 00167 * Release a previous memory section reserved for an ED 00168 * 00169 * @param ed address of the ED 00170 */ 00171 void freeED(volatile uint8_t * ed); 00172 00173 /* 00174 * Release a previous memory section reserved for an TD 00175 * 00176 * @param ed address of the TD 00177 */ 00178 void freeTD(volatile uint8_t * td); 00179 00180 00181 private: 00182 static void _usbisr(void); 00183 void UsbIrqhandler(); 00184 00185 void memInit(); 00186 00187 void process(); 00188 00189 static void staticCb(void const* p); 00190 00191 HCCA volatile * usb_hcca; //256 bytes aligned! 00192 uint8_t volatile * usb_edBuf; //4 bytes aligned! 00193 uint8_t volatile * usb_tdBuf; //4 bytes aligned! 00194 00195 static USBHALHost * instHost; 00196 00197 bool volatile edBufAlloc[MAX_ENDPOINT]; 00198 bool volatile tdBufAlloc[MAX_TD]; 00199 00200 //RTOS impl 00201 Thread thread; 00202 Mutex mtx; 00203 00204 }; 00205 00206 #endif
Generated on Tue Jul 12 2022 17:50:56 by
1.7.2