Пример #1
0
        public SmartScope(ISmartScopeInterface hwInterface) : base()
        {
            this.hardwareInterface      = hwInterface;
            this.SuspendViewportUpdates = false;
            DataOutOfRange = false;
            deviceReady    = false;

            foreach (DigitalChannel d in DigitalChannel.List)
            {
                this.triggerDigital[d] = DigitalTriggerValue.X;
            }

            yOffset        = new Dictionary <AnalogChannel, float>();
            verticalRanges = new Dictionary <AnalogChannel, Range>();
            foreach (AnalogChannel ch in AnalogChannel.List)
            {
                ch.SetProbe(Probe.DefaultX1Probe);
                yOffset[ch] = 0f;
            }

            dataSourceScope = new DataSources.DataSource(this);
            try {
                InitializeHardware();
            } catch (Exception e)
            {
                Logger.Error("Failed to initialize hardware, resetting scope: " + e.Message);
                if (HardwareInterface != null)
                {
                    hardwareInterface.Reset();
                }
                throw e;
            }
        }
        public ScopePicRegisterMemory(ISmartScopeInterface hwInterface)
        {
            this.hwInterface = hwInterface;

            foreach (PIC reg in Enum.GetValues(typeof(PIC)))
            {
                Registers.Add((uint)reg, new ByteRegister(this, (uint)reg, reg.ToString()));
            }
        }
Пример #3
0
        private void DestroyHardware()
        {
            this.dataSourceScope.Stop();

            stopPending = false;
            acquiring   = false;
            deviceReady = false;

            this.hardwareInterface = null;
            this.flashed           = false;
        }
Пример #4
0
        public ScopeFpgaI2cMemory(ISmartScopeInterface hwInterface, byte I2cAddress, int size = 0, bool readOnly = false)
        {
            if (I2cAddress != (I2cAddress & 0x7f))
            {
                throw new Exception(string.Format("I2c Address too large to be an I2C address: {0:X}", I2cAddress));
            }

            for (uint i = 0; i < size; i++)
            {
                Registers.Add(i, new ByteRegister(this, i, "Reg[" + i.ToString() + "]"));
            }
            this.hwInterface = hwInterface;
            this.I2cAddress  = I2cAddress;
            this.readOnly    = readOnly;
        }
Пример #5
0
        public HackerSpecial(ISmartScopeInterface iface)
        {
            this.iface  = iface;
            this.Ready  = true;
            this.Serial = iface.Serial;

            memories.Clear();
            byte FPGA_I2C_ADDRESS_SETTINGS = 0x0C;
            byte FPGA_I2C_ADDRESS_ROM      = 0x0D;
            byte FPGA_I2C_ADDRESS_USER     = 0x0E;

            FpgaSettingsMemory = new ByteMemoryEnum <REG>(new ScopeFpgaI2cMemory(iface, FPGA_I2C_ADDRESS_SETTINGS, 39));
            FpgaRom            = new ByteMemoryEnum <ROM>(new ScopeFpgaI2cMemory(iface, FPGA_I2C_ADDRESS_ROM, 256, true));
            FpgaUserMemory     = new ScopeFpgaI2cMemory(iface, FPGA_I2C_ADDRESS_USER, 256);

            memories.Add(FpgaSettingsMemory);
            memories.Add(FpgaRom);
            memories.Add(FpgaUserMemory);

            //Get FW contents
            string fwName = "blobs.SmartScopeHackerSpecial.bin";

            byte[] firmware = Resources.Load(fwName);

            if (firmware == null)
            {
                throw new ScopeIOException("Failed to read FW");
            }

            Logger.Info("Got firmware of length " + firmware.Length);
            if (!FlashFPGA(firmware))
            {
                throw new ScopeIOException("failed to flash FPGA");
            }

            Logger.Info("FPGA flashed...");

            iface.FlashFpga(firmware);
        }
Пример #6
0
        public ScopeFpgaRom(ISmartScopeInterface hwInterface, byte I2cAddress) : base(hwInterface, I2cAddress, 0, true)
        {
            foreach (ROM reg in Enum.GetValues(typeof(ROM)))
            {
                Registers.Add((uint)reg, new ByteRegister(this, (uint)reg, reg.ToString()));
            }

            int lastStrobe = 0;

            foreach (STR s in Enum.GetValues(typeof(STR)))
            {
                if ((int)s > lastStrobe)
                {
                    lastStrobe = (int)s;
                }
            }

            for (uint i = (uint)ROM.STROBES + 1; i < (uint)ROM.STROBES + lastStrobe / 8 + 1; i++)
            {
                Registers.Add(i, new ByteRegister(this, i, "STROBES " + (i - (int)ROM.STROBES)));
            }
        }
Пример #7
0
        private void InitializeHardware()
        {
            InitializeMemories();
            try
            {
                //FIXME: I have to do this synchronously here because there's no blocking on the USB traffic
                //but there should be when flashing the FPGA.

                byte[] response = GetPicFirmwareVersion();
                if (response == null)
                {
                    throw new Exception("Failed to read from device");
                }
                Logger.Debug(String.Format("PIC FW Version readout {0}", String.Join(".", response)));

                //Init ROM
                this.rom = new Rom(hardwareInterface);

                //Init FPGA
                LogWait("Starting fpga flashing...", 0);

                this.flashed = false;
                string fwName;
                byte[] firmware = null;

                //Get FW contents
                try
                {
                    LabNation.Common.SerialNumber s = new SerialNumber(this.Serial);
                    fwName   = String.Format("blobs.SmartScope_{0}.bin", Base36.Encode((long)s.model, 3).ToUpper());
                    firmware = Resources.Load(fwName);
                }
                catch (Exception e)
                {
                    throw new ScopeIOException("Opening FPGA FW file failed\n" + e.Message);
                }
                if (firmware == null)
                {
                    throw new ScopeIOException("Failed to read FW");
                }

                Logger.Info("Got firmware of length " + firmware.Length);
                if (!this.hardwareInterface.FlashFpga(firmware))
                {
                    throw new ScopeIOException("failed to flash FPGA");
                }
                if (GetFpgaFirmwareVersion() == FPGA_VERSION_UNFLASHED)
                {
                    throw new ScopeIOException("Got firmware version of unflashed FPGA");
                }
                LogWait("FPGA flashed...");
                this.flashed = true;

                InitializeMemories();
                LogWait("Memories initialized...");

                Logger.Debug(String.Format("FPGA FW version = 0x{0:x}", GetFpgaFirmwareVersion()));

                Configure();
                deviceReady = true;
            }
            catch (ScopeIOException e)
            {
                Logger.Error("Failure while connecting to device: " + e.Message);
                this.hardwareInterface = null;
                this.flashed           = false;
                InitializeMemories();
                throw e;
            }
        }
Пример #8
0
 internal Rom(ISmartScopeInterface hwInterface)
 {
     this.hwInterface = hwInterface;
     Download();
 }