SAMV71 Xplained Ultra Software Package 1.3

MSDIOFifo.h

Go to the documentation of this file.
00001 /* ----------------------------------------------------------------------------
00002  *         SAM Software Package License 
00003  * ----------------------------------------------------------------------------
00004  * Copyright (c) 2014, Atmel Corporation
00005  *
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions are met:
00010  *
00011  * - Redistributions of source code must retain the above copyright notice,
00012  * this list of conditions and the disclaimer below.
00013  *
00014  * Atmel's name may not be used to endorse or promote products derived from
00015  * this software without specific prior written permission.
00016  *
00017  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00019  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
00020  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00022  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00023  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00024  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00025  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
00026  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  * ----------------------------------------------------------------------------
00028  */
00029 
00030 #ifndef _MSDIOFIFO_H
00031 #define _MSDIOFIFO_H
00032 
00033 /** \file
00034  * \addtogroup usbd_msd
00035  *@{
00036  */
00037 
00038 /*------------------------------------------------------------------------------
00039  *         Headers
00040  *------------------------------------------------------------------------------*/
00041 
00042 /*------------------------------------------------------------------------------
00043  *         Definitions
00044  *------------------------------------------------------------------------------*/
00045 
00046 /** Idle state, do nothing */
00047 #define MSDIO_IDLE          0
00048 /** Start, to start IO operation */
00049 #define MSDIO_START         1
00050 /** Wait, waiting for IO operation done */
00051 #define MSDIO_WAIT          2
00052 /** Next, to check if the next block can be performed */
00053 #define MSDIO_NEXT          3
00054 /** Pause, to pause the process for buffer full or null */
00055 #define MSDIO_PAUSE         4
00056 /** Abort, to abort the process */
00057 #define MSDIO_ABORT         5
00058 /** Done, finish without error */
00059 #define MSDIO_DONE          6
00060 /** Error, any error happens */
00061 #define MSDIO_ERROR         7
00062 
00063 /** FIFO offset before USB transmit start */
00064 /*#define MSDIO_FIFO_OFFSET   (4*512) */
00065 
00066 
00067 /** FIFO trunk size (in each transfer, large amount of data) */
00068 #if !defined(MSD_OP_BUFFER)
00069 #define MSDIO_READ10_CHUNK_SIZE     (32 * 512)
00070 #define MSDIO_WRITE10_CHUNK_SIZE    (32 * 512)
00071 #endif
00072 
00073 /*------------------------------------------------------------------------------
00074  *         Types
00075  *------------------------------------------------------------------------------*/
00076 
00077 /** \brief FIFO buffer for READ/WRITE (disk) operation of a mass storage device */
00078 typedef struct _MSDIOFifo {
00079 
00080     /** Pointer to the ring buffer allocated for read/write */
00081     unsigned char * pBuffer;
00082     /** The size of the buffer allocated */
00083     unsigned int    bufferSize;
00084 #ifdef MSDIO_FIFO_OFFSET
00085     /** The offset to start USB transfer (READ10) */
00086     unsigned int    bufferOffset;
00087 #endif
00088     /** The index of input data (loaded to fifo buffer) */
00089     unsigned int    inputNdx;
00090     /** The total size of the loaded data */
00091     unsigned int    inputTotal;
00092     /** The index of output data (sent from the fifo buffer) */
00093     unsigned int    outputNdx;
00094     /** The total size of the output data */
00095     unsigned int    outputTotal;
00096 
00097     /** The total size of the data */
00098     unsigned int    dataTotal;
00099     /** The size of the block in bytes */
00100     unsigned short  blockSize;
00101 #if  defined(MSDIO_READ10_CHUNK_SIZE) || defined(MSDIO_WRITE10_CHUNK_SIZE)
00102     /** The size of one chunk */
00103     /** (1 block, or several blocks for large amount data R/W) */
00104     unsigned int    chunkSize;
00105 #endif
00106     /** State of input & output */
00107     unsigned char   inputState;
00108     unsigned char   outputState;
00109 
00110     /*- Statistics */
00111 
00112     /** Times when fifo has no data to send */
00113     unsigned short  nullCnt;
00114     /** Times when fifo can not load more input data */
00115     unsigned short  fullCnt;
00116 } MSDIOFifo, *PMSDIOFifo;
00117 
00118 /*------------------------------------------------------------------------------
00119  *         MACROS
00120  *------------------------------------------------------------------------------*/
00121 
00122 /*------------------------------------------------------------------------------
00123  * Increase the index, by defined block size, in the ring buffer
00124  * \param ndx          The index to be increased
00125  * \param sectSize     The defined block size
00126  * \param bufSize      The ring buffer size
00127  *------------------------------------------------------------------------------*/
00128 #define MSDIOFifo_IncNdx(ndx, sectSize, bufSize) \
00129     if ((ndx) >= (bufSize) - (sectSize)) (ndx) = 0; \
00130     else (ndx) += (sectSize)
00131 
00132 
00133 /*------------------------------------------------------------------------------
00134  *         Exported Functions
00135  *------------------------------------------------------------------------------*/
00136 
00137 
00138 extern void MSDIOFifo_Init(MSDIOFifo *pFifo,
00139                            void * pBuffer, unsigned short bufferSize);
00140 
00141 /**@}*/
00142 
00143 #endif /* _MSDIOFIFO_H */
00144 
00145 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines