2018.07.26

Dependencies:   FATFileSystem2 mbed-rtos

Fork of USBHost by mbed official

Committer:
sayzyas
Date:
Thu Jul 26 00:29:30 2018 +0000
Revision:
44:e437b1c7c61e
Parent:
43:78f328f311dc
2018.07.26

Who changed what in which revision?

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