MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Static Public Member Functions | Static Public Attributes
MFM::Parity2D_4x4 Class Reference

#include <Parity2D_4x4.h>

Public Types

enum  {
  W = 4, H = 4, DATA_BITS = W * H, ECC_BITS = W + H + 1,
  TABLE_SIZE = 1 << DATA_BITS, INDEX_MASK = TABLE_SIZE - 1, ECC_MASK = (1 << ECC_BITS) - 1
}
 

Static Public Member Functions

static u32 Compute2DParity (u32 dataBits)
 
static u32 ComputeParitySlow (u32 dataBits)
 
static u32 Add2DParity (u32 dataBits)
 
static bool Remove2DParity (u32 allBits, u32 &dataBits)
 
static bool Check2DParity (const u32 allBits)
 
static u32 CheckAndCorrect2DParity (const u32 allBits)
 
static u32 Correct2DParityIfPossible (u32 allBits)
 

Static Public Attributes

static const u8 indices2D [H+1][W+1]
 

Detailed Description

Parity2D_4x4 is an all-static class for manipulating (one particular instance of) two-dimensional parity error detection and correction. This class handles error detection and correction only of sixteen bit quantities being protected with nine additional bits. In addition, this class assumes the nine ECC bits will be placed to the left of the sixteen data bits when they are joined into a 25-bit quantity.

Redundancy at the level of nine bits protecting sixteen bits ensures that all single bit errors are correctable and all double bit errors are detectable. Most all triple bit errors are detectable as well.

This class uses a table lookup to accelerate the generation and checking of the parity bits. In particular, Compute2DParity and Check2DParity are both likely inlined and fast enough to use with impunity virtually anywhere. In addition, CheckAndCorrect2DParity and Remove2DParityFrom are fast if no errors are detected, but note only moderate effort has been made to accelerate Correct2DParityIfPossible, which is the routine that actually performs the error correction to the degree possible.

Member Function Documentation

static u32 MFM::Parity2D_4x4::Add2DParity ( u32  dataBits)
inlinestatic

Return the 25 bit quantity formed by prefixing the nine bits of 2D parity to the 16 bits of dataBits.

See Also
Compute2DParity
static bool MFM::Parity2D_4x4::Check2DParity ( const u32  allBits)
inlinestatic

Check the 2D parity of allBits, assuming it is laid out in bit number order from its most significant bit on the left to its least significant bit on the right, using the data bit and parity bit definitions given in the documentation for Compute2DParity.

Returns
true if allBits is a correctly formatted ECC+DATA value, with no detectable errors, or false otherwise
See Also
CheckAndCorrect2DParity
static u32 MFM::Parity2D_4x4::CheckAndCorrect2DParity ( const u32  allBits)
inlinestatic

Check the 2D parity of allBits, assuming it is laid out in bit number order from its most significant bit on the left to its least significant bit on the right, using the data bit and parity bit definitions given in the documentation for Compute2DParity.

The value returned is equal to allBits if the parity checks, is 0 if the parity does not check but allBits is so damaged it cannot be repaired. Otherwise the value returned is non-zero and not equal to allBits, and it represents the error-corrected value of allBits.

See Also
Compute2DParity
static u32 MFM::Parity2D_4x4::Compute2DParity ( u32  dataBits)
inlinestatic

Compute the nine bit quantity representing the 2D parity of the bottom 16 bits of dataBits. Assume 0..f represent the bottom sixteen bits of dataBits from least significant (0) to most significant (f) bit, and assume g..o represent the bottom nine bits of the computed 2D parity, from least significant (g) to most significant (o) bit. Then given this layout:

      f  e  d  c  j
      b  a  9  8  i
      7  6  5  4  h
      3  2  1  0  g
      k  l  m  n  o

this function returns the nine bits (corresponding to g..o) such that each 5-element row and 5-element column has odd parity, and the overall group of 25 bits has even parity (but is never all zero).

See Also
Add2DParity
u32 MFM::Parity2D_4x4::Correct2DParityIfPossible ( u32  allBits)
static

Attempt to error-correct allBits. Note: Usually callers will prefer to call CheckAndCorrect2DParity, because it's fast if the parity is correct, while this method is slow in all cases.

The value returned is equal to allBits if the parity checks, is 0 if the parity does not check but allBits is so damaged it cannot be repaired. Otherwise the value returned is non-zero and not equal to allBits, and it represents the error-corrected value of allBits.

See Also
CheckAndCorrect2DParity
static bool MFM::Parity2D_4x4::Remove2DParity ( u32  allBits,
u32 &  dataBits 
)
inlinestatic

Remove the nine parity bits from allBits if possible, storing the (possibly error-corrected) resulting sixteen bits in dataBits.

Returns
true if either the parity was correct or an error was detected and successfully corrected. In either case dataBits will have been updated to the extracted data value. Otherwise returns false and dataBits remains untouched.

Field Documentation

const u8 MFM::Parity2D_4x4::indices2D
static
Initial value:
= {
{ 0x0f, 0x0e, 0x0d, 0x0c, 0x13 },
{ 0x0b, 0x0a, 0x09, 0x08, 0x12 },
{ 0x07, 0x06, 0x05, 0x04, 0x11 },
{ 0x03, 0x02, 0x01, 0x00, 0x10 },
{ 0x14, 0x15, 0x16, 0x17, 0x18 },
}

The documentation for this class was generated from the following files: