/// <summary> /// Analyzes the result of a ZIF-socket read. /// </summary> /// <param name="results">The array of results.</param> /// <param name="eprom">The eprom.</param> /// <param name="address">The address.</param> /// <param name="result"> /// If <see cref="ReadSoundness.SeemsToBeAOkay"/> is returned, /// this result can be trusted. /// </param> /// <returns>The result of the analyzis.</returns> public static ReadSoundness AnalyzeEpromReadSoundness( ZIFSocket[] results, Eprom eprom, int address, out ZIFSocket result) { result = null; var refLenght = results.Length; var revResults = results.Reverse().ToArray(); var withCorrectAddresses = revResults.TakeWhile(x => eprom.GetAddress(x) == address).ToArray(); if (withCorrectAddresses.Length == 0) { return(ReadSoundness.TryRewrite); } if (withCorrectAddresses.Length != refLenght) { return(ReadSoundness.TryReread); } var refData = eprom.GetData(revResults[0]); var withRefData = revResults.TakeWhile(x => eprom.GetData(x).SequenceEqual(refData)).ToArray(); if (withRefData.Length != refLenght) { return(ReadSoundness.TryReread); } result = revResults[0]; return(ReadSoundness.SeemsToBeAOkay); }
/// <summary> /// NOT WORKING YET! /// </summary> /// <param name="eprom"></param> /// <param name="bytes"></param> public void WriteEpromFast(Eprom eprom, IList <byte> bytes) { if (eprom.VppPins.Any(p => eprom.OutputEnable.Any(q => p.Number == q.Number))) { throw new U2PaException("Fast Programming Algoritm can't by used for this EPROM (yet)"); } var totalNumberOfAdresses = eprom.AddressPins.Length == 0 ? 0 : 1 << eprom.AddressPins.Length; var translator = eprom.GetPinTranslator(ZIFType); { var zif = new ZIFSocket(ZIFType); zif.SetAll(true); zif.Disable(eprom.Program, translator.ToZIF); WriteZIF(zif, "Apply 1 to all pins"); SetVccLevel(eprom.VccLevel); SetVppLevel(eprom.VppLevel); ApplyGnd(translator.ToZIF, eprom.GndPins); ApplyVcc(translator.ToZIF, eprom.VccPins); ApplyVpp(translator.ToZIF, eprom.VppPins); } using (var progress = new ProgressBar(Shouter, totalNumberOfAdresses)) { progress.Init(); foreach (var address in Enumerable.Range(0, totalNumberOfAdresses)) { var pulse = 1; while (pulse <= 32) { // Writing var writerZif = new ZIFSocket(40); writerZif.SetAll(true); writerZif.Disable(eprom.GndPins, translator.ToZIF); writerZif.Enable(eprom.Constants, translator.ToZIF); writerZif.Disable(eprom.ChipEnable, translator.ToZIF); writerZif.Disable(eprom.OutputEnable, translator.ToZIF); writerZif.Disable(eprom.Program, translator.ToZIF); eprom.SetAddress(writerZif, address); var data = eprom.DataPins.Length > 8 ? new[] { bytes[2 * address], bytes[2 * address + 1] } : new[] { bytes[address] }; eprom.SetData(writerZif, data); WriteZIF(writerZif, "Write address & d ata to ZIF"); writerZif.Enable(eprom.ChipEnable, translator.ToZIF); writerZif.Enable(eprom.Program, translator.ToZIF); WriteZIF(writerZif, "Start pulse E"); writerZif.Disable(eprom.ChipEnable, translator.ToZIF); writerZif.Disable(eprom.Program, translator.ToZIF); BulkDevice.Delay(pulse); WriteZIF(writerZif, "End pulse E"); // Reading var addressZif = new ZIFSocket(40); addressZif.SetAll(true); addressZif.Disable(eprom.GndPins, translator.ToZIF); addressZif.Enable(eprom.Constants, translator.ToZIF); addressZif.Enable(eprom.ChipEnable, translator.ToZIF); addressZif.Enable(eprom.OutputEnable, translator.ToZIF); addressZif.Disable(eprom.Program, translator.ToZIF); eprom.SetAddress(addressZif, address); WriteZIF(addressZif, "Write address"); var dataZifs = ReadZIF("Read data"); ZIFSocket resultZif; if (Tools.AnalyzeEpromReadSoundness(dataZifs, eprom, address, out resultZif) == ReadSoundness.SeemsToBeAOkay) { if (eprom.GetData(resultZif).SequenceEqual(data)) { // Data validates; now we overprogram writerZif.Enable(eprom.ChipEnable, translator.ToZIF); writerZif.Enable(eprom.Program, translator.ToZIF); WriteZIF(writerZif, "Overprogram"); BulkDevice.Delay(3 * pulse); writerZif.Disable(eprom.ChipEnable, translator.ToZIF); writerZif.Disable(eprom.Program, translator.ToZIF); WriteZIF(writerZif, "End pulse E"); break; } else { Console.WriteLine("Pulse: {0}", pulse); Console.WriteLine("Address: {0}", address.ToString("X4")); Console.WriteLine(eprom.GetData(writerZif).First()); Console.WriteLine(eprom.GetData(resultZif).First()); } } pulse *= 2; } if (pulse > 32) { progress.Shout("Address {0} doesn't validate! }};-(", address.ToString("X4")); } progress.Progress(); } } }
/// <summary> /// Reads an EPROM. /// </summary> /// <param name="eprom">The EPROM type.</param> /// <param name="progressBar">The progress bar.</param> /// <param name="bytes">The list that accumulates the read bytes.</param> /// <param name="fromAddress">Start reading this address.</param> /// <param name="totalNumberOfAdresses">The total number of adesses.</param> /// <returns>The next adress to be read.</returns> public int ReadEprom( Eprom eprom, ProgressBar progressBar, IList <byte> bytes, int fromAddress, int totalNumberOfAdresses) { const int rewriteCount = 5; const int rereadCount = 5; Shouter.ShoutLine(2, "Reading EPROM{0}", eprom.Type); SetVccLevel(eprom.VccLevel); var translator = eprom.GetPinTranslator(ZIFType); ApplyVcc(translator.ToZIF, eprom.VccPins); ApplyGnd(translator.ToZIF, eprom.GndPins); PullUpsEnable(true); var zif = new ZIFSocket(ZIFType); var returnAddress = fromAddress; Shouter.ShoutLine(2, "Now reading bytes..."); progressBar.Init(); foreach (var address in Enumerable.Range(fromAddress, totalNumberOfAdresses - fromAddress)) { zif.SetAll(true); zif.Disable(eprom.GndPins, translator.ToZIF); zif.Enable(eprom.Constants, translator.ToZIF); zif.Enable(eprom.ChipEnable, translator.ToZIF); zif.Enable(eprom.OutputEnable, translator.ToZIF); eprom.SetAddress(zif, returnAddress = address); ZIFSocket resultZIF = null; var result = ReadSoundness.TryRewrite; for (var i = 0; i < rewriteCount; i++) { if (result == ReadSoundness.SeemsToBeAOkay) { break; } if (result == ReadSoundness.TryRewrite) { if (i > 0) { progressBar.Shout("A: {0}; WS: {1}ms", address.ToString("X4"), 100 * i); } WriteZIF(zif, String.Format("A: {0}", address.ToString("X4"))); if (i > 0) { Thread.Sleep(100 * i); } result = ReadSoundness.TryReread; } for (var j = 0; j < rereadCount; j++) { if (result != ReadSoundness.TryReread) { break; } if (j > 0) { progressBar.Shout("A: {0}; WS: {1}ms; RS: {2}ms", address.ToString("X4"), 100 * i, 100 * (j * i)); Thread.Sleep(100 * (j * i)); } var readZifs = ReadZIF(String.Format("for address {0}", address.ToString("X4"))); result = Tools.AnalyzeEpromReadSoundness(readZifs, eprom, address, out resultZIF); if (j == rereadCount - 1) { result = ReadSoundness.TryRewrite; } if (result == ReadSoundness.SeemsToBeAOkay && j > 0) { progressBar.Shout("Address: {0} read }};-P", address.ToString("X4")); } } } if (result != ReadSoundness.SeemsToBeAOkay) { return(returnAddress); } foreach (var b in eprom.GetData(resultZIF)) { bytes.Add(b); } progressBar.Progress(); } return(returnAddress + 1); }