/// <summary> /// Displays a list of all supported ROMs. /// </summary> /// <param name="shouter">The shouter instance.</param> /// <param name="option">If option "type" is passed, only the type is displayed.</param> /// <returns>Exit code. 0 is fine; all other is bad.</returns> public static int RomAll(IShouter shouter, string option) { var onlyDisplayTypeName = option == "type"; shouter.ShoutLine(1, "Supported ROMs:"); shouter.ShoutLine(1, "==============="); foreach (var pair in EpromXml.Specified.OrderBy(pair => pair.Key)) { if (onlyDisplayTypeName) { shouter.ShoutLine(1, pair.Key); } else { var rom = pair.Value; shouter.ShoutLine(1, "Type:"); shouter.ShoutLine(1, " {0}", rom.Type); if (!String.IsNullOrWhiteSpace(rom.Description)) { shouter.ShoutLine(1, "Description:"); shouter.ShoutLine(1, rom.Description); } if (!String.IsNullOrWhiteSpace(rom.Notes)) { shouter.ShoutLine(1, "Notes:"); shouter.ShoutLine(1, rom.Notes); } shouter.ShoutLine(1, "-----------"); } } return(0); }
/// <summary> /// Calculates and writes some statistics about the connected Top Programmer /// and the UBS connection. /// </summary> /// <param name="shouter">The public address instance.</param> /// <returns>Exit code. 0 is fine; all other is bad.</returns> public static int ProgStat(IShouter shouter) { using (var td = TopDevice.Create(shouter)) { var writeZif = new ZIFSocket(40); writeZif.SetAll(false); td.WriteZIF(writeZif, ""); td.WriteZIF(writeZif, ""); Stopwatch sw = new Stopwatch(); sw.Start(); for (var i = 0; i < 1000; i++) { td.WriteZIF(writeZif, ""); } sw.Stop(); shouter.ShoutLine(0, "Average WriteZif = {0}ms (1000 performed)", (double)sw.ElapsedMilliseconds / 1000); sw.Reset(); sw.Start(); for (var i = 0; i < 1000; i++) { td.ReadZIF(""); } sw.Stop(); shouter.ShoutLine(0, "Average ReadZif = {0}ms (1000 performed)", (double)sw.ElapsedMilliseconds / 1000); } return(0); }
/// <summary> /// A simple SRAM-test. /// </summary> /// <param name="shouter">The shouter instance.</param> /// <param name="type">The type of SRAM.</param> /// <returns>Exit code. 0 is fine; all other is bad.</returns> public static int SRamTest(IShouter shouter, string type) { var sram = SRamXml.Specified[type]; var totalNumberOfAdresses = sram.AddressPins.Length == 0 ? 0 : 1 << sram.AddressPins.Length; List <Tuple <int, string, string> > firstRandomPass, secondRandomPass, firstSimplePass, secondSimplePass; using (var progressBar = new ProgressBar(shouter, totalNumberOfAdresses * 8)) { using (var topDevice = TopDevice.Create(shouter)) { shouter.ShoutLine(1, "Testing SRAM{0}", type); progressBar.Init(); firstRandomPass = topDevice.SRamTestPass(shouter, sram, progressBar, "First random test", totalNumberOfAdresses, new RandomDataGenerator(sram.DataPins.Length, totalNumberOfAdresses)); secondRandomPass = topDevice.SRamTestPass(shouter, sram, progressBar, "Second random test", totalNumberOfAdresses, new RandomDataGenerator(sram.DataPins.Length, totalNumberOfAdresses)); firstSimplePass = topDevice.SRamTestPass(shouter, sram, progressBar, "First simple test (01..)", totalNumberOfAdresses, new SimpleDataGenerator(sram.DataPins.Length, false)); secondSimplePass = topDevice.SRamTestPass(shouter, sram, progressBar, "Second simple test (10..)", totalNumberOfAdresses, new SimpleDataGenerator(sram.DataPins.Length, true)); } } var returnValue = 0; var printingVerbosity = 1; returnValue = PrintTestPassResult(shouter, "first random", firstRandomPass, ref printingVerbosity); returnValue = PrintTestPassResult(shouter, "second random", secondRandomPass, ref printingVerbosity); returnValue = PrintTestPassResult(shouter, "first simple", firstSimplePass, ref printingVerbosity); returnValue = PrintTestPassResult(shouter, "second simple", secondSimplePass, ref printingVerbosity); if (returnValue == 0) { shouter.ShoutLine(1, "This piece of SRAM is just a'okay }};-P"); } return(returnValue); }
/// <summary> /// Initiates the instance. /// <remarks>Greatly inspired by the examples in the LibUsbDotNet documentation.</remarks> /// </summary> private void Init() { UsbDevice = UsbDevice.OpenUsbDevice(new UsbDeviceFinder(VendorId, ProductId)); if (UsbDevice == null) { throw new U2PaException( "Top Universal Programmer with VendorId: 0x{0} and ProductId: 0x{1} not found.", VendorId.ToString("X4"), ProductId.ToString("X4")); } Shouter.ShoutLine(4, "Top Universal Programmer with VendorId: 0x{0} and ProductId: 0x{1} found.", VendorId.ToString("X4"), ProductId.ToString("X4")); var wholeUsbDevice = UsbDevice as IUsbDevice; if (!ReferenceEquals(wholeUsbDevice, null)) { wholeUsbDevice.SetConfiguration(Configuration); byte temp; if (wholeUsbDevice.GetConfiguration(out temp)) { Shouter.ShoutLine(4, "Configuration with id: {0} selected.", temp.ToString("X2")); } else { throw new U2PaException("Failed to set configuration id: {0}", Configuration); } if (wholeUsbDevice.ClaimInterface(Interface)) { Shouter.ShoutLine(4, "Interface with id: {0} claimed.", Interface); } else { throw new U2PaException("Failed to claim interface with id: {0}", Interface); } } UsbEndpointReader = UsbDevice.OpenEndpointReader(ReadEndpointID); if (UsbEndpointReader == null) { throw new U2PaException("Unable to open read endpoint ${0}", ReadEndpointID.ToString()); } Shouter.ShoutLine(4, "Reader endpoint ${0} opened.", UsbEndpointReader.EndpointInfo.Descriptor.EndpointID.ToString("X2")); UsbEndpointWriter = UsbDevice.OpenEndpointWriter(WriteEndpointID); if (UsbEndpointWriter == null) { throw new U2PaException("Unable to open write endpoint ${0}", WriteEndpointID.ToString()); } Shouter.ShoutLine(4, "Writer endpoint ${0} opened.", UsbEndpointWriter.EndpointInfo.Descriptor.EndpointID.ToString("X2")); }
/// <summary> /// Entry point for the 'sram' 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 SRam(IShouter shouter, IList <string> args) { if (args.Count == 1) { args.Insert(0, "help"); Help(shouter, args); return(0); } switch (args[1]) { case "all": var option = args.Count == 3 ? args[2] : null; return(Kernel.SRamAll(shouter, option)); case "test": return(Kernel.SRamTest(shouter, args[2])); case "info": return(Kernel.SRamInfo(shouter, args[2])); default: shouter.ShoutLine(1, "Unknown sram command {0}", args[1]); return(1); } }
/// <summary> /// Processes a binary dump. /// </summary> /// <param name="shouter">The shouter instance.</param> /// <param name="format">Format.</param> /// <param name="numberOfOutputs">Number of input pins.</param> /// <param name="numberOfInputs">Number of output pins.</param> /// <param name="path">The file name.</param> /// <returns>Exit code. 0 is fine; all other is bad.</returns> public static int BDumpProcess( IShouter shouter, string format, int numberOfOutputs, int numberOfInputs, string path) { var processor = new BinaryDumpProcessor(path); string output; switch (format) { case "ceqn": output = processor.GenerateCUPLEquations(numberOfOutputs, numberOfInputs); break; case "ctt": output = processor.GenerateCUPLTruthTable(numberOfOutputs, numberOfInputs); break; case "tt": output = processor.GenerateHumanReadableTruthTable(numberOfOutputs, numberOfInputs); break; default: shouter.ShoutLine(1, "Unknown bdump format {0}", format); return(1); } Console.WriteLine(); Console.WriteLine(output); return(0); }
/// <summary> /// Creates a new instance of the Top Device connected to the Top Programmer. /// <remarks>Atm. only works for model Top2005+.</remarks> /// </summary> /// <param name="shouter">The shouter instance.</param> /// <param name="bulkDevice">The bulk device to use.</param> /// <returns>The created instance of the Top Device.</returns> public static TopDevice Create(IShouter shouter, IUsbBulkDevice bulkDevice) { var idString = ReadTopDeviceIdString(shouter, bulkDevice); shouter.ShoutLine(2, "Connected Top device is: {0}.", idString); if (idString.StartsWith("top2005+")) { return(new Top2005Plus(shouter, bulkDevice)); } throw new U2PaException("Not supported Top Programmer {0}", idString); }
/// <summary> /// Writes the id of the connected Top Programmer. /// </summary> /// <param name="shouter">The public address instance.</param> /// <returns>Exit code. 0 is fine; all other is bad.</returns> public static int ProgId(IShouter shouter) { var v = shouter.VerbosityLevel; try { shouter.VerbosityLevel = 0; shouter.ShoutLine(0, "Connected Top Programmer has id: {0}", TopDevice.ReadTopDeviceIdString(shouter)); return(0); } finally { shouter.VerbosityLevel = v; } }
private static int PrintTestPassResult(IShouter shouter, string text, List <Tuple <int, string, string> > pass, ref int printingVerbosity) { int returnValue = 0; var oldPrintingVerbosity = printingVerbosity; foreach (var tuple in pass) { shouter.ShoutLine(printingVerbosity, "Bad cell in {0} pass. Address: {1} Expected {2} Read {3}", text, tuple.Item1.ToString("X4"), tuple.Item3, tuple.Item2); printingVerbosity = 5; returnValue = 1; if (oldPrintingVerbosity <= 5) { break; } } return(returnValue); }
/// <summary> /// Entry point for the 'bdump' 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 BDump(IShouter shouter, IList <string> args) { if (args.Count < 6) { args.Insert(0, "help"); Help(shouter, args); return(0); } var numberOfOutputs = Int32.Parse(args[3]); var numberOfInputs = Int32.Parse(args[4]); switch (args[1]) { case "process": Kernel.BDumpProcess(shouter, args[2], numberOfOutputs, numberOfInputs, args[5]); return(0); default: shouter.ShoutLine(1, "Unknown bdump command {0}", args[1]); return(1); } }
/// <summary> /// Entry point for the 'prog' 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 Prog(IShouter shouter, IList <string> args) { if (args.Count == 1) { args.Insert(0, "help"); Help(shouter, args); return(0); } switch (args[1]) { case "id": Kernel.ProgId(shouter); return(0); case "stat": Kernel.ProgStat(shouter); return(0); default: shouter.ShoutLine(1, "Unknown prog command {0}", args[1]); return(1); } }
/// <summary> /// Entry point for the 'rom' category of commands. /// </summary> /// <param name="shouter">The shouter instance.</param> /// <param name="args">Command line arguments</param> /// <returns>Exit code. 0 is fine; all other is bad.</returns> private static int Rom(IShouter shouter, IList <string> args) { if (args.Count == 1) { args.Insert(0, "help"); Help(shouter, args); return(0); } switch (args[1]) { case "all": var option = args.Count == 3 ? args[2] : null; return(Kernel.RomAll(shouter, option)); case "id": shouter.ShoutLine(1, "rom id not yet implemented!"); return(1); case "info": return(Kernel.RomInfo(shouter, args[2])); case "read": var data = Kernel.RomRead(shouter, args[2]); Tools.WriteBinaryFile(args[3], data); shouter.ShoutLine(2, "EPROM{0} data written to file {1}", args[2], args[3]); return(0); case "verify": var fileData = Tools.ReadBinaryFile(args[3]).ToArray(); var didntVerify = Kernel.RomVerify(shouter, args[2], fileData).ToArray(); if (didntVerify.Any()) { foreach (var tuple in didntVerify) { shouter.ShoutLine( 3, "Address {0} didn't verify. In file {1}, in EPROM {2}. Can{3} be patched", tuple.Item1.ToString("X4"), tuple.Item2.ToString("X2"), tuple.Item3.ToString("X2"), Tools.CanBePatched(tuple.Item2, tuple.Item3) ? "" : "'t"); } } if (didntVerify.Length == 0) { shouter.ShoutLine(2, "EPROM verifies nicely }};-)"); } return(0); case "write": fileData = Tools.ReadBinaryFile(args[3]).ToArray(); Kernel.RomWrite(shouter, args[2], fileData); shouter.ShoutLine(2, "Filedata from {0} written to EPROM", args[2], args[3]); return(0); default: shouter.ShoutLine(1, "Unknown rom command {0}", args[1]); return(1); } }