Microchip® Advanced Software Framework

ecc-sw.c File Reference

Hamming ECC software implementation.

This file contains a software Hamming ECC implementation.

Copyright (c) 2012-2018 Microchip Technology Inc. and its subsidiaries.

#include "ecc-sw.h"

Functions

static void compute256 (const uint8_t *data, uint8_t *code)
 Calculates the 22-bit hamming code for a 256-bytes block of data. More...
 
static uint32_t count_bits_in_byte (uint8_t byte)
 Count and return the number of bits set to '1' in the given byte. More...
 
static uint32_t count_bits_in_code256 (uint8_t *code)
 Count and return the number of bits set to '1' in the given hamming code. More...
 
void hamming_compute_256x (const uint8_t *puc_data, uint32_t dw_size, uint8_t *puc_code)
 Computes 3-bytes hamming codes for a data block whose size is multiple of 256 bytes. More...
 
uint32_t hamming_verify_256x (uint8_t *puc_data, uint32_t dw_size, const uint8_t *puc_code)
 Verify 3-bytes hamming codes for a data block whose size is multiple of 256 bytes. More...
 
static uint32_t verify256 (uint8_t *puc_data, const uint8_t *puc_original_code)
 Verifies and corrects a 256-bytes block of data using the given 22-bits hamming code. More...
 

static void compute256 ( const uint8_t *  data,
uint8_t *  code 
)
static

Calculates the 22-bit hamming code for a 256-bytes block of data.

Parameters
dataData buffer to calculate code for.
codePointer to a buffer where the code should be stored.

References count_bits_in_byte().

Referenced by hamming_compute_256x(), and verify256().

static uint32_t count_bits_in_byte ( uint8_t  byte)
static

Count and return the number of bits set to '1' in the given byte.

Parameters
byteByte to count.

Referenced by compute256(), and count_bits_in_code256().

static uint32_t count_bits_in_code256 ( uint8_t *  code)
static

Count and return the number of bits set to '1' in the given hamming code.

Parameters
codeHamming code.

References count_bits_in_byte().

Referenced by verify256().

void hamming_compute_256x ( const uint8_t *  puc_data,
uint32_t  dw_size,
uint8_t *  puc_code 
)

Computes 3-bytes hamming codes for a data block whose size is multiple of 256 bytes.

Each 256 bytes block gets its own code.

Parameters
puc_dataPointer to data to compute code for.
dw_sizeData size in bytes.
puc_codePointer to codes buffer.

References compute256().

Referenced by nand_flash_ecc_write_page().

uint32_t hamming_verify_256x ( uint8_t *  puc_data,
uint32_t  dw_size,
const uint8_t *  puc_code 
)

Verify 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.

Parameters
puc_dataPointer to data buffer to verify.
dw_sizeSize of the data in bytes.
puc_codePointer to original codes.
Returns
0 if the data is correct, HAMMING_ERROR_SINGLE_BIT if one or more block(s) have had a single bit corrected, or either HAMMING_ERROR_ECC or HAMMING_ERROR_MULTIPLE_BITS.

References HAMMING_ERROR_SINGLE_BIT, and verify256().

Referenced by nand_flash_ecc_read_page().

static uint32_t verify256 ( uint8_t *  puc_data,
const uint8_t *  puc_original_code 
)
static

Verifies and corrects a 256-bytes block of data using the given 22-bits hamming code.

Parameters
puc_dataPointer to data buffer to check.
puc_original_codePointer to hamming code to use for verifying the data.
Returns
0 if there is no error, otherwise returns a HAMMING_ERROR code.

References compute256(), count_bits_in_code256(), HAMMING_ERROR_ECC, HAMMING_ERROR_MULTIPLE_BITS, and HAMMING_ERROR_SINGLE_BIT.

Referenced by hamming_verify_256x().