SBAA106A June 2020 – August 2021 ADS112C04 , ADS112U04 , ADS114S06 , ADS114S08 , ADS122C04 , ADS122U04 , ADS1235 , ADS1235-Q1 , ADS124S06 , ADS124S08 , ADS1259 , ADS1259-Q1 , ADS125H01 , ADS125H02 , ADS1260 , ADS1260-Q1 , ADS1261 , ADS1262 , ADS1263 , ADS127L01 , ADS131A02 , ADS131A04 , ADS131M04 , ADS131M06 , ADS131M08
After using the Hamming and checksum validation, it is possible to correct single bit error. The data validation and correction takes place first and the bit is corrected if possible. If the data are restored, the checksum is reevaluated. If a multiple bit error or checksum error occurs, the transmission is invalid.
uint32_t fixResults[] = {
0, // datablock OK
1 << 3, // no error in data (H0)
1 << 4, // no error in data (H1)
1u << 31, // data[23] error
1 << 5, // no error in data (H2)
1 << 30, // data[22] error
1 << 29, // data[21] error
1 << 28, // data[20] error
1 << 6, // no error in data (H3)
1 << 27, // data[19] error
1 << 26, // data[18] error
1 << 25, // data[17] error
1 << 24, // data[16] error
1 << 23, // data[15] error
1 << 22, // data[14] error
1 << 21, // data[13] error
1 << 7, // no error in data (H4)
1 << 20, // data[12] error
1 << 19, // data[11] error
1 << 18, // data[10] error
1 << 17, // data[9] error
1 << 16, // data[8] error
1 << 15, // data[7] error
1 << 14, // data[6] error
1 << 13, // data[5] error
1 << 12, // data[4] error
1 << 11, // data[3] error
1 << 10, // data[2] error
1 << 9, // data[1] error
1 << 8, // data[0] error
// not correctable 30
// not correctable 31
// As H0 covers 14 bits and H1-H4 cover 13 bits a
// multi-bit error will occur if hamming is 30
// or 31 and cannot be corrected
};
/**
* Data validation and repair of single-bit error.
*
* \details Validation and restoration of data using the Hamming bit
* information to correct for single-bit error. The 'in' value is checked
* first and if the XOR returns a 0, then the data contents are validated relative
* to the Hamming bits and then are checked for multi-bit error using the checksum.
* If the Hamming bits do not match the data, then the Hamming bits are used to
* correct the data if possible by using an XOR of the computed Hamming to the transmitted
* Hamming. Using a lookup table based on the correction factors and the XOR value the
* data is restored and then a checksum is computed to make sure there were no multi-bit
* errors.
*
* \param uint32_t in of the value to be computed and compared.
*
* \returns uint32_t res returns 0 if the data was correctable or valid.
* A non-zero is invalid data.
*/
uint32_t fixHamming(uint32_t in)
{
uint32_t res;
uint32_t fix;
// checkHamming will return the 5 hamming bits from the data 'in'
// When using an assignment in the conditional statement, the conditional evaluates the
// assignment.
// If checkHamming returns something other than '0', the result is attempted to be fixed
if(res = checkHamming(in))
{
// Based on the results of the hamming code not '0' the result is corrected from the
// lookup by adjusting the 32 bit value from 'in' from the table of 2^5 (or 32
// possible combinations). In summary, 24 values out of 32 are for 1-bit correction,
// 5 values for no error in data (1bit error in Hamming Code), 1 value for no error
// in both data and Hamming code and 2 values for more than 1 bit error in either
// data or Hamming Code or both. Since only two values are assigned for more than
// 1 bit error cases, there are high probabilities that more than 1 bit-error will
// be mistakenly treated as 1-bit error by the algorithm. To reduce such
// possibilities, 2 bit checksum are added for the error detection in addition to
// the Hamming Detection.
// Quick check for multi bit error in hamming value
fix = res >> 3;
// Then XOR computed hamming bits with 'in' value hamming bits
fix = fix ^ ((in & 0xFF) >> 3);
// If there is a known multi-bit error then fail the fix
if (fix > 29) return HC_FIX_FAIL;
else
{
// Bit error occurred and attempting to fix
fix = (fixResults[fix]);
// Identified error could be either hamming or data error where 'in' value is
// XORed with the fix value
res = in ^ fix;
}
}
else
{
res = in;
}
// res is now containing either the original or the fixed value of data which is
// data + hamming following the hamming check and data correction, multi-bit
// errors are checked using the checksum bits checkSum will exclude the hamming bits
// in the count. If the checkSum returns something other than 0, the
// checkSum fails, otherwise return 0
if(checkSum(res))
{
return HC_FIX_FAIL;
}
return res;
}