SAMV71 Xplained Ultra Software Package 1.5

Media.h

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------- */
00002 /*                  Atmel Microcontroller Software Support                      */
00003 /*                       SAM Software Package License                           */
00004 /* ---------------------------------------------------------------------------- */
00005 /* Copyright (c) 2015, Atmel Corporation                                        */
00006 /*                                                                              */
00007 /* All rights reserved.                                                         */
00008 /*                                                                              */
00009 /* Redistribution and use in source and binary forms, with or without           */
00010 /* modification, are permitted provided that the following condition is met:    */
00011 /*                                                                              */
00012 /* - Redistributions of source code must retain the above copyright notice,     */
00013 /* this list of conditions and the disclaimer below.                            */
00014 /*                                                                              */
00015 /* Atmel's name may not be used to endorse or promote products derived from     */
00016 /* this software without specific prior written permission.                     */
00017 /*                                                                              */
00018 /* DISCLAIMER:  THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR   */
00019 /* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
00020 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE   */
00021 /* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,      */
00022 /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */
00023 /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,  */
00024 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    */
00025 /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING         */
00026 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
00027 /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                           */
00028 /* ---------------------------------------------------------------------------- */
00029 
00030 /**
00031  * \file
00032  *
00033  *  \unit
00034  *  \section Purpose
00035  *
00036  *  Generic Media type, which provides transparent access to all types of
00037  *  memories.
00038  *
00039  *  \note The physical or HW related media operations (physical device
00040  *        connection & protection detecting, PIO configurations and interface
00041  *        driver initialization) are excluded.
00042  *
00043  *  \section Usage
00044  *  -# Do PIO initialization for peripheral interfaces.
00045  *  -# Initialize peripheral interface driver & device driver.
00046  *  -# Initialize specific media interface and link to this initialized driver.
00047  *
00048  */
00049 
00050 #ifndef _MEDIA_
00051 #define _MEDIA_
00052 
00053 #include <stdint.h>
00054 
00055 /*------------------------------------------------------------------------------
00056  *      Definitions
00057  *------------------------------------------------------------------------------*/
00058 
00059 /**
00060  *  \brief  Operation result code returned by media methods
00061  */
00062 #define MED_STATUS_SUCCESS      0x00    /** Operation success */
00063 #define MED_STATUS_ERROR        0x01    /** Operation error */
00064 #define MED_STATUS_BUSY         0x02    /** Failed because media is busy */
00065 #define MED_STATUS_PROTECTED    0x04    /** Write failed because of WP */
00066 
00067 /**
00068  *  \brief Media statuses
00069  */
00070 #define MED_STATE_NOT_READY     0xFF     /** Media is not connected */
00071 #define MED_STATE_READY         0x00     /** Media is ready for access */
00072 #define MED_STATE_BUSY          0x01     /** Media is busy */
00073 
00074 /*------------------------------------------------------------------------------
00075  *      Types
00076  *------------------------------------------------------------------------------*/
00077 
00078 typedef struct _Media sMedia;
00079 
00080 typedef void (*MediaCallback)(void *argument, uint8_t status,
00081                                uint32_t transferred, uint32_t  remaining);
00082 
00083 typedef uint8_t (*Media_write)(sMedia *pMedia, uint32_t address, void *data,
00084                                 uint32_t length, MediaCallback callback, void *argument);
00085 
00086 typedef uint8_t (*Media_read)(sMedia *pMedia, uint32_t address, void *data,
00087                                uint32_t length, MediaCallback callback, void *argument);
00088 
00089 typedef uint8_t (*Media_cancelIo)(sMedia *pMedia);
00090 
00091 typedef uint8_t (*Media_lock)(sMedia *pMedia, uint32_t start, uint32_t end,
00092                                uint32_t *pActualStart, uint32_t *pActualEnd);
00093 
00094 typedef uint8_t (*Media_unlock)(sMedia *pMedia, uint32_t start, uint32_t end,
00095                                  uint32_t *pActualStart, uint32_t *pActualEnd);
00096 
00097 typedef uint8_t (*Media_ioctl)(sMedia *pMedia, uint8_t ctrl, void *buff);
00098 
00099 typedef uint8_t (*Media_flush)(sMedia *pMedia);
00100 
00101 typedef void (*Media_handler)(sMedia *pMedia);
00102 
00103 /**
00104  *  \brief  Media transfer
00105  *  \see    TransferCallback
00106  */
00107 typedef struct {
00108     void *data;               /* < Pointer to the data buffer */
00109     uint32_t address;         /* < Address where to read/write the data */
00110     uint32_t length;          /* < Size of the data to read/write */
00111     MediaCallback callback;    /* < Callback to invoke when the transfer done */
00112     void *argument;           /* < Callback argument */
00113 } MEDTransfer;
00114 
00115 /**
00116  *  \brief  Media object
00117  *  \see    MEDTransfer
00118  */
00119 struct _Media {
00120     Media_write    write;        /* < Write method */
00121     Media_read     read;         /* < Read method */
00122     Media_cancelIo cancelIo;     /* < Cancel pending IO method */
00123     Media_lock     lock;         /* < lock method if possible */
00124     Media_unlock   unlock;       /* < unlock method if possible */
00125     Media_flush    flush;        /* < Flush method */
00126     Media_handler  handler;      /* < Interrupt handler */
00127 
00128     uint32_t   blockSize;    /* < Block size in bytes (1, 512, 1K, 2K ...) */
00129     uint32_t   baseAddress;  /* < Base address of media in number of blocks */
00130     uint32_t   size;         /* < Size of media in number of blocks */
00131     MEDTransfer    transfer;     /* < Current transfer operation */
00132     void           *interface;   /* < Pointer to the physical interface used */
00133     uint8_t  bReserved: 4,
00134              mappedRD: 1,  /* < Mapped to memory space to read */
00135              mappedWR: 1,  /* < Mapped to memory space to write */
00136              protected: 1, /* < Protected media? */
00137              removable: 1; /* < Removable/Fixed media? */
00138 
00139     uint8_t  state;        /* < Status of media */
00140     uint16_t reserved;
00141 };
00142 
00143 /*  Available medias. */
00144 //extern sMedia medias[5];
00145 
00146 /*
00147  *  Number of medias which are effectively used.
00148  *  Defined by Media, shared usage by USB MSD & FS ...
00149  */
00150 extern uint32_t gNbMedias;
00151 
00152 /*------------------------------------------------------------------------------
00153  *      Exported functions
00154  *------------------------------------------------------------------------------*/
00155 
00156 extern uint8_t MED_Write(sMedia *pMedia, uint32_t address, void *data,
00157                           uint32_t length, MediaCallback callback, void *argument);
00158 extern uint8_t MED_Read(sMedia *pMedia, uint32_t address, void *data,
00159                          uint32_t length, MediaCallback callback, void *argument);
00160 extern uint8_t MED_Lock(sMedia *pMedia, uint32_t start, uint32_t end,
00161                          uint32_t *pActualStart, uint32_t *pActualEnd);
00162 extern uint8_t MED_Unlock(sMedia *pMedia, uint32_t start, uint32_t end,
00163                            uint32_t *pActualStart, uint32_t *pActualEnd);
00164 extern uint8_t MED_Flush(sMedia *pMedia);
00165 extern void MED_Handler(sMedia *pMedia);
00166 extern void MED_DeInit(sMedia *pMedia);
00167 
00168 extern uint8_t MED_IsInitialized(sMedia *pMedia);
00169 extern uint8_t MED_IsBusy(sMedia *pMedia);
00170 extern uint8_t MED_IsMappedRDSupported(sMedia *pMedia);
00171 extern uint8_t MED_IsMappedWRSupported(sMedia *pMedia);
00172 extern uint8_t MED_IsProtected(sMedia *pMedia);
00173 
00174 extern void MED_HandleAll(sMedia *pMedias, uint8_t numMedias);
00175 
00176 extern uint8_t MED_GetState(sMedia *pMedia);
00177 extern uint32_t MED_GetBlockSize(sMedia *pMedia);
00178 extern uint32_t MED_GetSize(sMedia *pMedia);
00179 extern uint32_t MED_GetMappedAddress(sMedia *pMedia, uint32_t dwBlk);
00180 
00181 #endif /* _MEDIA_ */
00182 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines