Il y avait des problèmes dans la libraire...

Fork of USBDEVICE by ST

Committer:
qroche
Date:
Sun Sep 03 23:19:21 2017 +0000
Branch:
master
Revision:
5:3329e56e51d7
Parent:
1:2a3ae13b45ef
fin;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 2 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 4 * and associated documentation files (the "Software"), to deal in the Software without
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 7 * Software is furnished to do so, subject to the following conditions:
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 8 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 9 * The above copyright notice and this permission notice shall be included in all copies or
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 10 * substantial portions of the Software.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 11 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 17 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 18
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 19
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 20 #ifndef USBMSD_H
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 21 #define USBMSD_H
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 22
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 23 /* These headers are included for child class. */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 24 #include "USBEndpoints.h"
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 25 #include "USBDescriptor.h"
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 26 #include "USBDevice_Types.h"
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 27
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 28 #include "USBDevice.h"
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 29
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 30 /**
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 31 * USBMSD class: generic class in order to use all kinds of blocks storage chip
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 32 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 33 * Introduction
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 34 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 35 * The USBMSD implements the MSD protocol. It permits to access a memory chip (flash, sdcard,...)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 36 * from a computer over USB. But this class doesn't work standalone, you need to subclass this class
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 37 * and define virtual functions which are called in USBMSD.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 38 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 39 * How to use this class with your chip ?
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 40 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 41 * You have to inherit and define some pure virtual functions (mandatory step):
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 42 * - virtual int disk_read(char * data, int block): function to read a block
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 43 * - virtual int disk_write(const char * data, int block): function to write a block
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 44 * - virtual int disk_initialize(): function to initialize the memory
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 45 * - virtual int disk_sectors(): return the number of blocks
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 46 * - virtual int disk_size(): return the memory size
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 47 * - virtual int disk_status(): return the status of the storage chip (0: OK, 1: not initialized, 2: no medium in the drive, 4: write protection)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 48 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 49 * All functions names are compatible with the fat filesystem library. So you can imagine using your own class with
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 50 * USBMSD and the fat filesystem library in the same program. Just be careful because there are two different parts which
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 51 * will access the sd card. You can do a master/slave system using the disk_status method.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 52 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 53 * Once these functions defined, you can call connect() (at the end of the constructor of your class for instance)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 54 * of USBMSD to connect your mass storage device. connect() will first call disk_status() to test the status of the disk.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 55 * If disk_status() returns 1 (disk not initialized), then disk_initialize() is called. After this step, connect() will collect information
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 56 * such as the number of blocks and the memory size.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 57 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 58 class USBMSD: public USBDevice {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 59 public:
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 60
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 61 /**
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 62 * Constructor
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 63 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 64 * @param vendor_id Your vendor_id
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 65 * @param product_id Your product_id
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 66 * @param product_release Your preoduct_release
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 67 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 68 USBMSD(uint16_t vendor_id = 0x0703, uint16_t product_id = 0x0104, uint16_t product_release = 0x0001);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 69
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 70 /**
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 71 * Connect the USB MSD device. Establish disk initialization before really connect the device.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 72 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 73 * @param blocking if not configured
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 74 * @returns true if successful
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 75 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 76 bool connect(bool blocking = true);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 77
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 78 /**
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 79 * Disconnect the USB MSD device.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 80 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 81 void disconnect();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 82
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 83 /**
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 84 * Destructor
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 85 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 86 ~USBMSD();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 87
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 88 protected:
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 89
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 90 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 91 * read one or more blocks on a storage chip
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 92 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 93 * @param data pointer where will be stored read data
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 94 * @param block starting block number
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 95 * @param count number of blocks to read
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 96 * @returns 0 if successful
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 97 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 98 virtual int disk_read(uint8_t* data, uint64_t block, uint8_t count) = 0;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 99
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 100 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 101 * write one or more blocks on a storage chip
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 102 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 103 * @param data data to write
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 104 * @param block starting block number
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 105 * @param count number of blocks to write
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 106 * @returns 0 if successful
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 107 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 108 virtual int disk_write(const uint8_t* data, uint64_t block, uint8_t count) = 0;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 109
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 110 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 111 * Disk initilization
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 112 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 113 virtual int disk_initialize() = 0;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 114
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 115 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 116 * Return the number of blocks
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 117 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 118 * @returns number of blocks
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 119 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 120 virtual uint64_t disk_sectors() = 0;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 121
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 122 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 123 * Return memory size
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 124 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 125 * @returns memory size
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 126 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 127 virtual uint64_t disk_size() = 0;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 128
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 129
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 130 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 131 * To check the status of the storage chip
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 132 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 133 * @returns status: 0: OK, 1: disk not initialized, 2: no medium in the drive, 4: write protected
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 134 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 135 virtual int disk_status() = 0;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 136
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 137 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 138 * Get string product descriptor
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 139 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 140 * @returns pointer to the string product descriptor
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 141 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 142 virtual uint8_t * stringIproductDesc();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 143
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 144 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 145 * Get string interface descriptor
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 146 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 147 * @returns pointer to the string interface descriptor
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 148 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 149 virtual uint8_t * stringIinterfaceDesc();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 150
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 151 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 152 * Get configuration descriptor
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 153 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 154 * @returns pointer to the configuration descriptor
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 155 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 156 virtual uint8_t * configurationDesc();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 157
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 158 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 159 * Callback called when a packet is received
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 160 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 161 virtual bool EPBULK_OUT_callback();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 162
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 163 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 164 * Callback called when a packet has been sent
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 165 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 166 virtual bool EPBULK_IN_callback();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 167
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 168 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 169 * Set configuration of device. Add endpoints
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 170 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 171 virtual bool USBCallback_setConfiguration(uint8_t configuration);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 172
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 173 /*
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 174 * Callback called to process class specific requests
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 175 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 176 virtual bool USBCallback_request();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 177
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 178
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 179 private:
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 180
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 181 // MSC Bulk-only Stage
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 182 enum Stage {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 183 READ_CBW, // wait a CBW
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 184 ERROR, // error
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 185 PROCESS_CBW, // process a CBW request
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 186 SEND_CSW, // send a CSW
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 187 WAIT_CSW, // wait that a CSW has been effectively sent
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 188 };
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 189
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 190 // Bulk-only CBW
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 191 typedef struct {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 192 uint32_t Signature;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 193 uint32_t Tag;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 194 uint32_t DataLength;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 195 uint8_t Flags;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 196 uint8_t LUN;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 197 uint8_t CBLength;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 198 uint8_t CB[16];
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 199 } PACKED CBW;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 200
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 201 // Bulk-only CSW
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 202 typedef struct {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 203 uint32_t Signature;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 204 uint32_t Tag;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 205 uint32_t DataResidue;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 206 uint8_t Status;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 207 } PACKED CSW;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 208
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 209 //state of the bulk-only state machine
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 210 Stage stage;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 211
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 212 // current CBW
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 213 CBW cbw;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 214
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 215 // CSW which will be sent
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 216 CSW csw;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 217
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 218 // addr where will be read or written data
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 219 uint32_t addr;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 220
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 221 // length of a reading or writing
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 222 uint32_t length;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 223
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 224 // memory OK (after a memoryVerify)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 225 bool memOK;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 226
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 227 // cache in RAM before writing in memory. Useful also to read a block.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 228 uint8_t * page;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 229
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 230 int BlockSize;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 231 uint64_t MemorySize;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 232 uint64_t BlockCount;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 233
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 234 void CBWDecode(uint8_t * buf, uint16_t size);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 235 void sendCSW (void);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 236 bool inquiryRequest (void);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 237 bool write (uint8_t * buf, uint16_t size);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 238 bool readFormatCapacity();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 239 bool readCapacity (void);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 240 bool infoTransfer (void);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 241 void memoryRead (void);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 242 bool modeSense6 (void);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 243 void testUnitReady (void);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 244 bool requestSense (void);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 245 void memoryVerify (uint8_t * buf, uint16_t size);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 246 void memoryWrite (uint8_t * buf, uint16_t size);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 247 void reset();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 248 void fail();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 249 };
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 250
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 251 #endif