diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2013-12-01 07:39:20 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2013-12-01 07:39:20 -0600 |
commit | 94f14c031a0628cfaaeea0e59640be68aafc50cb (patch) | |
tree | 0c4efc7994629b03d6b8fc0dfacdecbe829e567f /nuttx/drivers/mtd | |
parent | af8953d9c92f277da32c594269dfac0063d0e07b (diff) | |
download | px4-nuttx-94f14c031a0628cfaaeea0e59640be68aafc50cb.tar.gz px4-nuttx-94f14c031a0628cfaaeea0e59640be68aafc50cb.tar.bz2 px4-nuttx-94f14c031a0628cfaaeea0e59640be68aafc50cb.zip |
Costmet updates, naming, debug output, README file
Diffstat (limited to 'nuttx/drivers/mtd')
-rw-r--r-- | nuttx/drivers/mtd/hamming.c | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/nuttx/drivers/mtd/hamming.c b/nuttx/drivers/mtd/hamming.c index 46ff94d94..6f8f617a3 100644 --- a/nuttx/drivers/mtd/hamming.c +++ b/nuttx/drivers/mtd/hamming.c @@ -57,7 +57,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: bitsinbyte + * Name: hamming_bitsinbyte * * Description: * Counts the number of bits set to '1' in the given byte. @@ -70,7 +70,7 @@ * ****************************************************************************/ -static unsigned int bitsinbyte(uint8_t byte) +static unsigned int hamming_bitsinbyte(uint8_t byte) { unsigned int count = 0; @@ -87,7 +87,7 @@ static unsigned int bitsinbyte(uint8_t byte) } /**************************************************************************** - * Name: bitsincode256 + * Name: hamming_bitsincode256 * * Description: * Counts the number of bits set to '1' in the given hamming code. @@ -100,13 +100,15 @@ static unsigned int bitsinbyte(uint8_t byte) * ****************************************************************************/ -static uint8_t bitsincode256(FAR uint8_t *code) +static uint8_t hamming_bitsincode256(FAR uint8_t *code) { - return bitsinbyte(code[0]) + bitsinbyte(code[1]) + bitsinbyte(code[2]); + return hamming_bitsinbyte(code[0]) + + hamming_bitsinbyte(code[1]) + + hamming_bitsinbyte(code[2]); } /**************************************************************************** - * Name: compute256 + * Name: hamming_compute256 * * Description: * Calculates the 22-bit hamming code for a 256-bytes block of data. @@ -120,7 +122,7 @@ static uint8_t bitsincode256(FAR uint8_t *code) * ****************************************************************************/ -static void compute256(FAR const uint8_t *data, FAR uint8_t *code) +static void hamming_compute256(FAR const uint8_t *data, FAR uint8_t *code) { uint8_t colsum = 0; uint8_t evenline = 0; @@ -141,7 +143,7 @@ static void compute256(FAR const uint8_t *data, FAR uint8_t *code) * the computed code; so check if the sum is 1. */ - if ((bitsinbyte(data[i]) & 1) == 1) + if ((hamming_bitsinbyte(data[i]) & 1) == 1) { /* Parity groups are formed by forcing a particular index bit to 0 * (even) or 1 (odd). @@ -258,11 +260,11 @@ static void compute256(FAR const uint8_t *data, FAR uint8_t *code) code[1] = (~(uint32_t)code[1]); code[2] = (~(uint32_t)code[2]); - fvdbg("Computed code: %02x %02x %02x\n", code[0], code[1], code[2]); + fvdbg("Computed: %02x %02x %02x\n", code[0], code[1], code[2]); } /**************************************************************************** - * Name: verify256 + * Name: hamming_verify256 * * Description: * Verifies and corrects a 256-bytes block of data using the given 22-bits @@ -277,14 +279,14 @@ static void compute256(FAR const uint8_t *data, FAR uint8_t *code) * ****************************************************************************/ -static int verify256(FAR uint8_t *data, FAR const uint8_t *original) +static int hamming_verify256(FAR uint8_t *data, FAR const uint8_t *original) { /* Calculate new code */ uint8_t computed[3]; uint8_t correction[3]; - compute256(data, computed); + hamming_compute256(data, computed); /* Xor both codes together */ @@ -292,7 +294,7 @@ static int verify256(FAR uint8_t *data, FAR const uint8_t *original) correction[1] = computed[1] ^ original[1]; correction[2] = computed[2] ^ original[2]; - fvdbg("Correction code: %02x %02x %02x\n", + fvdbg("Correction: %02x %02x %02x\n", correction[0], correction[1], correction[2]); /* If all bytes are 0, there is no error */ @@ -304,7 +306,7 @@ static int verify256(FAR uint8_t *data, FAR const uint8_t *original) /* If there is a single bit error, there are 11 bits set to 1 */ - if (bitsincode256(correction) == 11) + if (hamming_bitsincode256(correction) == 11) { uint8_t byte; uint8_t bit; @@ -335,7 +337,7 @@ static int verify256(FAR uint8_t *data, FAR const uint8_t *original) /* Check if ECC has been corrupted */ - if (bitsincode256(correction) == 1) + if (hamming_bitsincode256(correction) == 1) { return HAMMING_ERROR_ECC; } @@ -378,7 +380,7 @@ void hamming_compute256x(FAR const uint8_t *data, size_t size, uint8_t *code) while (remaining > 0) { - compute256(data, code); + hamming_compute256(data, code); /* Setup for the next 256 byte chunk */ @@ -419,7 +421,9 @@ int hamming_verify256x(FAR uint8_t *data, size_t size, FAR const uint8_t *code) while (remaining > 0) { - result = verify256(data, code); + fvdbg("Code: %02x %02x %02x\n", code[0], code[1], code[2]); + + result = hamming_verify256(data, code); if (result != HAMMING_SUCCESS) { /* Check for the case of a single bit error that was corrected */ |