Running multiple threads on mbed using RTOS

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

Committer:
wschon
Date:
Sun Feb 28 22:40:13 2016 +0000
Revision:
1:2129bb91c172
Added USB libraries;

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 #ifndef USBHOSTMSD_H
wschon 1:2129bb91c172 18 #define USBHOSTMSD_H
wschon 1:2129bb91c172 19
wschon 1:2129bb91c172 20 #include "USBHostConf.h"
wschon 1:2129bb91c172 21
wschon 1:2129bb91c172 22 #if USBHOST_MSD
wschon 1:2129bb91c172 23
wschon 1:2129bb91c172 24 #include "USBHost.h"
wschon 1:2129bb91c172 25 #include "FATFileSystem.h"
wschon 1:2129bb91c172 26
wschon 1:2129bb91c172 27 /**
wschon 1:2129bb91c172 28 * A class to communicate a USB flash disk
wschon 1:2129bb91c172 29 */
wschon 1:2129bb91c172 30 class USBHostMSD : public IUSBEnumerator, public FATFileSystem {
wschon 1:2129bb91c172 31 public:
wschon 1:2129bb91c172 32 /**
wschon 1:2129bb91c172 33 * Constructor
wschon 1:2129bb91c172 34 *
wschon 1:2129bb91c172 35 * @param rootdir mount name
wschon 1:2129bb91c172 36 */
wschon 1:2129bb91c172 37 USBHostMSD(const char * rootdir);
wschon 1:2129bb91c172 38
wschon 1:2129bb91c172 39 /**
wschon 1:2129bb91c172 40 * Check if a MSD device is connected
wschon 1:2129bb91c172 41 *
wschon 1:2129bb91c172 42 * @return true if a MSD device is connected
wschon 1:2129bb91c172 43 */
wschon 1:2129bb91c172 44 bool connected();
wschon 1:2129bb91c172 45
wschon 1:2129bb91c172 46 /**
wschon 1:2129bb91c172 47 * Try to connect to a MSD device
wschon 1:2129bb91c172 48 *
wschon 1:2129bb91c172 49 * @return true if connection was successful
wschon 1:2129bb91c172 50 */
wschon 1:2129bb91c172 51 bool connect();
wschon 1:2129bb91c172 52
wschon 1:2129bb91c172 53 protected:
wschon 1:2129bb91c172 54 //From IUSBEnumerator
wschon 1:2129bb91c172 55 virtual void setVidPid(uint16_t vid, uint16_t pid);
wschon 1:2129bb91c172 56 virtual bool parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol); //Must return true if the interface should be parsed
wschon 1:2129bb91c172 57 virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used
wschon 1:2129bb91c172 58
wschon 1:2129bb91c172 59 // From FATFileSystem
wschon 1:2129bb91c172 60 virtual int disk_initialize();
wschon 1:2129bb91c172 61 virtual int disk_status() {return 0;};
wschon 1:2129bb91c172 62 virtual int disk_read(uint8_t * buffer, uint64_t sector);
wschon 1:2129bb91c172 63 virtual int disk_write(const uint8_t * buffer, uint64_t sector);
wschon 1:2129bb91c172 64 virtual int disk_sync() {return 0;};
wschon 1:2129bb91c172 65 virtual uint64_t disk_sectors();
wschon 1:2129bb91c172 66
wschon 1:2129bb91c172 67 private:
wschon 1:2129bb91c172 68 USBHost * host;
wschon 1:2129bb91c172 69 USBDeviceConnected * dev;
wschon 1:2129bb91c172 70 bool dev_connected;
wschon 1:2129bb91c172 71 USBEndpoint * bulk_in;
wschon 1:2129bb91c172 72 USBEndpoint * bulk_out;
wschon 1:2129bb91c172 73 uint8_t nb_ep;
wschon 1:2129bb91c172 74
wschon 1:2129bb91c172 75 // Bulk-only CBW
wschon 1:2129bb91c172 76 typedef __packed struct {
wschon 1:2129bb91c172 77 uint32_t Signature;
wschon 1:2129bb91c172 78 uint32_t Tag;
wschon 1:2129bb91c172 79 uint32_t DataLength;
wschon 1:2129bb91c172 80 uint8_t Flags;
wschon 1:2129bb91c172 81 uint8_t LUN;
wschon 1:2129bb91c172 82 uint8_t CBLength;
wschon 1:2129bb91c172 83 uint8_t CB[16];
wschon 1:2129bb91c172 84 } CBW;
wschon 1:2129bb91c172 85
wschon 1:2129bb91c172 86 // Bulk-only CSW
wschon 1:2129bb91c172 87 typedef __packed struct {
wschon 1:2129bb91c172 88 uint32_t Signature;
wschon 1:2129bb91c172 89 uint32_t Tag;
wschon 1:2129bb91c172 90 uint32_t DataResidue;
wschon 1:2129bb91c172 91 uint8_t Status;
wschon 1:2129bb91c172 92 } CSW;
wschon 1:2129bb91c172 93
wschon 1:2129bb91c172 94 CBW cbw;
wschon 1:2129bb91c172 95 CSW csw;
wschon 1:2129bb91c172 96
wschon 1:2129bb91c172 97 int SCSITransfer(uint8_t * cmd, uint8_t cmd_len, int flags, uint8_t * data, uint32_t transfer_len);
wschon 1:2129bb91c172 98 int testUnitReady();
wschon 1:2129bb91c172 99 int readCapacity();
wschon 1:2129bb91c172 100 int inquiry(uint8_t lun, uint8_t page_code);
wschon 1:2129bb91c172 101 int SCSIRequestSense();
wschon 1:2129bb91c172 102 int dataTransfer(uint8_t * buf, uint32_t block, uint8_t nbBlock, int direction);
wschon 1:2129bb91c172 103 int checkResult(uint8_t res, USBEndpoint * ep);
wschon 1:2129bb91c172 104 int getMaxLun();
wschon 1:2129bb91c172 105
wschon 1:2129bb91c172 106 int blockSize;
wschon 1:2129bb91c172 107 uint64_t blockCount;
wschon 1:2129bb91c172 108
wschon 1:2129bb91c172 109 int msd_intf;
wschon 1:2129bb91c172 110 bool msd_device_found;
wschon 1:2129bb91c172 111 bool disk_init;
wschon 1:2129bb91c172 112
wschon 1:2129bb91c172 113 void init();
wschon 1:2129bb91c172 114
wschon 1:2129bb91c172 115 };
wschon 1:2129bb91c172 116
wschon 1:2129bb91c172 117 #endif
wschon 1:2129bb91c172 118
wschon 1:2129bb91c172 119 #endif