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