Opencv 3.1 project on GR-PEACH board

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

Committer:
thedo
Date:
Tue Jul 04 06:23:13 2017 +0000
Revision:
170:54ff26da7eb6
Parent:
166:3a9487d57a5c
project opencv 3.1 on GR PEACH board, no use SD card.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
thedo 166:3a9487d57a5c 1 /* mbed USBHost Library
thedo 166:3a9487d57a5c 2 * Copyright (c) 2006-2013 ARM Limited
thedo 166:3a9487d57a5c 3 *
thedo 166:3a9487d57a5c 4 * Licensed under the Apache License, Version 2.0 (the "License");
thedo 166:3a9487d57a5c 5 * you may not use this file except in compliance with the License.
thedo 166:3a9487d57a5c 6 * You may obtain a copy of the License at
thedo 166:3a9487d57a5c 7 *
thedo 166:3a9487d57a5c 8 * http://www.apache.org/licenses/LICENSE-2.0
thedo 166:3a9487d57a5c 9 *
thedo 166:3a9487d57a5c 10 * Unless required by applicable law or agreed to in writing, software
thedo 166:3a9487d57a5c 11 * distributed under the License is distributed on an "AS IS" BASIS,
thedo 166:3a9487d57a5c 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
thedo 166:3a9487d57a5c 13 * See the License for the specific language governing permissions and
thedo 166:3a9487d57a5c 14 * limitations under the License.
thedo 166:3a9487d57a5c 15 */
thedo 166:3a9487d57a5c 16
thedo 166:3a9487d57a5c 17
thedo 166:3a9487d57a5c 18 #include "dbg.h"
thedo 166:3a9487d57a5c 19 #include "USBEndpoint.h"
thedo 166:3a9487d57a5c 20
thedo 166:3a9487d57a5c 21 void USBEndpoint::init(HCED * hced_, ENDPOINT_TYPE type_, ENDPOINT_DIRECTION dir_, uint32_t size, uint8_t ep_number, HCTD* td_list_[2])
thedo 166:3a9487d57a5c 22 {
thedo 166:3a9487d57a5c 23 hced = hced_;
thedo 166:3a9487d57a5c 24 type = type_;
thedo 166:3a9487d57a5c 25 dir = dir_;
thedo 166:3a9487d57a5c 26 setup = (type == CONTROL_ENDPOINT) ? true : false;
thedo 166:3a9487d57a5c 27
thedo 166:3a9487d57a5c 28 //TDs have been allocated by the host
thedo 166:3a9487d57a5c 29 memcpy((HCTD**)td_list, td_list_, sizeof(HCTD*)*2); //TODO: Maybe should add a param for td_list size... at least a define
thedo 166:3a9487d57a5c 30 memset(td_list_[0], 0, sizeof(HCTD));
thedo 166:3a9487d57a5c 31 memset(td_list_[1], 0, sizeof(HCTD));
thedo 166:3a9487d57a5c 32
thedo 166:3a9487d57a5c 33 td_list[0]->ep = this;
thedo 166:3a9487d57a5c 34 td_list[1]->ep = this;
thedo 166:3a9487d57a5c 35
thedo 166:3a9487d57a5c 36 hced->control = 0;
thedo 166:3a9487d57a5c 37 //Empty queue
thedo 166:3a9487d57a5c 38 hced->tailTD = td_list[0];
thedo 166:3a9487d57a5c 39 hced->headTD = td_list[0];
thedo 166:3a9487d57a5c 40 hced->nextED = 0;
thedo 166:3a9487d57a5c 41
thedo 166:3a9487d57a5c 42 address = (ep_number & 0x7F) | ((dir - 1) << 7);
thedo 166:3a9487d57a5c 43
thedo 166:3a9487d57a5c 44 hced->control = ((ep_number & 0x7F) << 7) // Endpoint address
thedo 166:3a9487d57a5c 45 | (type != CONTROL_ENDPOINT ? ( dir << 11) : 0 ) // direction : Out = 1, 2 = In
thedo 166:3a9487d57a5c 46 | ((size & 0x3ff) << 16); // MaxPkt Size
thedo 166:3a9487d57a5c 47
thedo 166:3a9487d57a5c 48 transfer_len = 0;
thedo 166:3a9487d57a5c 49 transferred = 0;
thedo 166:3a9487d57a5c 50 buf_start = 0;
thedo 166:3a9487d57a5c 51 nextEp = NULL;
thedo 166:3a9487d57a5c 52
thedo 166:3a9487d57a5c 53 td_current = td_list[0];
thedo 166:3a9487d57a5c 54 td_next = td_list[1];
thedo 166:3a9487d57a5c 55
thedo 166:3a9487d57a5c 56 intf_nb = 0;
thedo 166:3a9487d57a5c 57
thedo 166:3a9487d57a5c 58 state = USB_TYPE_IDLE;
thedo 166:3a9487d57a5c 59 }
thedo 166:3a9487d57a5c 60
thedo 166:3a9487d57a5c 61 void USBEndpoint::setSize(uint32_t size)
thedo 166:3a9487d57a5c 62 {
thedo 166:3a9487d57a5c 63 hced->control &= ~(0x3ff << 16);
thedo 166:3a9487d57a5c 64 hced->control |= (size << 16);
thedo 166:3a9487d57a5c 65 }
thedo 166:3a9487d57a5c 66
thedo 166:3a9487d57a5c 67
thedo 166:3a9487d57a5c 68 void USBEndpoint::setDeviceAddress(uint8_t addr)
thedo 166:3a9487d57a5c 69 {
thedo 166:3a9487d57a5c 70 hced->control &= ~(0x7f);
thedo 166:3a9487d57a5c 71 hced->control |= (addr & 0x7F);
thedo 166:3a9487d57a5c 72 }
thedo 166:3a9487d57a5c 73
thedo 166:3a9487d57a5c 74 void USBEndpoint::setSpeed(uint8_t speed)
thedo 166:3a9487d57a5c 75 {
thedo 166:3a9487d57a5c 76 hced->control &= ~(1 << 13);
thedo 166:3a9487d57a5c 77 hced->control |= (speed << 13);
thedo 166:3a9487d57a5c 78 }
thedo 166:3a9487d57a5c 79
thedo 166:3a9487d57a5c 80 //Only for control Eps
thedo 166:3a9487d57a5c 81 void USBEndpoint::setNextToken(uint32_t token)
thedo 166:3a9487d57a5c 82 {
thedo 166:3a9487d57a5c 83 switch (token) {
thedo 166:3a9487d57a5c 84 case TD_SETUP:
thedo 166:3a9487d57a5c 85 dir = OUT;
thedo 166:3a9487d57a5c 86 setup = true;
thedo 166:3a9487d57a5c 87 break;
thedo 166:3a9487d57a5c 88 case TD_IN:
thedo 166:3a9487d57a5c 89 dir = IN;
thedo 166:3a9487d57a5c 90 setup = false;
thedo 166:3a9487d57a5c 91 break;
thedo 166:3a9487d57a5c 92 case TD_OUT:
thedo 166:3a9487d57a5c 93 dir = OUT;
thedo 166:3a9487d57a5c 94 setup = false;
thedo 166:3a9487d57a5c 95 break;
thedo 166:3a9487d57a5c 96 }
thedo 166:3a9487d57a5c 97 }
thedo 166:3a9487d57a5c 98
thedo 166:3a9487d57a5c 99 struct {
thedo 166:3a9487d57a5c 100 USB_TYPE type;
thedo 166:3a9487d57a5c 101 const char * str;
thedo 166:3a9487d57a5c 102 } static type_string[] = {
thedo 166:3a9487d57a5c 103 /*0*/ {USB_TYPE_OK, "USB_TYPE_OK"},
thedo 166:3a9487d57a5c 104 {USB_TYPE_CRC_ERROR, "USB_TYPE_CRC_ERROR"},
thedo 166:3a9487d57a5c 105 {USB_TYPE_BIT_STUFFING_ERROR, "USB_TYPE_BIT_STUFFING_ERROR"},
thedo 166:3a9487d57a5c 106 {USB_TYPE_DATA_TOGGLE_MISMATCH_ERROR, "USB_TYPE_DATA_TOGGLE_MISMATCH_ERROR"},
thedo 166:3a9487d57a5c 107 {USB_TYPE_STALL_ERROR, "USB_TYPE_STALL_ERROR"},
thedo 166:3a9487d57a5c 108 /*5*/ {USB_TYPE_DEVICE_NOT_RESPONDING_ERROR, "USB_TYPE_DEVICE_NOT_RESPONDING_ERROR"},
thedo 166:3a9487d57a5c 109 {USB_TYPE_PID_CHECK_FAILURE_ERROR, "USB_TYPE_PID_CHECK_FAILURE_ERROR"},
thedo 166:3a9487d57a5c 110 {USB_TYPE_UNEXPECTED_PID_ERROR, "USB_TYPE_UNEXPECTED_PID_ERROR"},
thedo 166:3a9487d57a5c 111 {USB_TYPE_DATA_OVERRUN_ERROR, "USB_TYPE_DATA_OVERRUN_ERROR"},
thedo 166:3a9487d57a5c 112 {USB_TYPE_DATA_UNDERRUN_ERROR, "USB_TYPE_DATA_UNDERRUN_ERROR"},
thedo 166:3a9487d57a5c 113 /*10*/ {USB_TYPE_ERROR, "USB_TYPE_ERROR"},
thedo 166:3a9487d57a5c 114 {USB_TYPE_ERROR, "USB_TYPE_ERROR"},
thedo 166:3a9487d57a5c 115 {USB_TYPE_BUFFER_OVERRUN_ERROR, "USB_TYPE_BUFFER_OVERRUN_ERROR"},
thedo 166:3a9487d57a5c 116 {USB_TYPE_BUFFER_UNDERRUN_ERROR, "USB_TYPE_BUFFER_UNDERRUN_ERROR"},
thedo 166:3a9487d57a5c 117 {USB_TYPE_DISCONNECTED, "USB_TYPE_DISCONNECTED"},
thedo 166:3a9487d57a5c 118 /*15*/ {USB_TYPE_FREE, "USB_TYPE_FREE"},
thedo 166:3a9487d57a5c 119 {USB_TYPE_IDLE, "USB_TYPE_IDLE"},
thedo 166:3a9487d57a5c 120 {USB_TYPE_PROCESSING, "USB_TYPE_PROCESSING"},
thedo 166:3a9487d57a5c 121 {USB_TYPE_ERROR, "USB_TYPE_ERROR"}
thedo 166:3a9487d57a5c 122 };
thedo 166:3a9487d57a5c 123
thedo 166:3a9487d57a5c 124 void USBEndpoint::setState(uint8_t st) {
thedo 166:3a9487d57a5c 125 if (st > 18)
thedo 166:3a9487d57a5c 126 return;
thedo 166:3a9487d57a5c 127 state = type_string[st].type;
thedo 166:3a9487d57a5c 128 }
thedo 166:3a9487d57a5c 129
thedo 166:3a9487d57a5c 130
thedo 166:3a9487d57a5c 131 const char * USBEndpoint::getStateString() {
thedo 166:3a9487d57a5c 132 return type_string[state].str;
thedo 166:3a9487d57a5c 133 }
thedo 166:3a9487d57a5c 134
thedo 166:3a9487d57a5c 135 void USBEndpoint::queueTransfer()
thedo 166:3a9487d57a5c 136 {
thedo 166:3a9487d57a5c 137 transfer_len = (uint32_t)td_current->bufEnd - (uint32_t)td_current->currBufPtr + 1;
thedo 166:3a9487d57a5c 138 transferred = transfer_len;
thedo 166:3a9487d57a5c 139 buf_start = (uint8_t *)td_current->currBufPtr;
thedo 166:3a9487d57a5c 140
thedo 166:3a9487d57a5c 141 //Now add this free TD at this end of the queue
thedo 166:3a9487d57a5c 142 state = USB_TYPE_PROCESSING;
thedo 166:3a9487d57a5c 143 td_current->nextTD = (hcTd*)td_next;
thedo 166:3a9487d57a5c 144 hced->tailTD = td_next;
thedo 166:3a9487d57a5c 145 }
thedo 166:3a9487d57a5c 146
thedo 166:3a9487d57a5c 147 void USBEndpoint::unqueueTransfer(volatile HCTD * td)
thedo 166:3a9487d57a5c 148 {
thedo 166:3a9487d57a5c 149 td->control=0;
thedo 166:3a9487d57a5c 150 td->currBufPtr=0;
thedo 166:3a9487d57a5c 151 td->bufEnd=0;
thedo 166:3a9487d57a5c 152 td->nextTD=0;
thedo 166:3a9487d57a5c 153 hced->headTD = (HCTD *)((uint32_t)hced->tailTD | ((uint32_t)hced->headTD & 0x2)); //Carry bit
thedo 166:3a9487d57a5c 154 td_current = td_next;
thedo 166:3a9487d57a5c 155 td_next = td;
thedo 166:3a9487d57a5c 156 }
thedo 166:3a9487d57a5c 157
thedo 166:3a9487d57a5c 158 void USBEndpoint::queueEndpoint(USBEndpoint * ed)
thedo 166:3a9487d57a5c 159 {
thedo 166:3a9487d57a5c 160 nextEp = ed;
thedo 166:3a9487d57a5c 161 hced->nextED = (ed == NULL) ? 0 : (hcEd*)(ed->getHCED());
thedo 166:3a9487d57a5c 162 }