only for STM32F769NI-DISCOVERY, porting from mbed OS5 unsupport functions
USBHost/USBHALHost.h@0:dae1ac0c0a7b, 2019-08-07 (annotated)
- Committer:
- kenjiArai
- Date:
- Wed Aug 07 05:33:53 2019 +0000
- Revision:
- 0:dae1ac0c0a7b
only for STM32F769NI-DISCOVERY, porting from mbed OS5 unsupport functions
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kenjiArai | 0:dae1ac0c0a7b | 1 | /* mbed USBHost Library |
kenjiArai | 0:dae1ac0c0a7b | 2 | * Copyright (c) 2006-2013 ARM Limited |
kenjiArai | 0:dae1ac0c0a7b | 3 | * |
kenjiArai | 0:dae1ac0c0a7b | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
kenjiArai | 0:dae1ac0c0a7b | 5 | * you may not use this file except in compliance with the License. |
kenjiArai | 0:dae1ac0c0a7b | 6 | * You may obtain a copy of the License at |
kenjiArai | 0:dae1ac0c0a7b | 7 | * |
kenjiArai | 0:dae1ac0c0a7b | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
kenjiArai | 0:dae1ac0c0a7b | 9 | * |
kenjiArai | 0:dae1ac0c0a7b | 10 | * Unless required by applicable law or agreed to in writing, software |
kenjiArai | 0:dae1ac0c0a7b | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
kenjiArai | 0:dae1ac0c0a7b | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kenjiArai | 0:dae1ac0c0a7b | 13 | * See the License for the specific language governing permissions and |
kenjiArai | 0:dae1ac0c0a7b | 14 | * limitations under the License. |
kenjiArai | 0:dae1ac0c0a7b | 15 | */ |
kenjiArai | 0:dae1ac0c0a7b | 16 | |
kenjiArai | 0:dae1ac0c0a7b | 17 | #ifndef USBHALHOST_H |
kenjiArai | 0:dae1ac0c0a7b | 18 | #define USBHALHOST_H |
kenjiArai | 0:dae1ac0c0a7b | 19 | |
kenjiArai | 0:dae1ac0c0a7b | 20 | #include "USBHostTypes.h" |
kenjiArai | 0:dae1ac0c0a7b | 21 | #include "USBHostConf.h" |
kenjiArai | 0:dae1ac0c0a7b | 22 | |
kenjiArai | 0:dae1ac0c0a7b | 23 | class USBHostHub; |
kenjiArai | 0:dae1ac0c0a7b | 24 | |
kenjiArai | 0:dae1ac0c0a7b | 25 | /** |
kenjiArai | 0:dae1ac0c0a7b | 26 | * USBHALHost class |
kenjiArai | 0:dae1ac0c0a7b | 27 | */ |
kenjiArai | 0:dae1ac0c0a7b | 28 | class USBHALHost { |
kenjiArai | 0:dae1ac0c0a7b | 29 | protected: |
kenjiArai | 0:dae1ac0c0a7b | 30 | |
kenjiArai | 0:dae1ac0c0a7b | 31 | /** |
kenjiArai | 0:dae1ac0c0a7b | 32 | * Constructor |
kenjiArai | 0:dae1ac0c0a7b | 33 | * init variables and memory where will be stored HCCA, ED and TD |
kenjiArai | 0:dae1ac0c0a7b | 34 | */ |
kenjiArai | 0:dae1ac0c0a7b | 35 | USBHALHost(); |
kenjiArai | 0:dae1ac0c0a7b | 36 | |
kenjiArai | 0:dae1ac0c0a7b | 37 | /** |
kenjiArai | 0:dae1ac0c0a7b | 38 | * Initialize host controller. Enable USB interrupts. This part is not in the constructor because, |
kenjiArai | 0:dae1ac0c0a7b | 39 | * this function calls a virtual method if a device is already connected |
kenjiArai | 0:dae1ac0c0a7b | 40 | */ |
kenjiArai | 0:dae1ac0c0a7b | 41 | void init(); |
kenjiArai | 0:dae1ac0c0a7b | 42 | |
kenjiArai | 0:dae1ac0c0a7b | 43 | /** |
kenjiArai | 0:dae1ac0c0a7b | 44 | * reset the root hub |
kenjiArai | 0:dae1ac0c0a7b | 45 | */ |
kenjiArai | 0:dae1ac0c0a7b | 46 | void resetRootHub(); |
kenjiArai | 0:dae1ac0c0a7b | 47 | |
kenjiArai | 0:dae1ac0c0a7b | 48 | /** |
kenjiArai | 0:dae1ac0c0a7b | 49 | * return the value contained in the control HEAD ED register |
kenjiArai | 0:dae1ac0c0a7b | 50 | * |
kenjiArai | 0:dae1ac0c0a7b | 51 | * @returns address of the control Head ED |
kenjiArai | 0:dae1ac0c0a7b | 52 | */ |
kenjiArai | 0:dae1ac0c0a7b | 53 | uint32_t controlHeadED(); |
kenjiArai | 0:dae1ac0c0a7b | 54 | |
kenjiArai | 0:dae1ac0c0a7b | 55 | /** |
kenjiArai | 0:dae1ac0c0a7b | 56 | * return the value contained in the bulk HEAD ED register |
kenjiArai | 0:dae1ac0c0a7b | 57 | * |
kenjiArai | 0:dae1ac0c0a7b | 58 | * @returns address of the bulk head ED |
kenjiArai | 0:dae1ac0c0a7b | 59 | */ |
kenjiArai | 0:dae1ac0c0a7b | 60 | uint32_t bulkHeadED(); |
kenjiArai | 0:dae1ac0c0a7b | 61 | |
kenjiArai | 0:dae1ac0c0a7b | 62 | /** |
kenjiArai | 0:dae1ac0c0a7b | 63 | * return the value of the head interrupt ED contained in the HCCA |
kenjiArai | 0:dae1ac0c0a7b | 64 | * |
kenjiArai | 0:dae1ac0c0a7b | 65 | * @returns address of the head interrupt ED contained in the HCCA |
kenjiArai | 0:dae1ac0c0a7b | 66 | */ |
kenjiArai | 0:dae1ac0c0a7b | 67 | uint32_t interruptHeadED(); |
kenjiArai | 0:dae1ac0c0a7b | 68 | |
kenjiArai | 0:dae1ac0c0a7b | 69 | /** |
kenjiArai | 0:dae1ac0c0a7b | 70 | * Update the head ED for control transfers |
kenjiArai | 0:dae1ac0c0a7b | 71 | */ |
kenjiArai | 0:dae1ac0c0a7b | 72 | void updateControlHeadED(uint32_t addr); |
kenjiArai | 0:dae1ac0c0a7b | 73 | |
kenjiArai | 0:dae1ac0c0a7b | 74 | /** |
kenjiArai | 0:dae1ac0c0a7b | 75 | * Update the head ED for bulk transfers |
kenjiArai | 0:dae1ac0c0a7b | 76 | */ |
kenjiArai | 0:dae1ac0c0a7b | 77 | void updateBulkHeadED(uint32_t addr); |
kenjiArai | 0:dae1ac0c0a7b | 78 | |
kenjiArai | 0:dae1ac0c0a7b | 79 | /** |
kenjiArai | 0:dae1ac0c0a7b | 80 | * Update the head ED for interrupt transfers |
kenjiArai | 0:dae1ac0c0a7b | 81 | */ |
kenjiArai | 0:dae1ac0c0a7b | 82 | void updateInterruptHeadED(uint32_t addr); |
kenjiArai | 0:dae1ac0c0a7b | 83 | |
kenjiArai | 0:dae1ac0c0a7b | 84 | /** |
kenjiArai | 0:dae1ac0c0a7b | 85 | * Enable List for the specified endpoint type |
kenjiArai | 0:dae1ac0c0a7b | 86 | * |
kenjiArai | 0:dae1ac0c0a7b | 87 | * @param type enable the list of ENDPOINT_TYPE type |
kenjiArai | 0:dae1ac0c0a7b | 88 | */ |
kenjiArai | 0:dae1ac0c0a7b | 89 | void enableList(ENDPOINT_TYPE type); |
kenjiArai | 0:dae1ac0c0a7b | 90 | |
kenjiArai | 0:dae1ac0c0a7b | 91 | /** |
kenjiArai | 0:dae1ac0c0a7b | 92 | * Disable List for the specified endpoint type |
kenjiArai | 0:dae1ac0c0a7b | 93 | * |
kenjiArai | 0:dae1ac0c0a7b | 94 | * @param type disable the list of ENDPOINT_TYPE type |
kenjiArai | 0:dae1ac0c0a7b | 95 | */ |
kenjiArai | 0:dae1ac0c0a7b | 96 | bool disableList(ENDPOINT_TYPE type); |
kenjiArai | 0:dae1ac0c0a7b | 97 | |
kenjiArai | 0:dae1ac0c0a7b | 98 | /** |
kenjiArai | 0:dae1ac0c0a7b | 99 | * Virtual method called when a device has been connected |
kenjiArai | 0:dae1ac0c0a7b | 100 | * |
kenjiArai | 0:dae1ac0c0a7b | 101 | * @param hub hub number of the device |
kenjiArai | 0:dae1ac0c0a7b | 102 | * @param port port number of the device |
kenjiArai | 0:dae1ac0c0a7b | 103 | * @param lowSpeed 1 if low speed, 0 otherwise |
kenjiArai | 0:dae1ac0c0a7b | 104 | * @param hub_parent reference to the hub where the device is connected (NULL if the hub parent is the root hub) |
kenjiArai | 0:dae1ac0c0a7b | 105 | */ |
kenjiArai | 0:dae1ac0c0a7b | 106 | virtual void deviceConnected(int hub, int port, bool lowSpeed, USBHostHub * hub_parent = NULL) = 0; |
kenjiArai | 0:dae1ac0c0a7b | 107 | |
kenjiArai | 0:dae1ac0c0a7b | 108 | /** |
kenjiArai | 0:dae1ac0c0a7b | 109 | * Virtual method called when a device has been disconnected |
kenjiArai | 0:dae1ac0c0a7b | 110 | * |
kenjiArai | 0:dae1ac0c0a7b | 111 | * @param hub hub number of the device |
kenjiArai | 0:dae1ac0c0a7b | 112 | * @param port port number of the device |
kenjiArai | 0:dae1ac0c0a7b | 113 | * @param hub_parent reference to the hub where the device is connected (NULL if the hub parent is the root hub) |
kenjiArai | 0:dae1ac0c0a7b | 114 | * @param addr list of the TDs which have been completed to dequeue freed TDs |
kenjiArai | 0:dae1ac0c0a7b | 115 | */ |
kenjiArai | 0:dae1ac0c0a7b | 116 | virtual void deviceDisconnected(int hub, int port, USBHostHub * hub_parent, volatile uint32_t addr) = 0; |
kenjiArai | 0:dae1ac0c0a7b | 117 | |
kenjiArai | 0:dae1ac0c0a7b | 118 | /** |
kenjiArai | 0:dae1ac0c0a7b | 119 | * Virtual method called when a transfer has been completed |
kenjiArai | 0:dae1ac0c0a7b | 120 | * |
kenjiArai | 0:dae1ac0c0a7b | 121 | * @param addr list of the TDs which have been completed |
kenjiArai | 0:dae1ac0c0a7b | 122 | */ |
kenjiArai | 0:dae1ac0c0a7b | 123 | virtual void transferCompleted(volatile uint32_t addr) = 0; |
kenjiArai | 0:dae1ac0c0a7b | 124 | |
kenjiArai | 0:dae1ac0c0a7b | 125 | /** |
kenjiArai | 0:dae1ac0c0a7b | 126 | * Find a memory section for a new ED |
kenjiArai | 0:dae1ac0c0a7b | 127 | * |
kenjiArai | 0:dae1ac0c0a7b | 128 | * @returns the address of the new ED |
kenjiArai | 0:dae1ac0c0a7b | 129 | */ |
kenjiArai | 0:dae1ac0c0a7b | 130 | volatile uint8_t * getED(); |
kenjiArai | 0:dae1ac0c0a7b | 131 | |
kenjiArai | 0:dae1ac0c0a7b | 132 | /** |
kenjiArai | 0:dae1ac0c0a7b | 133 | * Find a memory section for a new TD |
kenjiArai | 0:dae1ac0c0a7b | 134 | * |
kenjiArai | 0:dae1ac0c0a7b | 135 | * @returns the address of the new TD |
kenjiArai | 0:dae1ac0c0a7b | 136 | */ |
kenjiArai | 0:dae1ac0c0a7b | 137 | volatile uint8_t * getTD(); |
kenjiArai | 0:dae1ac0c0a7b | 138 | |
kenjiArai | 0:dae1ac0c0a7b | 139 | /** |
kenjiArai | 0:dae1ac0c0a7b | 140 | * Release a previous memory section reserved for an ED |
kenjiArai | 0:dae1ac0c0a7b | 141 | * |
kenjiArai | 0:dae1ac0c0a7b | 142 | * @param ed address of the ED |
kenjiArai | 0:dae1ac0c0a7b | 143 | */ |
kenjiArai | 0:dae1ac0c0a7b | 144 | void freeED(volatile uint8_t * ed); |
kenjiArai | 0:dae1ac0c0a7b | 145 | |
kenjiArai | 0:dae1ac0c0a7b | 146 | /** |
kenjiArai | 0:dae1ac0c0a7b | 147 | * Release a previous memory section reserved for an TD |
kenjiArai | 0:dae1ac0c0a7b | 148 | * |
kenjiArai | 0:dae1ac0c0a7b | 149 | * @param td address of the TD |
kenjiArai | 0:dae1ac0c0a7b | 150 | */ |
kenjiArai | 0:dae1ac0c0a7b | 151 | void freeTD(volatile uint8_t * td); |
kenjiArai | 0:dae1ac0c0a7b | 152 | |
kenjiArai | 0:dae1ac0c0a7b | 153 | private: |
kenjiArai | 0:dae1ac0c0a7b | 154 | static void _usbisr(void); |
kenjiArai | 0:dae1ac0c0a7b | 155 | void UsbIrqhandler(); |
kenjiArai | 0:dae1ac0c0a7b | 156 | |
kenjiArai | 0:dae1ac0c0a7b | 157 | void memInit(); |
kenjiArai | 0:dae1ac0c0a7b | 158 | |
kenjiArai | 0:dae1ac0c0a7b | 159 | HCCA volatile * usb_hcca; //256 bytes aligned |
kenjiArai | 0:dae1ac0c0a7b | 160 | uint8_t volatile * usb_edBuf; //4 bytes aligned |
kenjiArai | 0:dae1ac0c0a7b | 161 | uint8_t volatile * usb_tdBuf; //4 bytes aligned |
kenjiArai | 0:dae1ac0c0a7b | 162 | |
kenjiArai | 0:dae1ac0c0a7b | 163 | static USBHALHost * instHost; |
kenjiArai | 0:dae1ac0c0a7b | 164 | |
kenjiArai | 0:dae1ac0c0a7b | 165 | bool volatile edBufAlloc[MAX_ENDPOINT]; |
kenjiArai | 0:dae1ac0c0a7b | 166 | bool volatile tdBufAlloc[MAX_TD]; |
kenjiArai | 0:dae1ac0c0a7b | 167 | #ifdef USBHOST_OTHER |
kenjiArai | 0:dae1ac0c0a7b | 168 | int control_disable; |
kenjiArai | 0:dae1ac0c0a7b | 169 | #endif |
kenjiArai | 0:dae1ac0c0a7b | 170 | |
kenjiArai | 0:dae1ac0c0a7b | 171 | }; |
kenjiArai | 0:dae1ac0c0a7b | 172 | |
kenjiArai | 0:dae1ac0c0a7b | 173 | #endif |