From c777f90b8a780337e23cb1ad887350edd395af39 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 1 Dec 2013 07:39:20 -0600 Subject: [PATCH] Costmet updates, naming, debug output, README file --- configs/sama5d3x-ek/README.txt | 12 +++++++++++ drivers/mtd/hamming.c | 38 +++++++++++++++++++--------------- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/configs/sama5d3x-ek/README.txt b/configs/sama5d3x-ek/README.txt index b51e0a705c..060bbe601b 100644 --- a/configs/sama5d3x-ek/README.txt +++ b/configs/sama5d3x-ek/README.txt @@ -707,6 +707,18 @@ NAND Support Other file systems are not recommended because only NXFFS can handle bad blocks and only NXFFS performs wear-leveling. + NOTE: NXFFS is very slow. The first time that you start the system, + be prepared for a long wait. I have lots of debug on so I don't know + what the optimized wait will be. But with debug ON, the wait is in + units of hours. + + NOTE: There is another NXFFS related issue: When the FLASH is + fully used, NXFFS will restructure the entire FLASH, the delay to + restructure the entire FLASH will probably be even larger. This + solution in this case is to implement an NXFSS clean-up daemon that + does the job a little-at-a-time so that there is no massive clean-up + when the FLASH becomes full. + Application Configuration -> NSH Library CONFIG_NSH_ARCHINIT=y : Use architecture-specific initialization diff --git a/drivers/mtd/hamming.c b/drivers/mtd/hamming.c index 46ff94d941..6f8f617a3a 100644 --- a/drivers/mtd/hamming.c +++ b/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 */