// Tang Primer 25K programmer: a window around openFPGALoader (-c dirtyJtag) // for loading FPGA bitstreams, plus flashing of the BL616 bridge firmware // (what scripts\flash.ps1 does). Build with scripts\build_gui.ps1. using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.InteropServices; using System.Text; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; namespace TangProgrammer { static class Program { [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); } } enum ToolKind { Ofl, BlFlash } sealed class RunResult { public int ExitCode = -1; public bool FailSeen; public readonly List Lines = new List(); // openFPGALoader exits with 0 even when loading the SRAM fails public bool Ok { get { return ExitCode == 0 && !FailSeen; } } public bool Has(string text) { return Lines.Any(l => l.IndexOf(text, StringComparison.OrdinalIgnoreCase) >= 0); } public string Find(Regex rx) { foreach (string l in Lines) { Match m = rx.Match(l); if (m.Success) return m.Groups[1].Value; } return null; } } sealed class LogEntry { public string Text; public Tone Tone; public bool Bold; } sealed class MainForm : Form { const string AppTitle = "Tang Primer 25K — программатор"; // where the tools and the bridge firmware are: the source tree, or the // portable copy made by scripts\make_portable.ps1 static readonly string[] BlFlashPaths = { @"third_party\bouffalo_sdk\tools\bflb_tools\bouffalo_flash_cube\BLFlashCommand.exe", @"tools\bouffalo_flash_cube\BLFlashCommand.exe", }; static readonly string[] BridgeFwPaths = { @"build\build_out\tang25k_debugger_bl616.bin", @"firmware\tang25k_debugger_bl616.bin", }; static readonly int[] FreqList = { 1, 2, 4, 6, 10, 15, 20, 30 }; // MHz; the firmware does up to 30 const int DefaultFreq = 6; // what the firmware starts with const int MaxLogEntries = 4000; // openFPGALoader: "Load SRAM: [===== ] 33.00%" static readonly Regex OflProgressRx = new Regex(@"^(?