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