/// <summary> /// Uploads the ictest.bin FPGA-program to the device. /// </summary> /// <param name="fileName">The name of the file.</param> /// <remarks> /// I don't fully understand all of the stuff going on in this method, as I have /// just used an USB-sniffer to see what TopWin6 does when uploading ictest.bin. /// </remarks> private void UpLoadFPGAProgramTopWin6Style(string fileName) { // Prelude of black magic BulkDevice.SendPackage(5, new byte[] { 0x0A, 0x1B, 0x00 }, "???"); BulkDevice.SendPackage(5, new byte[] { 0x0E, 0x21, 0x00, 0x00 }, "Start bitstream upload"); BulkDevice.SendPackage(5, new byte[] { 0x07 }, "Some kind of finish-up/execute command?"); BulkDevice.RecievePackage(5, "Some values that maby should be validated in some way"); var fpgaProgram = new FPGAProgram(fileName); var bytesToSend = PackFPGABytes(fpgaProgram.Payload).SelectMany(x => x).ToArray(); Shouter.ShoutLine(5, fpgaProgram.ToString()); BulkDevice.SendPackage(5, bytesToSend, "Uploading file: {0}", fileName); // Postlude of black magic BulkDevice.SendPackage(5, new byte[] { 0x0E, 0x12, 0x00, 0x00 }, "Set Vpp boost off"); BulkDevice.SendPackage(5, new byte[] { 0x1B }, "???"); // Why 2 times??? BulkDevice.SendPackage(5, new byte[] { 0x0E, 0x12, 0x00, 0x00 }, "Set Vpp boost off"); BulkDevice.SendPackage(5, new byte[] { 0x1B }, "???"); BulkDevice.SendPackage(5, new byte[] { 0x0E, 0x13, 0x32, 0x00 }, "Set Vcc = 5V"); BulkDevice.SendPackage(5, new byte[] { 0x1B }, "???"); BulkDevice.SendPackage(5, new byte[] { 0x0E, 0x15, 0x00, 0x00 }, "Clear all Vcc assignments"); // Why no 0x1B here??? BulkDevice.SendPackage(5, new byte[] { 0x0E, 0x17, 0x00, 0x00 }, "Clear all ??? assignments"); // Why no 0x1B here??? BulkDevice.SendPackage(5, new byte[] { 0x0A, 0x1D, 0x86 }, "???"); BulkDevice.SendPackage(5, new byte[] { 0x0E, 0x16, 0x00, 0x00 }, "Clear all Gnd assignments"); var clueless = new byte[] { 0x3E, 0x00, 0x3E, 0x01, 0x3E, 0x02, 0x3E, 0x03, 0x3E, 0x04, 0x3E, 0x05, 0x3E, 0x06, 0x3E, 0x07, 0x3E, 0x08, 0x3E, 0x09, 0x3E, 0x0A, 0x3E, 0x0B, 0x3E, 0x0C, 0x3E, 0x0D, 0x3E, 0x0E, 0x3E, 0x0F, 0x3E, 0x10, 0x3E, 0x11, 0x3E, 0x12, 0x3E, 0x13, 0x3E, 0x14, 0x3E, 0x15, 0x3E, 0x16, 0x3E, 0x17, 0x07 }; BulkDevice.SendPackage(5, clueless, "I´m clueless on this one atm"); BulkDevice.RecievePackage(5, "Properly answer to clueless that maby should be validated in some way"); // Again? BulkDevice.SendPackage(5, new byte[] { 0x0E, 0x12, 0x00, 0x00 }, "Set Vpp boost off"); BulkDevice.SendPackage(5, new byte[] { 0x1B }, "???"); // Again, again??? BulkDevice.SendPackage(5, new byte[] { 0x0E, 0x12, 0x00, 0x00 }, "Set Vpp boost off"); }
/// <summary> /// Entry point for the 'vector' category of commands. /// </summary> /// <param name="shouter">The shouter instance.</param> /// <param name="args">Command line argumsnts</param> /// <returns>Exit code. 0 is fine; all other is bad.</returns> private static int Vector(Shouter shouter, List <string> args) { if (args.Count == 1) { args.Insert(0, "help"); Help(shouter, args); return(0); } switch (args[1]) { case "test": return(Kernel.VectorTest(shouter, args[2])); default: shouter.ShoutLine(1, "Unknown vector command {0}", args[1]); return(1); } }
// Verbosity: // 0 totally silent // 1 only display fatal errors ie exceptions resulting in abort // 2 startup message and few messages // 3 ... // 4 ... // 5 all messages /// <summary> /// Main entry point for the whole application. /// </summary> /// <param name="args">Command line arguments.</param> /// <returns>Exit code. 0 is fine; all other is bad.</returns> public static int Main(string[] args) { var timestamp = DateTime.Now; var shouter = new Shouter(3); try { var cleanedArgs = new List <string>(); var options = new Dictionary <string, string>(); for (var i = 0; i < args.Length; i++) { if (args[i].StartsWith("-")) { if (i == args.Length - 1 || args[i + 1].StartsWith("-")) { throw new U2PaException("Syntax error: option {0} provided without an argument.", args[i]); } options.Add(args[i].TrimStart('-'), args[i + 1]); i++; } else { cleanedArgs.Add(args[i]); } } if (cleanedArgs.Count == 0 || cleanedArgs[0] == "help") { return(Help(shouter, cleanedArgs)); } if (options.ContainsKey("v")) { shouter.VerbosityLevel = Int32.Parse(options["v"]); } else if (options.ContainsKey("verbosity")) { shouter.VerbosityLevel = Int32.Parse(options["verbosity"]); } shouter.ShoutLine(2, "************* U2Pa (C) Elgen 2012 }};-P ***************"); shouter.ShoutLine(2, "* Alternative software for Top Universal Programmers *"); shouter.ShoutLine(2, "******************************************************"); shouter.ShoutLine(2, "Verbosity level: {0}", shouter.VerbosityLevel); shouter.ShoutLine(2, "OS: {0}", OsDetector.Platform); shouter.ShoutLine(2, "U2Pa initiated at {0}", timestamp); var returnCode = 0; switch (cleanedArgs[0]) { case "rom": returnCode = Rom(shouter, cleanedArgs); break; case "sram": returnCode = SRam(shouter, cleanedArgs); break; case "prog": returnCode = Prog(shouter, cleanedArgs); break; case "bdump": returnCode = BDump(shouter, cleanedArgs); break; case "vector": returnCode = Vector(shouter, cleanedArgs); break; case "help": returnCode = Help(shouter, cleanedArgs); break; case "dev": returnCode = Dev(shouter, cleanedArgs); break; } shouter.ShoutLine(2, "Elapsed time: {0}", DateTime.Now - timestamp); return(returnCode); } catch (Exception e) { shouter.ShoutLine(1, "Fatal error: {0}", e.Message); shouter.ShoutLine(5, "Exception:\n{0}", e); return(1); } }
/// <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); }