1 /* 2 This file is part of UFFS, the Ultra-low-cost Flash File System. 3 4 Copyright (C) 2005-2009 Ricky Zheng <[email protected]> 5 6 UFFS is free software; you can redistribute it and/or modify it under 7 the GNU Library General Public License as published by the Free Software 8 Foundation; either version 2 of the License, or (at your option) any 9 later version. 10 11 UFFS is distributed in the hope that it will be useful, but WITHOUT 12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 or GNU Library General Public License, as applicable, for more details. 15 16 You should have received a copy of the GNU General Public License 17 and GNU Library General Public License along with UFFS; if not, write 18 to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 Boston, MA 02110-1301, USA. 20 21 As a special exception, if other files instantiate templates or use 22 macros or inline functions from this file, or you compile this file 23 and link it with other works to produce a work based on this file, 24 this file does not by itself cause the resulting work to be covered 25 by the GNU General Public License. However the source code for this 26 file must still be made available in accordance with section (3) of 27 the GNU General Public License v2. 28 29 This exception does not invalidate any other reasons why a work based 30 on this file might be covered by the GNU General Public License. 31 */ 32 33 /** 34 * \file uffs_ecc.h 35 * \brief file handle operations 36 * \author Ricky Zheng, created 8th Jun, 2005 37 */ 38 39 #ifndef _UFFS_ECC_H_ 40 #define _UFFS_ECC_H_ 41 42 #include <string.h> 43 44 #include "uffs/uffs_fs.h" 45 #include "uffs/uffs_core.h" 46 47 #ifdef __cplusplus 48 extern "C"{ 49 #endif 50 51 52 53 #define MAX_ECC_LENGTH 24 //!< 2K page ecc length is 24 bytes. 54 55 /** 56 * calculate ECC 57 * \return length of generated ECC. (3 bytes ECC per 256 data) 58 */ 59 int uffs_EccMake(const void *data, int data_len, void *ecc); 60 61 /** 62 * correct data by ECC. 63 * 64 * return: 0 -- no error 65 * -1 -- can not be corrected 66 * >0 -- how many bits are corrected 67 */ 68 int uffs_EccCorrect(void *data, int data_len, void *read_ecc, const void *test_ecc); 69 70 71 /** 72 * generate 12 bit ecc for maximum 8 bytes data 73 */ 74 u16 uffs_EccMake8(const void *data, int data_len); 75 76 /** 77 * correct maximum 8 bytes data from 12 bits ECC 78 * 79 * return: 0 -- no error 80 * -1 -- can not be corrected 81 * >0 -- how many bits are corrected 82 */ 83 int uffs_EccCorrect8(void *data, u16 read_ecc, u16 test_ecc, int errtop); 84 85 86 #ifdef __cplusplus 87 } 88 #endif 89 #endif 90