2013-11-17 22:56:30 +08:00
|
|
|
/****************************************************************************
|
2013-11-18 23:43:44 +08:00
|
|
|
* include/nuttx/mtd/hamming.h
|
2013-11-17 22:56:30 +08:00
|
|
|
*
|
|
|
|
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
|
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
|
|
|
*
|
2013-11-18 23:43:44 +08:00
|
|
|
* This logic was taken directly from Atmel sample code with only
|
|
|
|
* modifications for better integration with NuttX. The Atmel sample
|
|
|
|
* code has a BSD compatibile license that requires this copyright notice:
|
2013-11-17 22:56:30 +08:00
|
|
|
*
|
2013-11-18 23:43:44 +08:00
|
|
|
* Copyright (c) 2011, Atmel Corporation
|
2013-11-17 22:56:30 +08:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the names NuttX nor Atmel nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-11-18 23:43:44 +08:00
|
|
|
#ifndef __INCLUDE_NUTTX_HAMMING_H
|
|
|
|
#define __INCLUDE_NUTTX_HAMMING_H
|
|
|
|
|
2013-11-17 22:56:30 +08:00
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2013-11-18 23:43:44 +08:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <semaphore.h>
|
2013-11-17 22:56:30 +08:00
|
|
|
|
2013-11-18 23:43:44 +08:00
|
|
|
#include <nuttx/mtd/mtd.h>
|
2013-11-17 22:56:30 +08:00
|
|
|
#include <nuttx/mtd/nand_raw.h>
|
|
|
|
|
|
|
|
/****************************************************************************
|
2013-11-18 23:43:44 +08:00
|
|
|
* Pre-Processor Definitions
|
2013-11-17 22:56:30 +08:00
|
|
|
****************************************************************************/
|
2013-11-18 23:43:44 +08:00
|
|
|
/* These are the possible errors when trying to verify a block of data
|
|
|
|
* encoded using a Hamming code:
|
|
|
|
*
|
|
|
|
* HAMMING_SUCCESS - Block verified without errors
|
|
|
|
* HAMMING_ERROR_SINGLEBIT - A single bit was incorrect but has been
|
|
|
|
* recovered
|
|
|
|
* HAMMING_ERROR_ECC - The original code has been corrupted
|
|
|
|
* HAMMING_ERROR_MULTIPLEBITS - Multiple bits are incorrect in the data
|
|
|
|
* and they cannot be corrected
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define HAMMING_SUCCESS 0
|
|
|
|
#define HAMMING_ERROR_SINGLEBIT 1
|
|
|
|
#define HAMMING_ERROR_ECC 2
|
|
|
|
#define HAMMING_ERROR_MULTIPLEBITS 3
|
2013-11-17 22:56:30 +08:00
|
|
|
|
|
|
|
/****************************************************************************
|
2013-11-18 23:43:44 +08:00
|
|
|
* Public Types
|
2013-11-17 22:56:30 +08:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2013-11-18 23:43:44 +08:00
|
|
|
* Public Data
|
2013-11-17 22:56:30 +08:00
|
|
|
****************************************************************************/
|
|
|
|
|
2013-11-18 23:43:44 +08:00
|
|
|
#ifndef __ASSEMBLY__
|
2013-11-17 22:56:30 +08:00
|
|
|
|
2013-11-18 23:43:44 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
#define EXTERN extern "C"
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#else
|
|
|
|
#define EXTERN extern
|
|
|
|
#endif
|
2013-11-17 22:56:30 +08:00
|
|
|
|
|
|
|
/****************************************************************************
|
2013-11-18 23:43:44 +08:00
|
|
|
* Public Function Prototypes
|
2013-11-17 22:56:30 +08:00
|
|
|
****************************************************************************/
|
|
|
|
|
2013-11-19 01:42:17 +08:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: hamming_compute256x
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Computes 3-bytes hamming codes for a data block whose size is multiple
|
|
|
|
* of 256 bytes. Each 256 bytes block gets its own code.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* data - Data to compute code for
|
|
|
|
* size - Data size in bytes
|
|
|
|
* code - Codes buffer
|
|
|
|
*
|
|
|
|
* Returned Values:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void hamming_compute256x(FAR const uint8_t *data, size_t size, uint8_t *code);
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: hamming_verify256x
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Verifies 3-bytes hamming codes for a data block whose size is multiple
|
|
|
|
* of 256 bytes. Each 256-bytes block is verified with its own code.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* data - Data buffer to verify
|
|
|
|
* size - Size of the data in bytes
|
|
|
|
* code - Original codes
|
|
|
|
*
|
|
|
|
* Returned Values:
|
|
|
|
* Return 0 if the data is correct, HAMMING_ERROR_SINGLEBIT if one or more
|
|
|
|
* block(s) have had a single bit corrected, or either HAMMING_ERROR_ECC
|
|
|
|
* or HAMMING_ERROR_MULTIPLEBITS.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int hamming_verify256x(FAR uint8_t *data, size_t size, FAR const uint8_t *code);
|
|
|
|
|
2013-11-18 23:43:44 +08:00
|
|
|
#undef EXTERN
|
|
|
|
#ifdef __cplusplus
|
2013-11-17 22:56:30 +08:00
|
|
|
}
|
2013-11-18 23:43:44 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __ASSEMBLY__ */
|
|
|
|
#endif /* __INCLUDE_NUTTX_HAMMING_H */
|