Renesas GR-PEACH OpenCV Development / gr-peach-opencv-project-sd-card_update

Fork of gr-peach-opencv-project-sd-card by the do

Committer:
thedo
Date:
Fri Jul 21 01:26:54 2017 +0000
Revision:
167:2ee3e82cb6f5
Parent:
166:240bc5a0f42a
gr-peach-opencv-project-sd-card

Who changed what in which revision?

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