Adaptation of the official mbed USBHost repository to work with the LPC4088 Display Module
Dependents: DMSupport DMSupport DMSupport DMSupport
Fork of DM_USBHost by
USBHost/USBHALHost.h@27:aa2fd412f1d3, 2014-12-02 (annotated)
- Committer:
- embeddedartists
- Date:
- Tue Dec 02 15:16:39 2014 +0000
- Revision:
- 27:aa2fd412f1d3
- Parent:
- 24:868cbfe611a7
- Child:
- 31:9a462d032742
Adaptation of the official mbed USBHost repository to work with the LPC4088 Display Module. The changes include: basic setup, move of all memory to the AHBSRAM0, switch to USB port 2, adding a memory allocator for users.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
samux | 8:93da8ea2708b | 1 | /* mbed USBHost Library |
samux | 8:93da8ea2708b | 2 | * Copyright (c) 2006-2013 ARM Limited |
samux | 8:93da8ea2708b | 3 | * |
samux | 8:93da8ea2708b | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
samux | 8:93da8ea2708b | 5 | * you may not use this file except in compliance with the License. |
samux | 8:93da8ea2708b | 6 | * You may obtain a copy of the License at |
samux | 8:93da8ea2708b | 7 | * |
samux | 8:93da8ea2708b | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
samux | 8:93da8ea2708b | 9 | * |
samux | 8:93da8ea2708b | 10 | * Unless required by applicable law or agreed to in writing, software |
samux | 8:93da8ea2708b | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
samux | 8:93da8ea2708b | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
samux | 8:93da8ea2708b | 13 | * See the License for the specific language governing permissions and |
samux | 8:93da8ea2708b | 14 | * limitations under the License. |
samux | 8:93da8ea2708b | 15 | */ |
mbed_official | 0:a554658735bf | 16 | |
mbed_official | 0:a554658735bf | 17 | #ifndef USBHALHOST_H |
mbed_official | 0:a554658735bf | 18 | #define USBHALHOST_H |
mbed_official | 0:a554658735bf | 19 | |
mbed_official | 0:a554658735bf | 20 | #include "USBHostTypes.h" |
mbed_official | 0:a554658735bf | 21 | #include "USBHostConf.h" |
embeddedartists | 27:aa2fd412f1d3 | 22 | #include "rtos.h" |
mbed_official | 0:a554658735bf | 23 | |
mbed_official | 0:a554658735bf | 24 | class USBHostHub; |
mbed_official | 0:a554658735bf | 25 | |
embeddedartists | 27:aa2fd412f1d3 | 26 | #if defined(TARGET_LPC4088) |
embeddedartists | 27:aa2fd412f1d3 | 27 | #define HcRevision Revision |
embeddedartists | 27:aa2fd412f1d3 | 28 | #define HcControl Control |
embeddedartists | 27:aa2fd412f1d3 | 29 | #define HcCommandStatus CommandStatus |
embeddedartists | 27:aa2fd412f1d3 | 30 | #define HcInterruptStatus InterruptStatus |
embeddedartists | 27:aa2fd412f1d3 | 31 | #define HcInterruptEnable InterruptEnable |
embeddedartists | 27:aa2fd412f1d3 | 32 | #define HcHCCA HCCA |
embeddedartists | 27:aa2fd412f1d3 | 33 | #define HcControlHeadED ControlHeadED |
embeddedartists | 27:aa2fd412f1d3 | 34 | #define HcBulkHeadED BulkHeadED |
embeddedartists | 27:aa2fd412f1d3 | 35 | #define HcFmInterval FmInterval |
embeddedartists | 27:aa2fd412f1d3 | 36 | #define HcFmNumber FmNumber |
embeddedartists | 27:aa2fd412f1d3 | 37 | #define HcPeriodicStart PeriodicStart |
embeddedartists | 27:aa2fd412f1d3 | 38 | #define HcRhStatus RhStatus |
embeddedartists | 27:aa2fd412f1d3 | 39 | #define HcRhPortStatus1 RhPortStatus1 |
embeddedartists | 27:aa2fd412f1d3 | 40 | #define HcRhPortStatus2 RhPortStatus2 |
embeddedartists | 27:aa2fd412f1d3 | 41 | #define OTGStCtrl StCtrl |
embeddedartists | 27:aa2fd412f1d3 | 42 | #endif |
embeddedartists | 27:aa2fd412f1d3 | 43 | |
samux | 8:93da8ea2708b | 44 | /** |
samux | 8:93da8ea2708b | 45 | * USBHALHost class |
samux | 8:93da8ea2708b | 46 | */ |
mbed_official | 0:a554658735bf | 47 | class USBHALHost { |
embeddedartists | 27:aa2fd412f1d3 | 48 | public: |
embeddedartists | 27:aa2fd412f1d3 | 49 | uint8_t* getSafeMem(uint32_t size); |
embeddedartists | 27:aa2fd412f1d3 | 50 | void returnSafeMem(uint8_t* mem); |
embeddedartists | 27:aa2fd412f1d3 | 51 | |
samux | 8:93da8ea2708b | 52 | protected: |
mbed_official | 0:a554658735bf | 53 | |
mbed_official | 0:a554658735bf | 54 | /** |
mbed_official | 0:a554658735bf | 55 | * Constructor |
mbed_official | 0:a554658735bf | 56 | * init variables and memory where will be stored HCCA, ED and TD |
mbed_official | 0:a554658735bf | 57 | */ |
mbed_official | 0:a554658735bf | 58 | USBHALHost(); |
mbed_official | 24:868cbfe611a7 | 59 | |
mbed_official | 0:a554658735bf | 60 | /** |
mbed_official | 24:868cbfe611a7 | 61 | * Initialize host controller. Enable USB interrupts. This part is not in the constructor because, |
mbed_official | 0:a554658735bf | 62 | * this function calls a virtual method if a device is already connected |
mbed_official | 0:a554658735bf | 63 | */ |
mbed_official | 0:a554658735bf | 64 | void init(); |
mbed_official | 24:868cbfe611a7 | 65 | |
mbed_official | 0:a554658735bf | 66 | /** |
mbed_official | 0:a554658735bf | 67 | * reset the root hub |
mbed_official | 0:a554658735bf | 68 | */ |
mbed_official | 0:a554658735bf | 69 | void resetRootHub(); |
mbed_official | 24:868cbfe611a7 | 70 | |
mbed_official | 0:a554658735bf | 71 | /** |
mbed_official | 0:a554658735bf | 72 | * return the value contained in the control HEAD ED register |
mbed_official | 0:a554658735bf | 73 | * |
mbed_official | 0:a554658735bf | 74 | * @returns address of the control Head ED |
mbed_official | 0:a554658735bf | 75 | */ |
mbed_official | 0:a554658735bf | 76 | uint32_t controlHeadED(); |
mbed_official | 24:868cbfe611a7 | 77 | |
mbed_official | 0:a554658735bf | 78 | /** |
mbed_official | 0:a554658735bf | 79 | * return the value contained in the bulk HEAD ED register |
mbed_official | 0:a554658735bf | 80 | * |
mbed_official | 0:a554658735bf | 81 | * @returns address of the bulk head ED |
mbed_official | 0:a554658735bf | 82 | */ |
mbed_official | 0:a554658735bf | 83 | uint32_t bulkHeadED(); |
mbed_official | 24:868cbfe611a7 | 84 | |
mbed_official | 0:a554658735bf | 85 | /** |
mbed_official | 0:a554658735bf | 86 | * return the value of the head interrupt ED contained in the HCCA |
mbed_official | 0:a554658735bf | 87 | * |
mbed_official | 0:a554658735bf | 88 | * @returns address of the head interrupt ED contained in the HCCA |
mbed_official | 0:a554658735bf | 89 | */ |
mbed_official | 0:a554658735bf | 90 | uint32_t interruptHeadED(); |
mbed_official | 24:868cbfe611a7 | 91 | |
mbed_official | 0:a554658735bf | 92 | /** |
mbed_official | 0:a554658735bf | 93 | * Update the head ED for control transfers |
mbed_official | 0:a554658735bf | 94 | */ |
mbed_official | 0:a554658735bf | 95 | void updateControlHeadED(uint32_t addr); |
mbed_official | 24:868cbfe611a7 | 96 | |
mbed_official | 0:a554658735bf | 97 | /** |
mbed_official | 0:a554658735bf | 98 | * Update the head ED for bulk transfers |
mbed_official | 0:a554658735bf | 99 | */ |
mbed_official | 0:a554658735bf | 100 | void updateBulkHeadED(uint32_t addr); |
mbed_official | 24:868cbfe611a7 | 101 | |
mbed_official | 0:a554658735bf | 102 | /** |
mbed_official | 0:a554658735bf | 103 | * Update the head ED for interrupt transfers |
mbed_official | 0:a554658735bf | 104 | */ |
mbed_official | 0:a554658735bf | 105 | void updateInterruptHeadED(uint32_t addr); |
mbed_official | 24:868cbfe611a7 | 106 | |
samux | 8:93da8ea2708b | 107 | /** |
mbed_official | 0:a554658735bf | 108 | * Enable List for the specified endpoint type |
samux | 8:93da8ea2708b | 109 | * |
samux | 8:93da8ea2708b | 110 | * @param type enable the list of ENDPOINT_TYPE type |
mbed_official | 0:a554658735bf | 111 | */ |
mbed_official | 0:a554658735bf | 112 | void enableList(ENDPOINT_TYPE type); |
mbed_official | 24:868cbfe611a7 | 113 | |
mbed_official | 0:a554658735bf | 114 | /** |
mbed_official | 0:a554658735bf | 115 | * Disable List for the specified endpoint type |
samux | 8:93da8ea2708b | 116 | * |
samux | 8:93da8ea2708b | 117 | * @param type disable the list of ENDPOINT_TYPE type |
mbed_official | 0:a554658735bf | 118 | */ |
mbed_official | 0:a554658735bf | 119 | bool disableList(ENDPOINT_TYPE type); |
mbed_official | 0:a554658735bf | 120 | |
mbed_official | 0:a554658735bf | 121 | /** |
mbed_official | 0:a554658735bf | 122 | * Virtual method called when a device has been connected |
mbed_official | 0:a554658735bf | 123 | * |
mbed_official | 0:a554658735bf | 124 | * @param hub hub number of the device |
mbed_official | 0:a554658735bf | 125 | * @param port port number of the device |
mbed_official | 0:a554658735bf | 126 | * @param lowSpeed 1 if low speed, 0 otherwise |
mbed_official | 0:a554658735bf | 127 | * @param hub_parent reference to the hub where the device is connected (NULL if the hub parent is the root hub) |
mbed_official | 0:a554658735bf | 128 | */ |
samux | 8:93da8ea2708b | 129 | virtual void deviceConnected(int hub, int port, bool lowSpeed, USBHostHub * hub_parent = NULL) = 0; |
mbed_official | 24:868cbfe611a7 | 130 | |
mbed_official | 0:a554658735bf | 131 | /** |
mbed_official | 0:a554658735bf | 132 | * Virtual method called when a device has been disconnected |
mbed_official | 0:a554658735bf | 133 | * |
mbed_official | 0:a554658735bf | 134 | * @param hub hub number of the device |
mbed_official | 0:a554658735bf | 135 | * @param port port number of the device |
mbed_official | 0:a554658735bf | 136 | * @param hub_parent reference to the hub where the device is connected (NULL if the hub parent is the root hub) |
mbed_official | 0:a554658735bf | 137 | * @param addr list of the TDs which have been completed to dequeue freed TDs |
mbed_official | 0:a554658735bf | 138 | */ |
samux | 8:93da8ea2708b | 139 | virtual void deviceDisconnected(int hub, int port, USBHostHub * hub_parent, volatile uint32_t addr) = 0; |
mbed_official | 24:868cbfe611a7 | 140 | |
mbed_official | 0:a554658735bf | 141 | /** |
mbed_official | 0:a554658735bf | 142 | * Virtual method called when a transfer has been completed |
mbed_official | 0:a554658735bf | 143 | * |
mbed_official | 0:a554658735bf | 144 | * @param addr list of the TDs which have been completed |
mbed_official | 0:a554658735bf | 145 | */ |
samux | 8:93da8ea2708b | 146 | virtual void transferCompleted(volatile uint32_t addr) = 0; |
mbed_official | 24:868cbfe611a7 | 147 | |
mbed_official | 0:a554658735bf | 148 | /** |
mbed_official | 0:a554658735bf | 149 | * Find a memory section for a new ED |
mbed_official | 0:a554658735bf | 150 | * |
samux | 8:93da8ea2708b | 151 | * @returns the address of the new ED |
mbed_official | 0:a554658735bf | 152 | */ |
mbed_official | 0:a554658735bf | 153 | volatile uint8_t * getED(); |
mbed_official | 24:868cbfe611a7 | 154 | |
mbed_official | 0:a554658735bf | 155 | /** |
mbed_official | 0:a554658735bf | 156 | * Find a memory section for a new TD |
mbed_official | 0:a554658735bf | 157 | * |
samux | 8:93da8ea2708b | 158 | * @returns the address of the new TD |
mbed_official | 0:a554658735bf | 159 | */ |
mbed_official | 0:a554658735bf | 160 | volatile uint8_t * getTD(); |
mbed_official | 24:868cbfe611a7 | 161 | |
mbed_official | 0:a554658735bf | 162 | /** |
mbed_official | 0:a554658735bf | 163 | * Release a previous memory section reserved for an ED |
mbed_official | 0:a554658735bf | 164 | * |
mbed_official | 0:a554658735bf | 165 | * @param ed address of the ED |
mbed_official | 0:a554658735bf | 166 | */ |
mbed_official | 0:a554658735bf | 167 | void freeED(volatile uint8_t * ed); |
mbed_official | 24:868cbfe611a7 | 168 | |
mbed_official | 0:a554658735bf | 169 | /** |
mbed_official | 0:a554658735bf | 170 | * Release a previous memory section reserved for an TD |
mbed_official | 0:a554658735bf | 171 | * |
samux | 2:5e8fdc541b98 | 172 | * @param td address of the TD |
mbed_official | 0:a554658735bf | 173 | */ |
mbed_official | 0:a554658735bf | 174 | void freeTD(volatile uint8_t * td); |
mbed_official | 0:a554658735bf | 175 | |
mbed_official | 0:a554658735bf | 176 | private: |
mbed_official | 0:a554658735bf | 177 | static void _usbisr(void); |
mbed_official | 0:a554658735bf | 178 | void UsbIrqhandler(); |
mbed_official | 0:a554658735bf | 179 | |
mbed_official | 0:a554658735bf | 180 | void memInit(); |
mbed_official | 0:a554658735bf | 181 | |
mbed_official | 0:a554658735bf | 182 | HCCA volatile * usb_hcca; //256 bytes aligned |
mbed_official | 0:a554658735bf | 183 | uint8_t volatile * usb_edBuf; //4 bytes aligned |
mbed_official | 0:a554658735bf | 184 | uint8_t volatile * usb_tdBuf; //4 bytes aligned |
mbed_official | 0:a554658735bf | 185 | |
mbed_official | 0:a554658735bf | 186 | static USBHALHost * instHost; |
mbed_official | 24:868cbfe611a7 | 187 | |
mbed_official | 0:a554658735bf | 188 | bool volatile edBufAlloc[MAX_ENDPOINT]; |
mbed_official | 0:a554658735bf | 189 | bool volatile tdBufAlloc[MAX_TD]; |
embeddedartists | 27:aa2fd412f1d3 | 190 | |
embeddedartists | 27:aa2fd412f1d3 | 191 | Mutex safemem_mutex; |
mbed_official | 0:a554658735bf | 192 | }; |
mbed_official | 0:a554658735bf | 193 | |
mbed_official | 0:a554658735bf | 194 | #endif |