SAMV71 Xplained Ultra Software Package 1.0

ManagedNandFlash.h

Go to the documentation of this file.
00001 /* ----------------------------------------------------------------------------
00002  *         ATMEL Microcontroller Software Support
00003  * ----------------------------------------------------------------------------
00004  * Copyright (c) 2009, 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  *  \file
00031  *
00032  *  Include Defines & macros for the managered nand flash layer.
00033  */
00034 
00035 #ifndef MANAGEDNANDFLASH_H
00036 #define MANAGEDNANDFLASH_H
00037 
00038 /*----------------------------------------------------------------------------
00039  *        Headers
00040  *----------------------------------------------------------------------------*/
00041 
00042 #include "NandCommon.h"
00043 #include "EccNandFlash.h"
00044 
00045 /*----------------------------------------------------------------------------
00046  *        Definitions
00047  *----------------------------------------------------------------------------*/
00048 
00049 #define NandBlockStatus_DEFAULT         0xF
00050 #define NandBlockStatus_FREE            0xE
00051 #define NandBlockStatus_LIVE            0xC
00052 #define NandBlockStatus_DIRTY           0x8
00053 #define NandBlockStatus_BAD             0x0
00054 
00055 /** Erase dirty blocks only*/
00056 #define NandEraseDIRTY                  0
00057 /** Erase all data, calculate count*/
00058 #define NandEraseDATA                   1
00059 /** Erase all, reset erase count */
00060 #define NandEraseFULL                   2
00061 
00062 /*----------------------------------------------------------------------------
00063  *        Types
00064  *----------------------------------------------------------------------------*/
00065 struct NandBlockStatus {
00066 
00067     uint32_t status:4,
00068              eraseCount:28;
00069 };
00070 
00071 struct ManagedNandFlash {
00072 
00073     struct EccNandFlash ecc;
00074     struct NandBlockStatus blockStatuses[NandCommon_MAXNUMBLOCKS];
00075     uint16_t baseBlock;
00076     uint16_t sizeInBlocks;
00077 };
00078 
00079 /*----------------------------------------------------------------------------
00080  *        Exported functions
00081  *----------------------------------------------------------------------------*/
00082 
00083 extern uint8_t ManagedNandFlash_Initialize(
00084     struct ManagedNandFlash *managed,
00085     const struct NandFlashModel *model,
00086     uint32_t commandAddress,
00087     uint32_t addressAddress,
00088     uint32_t dataAddress,
00089     const Pin pinChipEnable,
00090     const Pin pinReadyBusy,
00091     uint16_t baseBlock,
00092     uint16_t sizeInBlocks);
00093 
00094 extern uint8_t ManagedNandFlash_AllocateBlock(
00095     struct ManagedNandFlash *managed,
00096     uint16_t block);
00097 
00098 extern uint8_t ManagedNandFlash_ReleaseBlock(
00099     struct ManagedNandFlash *managed,
00100     uint16_t block);
00101 
00102 extern uint8_t ManagedNandFlash_EraseBlock(
00103     struct ManagedNandFlash *managed,
00104     uint16_t block);
00105 
00106 extern uint8_t ManagedNandFlash_ReadPage(
00107     const struct ManagedNandFlash *managed,
00108     uint16_t block,
00109     uint16_t page,
00110     void *data,
00111     void *spare);
00112 
00113 extern uint8_t ManagedNandFlash_WritePage(
00114     const struct ManagedNandFlash *managed,
00115     uint16_t block,
00116     uint16_t page,
00117     void *data,
00118     void *spare);
00119 
00120 extern uint8_t ManagedNandFlash_CopyPage(
00121     const struct ManagedNandFlash *managed,
00122     uint16_t sourceBlock,
00123     uint16_t sourcePage,
00124     uint16_t destBlock,
00125     uint16_t destPage);
00126 
00127 extern uint8_t ManagedNandFlash_CopyBlock(
00128     const struct ManagedNandFlash *managed,
00129     uint16_t sourceBlock,
00130     uint16_t destBlock);
00131 
00132 extern uint8_t ManagedNandFlash_EraseDirtyBlocks(
00133     struct ManagedNandFlash *managed);
00134 
00135 extern uint8_t ManagedNandFlash_FindYoungestBlock(
00136     const struct ManagedNandFlash *managed,
00137     uint8_t status,
00138     uint16_t *block);
00139 
00140 extern uint16_t ManagedNandFlash_CountBlocks(
00141     const struct ManagedNandFlash *managed,
00142     uint8_t status);
00143 
00144 extern uint16_t ManagedNandFlash_GetDeviceSizeInBlocks(
00145     const struct ManagedNandFlash *managed);
00146 
00147 extern uint8_t ManagedNandFlash_EraseAll(
00148     struct ManagedNandFlash *managed,
00149     uint8_t level);
00150 
00151 #endif /*#ifndef MANAGEDNANDFLASH_H*/
00152 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines