RAMDisk example for the USBFileSystem

Dependencies:   mbed USBFileSystem

Fork of USBFileSystem_RAMDISK_HelloWorld by Erik -

Committer:
Sissors
Date:
Tue Jul 30 18:27:18 2013 +0000
Revision:
1:e1b0157ce547
Memory leaks -_-

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Sissors 1:e1b0157ce547 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
Sissors 1:e1b0157ce547 2 *
Sissors 1:e1b0157ce547 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
Sissors 1:e1b0157ce547 4 * and associated documentation files (the "Software"), to deal in the Software without
Sissors 1:e1b0157ce547 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
Sissors 1:e1b0157ce547 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
Sissors 1:e1b0157ce547 7 * Software is furnished to do so, subject to the following conditions:
Sissors 1:e1b0157ce547 8 *
Sissors 1:e1b0157ce547 9 * The above copyright notice and this permission notice shall be included in all copies or
Sissors 1:e1b0157ce547 10 * substantial portions of the Software.
Sissors 1:e1b0157ce547 11 *
Sissors 1:e1b0157ce547 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
Sissors 1:e1b0157ce547 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Sissors 1:e1b0157ce547 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
Sissors 1:e1b0157ce547 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Sissors 1:e1b0157ce547 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Sissors 1:e1b0157ce547 17 */
Sissors 1:e1b0157ce547 18
Sissors 1:e1b0157ce547 19 #ifndef USBDEVICE_TYPES_H
Sissors 1:e1b0157ce547 20 #define USBDEVICE_TYPES_H
Sissors 1:e1b0157ce547 21
Sissors 1:e1b0157ce547 22 /* Standard requests */
Sissors 1:e1b0157ce547 23 #define GET_STATUS (0)
Sissors 1:e1b0157ce547 24 #define CLEAR_FEATURE (1)
Sissors 1:e1b0157ce547 25 #define SET_FEATURE (3)
Sissors 1:e1b0157ce547 26 #define SET_ADDRESS (5)
Sissors 1:e1b0157ce547 27 #define GET_DESCRIPTOR (6)
Sissors 1:e1b0157ce547 28 #define SET_DESCRIPTOR (7)
Sissors 1:e1b0157ce547 29 #define GET_CONFIGURATION (8)
Sissors 1:e1b0157ce547 30 #define SET_CONFIGURATION (9)
Sissors 1:e1b0157ce547 31 #define GET_INTERFACE (10)
Sissors 1:e1b0157ce547 32 #define SET_INTERFACE (11)
Sissors 1:e1b0157ce547 33
Sissors 1:e1b0157ce547 34 /* bmRequestType.dataTransferDirection */
Sissors 1:e1b0157ce547 35 #define HOST_TO_DEVICE (0)
Sissors 1:e1b0157ce547 36 #define DEVICE_TO_HOST (1)
Sissors 1:e1b0157ce547 37
Sissors 1:e1b0157ce547 38 /* bmRequestType.Type*/
Sissors 1:e1b0157ce547 39 #define STANDARD_TYPE (0)
Sissors 1:e1b0157ce547 40 #define CLASS_TYPE (1)
Sissors 1:e1b0157ce547 41 #define VENDOR_TYPE (2)
Sissors 1:e1b0157ce547 42 #define RESERVED_TYPE (3)
Sissors 1:e1b0157ce547 43
Sissors 1:e1b0157ce547 44 /* bmRequestType.Recipient */
Sissors 1:e1b0157ce547 45 #define DEVICE_RECIPIENT (0)
Sissors 1:e1b0157ce547 46 #define INTERFACE_RECIPIENT (1)
Sissors 1:e1b0157ce547 47 #define ENDPOINT_RECIPIENT (2)
Sissors 1:e1b0157ce547 48 #define OTHER_RECIPIENT (3)
Sissors 1:e1b0157ce547 49
Sissors 1:e1b0157ce547 50 /* Descriptors */
Sissors 1:e1b0157ce547 51 #define DESCRIPTOR_TYPE(wValue) (wValue >> 8)
Sissors 1:e1b0157ce547 52 #define DESCRIPTOR_INDEX(wValue) (wValue & 0xf)
Sissors 1:e1b0157ce547 53
Sissors 1:e1b0157ce547 54 typedef struct {
Sissors 1:e1b0157ce547 55 struct {
Sissors 1:e1b0157ce547 56 uint8_t dataTransferDirection;
Sissors 1:e1b0157ce547 57 uint8_t Type;
Sissors 1:e1b0157ce547 58 uint8_t Recipient;
Sissors 1:e1b0157ce547 59 } bmRequestType;
Sissors 1:e1b0157ce547 60 uint8_t bRequest;
Sissors 1:e1b0157ce547 61 uint16_t wValue;
Sissors 1:e1b0157ce547 62 uint16_t wIndex;
Sissors 1:e1b0157ce547 63 uint16_t wLength;
Sissors 1:e1b0157ce547 64 } SETUP_PACKET;
Sissors 1:e1b0157ce547 65
Sissors 1:e1b0157ce547 66 typedef struct {
Sissors 1:e1b0157ce547 67 SETUP_PACKET setup;
Sissors 1:e1b0157ce547 68 uint8_t *ptr;
Sissors 1:e1b0157ce547 69 uint32_t remaining;
Sissors 1:e1b0157ce547 70 uint8_t direction;
Sissors 1:e1b0157ce547 71 bool zlp;
Sissors 1:e1b0157ce547 72 bool notify;
Sissors 1:e1b0157ce547 73 } CONTROL_TRANSFER;
Sissors 1:e1b0157ce547 74
Sissors 1:e1b0157ce547 75 typedef enum {ATTACHED, POWERED, DEFAULT, ADDRESS, CONFIGURED} DEVICE_STATE;
Sissors 1:e1b0157ce547 76
Sissors 1:e1b0157ce547 77 typedef struct {
Sissors 1:e1b0157ce547 78 volatile DEVICE_STATE state;
Sissors 1:e1b0157ce547 79 uint8_t configuration;
Sissors 1:e1b0157ce547 80 bool suspended;
Sissors 1:e1b0157ce547 81 } USB_DEVICE;
Sissors 1:e1b0157ce547 82
Sissors 1:e1b0157ce547 83 #endif