Beispiel #1
0
Datei: ECC.cs Projekt: gxk/dm6467
        // *************************************************
        // *            Private Constructors               *
        // *************************************************


        // *************************************************
        // *               Private Methods                 *
        // *************************************************


        // *************************************************
        // *        Public properties and Indexer          *
        // *************************************************


        // *************************************************
        // *             Public constructors               *
        // *************************************************

        public ReedSolomonECC(Int32 msgSymbolCnt, Int32 maxCorrectibleErrorCnt, Byte symbolBitWidth)
        {
            k = msgSymbolCnt;
            s = maxCorrectibleErrorCnt;
            N = k + 2 * s;

            // Create Binary Galois Field ( that is GF(2^symbolBitWidth) )
            galoisField = new BinaryGaloisField(symbolBitWidth);

            // Create the generator polynomial, g(x)
            generatorPoly = ReedSolomonECC.createGeneratorPolynomial(galoisField, maxCorrectibleErrorCnt);
        }
        /// <summary>
        /// Main program.
        /// </summary>
        /// <param name="args">Input commandline arguments</param>
        /// <returns>Return code: 0 for correct exit, -1 for unexpected exit</returns>
        static Int32 Main(String[] args)
        {
            // Assumes that in AssemblyInfo.cs, the version is specified as 1.0.* or the like,
              // with only 2 numbers specified;  the next two are generated from the date.
              System.Version v = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;

              // v.Build is days since Jan. 1, 2000, v.Revision*2 is seconds since local midnight
              Int32 buildYear = new DateTime( v.Build * TimeSpan.TicksPerDay + v.Revision * TimeSpan.TicksPerSecond * 2 ).AddYears(1999).Year;

              // Begin main code
              //Console.Clear();
              Console.WriteLine("-----------------------------------------------------");
              Console.WriteLine("   TI EMIF2.5 ECC Parity Generator for " + devString  );
              Console.WriteLine("   (C) "+buildYear+", Texas Instruments, Inc."        );
              Console.WriteLine("   Ver. "+v.Major+"."+v.Minor.ToString("D2")          );
              Console.WriteLine("-----------------------------------------------------");
              Console.Write("\n\n");

              // Parse the input command line parameters
              ProgramCmdParams cmdParams = ParseCmdLine(args);
              if (!cmdParams.valid)
              {
              DispHelp();
              return -1;
              }

              // Create Reed Solomon ECC Object
              // Usage: ReedSolomonECC(Int32 msgSymbolCnt, Int32 maxCorrectibleErrorCnt, Byte symbolBitWidth)
              ReedSolomonECC rs = new ReedSolomonECC(512,4,10);

              // Create binary writer for saving ECC data to output file
              BinaryWriter bw = new BinaryWriter(new FileStream(cmdParams.outputFileName,FileMode.Create,FileAccess.Write));

              // Read input data from file
              Byte[] fileData = FileIO.GetFileData(cmdParams.inputfileName);

              Int32[] subArray = new Int32[512];
              Int32[] parityArray;

              for (int i=0; i<fileData.Length; i+=512)
              {
            for (int j=0; j<512; j++)
            {
              // Swap order of message data since this is apparently what the hardware does
              // for its RS calculations
              subArray[511-j] = ((i+j) >= fileData.Length) ? (0xFF) : ((Int32) fileData[i+j]);
            }

            // Calculate parity of the message data
            parityArray = rs.GenerateParity(subArray);

            // Prep the parity data and output it to file
            if (cmdParams.verbose)
            {
              Console.WriteLine("NAND operation #{0}",(i/512)+1);
            }
            for (int j=0; j<8; j+=2)
            {
              if (cmdParams.verbose)
              {
            Console.WriteLine("\tNAND4BITECC{0} = {1:X8}", (j/2 + 1),( (parityArray[j+1] & 0x3FF) << 16) | (parityArray[j] & 0x3FF) );
              }
              bw.Write( ( (parityArray[j+1] & 0x3FF) << 16) | (parityArray[j] & 0x3FF) );
            }
              }

              return 0;
        }