Running multiple threads on mbed using RTOS

Dependencies:   4DGL-uLCD-SE SDFileSystem mbed-rtos mbed wave_player_appbd

Committer:
wschon
Date:
Mon Feb 29 03:46:10 2016 +0000
Revision:
4:5fdadaef5b1f
Parent:
1:2129bb91c172
fixed EVERYTHING

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wschon 1:2129bb91c172 1 /* mbed USBHost Library
wschon 1:2129bb91c172 2 * Copyright (c) 2006-2013 ARM Limited
wschon 1:2129bb91c172 3 *
wschon 1:2129bb91c172 4 * Licensed under the Apache License, Version 2.0 (the "License");
wschon 1:2129bb91c172 5 * you may not use this file except in compliance with the License.
wschon 1:2129bb91c172 6 * You may obtain a copy of the License at
wschon 1:2129bb91c172 7 *
wschon 1:2129bb91c172 8 * http://www.apache.org/licenses/LICENSE-2.0
wschon 1:2129bb91c172 9 *
wschon 1:2129bb91c172 10 * Unless required by applicable law or agreed to in writing, software
wschon 1:2129bb91c172 11 * distributed under the License is distributed on an "AS IS" BASIS,
wschon 1:2129bb91c172 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
wschon 1:2129bb91c172 13 * See the License for the specific language governing permissions and
wschon 1:2129bb91c172 14 * limitations under the License.
wschon 1:2129bb91c172 15 */
wschon 1:2129bb91c172 16
wschon 1:2129bb91c172 17 #include "USBDeviceConnected.h"
wschon 1:2129bb91c172 18 #include "dbg.h"
wschon 1:2129bb91c172 19
wschon 1:2129bb91c172 20 USBDeviceConnected::USBDeviceConnected() {
wschon 1:2129bb91c172 21 init();
wschon 1:2129bb91c172 22 }
wschon 1:2129bb91c172 23
wschon 1:2129bb91c172 24 void USBDeviceConnected::init() {
wschon 1:2129bb91c172 25 hub_nb = 0;
wschon 1:2129bb91c172 26 port = 0;
wschon 1:2129bb91c172 27 vid = 0;
wschon 1:2129bb91c172 28 pid = 0;
wschon 1:2129bb91c172 29 nb_interf = 0;
wschon 1:2129bb91c172 30 enumerated = false;
wschon 1:2129bb91c172 31 activeAddr = false;
wschon 1:2129bb91c172 32 sizeControlEndpoint = 8;
wschon 1:2129bb91c172 33 device_class = 0;
wschon 1:2129bb91c172 34 device_subclass = 0;
wschon 1:2129bb91c172 35 proto = 0;
wschon 1:2129bb91c172 36 speed = false;
wschon 1:2129bb91c172 37 for (int i = 0; i < MAX_INTF; i++) {
wschon 1:2129bb91c172 38 memset((void *)&intf[i], 0, sizeof(INTERFACE));
wschon 1:2129bb91c172 39 intf[i].in_use = false;
wschon 1:2129bb91c172 40 for (int j = 0; j < MAX_ENDPOINT_PER_INTERFACE; j++) {
wschon 1:2129bb91c172 41 intf[i].ep[j] = NULL;
wschon 1:2129bb91c172 42 strcpy(intf[i].name, "Unknown");
wschon 1:2129bb91c172 43 }
wschon 1:2129bb91c172 44 }
wschon 1:2129bb91c172 45 hub_parent = NULL;
wschon 1:2129bb91c172 46 hub = NULL;
wschon 1:2129bb91c172 47 nb_interf = 0;
wschon 1:2129bb91c172 48 }
wschon 1:2129bb91c172 49
wschon 1:2129bb91c172 50 INTERFACE * USBDeviceConnected::getInterface(uint8_t index) {
wschon 1:2129bb91c172 51 if (index >= MAX_INTF)
wschon 1:2129bb91c172 52 return NULL;
wschon 1:2129bb91c172 53
wschon 1:2129bb91c172 54 if (intf[index].in_use)
wschon 1:2129bb91c172 55 return &intf[index];
wschon 1:2129bb91c172 56
wschon 1:2129bb91c172 57 return NULL;
wschon 1:2129bb91c172 58 }
wschon 1:2129bb91c172 59
wschon 1:2129bb91c172 60 bool USBDeviceConnected::addInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) {
wschon 1:2129bb91c172 61 if ((intf_nb >= MAX_INTF) || (intf[intf_nb].in_use)) {
wschon 1:2129bb91c172 62 return false;
wschon 1:2129bb91c172 63 }
wschon 1:2129bb91c172 64 intf[intf_nb].in_use = true;
wschon 1:2129bb91c172 65 intf[intf_nb].intf_class = intf_class;
wschon 1:2129bb91c172 66 intf[intf_nb].intf_subclass = intf_subclass;
wschon 1:2129bb91c172 67 intf[intf_nb].intf_protocol = intf_protocol;
wschon 1:2129bb91c172 68 intf[intf_nb].nb_endpoint = 0;
wschon 1:2129bb91c172 69 return true;
wschon 1:2129bb91c172 70 }
wschon 1:2129bb91c172 71
wschon 1:2129bb91c172 72 bool USBDeviceConnected::addEndpoint(uint8_t intf_nb, USBEndpoint * ept) {
wschon 1:2129bb91c172 73 if ((intf_nb >= MAX_INTF) || (intf[intf_nb].in_use == false) || (intf[intf_nb].nb_endpoint >= MAX_ENDPOINT_PER_INTERFACE)) {
wschon 1:2129bb91c172 74 return false;
wschon 1:2129bb91c172 75 }
wschon 1:2129bb91c172 76 intf[intf_nb].nb_endpoint++;
wschon 1:2129bb91c172 77
wschon 1:2129bb91c172 78 for (int i = 0; i < MAX_ENDPOINT_PER_INTERFACE; i++) {
wschon 1:2129bb91c172 79 if (intf[intf_nb].ep[i] == NULL) {
wschon 1:2129bb91c172 80 intf[intf_nb].ep[i] = ept;
wschon 1:2129bb91c172 81 return true;
wschon 1:2129bb91c172 82 }
wschon 1:2129bb91c172 83 }
wschon 1:2129bb91c172 84 return false;
wschon 1:2129bb91c172 85 }
wschon 1:2129bb91c172 86
wschon 1:2129bb91c172 87 void USBDeviceConnected::init(uint8_t hub_, uint8_t port_, bool lowSpeed_) {
wschon 1:2129bb91c172 88 USB_DBG("init dev: %p", this);
wschon 1:2129bb91c172 89 init();
wschon 1:2129bb91c172 90 hub_nb = hub_;
wschon 1:2129bb91c172 91 port = port_;
wschon 1:2129bb91c172 92 speed = lowSpeed_;
wschon 1:2129bb91c172 93 }
wschon 1:2129bb91c172 94
wschon 1:2129bb91c172 95 void USBDeviceConnected::disconnect() {
wschon 1:2129bb91c172 96 for(int i = 0; i < MAX_INTF; i++) {
wschon 1:2129bb91c172 97 intf[i].detach.call();
wschon 1:2129bb91c172 98 }
wschon 1:2129bb91c172 99 init();
wschon 1:2129bb91c172 100 }
wschon 1:2129bb91c172 101
wschon 1:2129bb91c172 102
wschon 1:2129bb91c172 103 USBEndpoint * USBDeviceConnected::getEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint8_t index) {
wschon 1:2129bb91c172 104 if (intf_nb >= MAX_INTF) {
wschon 1:2129bb91c172 105 return NULL;
wschon 1:2129bb91c172 106 }
wschon 1:2129bb91c172 107 for (int i = 0; i < MAX_ENDPOINT_PER_INTERFACE; i++) {
wschon 1:2129bb91c172 108 if ((intf[intf_nb].ep[i]->getType() == type) && (intf[intf_nb].ep[i]->getDir() == dir)) {
wschon 1:2129bb91c172 109 if(index) {
wschon 1:2129bb91c172 110 index--;
wschon 1:2129bb91c172 111 } else {
wschon 1:2129bb91c172 112 return intf[intf_nb].ep[i];
wschon 1:2129bb91c172 113 }
wschon 1:2129bb91c172 114 }
wschon 1:2129bb91c172 115 }
wschon 1:2129bb91c172 116 return NULL;
wschon 1:2129bb91c172 117 }
wschon 1:2129bb91c172 118
wschon 1:2129bb91c172 119 USBEndpoint * USBDeviceConnected::getEndpoint(uint8_t intf_nb, uint8_t index) {
wschon 1:2129bb91c172 120 if ((intf_nb >= MAX_INTF) || (index >= MAX_ENDPOINT_PER_INTERFACE)) {
wschon 1:2129bb91c172 121 return NULL;
wschon 1:2129bb91c172 122 }
wschon 1:2129bb91c172 123 return intf[intf_nb].ep[index];
wschon 1:2129bb91c172 124 }