Beispiel #1
0
    static (SerialPort, SerialPort) tryGetSerialFlasher(string port)
    {
        if (port == null)
        {
            Console.WriteLine("Port cannot be null here!");
            Environment.Exit(1);
        }
        SerialPort flash = new SerialPort(
            portName: port,
            parity: Parity.None,
            baudRate: 9600,
            stopBits: StopBits.One,
            dataBits: 8
            );

        tryWakeGenericDevice(flash);

        // Reset
        var device = tryGetICEDevice(IceSerialInfo.tryFindDevicePort());

        // Wait for serial ports to reset
        Thread.Sleep(2000);
        Console.WriteLine("Resetting serial devices...");

        // Reset FPGA
        IceSerial.resetFpga(device);
        IceSerial.runFpga(device);

        // Simply wait
        Console.WriteLine("Waiting for CPU to wake...");
        Thread.Sleep(500);

        return(flash, device);
    }
Beispiel #2
0
    static void Main(string[] args)
    {
        var info    = new IceSerialInfo();
        var argport = new Option <string>(
            aliases: new string[] { "--port", "-p" },
            description: "Set device name (can be null)",
            getDefaultValue: () =>
        {
            return(null);
        });
        var argfile = new Argument <FileInfo>(
            name: "file",
            description: "Binary bitstream file to upload",
            getDefaultValue: () => null);
        var argverify = new Option <bool>(
            aliases: new string[] { "--verify", "-v" },
            description: "Verify after upload");
        var cmdlist = new Command("list", "Enumerate serial port devices");
        var cmdrun  = new Command("run", "Run the FPGA device");

        cmdrun.AddOption(argport);
        var cmdreset = new Command("reset", "Reset (not erase) the FPGA device");

        cmdreset.AddOption(argport);
        var cmdprogram = new Command("program", "Upload binary bitstream to the FPGA");

        cmdprogram.AddOption(argport);
        cmdprogram.AddOption(argverify);
        cmdprogram.AddArgument(argfile);
        var root = new RootCommand {
            cmdlist, cmdrun, cmdreset, cmdprogram
        };

        cmdlist.Handler = CommandHandler.Create <string, FileInfo>(
            (port, file) =>
        {
            info.enumerate();
        });
        cmdrun.Handler = CommandHandler.Create <string>(
            (port) =>
        {
            var device = tryGetDevice(port == null ? info.tryFindDevicePort() : port);
            runFpga(device);
            Console.WriteLine("Running...");
        });
        cmdreset.Handler = CommandHandler.Create <string>(
            (port) =>
        {
            var device = tryGetDevice(port == null ? info.tryFindDevicePort() : port);
            resetFpga(device);
            Console.WriteLine("Done.");
        });
        cmdprogram.Handler = CommandHandler.Create <bool, string, FileInfo>(
            (verify, port, file) =>
        {
            var device = tryGetDevice(port == null ? info.tryFindDevicePort() : port);
            doUpload(device, file, verify);
        });
        root.Invoke(args);
        Environment.Exit(0);
    }
Beispiel #3
0
    static void Main(string[] args)
    {
        var argport = new Option <string>(
            aliases: new string[] { "--port", "-p" },
            description: "Set device name (can be null)",
            getDefaultValue: () =>
        {
            return(null);
        });
        var argfile = new Argument <FileInfo>(
            name: "file",
            description: "Binary file to upload",
            getDefaultValue: () => null);
        var argverify = new Option <bool>(
            aliases: new string[] { "--verify", "-v" },
            description: "Verify after upload");
        var argtty = new Option <bool>(
            aliases: new string[] { "--tty", "-i" },
            description: "Enter tty mode after flashing");
        var cmdlist = new Command("list", "Enumerate serial port devices");
        var cmdrun  = new Command("run", "Run the FPGA device");

        cmdrun.AddOption(argport);
        var cmdreset = new Command("reset", "Reset (not erase) the FPGA device");

        cmdreset.AddOption(argport);
        var cmdprogram = new Command("program", "Upload binary bitstream to the FPGA");

        cmdprogram.AddOption(argport);
        cmdprogram.AddOption(argverify);
        cmdprogram.AddArgument(argfile);
        var cmdflashboot = new Command("flash", "Upload program to bootstrap using the serial port of the uploader");

        cmdflashboot.AddOption(argport);
        cmdflashboot.AddOption(argverify);
        cmdflashboot.AddOption(argtty);
        cmdflashboot.AddArgument(argfile);
        var cmdmemtest = new Command("memtest", "Runs the UART memtest");

        cmdmemtest.AddOption(argport);
        var root = new RootCommand {
            cmdlist, cmdrun, cmdreset, cmdprogram, cmdflashboot, cmdmemtest
        };

        cmdlist.Handler = CommandHandler.Create <string, FileInfo>(
            (port, file) => {
            IceSerialInfo.enumerate();
        });
        cmdrun.Handler = CommandHandler.Create <string>(
            (port) => {
            var device = tryGetICEDevice(port == null ? IceSerialInfo.tryFindDevicePort() : port);
            IceSerial.runFpga(device);
            Console.WriteLine("Running...");
        });
        cmdreset.Handler = CommandHandler.Create <string>(
            (port) => {
            var device = tryGetICEDevice(port == null ? IceSerialInfo.tryFindDevicePort() : port);
            IceSerial.resetFpga(device);
            Console.WriteLine("Done.");
        });
        cmdprogram.Handler = CommandHandler.Create <bool, string, FileInfo>(
            (verify, port, file) => {
            var device = tryGetICEDevice(port == null ? IceSerialInfo.tryFindDevicePort() : port);
            IceSerial.doUpload(device, file, verify);
        });
        cmdflashboot.Handler = CommandHandler.Create <bool, string, FileInfo, bool>(
            (verify, port, file, tty) => {
            var(flash, device) = tryGetSerialFlasher(port);
            BootSerial.doUpload(flash, file, verify);
            if (tty)
            {
                enterTtyMode(flash);
            }
            flash.Close();
            device.Close();
        });
        cmdmemtest.Handler = CommandHandler.Create <string>(
            (port) => {
            var(flash, device) = tryGetSerialFlasher(port);
            BootSerial.doMemtest(flash, device);
            flash.Close();
            device.Close();
        });
        root.Invoke(args);
        Environment.Exit(0);
    }