Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame^] | 1 | /* ---------------------------------------------------------------------------- |
| 2 | * ATMEL Microcontroller Software Support |
| 3 | * ---------------------------------------------------------------------------- |
| 4 | * Copyright (c) 2008, Atmel Corporation |
| 5 | * |
| 6 | * All rights reserved. |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions are met: |
| 10 | * |
| 11 | * - Redistributions of source code must retain the above copyright notice, |
| 12 | * this list of conditions and the disclaimer below. |
| 13 | * |
| 14 | * Atmel's name may not be used to endorse or promote products derived from |
| 15 | * this software without specific prior written permission. |
| 16 | * |
| 17 | * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR |
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE |
| 20 | * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, |
| 23 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 24 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 25 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
| 26 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | * ---------------------------------------------------------------------------- |
| 28 | */ |
| 29 | |
| 30 | /** \file |
| 31 | * \section Purpose |
| 32 | * |
| 33 | * Logical Unit Number (LUN) used by the Mass Storage driver and the SCSI |
| 34 | * protocol. Represents a logical hard-drive. |
| 35 | * |
| 36 | * \section Usage |
| 37 | * -# Initialize Memory related pins (see pio & board.h). |
| 38 | * -# Initialize a Media instance for the LUN (see memories). |
| 39 | * -# Initlalize the LUN with LUN_Init, and link to the initialized Media. |
| 40 | * -# To read data from the LUN linked media, uses LUN_Read. |
| 41 | * -# To write data to the LUN linked media, uses LUN_Write. |
| 42 | * -# To unlink the media, uses LUN_Eject. |
| 43 | */ |
| 44 | |
| 45 | #ifndef MSDLUN_H |
| 46 | #define MSDLUN_H |
| 47 | |
| 48 | /** \addtogroup usbd_msd |
| 49 | *@{ |
| 50 | */ |
| 51 | |
| 52 | /*------------------------------------------------------------------------------ |
| 53 | * Headers |
| 54 | *------------------------------------------------------------------------------*/ |
| 55 | |
| 56 | #include <stdint.h> |
| 57 | #include "memories.h" |
| 58 | |
| 59 | #include "SBC.h" |
| 60 | #include "MSDIOFifo.h" |
| 61 | #include "USBD.h" |
| 62 | |
| 63 | /*------------------------------------------------------------------------------ |
| 64 | * Definitions |
| 65 | *------------------------------------------------------------------------------*/ |
| 66 | |
| 67 | /** LUN RC: success */ |
| 68 | #define LUN_STATUS_SUCCESS 0x00 |
| 69 | /** LUN RC: error */ |
| 70 | #define LUN_STATUS_ERROR 0x02 |
| 71 | |
| 72 | /** Media of LUN is removed */ |
| 73 | #define LUN_NOT_PRESENT 0x00 |
| 74 | /** LUN is ejected by host */ |
| 75 | #define LUN_EJECTED 0x01 |
| 76 | /** Media of LUN is changed */ |
| 77 | #define LUN_CHANGED 0x10 |
| 78 | /** LUN Not Ready to Ready transition */ |
| 79 | #define LUN_TRANS_READY LUN_CHANGED |
| 80 | /** Media of LUN is ready */ |
| 81 | #define LUN_READY 0x11 |
| 82 | |
| 83 | /*------------------------------------------------------------------------------ |
| 84 | * Types |
| 85 | *------------------------------------------------------------------------------*/ |
| 86 | |
| 87 | /** Mass storage device data flow monitor function type |
| 88 | * \param flowDirection 1 - device to host (READ10) |
| 89 | * 0 - host to device (WRITE10) |
| 90 | * \param dataLength Length of data transferred in bytes. |
| 91 | * \param fifoNullCount Times that FIFO is NULL to wait |
| 92 | * \param fifoFullCount Times that FIFO is filled to wait |
| 93 | */ |
| 94 | typedef void(*MSDLunDataMonitorFunction)(uint8_t flowDirection, |
| 95 | uint32_t dataLength, |
| 96 | uint32_t fifoNullCount, |
| 97 | uint32_t fifoFullCount); |
| 98 | |
| 99 | /*------------------------------------------------------------------------------ |
| 100 | * Structures |
| 101 | *------------------------------------------------------------------------------*/ |
| 102 | |
| 103 | /** \brief LUN structure */ |
| 104 | typedef struct { |
| 105 | |
| 106 | /** Pointer to a SBCInquiryData instance. */ |
| 107 | SBCInquiryData *inquiryData; |
| 108 | /** Fifo for USB transfer, must be assigned. */ |
| 109 | MSDIOFifo ioFifo; |
| 110 | /** Pointer to Media instance for the LUN. */ |
| 111 | Media *media; |
| 112 | /** Pointer to a Monitor Function to analyze the flow of LUN. |
| 113 | * \param flowDirection 1 - device to host (READ10) |
| 114 | * 0 - host to device (WRITE10) |
| 115 | * \param dataLength Length of data transferred in bytes. |
| 116 | * \param fifoNullCount Times that FIFO is NULL to wait |
| 117 | * \param fifoFullCount Times that FIFO is filled to wait |
| 118 | */ |
| 119 | void (*dataMonitor)(uint8_t flowDirection, |
| 120 | uint32_t dataLength, |
| 121 | uint32_t fifoNullCount, |
| 122 | uint32_t fifoFullCount); |
| 123 | /** The start position of the media (blocks) allocated to the LUN. */ |
| 124 | uint32_t baseAddress; |
| 125 | /** The size of the media (blocks) allocated to the LUN. */ |
| 126 | uint32_t size; |
| 127 | /** Sector size of the media in number of media blocks */ |
| 128 | uint16_t blockSize; |
| 129 | /** The LUN can be readonly even the media is writable */ |
| 130 | uint8_t protected; |
| 131 | /** The LUN status (Ejected/Changed/) */ |
| 132 | uint8_t status; |
| 133 | |
| 134 | /** Data for the RequestSense command. */ |
| 135 | SBCRequestSenseData requestSenseData; |
| 136 | /** Data for the ReadCapacity command. */ |
| 137 | SBCReadCapacity10Data readCapacityData; |
| 138 | |
| 139 | } MSDLun; |
| 140 | |
| 141 | /*------------------------------------------------------------------------------ |
| 142 | * Exported functions |
| 143 | *------------------------------------------------------------------------------*/ |
| 144 | extern void LUN_Init(MSDLun *lun, |
| 145 | Media *media, |
| 146 | uint8_t *ioBuffer, |
| 147 | uint32_t ioBufferSize, |
| 148 | uint32_t baseAddress, |
| 149 | uint32_t size, |
| 150 | uint16_t blockSize, |
| 151 | uint8_t protected, |
| 152 | void (*dataMonitor)(uint8_t flowDirection, |
| 153 | uint32_t dataLength, |
| 154 | uint32_t fifoNullCount, |
| 155 | uint32_t fifoFullCount)); |
| 156 | |
| 157 | extern uint32_t LUN_Eject(MSDLun *lun); |
| 158 | |
| 159 | extern uint32_t LUN_Write(MSDLun *lun, |
| 160 | uint32_t blockAddress, |
| 161 | void *data, |
| 162 | uint32_t length, |
| 163 | TransferCallback callback, |
| 164 | void *argument); |
| 165 | |
| 166 | extern uint32_t LUN_Read(MSDLun *lun, |
| 167 | uint32_t blockAddress, |
| 168 | void *data, |
| 169 | uint32_t length, |
| 170 | TransferCallback callback, |
| 171 | void *argument); |
| 172 | |
| 173 | /**@}*/ |
| 174 | |
| 175 | #endif /*#ifndef MSDLUN_H */ |
| 176 | |