Microchip® Advanced Software Framework

ecc-sw.c File Reference
#include "nand.h"
#include "ecc-sw.h"

Functions

int ecc_compare_block_256b (unsigned long *ecc1, unsigned long *ecc2, unsigned char *data, unsigned long *error_offset, unsigned char *corrected_value)
 Compare two ECCs for a 256 byte block. More...
 
void ecc_make_block_256b (unsigned long *ecc, unsigned char *data)
 Generate ECC for a 256 byte block. More...
 

Variables

static const unsigned char ecc_parity_table []
 Pre-calculated parity table. More...
 

int ecc_compare_block_256b ( unsigned long *  ecc1,
unsigned long *  ecc2,
unsigned char *  data,
unsigned long *  error_offset,
unsigned char *  corrected_value 
)

Compare two ECCs for a 256 byte block.

This function will compare two 3 byte ECC for a 256 byte data block. If an error is found the compare function will provide a fix if a single one bit error is found. Multiple errors are not possible to fix.

Parameters
ecc1Pointer to a variable for ECC value to compare against ecc2.
ecc2Pointer to a variable for ECC value to compare against ecc1.
dataPointer to a 256 byte large buffer used when calculating the ecc1 and ecc2 ECC values.
error_offsetPointer to a variable to store the byte offset of a detected single bit error.
corrected_valuePointer to a variable to store the corrected byte if a single bit error was detected.
Returns
0 on success, an error number otherwise.

References i.

void ecc_make_block_256b ( unsigned long *  ecc,
unsigned char *  data 
)

Generate ECC for a 256 byte block.

This function will generate a 3 byte ECC for a 256 byte data block.

Parameters
eccPointer to a variable to store the calculated ECC.
dataPointer to a 256 byte large buffer to calculate the ECC value of.

References data, ecc_parity_table, i, and NAND_ECC_CHUNK_SIZE.

const unsigned char ecc_parity_table[]
static
Initial value:
= {
0x00, 0x55, 0x56, 0x03, 0x59, 0x0c, 0x0f, 0x5a, 0x5a, 0x0f,
0x0c, 0x59, 0x03, 0x56, 0x55, 0x00, 0x65, 0x30, 0x33, 0x66,
0x3c, 0x69, 0x6a, 0x3f, 0x3f, 0x6a, 0x69, 0x3c, 0x66, 0x33,
0x30, 0x65, 0x66, 0x33, 0x30, 0x65, 0x3f, 0x6a, 0x69, 0x3c,
0x3c, 0x69, 0x6a, 0x3f, 0x65, 0x30, 0x33, 0x66, 0x03, 0x56,
0x55, 0x00, 0x5a, 0x0f, 0x0c, 0x59, 0x59, 0x0c, 0x0f, 0x5a,
0x00, 0x55, 0x56, 0x03, 0x69, 0x3c, 0x3f, 0x6a, 0x30, 0x65,
0x66, 0x33, 0x33, 0x66, 0x65, 0x30, 0x6a, 0x3f, 0x3c, 0x69,
0x0c, 0x59, 0x5a, 0x0f, 0x55, 0x00, 0x03, 0x56, 0x56, 0x03,
0x00, 0x55, 0x0f, 0x5a, 0x59, 0x0c, 0x0f, 0x5a, 0x59, 0x0c,
0x56, 0x03, 0x00, 0x55, 0x55, 0x00, 0x03, 0x56, 0x0c, 0x59,
0x5a, 0x0f, 0x6a, 0x3f, 0x3c, 0x69, 0x33, 0x66, 0x65, 0x30,
0x30, 0x65, 0x66, 0x33, 0x69, 0x3c, 0x3f, 0x6a, 0x6a, 0x3f,
0x3c, 0x69, 0x33, 0x66, 0x65, 0x30, 0x30, 0x65, 0x66, 0x33,
0x69, 0x3c, 0x3f, 0x6a, 0x0f, 0x5a, 0x59, 0x0c, 0x56, 0x03,
0x00, 0x55, 0x55, 0x00, 0x03, 0x56, 0x0c, 0x59, 0x5a, 0x0f,
0x0c, 0x59, 0x5a, 0x0f, 0x55, 0x00, 0x03, 0x56, 0x56, 0x03,
0x00, 0x55, 0x0f, 0x5a, 0x59, 0x0c, 0x69, 0x3c, 0x3f, 0x6a,
0x30, 0x65, 0x66, 0x33, 0x33, 0x66, 0x65, 0x30, 0x6a, 0x3f,
0x3c, 0x69, 0x03, 0x56, 0x55, 0x00, 0x5a, 0x0f, 0x0c, 0x59,
0x59, 0x0c, 0x0f, 0x5a, 0x00, 0x55, 0x56, 0x03, 0x66, 0x33,
0x30, 0x65, 0x3f, 0x6a, 0x69, 0x3c, 0x3c, 0x69, 0x6a, 0x3f,
0x65, 0x30, 0x33, 0x66, 0x65, 0x30, 0x33, 0x66, 0x3c, 0x69,
0x6a, 0x3f, 0x3f, 0x6a, 0x69, 0x3c, 0x66, 0x33, 0x30, 0x65,
0x00, 0x55, 0x56, 0x03, 0x59, 0x0c, 0x0f, 0x5a, 0x5a, 0x0f,
0x0c, 0x59, 0x03, 0x56, 0x55, 0x00,
}

Pre-calculated parity table.

This table is a pre-calculation of the 256 possible parities used when calculating ECC. Each value in this table represents a 6-bit value of the column parity and a 1-bit value of the row parity.

Storage form: null [7], row parity [6], column parity [5:0]

Referenced by ecc_make_block_256b().