test

Dependencies:   mbed-rtos

Dependents:   Production_version1_0 Production_ver1_0 USBHost_TEST USBHost_Test5 ... more

Fork of USBHost by mbed official

Committer:
mbed_official
Date:
Thu Feb 18 09:46:13 2016 +0000
Revision:
34:028508fd50fa
Parent:
24:868cbfe611a7
Child:
37:f1e388e7b752
Synchronized with git revision b57f7d56840134d072ca567460a86b77fb7adcf8

Full URL: https://github.com/mbedmicro/mbed/commit/b57f7d56840134d072ca567460a86b77fb7adcf8/

Support of export function to the IAR.

Who changed what in which revision?

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