Example #1
0
 public void ResetDevice(bool r)
 {
     using (_lockFactory.GetLock(LockType.CommandLock))
     {
         _evalBoard.DeviceState.ClearRegisterCache();
         byte[] buffer = { (byte)(r ? 1 : 0) };
         _usbControlTransferCommand.UsbControlTransfer(
             (byte)UsbRequestType.TypeVendor,
             0xA0,
             0xE600,
             0,
             buffer,
             buffer.Length);
         Thread.Sleep(r ? 50 : 400); // give the firmware some time for initialization
     }
 }
        public void SendDeviceCommand(DeviceCommand deviceCommand, uint setupData)
        {
            using (_lockFactory.GetLock(LockType.CommandLock))
            {
                if (!_evalBoard.DeviceState.SPI_Initialized && deviceCommand != DeviceCommand.InitializeSPIPins)
                {
                    _initializeSPIPinsCommand.InitializeSPIPins();
                }

                _usbControlTransferCommand.UsbControlTransfer(
                    (byte)UsbRequestType.TypeVendor,
                    (byte)deviceCommand,
                    (ushort)(setupData & (uint)BasicMasks.SixteenBits),
                    (ushort)((setupData & 0xFF0000) / 0x10000),
                    null,
                    0);
            }
        }
        public void UploadFirmware(IhxFile ihxFile)
        {
            using (_lockFactory.GetLock(LockType.CommandLock))
            {
                const int transactionBytes = 256;
                var       buffer           = new byte[transactionBytes];

                _resetDeviceCommand.ResetDevice(true); // reset = 1

                var j = 0;
                for (var i = 0; i <= ihxFile.IhxData.Length; i++)
                {
                    if (i >= ihxFile.IhxData.Length || ihxFile.IhxData[i] < 0 || j >= transactionBytes)
                    {
                        if (j > 0)
                        {
                            _usbControlTransferCommand.UsbControlTransfer(
                                (byte)UsbRequestType.TypeVendor,
                                0xA0,
                                i - j,
                                0,
                                buffer,
                                j);
                            Thread.Sleep(1); // to avoid package loss
                        }
                        j = 0;
                    }

                    if (i >= ihxFile.IhxData.Length || ihxFile.IhxData[i] < 0 || ihxFile.IhxData[i] > 255)
                    {
                        continue;
                    }
                    buffer[j] = (byte)ihxFile.IhxData[i];
                    j        += 1;
                }
                _resetDeviceCommand.ResetDevice(false); //error (may caused re-numeration) can be ignored
            }
        }
Example #4
0
        public ushort ReadSPI()
        {
            using (_lockFactory.GetLock(LockType.CommandLock))
            {
                if (!_evalBoard.DeviceState.SPI_Initialized)
                {
                    _initializeSPIPinsCommand.InitializeSPIPins();
                }

                const ushort len = 3;
                var          buf = new byte[len];

                _usbControlTransferCommand.UsbControlTransfer(
                    (byte)UsbRequestType.TypeVendor | (byte)UsbCtrlFlags.Direction_In,
                    (byte)DeviceCommand.SendSPI,
                    0,
                    0,
                    buf,
                    len
                    );
                return((ushort)(buf[0] | (buf[1] << 8)));
            }
        }