Dependencies:   FATFileSystem

Committer:
nhiro3303
Date:
Tue Aug 22 06:18:15 2017 +0000
Revision:
0:42b8e1bc6235
ps3 test library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nhiro3303 0:42b8e1bc6235 1 /* mbed USBHost Library
nhiro3303 0:42b8e1bc6235 2 * Copyright (c) 2006-2013 ARM Limited
nhiro3303 0:42b8e1bc6235 3 *
nhiro3303 0:42b8e1bc6235 4 * Licensed under the Apache License, Version 2.0 (the "License");
nhiro3303 0:42b8e1bc6235 5 * you may not use this file except in compliance with the License.
nhiro3303 0:42b8e1bc6235 6 * You may obtain a copy of the License at
nhiro3303 0:42b8e1bc6235 7 *
nhiro3303 0:42b8e1bc6235 8 * http://www.apache.org/licenses/LICENSE-2.0
nhiro3303 0:42b8e1bc6235 9 *
nhiro3303 0:42b8e1bc6235 10 * Unless required by applicable law or agreed to in writing, software
nhiro3303 0:42b8e1bc6235 11 * distributed under the License is distributed on an "AS IS" BASIS,
nhiro3303 0:42b8e1bc6235 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
nhiro3303 0:42b8e1bc6235 13 * See the License for the specific language governing permissions and
nhiro3303 0:42b8e1bc6235 14 * limitations under the License.
nhiro3303 0:42b8e1bc6235 15 */
nhiro3303 0:42b8e1bc6235 16
nhiro3303 0:42b8e1bc6235 17 #pragma once
nhiro3303 0:42b8e1bc6235 18 #include "FunctionPointer.h"
nhiro3303 0:42b8e1bc6235 19 #include "USBHostTypes.h"
nhiro3303 0:42b8e1bc6235 20 #include "USBDeviceConnected.h"
nhiro3303 0:42b8e1bc6235 21
nhiro3303 0:42b8e1bc6235 22 class USBDeviceConnected;
nhiro3303 0:42b8e1bc6235 23
nhiro3303 0:42b8e1bc6235 24 /**
nhiro3303 0:42b8e1bc6235 25 * USBEndpoint class
nhiro3303 0:42b8e1bc6235 26 */
nhiro3303 0:42b8e1bc6235 27 class USBEndpoint {
nhiro3303 0:42b8e1bc6235 28 public:
nhiro3303 0:42b8e1bc6235 29 /**
nhiro3303 0:42b8e1bc6235 30 * Constructor
nhiro3303 0:42b8e1bc6235 31 */
nhiro3303 0:42b8e1bc6235 32 USBEndpoint(USBDeviceConnected* _dev) {
nhiro3303 0:42b8e1bc6235 33 init(CONTROL_ENDPOINT, IN, 8, 0);
nhiro3303 0:42b8e1bc6235 34 dev = _dev;
nhiro3303 0:42b8e1bc6235 35 pData = NULL;
nhiro3303 0:42b8e1bc6235 36 }
nhiro3303 0:42b8e1bc6235 37
nhiro3303 0:42b8e1bc6235 38 /**
nhiro3303 0:42b8e1bc6235 39 * Initialize an endpoint
nhiro3303 0:42b8e1bc6235 40 *
nhiro3303 0:42b8e1bc6235 41 * @param type endpoint type
nhiro3303 0:42b8e1bc6235 42 * @param dir endpoint direction
nhiro3303 0:42b8e1bc6235 43 * @param size endpoint size
nhiro3303 0:42b8e1bc6235 44 * @param ep_number endpoint number
nhiro3303 0:42b8e1bc6235 45 */
nhiro3303 0:42b8e1bc6235 46 void init(ENDPOINT_TYPE _type, ENDPOINT_DIRECTION _dir, uint32_t size, uint8_t ep_number) {
nhiro3303 0:42b8e1bc6235 47 setState(USB_TYPE_FREE);
nhiro3303 0:42b8e1bc6235 48 setType(_type);
nhiro3303 0:42b8e1bc6235 49 dir = _dir;
nhiro3303 0:42b8e1bc6235 50 MaxPacketSize = size;
nhiro3303 0:42b8e1bc6235 51 address = ep_number;
nhiro3303 0:42b8e1bc6235 52 data01_toggle = DATA0;
nhiro3303 0:42b8e1bc6235 53 }
nhiro3303 0:42b8e1bc6235 54
nhiro3303 0:42b8e1bc6235 55 void ohci_init(uint8_t frameCount, uint8_t queueLimit) {
nhiro3303 0:42b8e1bc6235 56 ohci.frameCount = frameCount;
nhiro3303 0:42b8e1bc6235 57 ohci.queueLimit = queueLimit;
nhiro3303 0:42b8e1bc6235 58 }
nhiro3303 0:42b8e1bc6235 59
nhiro3303 0:42b8e1bc6235 60 /**
nhiro3303 0:42b8e1bc6235 61 * Attach a member function to call when a transfer is finished
nhiro3303 0:42b8e1bc6235 62 *
nhiro3303 0:42b8e1bc6235 63 * @param tptr pointer to the object to call the member function on
nhiro3303 0:42b8e1bc6235 64 * @param mptr pointer to the member function to be called
nhiro3303 0:42b8e1bc6235 65 */
nhiro3303 0:42b8e1bc6235 66 template<typename T>
nhiro3303 0:42b8e1bc6235 67 inline void attach(T* tptr, void (T::*mptr)(void)) {
nhiro3303 0:42b8e1bc6235 68 if((mptr != NULL) && (tptr != NULL)) {
nhiro3303 0:42b8e1bc6235 69 rx.attach(tptr, mptr);
nhiro3303 0:42b8e1bc6235 70 }
nhiro3303 0:42b8e1bc6235 71 }
nhiro3303 0:42b8e1bc6235 72
nhiro3303 0:42b8e1bc6235 73 /**
nhiro3303 0:42b8e1bc6235 74 * Attach a callback called when a transfer is finished
nhiro3303 0:42b8e1bc6235 75 *
nhiro3303 0:42b8e1bc6235 76 * @param fptr function pointer
nhiro3303 0:42b8e1bc6235 77 */
nhiro3303 0:42b8e1bc6235 78 inline void attach(void (*fptr)(void)) {
nhiro3303 0:42b8e1bc6235 79 if(fptr != NULL) {
nhiro3303 0:42b8e1bc6235 80 rx.attach(fptr);
nhiro3303 0:42b8e1bc6235 81 }
nhiro3303 0:42b8e1bc6235 82 }
nhiro3303 0:42b8e1bc6235 83
nhiro3303 0:42b8e1bc6235 84 /**
nhiro3303 0:42b8e1bc6235 85 * Call the handler associted to the end of a transfer
nhiro3303 0:42b8e1bc6235 86 */
nhiro3303 0:42b8e1bc6235 87 inline void call() {
nhiro3303 0:42b8e1bc6235 88 rx.call();
nhiro3303 0:42b8e1bc6235 89 };
nhiro3303 0:42b8e1bc6235 90
nhiro3303 0:42b8e1bc6235 91 void setType(ENDPOINT_TYPE _type) { type = _type; }
nhiro3303 0:42b8e1bc6235 92 void setState(USB_TYPE st) { state = st; }
nhiro3303 0:42b8e1bc6235 93 void setDevice(USBDeviceConnected* _dev) { dev = _dev; }
nhiro3303 0:42b8e1bc6235 94 void setBuffer(uint8_t* buf, int size) { buf_start = buf, buf_size = size; }
nhiro3303 0:42b8e1bc6235 95 void setLengthTransferred(int len) { transferred = len; };
nhiro3303 0:42b8e1bc6235 96 void setAddress(int addr) { address = addr; }
nhiro3303 0:42b8e1bc6235 97 void setSize(int size) { MaxPacketSize = size; }
nhiro3303 0:42b8e1bc6235 98 void setData01(uint8_t data01) { data01_toggle = data01; }
nhiro3303 0:42b8e1bc6235 99 void setNextEndpoint(USBEndpoint* ep) { nextEp = ep; };
nhiro3303 0:42b8e1bc6235 100 template<class T>
nhiro3303 0:42b8e1bc6235 101 void setHALData(T data) { pData = data; }
nhiro3303 0:42b8e1bc6235 102
nhiro3303 0:42b8e1bc6235 103 USBDeviceConnected* getDevice() { return dev; }
nhiro3303 0:42b8e1bc6235 104 ENDPOINT_TYPE getType() { return type; };
nhiro3303 0:42b8e1bc6235 105 USB_TYPE getState() { return state; }
nhiro3303 0:42b8e1bc6235 106 int getLengthTransferred() { return transferred; }
nhiro3303 0:42b8e1bc6235 107 uint8_t *getBufStart() { return buf_start; }
nhiro3303 0:42b8e1bc6235 108 int getBufSize() { return buf_size; }
nhiro3303 0:42b8e1bc6235 109 uint8_t getAddress(){ return address; };
nhiro3303 0:42b8e1bc6235 110 int getSize() { return MaxPacketSize; }
nhiro3303 0:42b8e1bc6235 111 ENDPOINT_DIRECTION getDir() { return dir; }
nhiro3303 0:42b8e1bc6235 112 uint8_t getData01() { return data01_toggle; }
nhiro3303 0:42b8e1bc6235 113 void toggleData01() {
nhiro3303 0:42b8e1bc6235 114 data01_toggle = (data01_toggle == DATA0) ? DATA1 : DATA0;
nhiro3303 0:42b8e1bc6235 115 }
nhiro3303 0:42b8e1bc6235 116 USBEndpoint* nextEndpoint() { return nextEp; };
nhiro3303 0:42b8e1bc6235 117 template<class T>
nhiro3303 0:42b8e1bc6235 118 T getHALData() { return reinterpret_cast<T>(pData); }
nhiro3303 0:42b8e1bc6235 119
nhiro3303 0:42b8e1bc6235 120 struct {
nhiro3303 0:42b8e1bc6235 121 uint8_t queueLimit;
nhiro3303 0:42b8e1bc6235 122 uint8_t frameCount; // 1-8
nhiro3303 0:42b8e1bc6235 123 } ohci;
nhiro3303 0:42b8e1bc6235 124 private:
nhiro3303 0:42b8e1bc6235 125 USBEndpoint(){}
nhiro3303 0:42b8e1bc6235 126 ENDPOINT_TYPE type;
nhiro3303 0:42b8e1bc6235 127 USB_TYPE state;
nhiro3303 0:42b8e1bc6235 128 ENDPOINT_DIRECTION dir;
nhiro3303 0:42b8e1bc6235 129 USBDeviceConnected* dev;
nhiro3303 0:42b8e1bc6235 130 uint8_t data01_toggle; // DATA0,DATA1
nhiro3303 0:42b8e1bc6235 131 uint8_t address;
nhiro3303 0:42b8e1bc6235 132 int transferred;
nhiro3303 0:42b8e1bc6235 133 uint8_t * buf_start;
nhiro3303 0:42b8e1bc6235 134 int buf_size;
nhiro3303 0:42b8e1bc6235 135 FunctionPointer rx;
nhiro3303 0:42b8e1bc6235 136 int MaxPacketSize;
nhiro3303 0:42b8e1bc6235 137 USBEndpoint* nextEp;
nhiro3303 0:42b8e1bc6235 138 void* pData;
nhiro3303 0:42b8e1bc6235 139 };
nhiro3303 0:42b8e1bc6235 140
nhiro3303 0:42b8e1bc6235 141 class EndpointQueue {
nhiro3303 0:42b8e1bc6235 142 public:
nhiro3303 0:42b8e1bc6235 143 EndpointQueue():head(NULL),tail(NULL) {}
nhiro3303 0:42b8e1bc6235 144 void push(USBEndpoint* ep) {
nhiro3303 0:42b8e1bc6235 145 if (head) {
nhiro3303 0:42b8e1bc6235 146 tail->setNextEndpoint(ep);
nhiro3303 0:42b8e1bc6235 147 } else {
nhiro3303 0:42b8e1bc6235 148 head = ep;
nhiro3303 0:42b8e1bc6235 149 }
nhiro3303 0:42b8e1bc6235 150 tail = ep;
nhiro3303 0:42b8e1bc6235 151 ep->setNextEndpoint(NULL);
nhiro3303 0:42b8e1bc6235 152 }
nhiro3303 0:42b8e1bc6235 153 USBEndpoint* pop() {
nhiro3303 0:42b8e1bc6235 154 USBEndpoint* ep = head;
nhiro3303 0:42b8e1bc6235 155 if (ep) {
nhiro3303 0:42b8e1bc6235 156 head = ep->nextEndpoint();
nhiro3303 0:42b8e1bc6235 157 }
nhiro3303 0:42b8e1bc6235 158 return ep;
nhiro3303 0:42b8e1bc6235 159 }
nhiro3303 0:42b8e1bc6235 160 bool empty() { return head == NULL; }
nhiro3303 0:42b8e1bc6235 161
nhiro3303 0:42b8e1bc6235 162 private:
nhiro3303 0:42b8e1bc6235 163 USBEndpoint* head;
nhiro3303 0:42b8e1bc6235 164 USBEndpoint* tail;
nhiro3303 0:42b8e1bc6235 165 };
nhiro3303 0:42b8e1bc6235 166
nhiro3303 0:42b8e1bc6235 167