Axeda Ready Demo for Freescale FRDM-KL46Z as accident alert system
Dependencies: FRDM_MMA8451Q KL46Z-USBHost MAG3110 SocketModem TSI mbed FATFileSystem
Fork of AxedaGo-Freescal_FRDM-KL46Z revert by
KL46Z-USBHost/USBHostMSD/USBHostMSD.h@0:65004368569c, 2014-07-01 (annotated)
- Committer:
- AxedaCorp
- Date:
- Tue Jul 01 21:31:54 2014 +0000
- Revision:
- 0:65004368569c
Made initial
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AxedaCorp | 0:65004368569c | 1 | /* mbed USBHost Library |
AxedaCorp | 0:65004368569c | 2 | * Copyright (c) 2006-2013 ARM Limited |
AxedaCorp | 0:65004368569c | 3 | * |
AxedaCorp | 0:65004368569c | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
AxedaCorp | 0:65004368569c | 5 | * you may not use this file except in compliance with the License. |
AxedaCorp | 0:65004368569c | 6 | * You may obtain a copy of the License at |
AxedaCorp | 0:65004368569c | 7 | * |
AxedaCorp | 0:65004368569c | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
AxedaCorp | 0:65004368569c | 9 | * |
AxedaCorp | 0:65004368569c | 10 | * Unless required by applicable law or agreed to in writing, software |
AxedaCorp | 0:65004368569c | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
AxedaCorp | 0:65004368569c | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
AxedaCorp | 0:65004368569c | 13 | * See the License for the specific language governing permissions and |
AxedaCorp | 0:65004368569c | 14 | * limitations under the License. |
AxedaCorp | 0:65004368569c | 15 | */ |
AxedaCorp | 0:65004368569c | 16 | |
AxedaCorp | 0:65004368569c | 17 | #ifndef USBHOSTMSD_H |
AxedaCorp | 0:65004368569c | 18 | #define USBHOSTMSD_H |
AxedaCorp | 0:65004368569c | 19 | |
AxedaCorp | 0:65004368569c | 20 | #if _USB_DBG |
AxedaCorp | 0:65004368569c | 21 | #define USB_DBG(...) do{fprintf(stderr,"[%s@%d] ",__PRETTY_FUNCTION__,__LINE__);fprintf(stderr,__VA_ARGS__);fprintf(stderr,"\r\n");} while(0); |
AxedaCorp | 0:65004368569c | 22 | #else |
AxedaCorp | 0:65004368569c | 23 | #define USB_DBG(...) while(0); |
AxedaCorp | 0:65004368569c | 24 | #endif |
AxedaCorp | 0:65004368569c | 25 | |
AxedaCorp | 0:65004368569c | 26 | #if 0 |
AxedaCorp | 0:65004368569c | 27 | #define USB_DBG2(...) do{fprintf(stderr,"[%s@%d] ",__PRETTY_FUNCTION__,__LINE__);fprintf(stderr,__VA_ARGS__);fprintf(stderr,"\r\n");} while(0); |
AxedaCorp | 0:65004368569c | 28 | #else |
AxedaCorp | 0:65004368569c | 29 | #define USB_DBG2(...) while(0); |
AxedaCorp | 0:65004368569c | 30 | #endif |
AxedaCorp | 0:65004368569c | 31 | |
AxedaCorp | 0:65004368569c | 32 | #if 1 |
AxedaCorp | 0:65004368569c | 33 | #define USB_INFO(...) do{fprintf(stderr,__VA_ARGS__);fprintf(stderr,"\r\n");}while(0); |
AxedaCorp | 0:65004368569c | 34 | #else |
AxedaCorp | 0:65004368569c | 35 | #define USB_INFO(...) while(0); |
AxedaCorp | 0:65004368569c | 36 | #endif |
AxedaCorp | 0:65004368569c | 37 | |
AxedaCorp | 0:65004368569c | 38 | #include "USBHostConf.h" |
AxedaCorp | 0:65004368569c | 39 | #include "USBHost.h" |
AxedaCorp | 0:65004368569c | 40 | #include "FATFileSystem.h" |
AxedaCorp | 0:65004368569c | 41 | |
AxedaCorp | 0:65004368569c | 42 | /** |
AxedaCorp | 0:65004368569c | 43 | * A class to communicate a USB flash disk |
AxedaCorp | 0:65004368569c | 44 | */ |
AxedaCorp | 0:65004368569c | 45 | class USBHostMSD : public IUSBEnumerator, public FATFileSystem { |
AxedaCorp | 0:65004368569c | 46 | public: |
AxedaCorp | 0:65004368569c | 47 | /** |
AxedaCorp | 0:65004368569c | 48 | * Constructor |
AxedaCorp | 0:65004368569c | 49 | * |
AxedaCorp | 0:65004368569c | 50 | * @param rootdir mount name |
AxedaCorp | 0:65004368569c | 51 | */ |
AxedaCorp | 0:65004368569c | 52 | USBHostMSD(const char * rootdir); |
AxedaCorp | 0:65004368569c | 53 | |
AxedaCorp | 0:65004368569c | 54 | /** |
AxedaCorp | 0:65004368569c | 55 | * Check if a MSD device is connected |
AxedaCorp | 0:65004368569c | 56 | * |
AxedaCorp | 0:65004368569c | 57 | * @return true if a MSD device is connected |
AxedaCorp | 0:65004368569c | 58 | */ |
AxedaCorp | 0:65004368569c | 59 | bool connected(); |
AxedaCorp | 0:65004368569c | 60 | |
AxedaCorp | 0:65004368569c | 61 | /** |
AxedaCorp | 0:65004368569c | 62 | * Try to connect to a MSD device |
AxedaCorp | 0:65004368569c | 63 | * |
AxedaCorp | 0:65004368569c | 64 | * @return true if connection was successful |
AxedaCorp | 0:65004368569c | 65 | */ |
AxedaCorp | 0:65004368569c | 66 | bool connect(); |
AxedaCorp | 0:65004368569c | 67 | |
AxedaCorp | 0:65004368569c | 68 | protected: |
AxedaCorp | 0:65004368569c | 69 | //From IUSBEnumerator |
AxedaCorp | 0:65004368569c | 70 | virtual void setVidPid(uint16_t vid, uint16_t pid); |
AxedaCorp | 0:65004368569c | 71 | 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 |
AxedaCorp | 0:65004368569c | 72 | virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used |
AxedaCorp | 0:65004368569c | 73 | |
AxedaCorp | 0:65004368569c | 74 | // From FATFileSystem |
AxedaCorp | 0:65004368569c | 75 | virtual int disk_initialize(); |
AxedaCorp | 0:65004368569c | 76 | virtual int disk_status() {return 0;}; |
AxedaCorp | 0:65004368569c | 77 | virtual int disk_read(uint8_t * buffer, uint64_t sector); |
AxedaCorp | 0:65004368569c | 78 | virtual int disk_write(const uint8_t * buffer, uint64_t sector); |
AxedaCorp | 0:65004368569c | 79 | virtual int disk_sync() {return 0;}; |
AxedaCorp | 0:65004368569c | 80 | virtual uint64_t disk_sectors(); |
AxedaCorp | 0:65004368569c | 81 | |
AxedaCorp | 0:65004368569c | 82 | private: |
AxedaCorp | 0:65004368569c | 83 | USBHost * host; |
AxedaCorp | 0:65004368569c | 84 | USBDeviceConnected * dev; |
AxedaCorp | 0:65004368569c | 85 | bool dev_connected; |
AxedaCorp | 0:65004368569c | 86 | USBEndpoint * bulk_in; |
AxedaCorp | 0:65004368569c | 87 | USBEndpoint * bulk_out; |
AxedaCorp | 0:65004368569c | 88 | uint8_t nb_ep; |
AxedaCorp | 0:65004368569c | 89 | |
AxedaCorp | 0:65004368569c | 90 | // Bulk-only CBW |
AxedaCorp | 0:65004368569c | 91 | typedef __packed struct { |
AxedaCorp | 0:65004368569c | 92 | uint32_t Signature; |
AxedaCorp | 0:65004368569c | 93 | uint32_t Tag; |
AxedaCorp | 0:65004368569c | 94 | uint32_t DataLength; |
AxedaCorp | 0:65004368569c | 95 | uint8_t Flags; |
AxedaCorp | 0:65004368569c | 96 | uint8_t LUN; |
AxedaCorp | 0:65004368569c | 97 | uint8_t CBLength; |
AxedaCorp | 0:65004368569c | 98 | uint8_t CB[16]; |
AxedaCorp | 0:65004368569c | 99 | } CBW; |
AxedaCorp | 0:65004368569c | 100 | |
AxedaCorp | 0:65004368569c | 101 | // Bulk-only CSW |
AxedaCorp | 0:65004368569c | 102 | typedef __packed struct { |
AxedaCorp | 0:65004368569c | 103 | uint32_t Signature; |
AxedaCorp | 0:65004368569c | 104 | uint32_t Tag; |
AxedaCorp | 0:65004368569c | 105 | uint32_t DataResidue; |
AxedaCorp | 0:65004368569c | 106 | uint8_t Status; |
AxedaCorp | 0:65004368569c | 107 | } CSW; |
AxedaCorp | 0:65004368569c | 108 | |
AxedaCorp | 0:65004368569c | 109 | CBW cbw; |
AxedaCorp | 0:65004368569c | 110 | CSW csw; |
AxedaCorp | 0:65004368569c | 111 | |
AxedaCorp | 0:65004368569c | 112 | int SCSITransfer(uint8_t * cmd, uint8_t cmd_len, int flags, uint8_t * data, uint32_t transfer_len); |
AxedaCorp | 0:65004368569c | 113 | int testUnitReady(); |
AxedaCorp | 0:65004368569c | 114 | int readCapacity(); |
AxedaCorp | 0:65004368569c | 115 | int inquiry(uint8_t lun, uint8_t page_code); |
AxedaCorp | 0:65004368569c | 116 | int SCSIRequestSense(); |
AxedaCorp | 0:65004368569c | 117 | int dataTransfer(uint8_t * buf, uint32_t block, uint8_t nbBlock, int direction); |
AxedaCorp | 0:65004368569c | 118 | int checkResult(uint8_t res, USBEndpoint * ep); |
AxedaCorp | 0:65004368569c | 119 | int getMaxLun(); |
AxedaCorp | 0:65004368569c | 120 | |
AxedaCorp | 0:65004368569c | 121 | int blockSize; |
AxedaCorp | 0:65004368569c | 122 | uint64_t blockCount; |
AxedaCorp | 0:65004368569c | 123 | |
AxedaCorp | 0:65004368569c | 124 | int msd_intf; |
AxedaCorp | 0:65004368569c | 125 | bool msd_device_found; |
AxedaCorp | 0:65004368569c | 126 | bool disk_init; |
AxedaCorp | 0:65004368569c | 127 | |
AxedaCorp | 0:65004368569c | 128 | void init(); |
AxedaCorp | 0:65004368569c | 129 | }; |
AxedaCorp | 0:65004368569c | 130 | |
AxedaCorp | 0:65004368569c | 131 | #endif |