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 | #ifndef _MSDIOFIFO_H |
| 31 | #define _MSDIOFIFO_H |
| 32 | |
| 33 | /** \file |
| 34 | * \addtogroup usbd_msd |
| 35 | *@{ |
| 36 | */ |
| 37 | |
| 38 | /*------------------------------------------------------------------------------ |
| 39 | * Headers |
| 40 | *------------------------------------------------------------------------------*/ |
| 41 | |
| 42 | /*------------------------------------------------------------------------------ |
| 43 | * Definitions |
| 44 | *------------------------------------------------------------------------------*/ |
| 45 | |
| 46 | /** Idle state, do nothing */ |
| 47 | #define MSDIO_IDLE 0 |
| 48 | /** Start, to start IO operation */ |
| 49 | #define MSDIO_START 1 |
| 50 | /** Wait, waiting for IO operation done */ |
| 51 | #define MSDIO_WAIT 2 |
| 52 | /** Next, to check if the next block can be performed */ |
| 53 | #define MSDIO_NEXT 3 |
| 54 | /** Pause, to pause the process for buffer full or null */ |
| 55 | #define MSDIO_PAUSE 4 |
| 56 | /** Abort, to abort the process */ |
| 57 | #define MSDIO_ABORT 5 |
| 58 | /** Done, finish without error */ |
| 59 | #define MSDIO_DONE 6 |
| 60 | /** Error, any error happens */ |
| 61 | #define MSDIO_ERROR 7 |
| 62 | |
| 63 | /** FIFO offset before USB transmit start */ |
| 64 | /*#define MSDIO_FIFO_OFFSET (4*512) */ |
| 65 | |
| 66 | |
| 67 | /** FIFO trunk size (in each transfer, large amount of data) */ |
| 68 | #if !defined(MSD_OP_BUFFER) |
| 69 | #define MSDIO_READ10_CHUNK_SIZE (4*512) |
| 70 | #define MSDIO_WRITE10_CHUNK_SIZE (4*512) |
| 71 | #endif |
| 72 | |
| 73 | /*------------------------------------------------------------------------------ |
| 74 | * Types |
| 75 | *------------------------------------------------------------------------------*/ |
| 76 | |
| 77 | /** \brief FIFO buffer for READ/WRITE (disk) operation of a mass storage device */ |
| 78 | typedef struct _MSDIOFifo { |
| 79 | |
| 80 | /** Pointer to the ring buffer allocated for read/write */ |
| 81 | unsigned char * pBuffer; |
| 82 | /** The size of the buffer allocated */ |
| 83 | unsigned int bufferSize; |
| 84 | #ifdef MSDIO_FIFO_OFFSET |
| 85 | /** The offset to start USB transfer (READ10) */ |
| 86 | unsigned int bufferOffset; |
| 87 | #endif |
| 88 | /** The index of input data (loaded to fifo buffer) */ |
| 89 | unsigned int inputNdx; |
| 90 | /** The total size of the loaded data */ |
| 91 | unsigned int inputTotal; |
| 92 | /** The index of output data (sent from the fifo buffer) */ |
| 93 | unsigned int outputNdx; |
| 94 | /** The total size of the output data */ |
| 95 | unsigned int outputTotal; |
| 96 | |
| 97 | /** The total size of the data */ |
| 98 | unsigned int dataTotal; |
| 99 | /** The size of the block in bytes */ |
| 100 | unsigned short blockSize; |
| 101 | #if defined(MSDIO_READ10_CHUNK_SIZE) || defined(MSDIO_WRITE10_CHUNK_SIZE) |
| 102 | /** The size of one chunk */ |
| 103 | /** (1 block, or several blocks for large amount data R/W) */ |
| 104 | unsigned int chunkSize; |
| 105 | #endif |
| 106 | /** State of input & output */ |
| 107 | unsigned char inputState; |
| 108 | unsigned char outputState; |
| 109 | |
| 110 | /*- Statistics */ |
| 111 | |
| 112 | /** Times when fifo has no data to send */ |
| 113 | unsigned short nullCnt; |
| 114 | /** Times when fifo can not load more input data */ |
| 115 | unsigned short fullCnt; |
| 116 | } MSDIOFifo, *PMSDIOFifo; |
| 117 | |
| 118 | /*------------------------------------------------------------------------------ |
| 119 | * MACROS |
| 120 | *------------------------------------------------------------------------------*/ |
| 121 | |
| 122 | /*------------------------------------------------------------------------------ |
| 123 | * Increase the index, by defined block size, in the ring buffer |
| 124 | * \param ndx The index to be increased |
| 125 | * \param sectSize The defined block size |
| 126 | * \param bufSize The ring buffer size |
| 127 | *------------------------------------------------------------------------------*/ |
| 128 | #define MSDIOFifo_IncNdx(ndx, sectSize, bufSize) \ |
| 129 | if ((ndx) >= (bufSize) - (sectSize)) (ndx) = 0; \ |
| 130 | else (ndx) += (sectSize) |
| 131 | |
| 132 | |
| 133 | /*------------------------------------------------------------------------------ |
| 134 | * Exported Functions |
| 135 | *------------------------------------------------------------------------------*/ |
| 136 | |
| 137 | |
| 138 | extern void MSDIOFifo_Init(MSDIOFifo *pFifo, |
| 139 | void * pBuffer, unsigned short bufferSize); |
| 140 | |
| 141 | /**@}*/ |
| 142 | |
| 143 | #endif /* _MSDIOFIFO_H */ |
| 144 | |
| 145 | |