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