public Test library for usbhostmsd looking at ridiculous resource usage

Dependencies:   FATFileSystem mbed-rtos

Fork of USBHost by mbed official

Committer:
samux
Date:
Tue Mar 12 17:23:37 2013 +0000
Revision:
4:b320d68e98e7
Parent:
2:5e8fdc541b98
Child:
8:93da8ea2708b
bug fixes - support composite device

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:a554658735bf 1 /* Copyright (c) 2010-2012 mbed.org, MIT License
mbed_official 0:a554658735bf 2 *
mbed_official 0:a554658735bf 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
mbed_official 0:a554658735bf 4 * and associated documentation files (the "Software"), to deal in the Software without
mbed_official 0:a554658735bf 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
mbed_official 0:a554658735bf 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
mbed_official 0:a554658735bf 7 * Software is furnished to do so, subject to the following conditions:
mbed_official 0:a554658735bf 8 *
mbed_official 0:a554658735bf 9 * The above copyright notice and this permission notice shall be included in all copies or
mbed_official 0:a554658735bf 10 * substantial portions of the Software.
mbed_official 0:a554658735bf 11 *
mbed_official 0:a554658735bf 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
mbed_official 0:a554658735bf 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
mbed_official 0:a554658735bf 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
mbed_official 0:a554658735bf 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
mbed_official 0:a554658735bf 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
mbed_official 0:a554658735bf 17 */
mbed_official 0:a554658735bf 18
mbed_official 0:a554658735bf 19 #ifndef USBHALHOST_H
mbed_official 0:a554658735bf 20 #define USBHALHOST_H
mbed_official 0:a554658735bf 21
mbed_official 0:a554658735bf 22 #include "USBHostTypes.h"
mbed_official 0:a554658735bf 23 #include "USBHostConf.h"
mbed_official 0:a554658735bf 24
mbed_official 0:a554658735bf 25 class USBHostHub;
mbed_official 0:a554658735bf 26
mbed_official 0:a554658735bf 27 class USBHALHost {
mbed_official 0:a554658735bf 28 public:
mbed_official 0:a554658735bf 29
mbed_official 0:a554658735bf 30 /**
mbed_official 0:a554658735bf 31 * Constructor
mbed_official 0:a554658735bf 32 * init variables and memory where will be stored HCCA, ED and TD
mbed_official 0:a554658735bf 33 */
mbed_official 0:a554658735bf 34 USBHALHost();
mbed_official 0:a554658735bf 35
mbed_official 0:a554658735bf 36 /**
mbed_official 0:a554658735bf 37 * Initialize host controller. Enable USB interrupts. This part is not in the constructor because,
mbed_official 0:a554658735bf 38 * this function calls a virtual method if a device is already connected
mbed_official 0:a554658735bf 39 */
mbed_official 0:a554658735bf 40 void init();
mbed_official 0:a554658735bf 41
mbed_official 0:a554658735bf 42 /**
mbed_official 0:a554658735bf 43 * reset the root hub
mbed_official 0:a554658735bf 44 */
mbed_official 0:a554658735bf 45 void resetRootHub();
mbed_official 0:a554658735bf 46
mbed_official 0:a554658735bf 47 /**
mbed_official 0:a554658735bf 48 * return the value contained in the control HEAD ED register
mbed_official 0:a554658735bf 49 *
mbed_official 0:a554658735bf 50 * @returns address of the control Head ED
mbed_official 0:a554658735bf 51 */
mbed_official 0:a554658735bf 52 uint32_t controlHeadED();
mbed_official 0:a554658735bf 53
mbed_official 0:a554658735bf 54 /**
mbed_official 0:a554658735bf 55 * return the value contained in the bulk HEAD ED register
mbed_official 0:a554658735bf 56 *
mbed_official 0:a554658735bf 57 * @returns address of the bulk head ED
mbed_official 0:a554658735bf 58 */
mbed_official 0:a554658735bf 59 uint32_t bulkHeadED();
mbed_official 0:a554658735bf 60
mbed_official 0:a554658735bf 61 /**
mbed_official 0:a554658735bf 62 * return the value of the head interrupt ED contained in the HCCA
mbed_official 0:a554658735bf 63 *
mbed_official 0:a554658735bf 64 * @returns address of the head interrupt ED contained in the HCCA
mbed_official 0:a554658735bf 65 */
mbed_official 0:a554658735bf 66 uint32_t interruptHeadED();
mbed_official 0:a554658735bf 67
mbed_official 0:a554658735bf 68
mbed_official 0:a554658735bf 69 /**
mbed_official 0:a554658735bf 70 * Update the head ED for control transfers
mbed_official 0:a554658735bf 71 */
mbed_official 0:a554658735bf 72 void updateControlHeadED(uint32_t addr);
mbed_official 0:a554658735bf 73
mbed_official 0:a554658735bf 74 /**
mbed_official 0:a554658735bf 75 * Update the head ED for bulk transfers
mbed_official 0:a554658735bf 76 */
mbed_official 0:a554658735bf 77 void updateBulkHeadED(uint32_t addr);
mbed_official 0:a554658735bf 78
mbed_official 0:a554658735bf 79 /**
mbed_official 0:a554658735bf 80 * Update the head ED for interrupt transfers
mbed_official 0:a554658735bf 81 */
mbed_official 0:a554658735bf 82 void updateInterruptHeadED(uint32_t addr);
mbed_official 0:a554658735bf 83
mbed_official 0:a554658735bf 84 /* *
mbed_official 0:a554658735bf 85 * Enable List for the specified endpoint type
mbed_official 0:a554658735bf 86 */
mbed_official 0:a554658735bf 87 void enableList(ENDPOINT_TYPE type);
mbed_official 0:a554658735bf 88
mbed_official 0:a554658735bf 89 /**
mbed_official 0:a554658735bf 90 * Disable List for the specified endpoint type
mbed_official 0:a554658735bf 91 */
mbed_official 0:a554658735bf 92 bool disableList(ENDPOINT_TYPE type);
mbed_official 0:a554658735bf 93
mbed_official 0:a554658735bf 94 protected:
mbed_official 0:a554658735bf 95 /**
mbed_official 0:a554658735bf 96 * Virtual method called when a device has been connected
mbed_official 0:a554658735bf 97 *
mbed_official 0:a554658735bf 98 * @param hub hub number of the device
mbed_official 0:a554658735bf 99 * @param port port number of the device
mbed_official 0:a554658735bf 100 * @param lowSpeed 1 if low speed, 0 otherwise
mbed_official 0:a554658735bf 101 * @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 102 */
mbed_official 0:a554658735bf 103 virtual void deviceConnected(int hub, int port, bool lowSpeed, USBHostHub * hub_parent = NULL) {};
mbed_official 0:a554658735bf 104
mbed_official 0:a554658735bf 105 /**
mbed_official 0:a554658735bf 106 * Virtual method called when a device has been disconnected
mbed_official 0:a554658735bf 107 *
mbed_official 0:a554658735bf 108 * @param hub hub number of the device
mbed_official 0:a554658735bf 109 * @param port port number of the device
mbed_official 0:a554658735bf 110 * @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 111 * @param addr list of the TDs which have been completed to dequeue freed TDs
mbed_official 0:a554658735bf 112 */
mbed_official 0:a554658735bf 113 virtual void deviceDisconnected(int hub, int port, USBHostHub * hub_parent, volatile uint32_t addr) {};
mbed_official 0:a554658735bf 114
mbed_official 0:a554658735bf 115 /**
mbed_official 0:a554658735bf 116 * Virtual method called when a transfer has been completed
mbed_official 0:a554658735bf 117 *
mbed_official 0:a554658735bf 118 * @param addr list of the TDs which have been completed
mbed_official 0:a554658735bf 119 */
mbed_official 0:a554658735bf 120 virtual void transferCompleted(volatile uint32_t addr){};
mbed_official 0:a554658735bf 121
mbed_official 0:a554658735bf 122 /**
mbed_official 0:a554658735bf 123 * Find a memory section for a new ED
mbed_official 0:a554658735bf 124 *
mbed_official 0:a554658735bf 125 * @returns the address of this section
mbed_official 0:a554658735bf 126 */
mbed_official 0:a554658735bf 127 volatile uint8_t * getED();
mbed_official 0:a554658735bf 128
mbed_official 0:a554658735bf 129 /**
mbed_official 0:a554658735bf 130 * Find a memory section for a new TD
mbed_official 0:a554658735bf 131 *
mbed_official 0:a554658735bf 132 * @returns the address of this section
mbed_official 0:a554658735bf 133 */
mbed_official 0:a554658735bf 134 volatile uint8_t * getTD();
mbed_official 0:a554658735bf 135
mbed_official 0:a554658735bf 136 /**
mbed_official 0:a554658735bf 137 * Release a previous memory section reserved for an ED
mbed_official 0:a554658735bf 138 *
mbed_official 0:a554658735bf 139 * @param ed address of the ED
mbed_official 0:a554658735bf 140 */
mbed_official 0:a554658735bf 141 void freeED(volatile uint8_t * ed);
mbed_official 0:a554658735bf 142
mbed_official 0:a554658735bf 143 /**
mbed_official 0:a554658735bf 144 * Release a previous memory section reserved for an TD
mbed_official 0:a554658735bf 145 *
samux 2:5e8fdc541b98 146 * @param td address of the TD
mbed_official 0:a554658735bf 147 */
mbed_official 0:a554658735bf 148 void freeTD(volatile uint8_t * td);
mbed_official 0:a554658735bf 149
mbed_official 0:a554658735bf 150 private:
mbed_official 0:a554658735bf 151 static void _usbisr(void);
mbed_official 0:a554658735bf 152 void UsbIrqhandler();
mbed_official 0:a554658735bf 153
mbed_official 0:a554658735bf 154 void memInit();
mbed_official 0:a554658735bf 155
mbed_official 0:a554658735bf 156 HCCA volatile * usb_hcca; //256 bytes aligned
mbed_official 0:a554658735bf 157 uint8_t volatile * usb_edBuf; //4 bytes aligned
mbed_official 0:a554658735bf 158 uint8_t volatile * usb_tdBuf; //4 bytes aligned
mbed_official 0:a554658735bf 159
mbed_official 0:a554658735bf 160 static USBHALHost * instHost;
mbed_official 0:a554658735bf 161
mbed_official 0:a554658735bf 162 bool volatile edBufAlloc[MAX_ENDPOINT];
mbed_official 0:a554658735bf 163 bool volatile tdBufAlloc[MAX_TD];
mbed_official 0:a554658735bf 164 };
mbed_official 0:a554658735bf 165
mbed_official 0:a554658735bf 166 #endif