SAMV71 Xplained Ultra Software Package 1.3

Media.h

Go to the documentation of this file.
00001 /* ----------------------------------------------------------------------------
00002  *         SAM Software Package License 
00003  * ----------------------------------------------------------------------------
00004  * Copyright (c) 2011, 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 /**
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, uint32_t transferred, uint32_t  remaining ) ;
00081 
00082 typedef uint8_t (*Media_write)( sMedia* pMedia, uint32_t address, void *data, uint32_t length, MediaCallback callback, void *argument ) ;
00083 
00084 typedef uint8_t (*Media_read)( sMedia* pMedia, uint32_t address, void *data, uint32_t length, MediaCallback callback, void *argument ) ;
00085 
00086 typedef uint8_t (*Media_cancelIo)( sMedia* pMedia ) ;
00087 
00088 typedef uint8_t (*Media_lock)( sMedia* pMedia, uint32_t start, uint32_t end, uint32_t *pActualStart, uint32_t *pActualEnd ) ;
00089 
00090 typedef uint8_t (*Media_unlock)( sMedia* pMedia, uint32_t start, uint32_t end, uint32_t *pActualStart, uint32_t *pActualEnd ) ;
00091 
00092 typedef uint8_t (*Media_ioctl)( sMedia* pMedia, uint8_t ctrl, void *buff ) ;
00093 
00094 typedef uint8_t (*Media_flush)( sMedia* pMedia ) ;
00095 
00096 typedef void (*Media_handler)( sMedia* pMedia ) ;
00097 
00098 /**
00099  *  \brief  Media transfer
00100  *  \see    TransferCallback
00101  */
00102 typedef struct
00103 {
00104     void* data ;               /* < Pointer to the data buffer */
00105     uint32_t address ;         /* < Address where to read/write the data */
00106     uint32_t length ;          /* < Size of the data to read/write */
00107     MediaCallback callback;    /* < Callback to invoke when the transfer done */
00108     void* argument ;           /* < Callback argument */
00109 } MEDTransfer ;
00110 
00111 /**
00112  *  \brief  Media object
00113  *  \see    MEDTransfer
00114  */
00115 struct _Media
00116 {
00117   Media_write    write;        /* < Write method */
00118   Media_read     read;         /* < Read method */
00119   Media_cancelIo cancelIo;     /* < Cancel pending IO method */
00120   Media_lock     lock;         /* < lock method if possible */
00121   Media_unlock   unlock;       /* < unlock method if possible */
00122   Media_flush    flush;        /* < Flush method */
00123   Media_handler  handler;      /* < Interrupt handler */
00124 
00125   uint32_t   blockSize;    /* < Block size in bytes (1, 512, 1K, 2K ...) */
00126   uint32_t   baseAddress;  /* < Base address of media in number of blocks */
00127   uint32_t   size;         /* < Size of media in number of blocks */
00128   MEDTransfer    transfer;     /* < Current transfer operation */
00129   void           *interface;   /* < Pointer to the physical interface used */
00130   uint8_t  bReserved:4,
00131     mappedRD:1,   /* < Mapped to memory space to read */
00132     mappedWR:1,   /* < Mapped to memory space to write */
00133     protected:1,  /* < Protected media? */
00134     removable:1;  /* < Removable/Fixed media? */
00135 
00136   uint8_t  state;        /* < Status of media */
00137   uint16_t reserved ;
00138 } ;
00139 
00140 /*  Available medias. */
00141 //extern sMedia medias[5];
00142 
00143 /*
00144  *  Number of medias which are effectively used.
00145  *  Defined by Media, shared usage by USB MSD & FS ...
00146  */
00147 extern uint32_t gNbMedias ;
00148 
00149 /*------------------------------------------------------------------------------
00150  *      Exported functions
00151  *------------------------------------------------------------------------------*/
00152 
00153 extern uint8_t MED_Write( sMedia* pMedia, uint32_t address, void* data, uint32_t length, MediaCallback callback, void* argument ) ;
00154 extern uint8_t MED_Read( sMedia* pMedia, uint32_t address, void* data, uint32_t length, MediaCallback callback, void* argument ) ;
00155 extern uint8_t MED_Lock( sMedia* pMedia, uint32_t start, uint32_t end, uint32_t *pActualStart, uint32_t *pActualEnd ) ;
00156 extern uint8_t MED_Unlock( sMedia* pMedia, uint32_t start, uint32_t end, uint32_t *pActualStart, uint32_t *pActualEnd ) ;
00157 extern uint8_t MED_Flush( sMedia* pMedia ) ;
00158 extern void MED_Handler( sMedia* pMedia ) ;
00159 extern void MED_DeInit( sMedia* pMedia ) ;
00160 
00161 extern uint8_t MED_IsInitialized( sMedia* pMedia ) ;
00162 extern uint8_t MED_IsBusy( sMedia* pMedia );
00163 extern uint8_t MED_IsMappedRDSupported( sMedia * pMedia );
00164 extern uint8_t MED_IsMappedWRSupported( sMedia * pMedia );
00165 extern uint8_t MED_IsProtected( sMedia * pMedia );
00166 
00167 extern void MED_HandleAll( sMedia *pMedias, uint8_t numMedias ) ;
00168 
00169 extern uint8_t MED_GetState( sMedia *pMedia );
00170 extern uint32_t MED_GetBlockSize( sMedia * pMedia );
00171 extern uint32_t MED_GetSize( sMedia * pMedia );
00172 extern uint32_t MED_GetMappedAddress( sMedia * pMedia, uint32_t dwBlk );
00173 
00174 #endif /* _MEDIA_ */
00175 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines