Ejemplo n.º 1
0
        public void WriteMemory(UInt32 address, byte[] buffer, OnFelProgress callback = null)
        {
            if (address >= dram_base)
            {
                InitDram();
            }

            UInt32 length = (UInt32)buffer.Length;

            if (length != (length & ~((UInt32)3)))
            {
                length = (length + 3) & ~((UInt32)3);
                var newBuffer = new byte[length];
                Array.Copy(buffer, 0, newBuffer, 0, buffer.Length);
                buffer = newBuffer;
            }

            int pos = 0;

            while (pos < buffer.Length)
            {
                callback?.Invoke(CurrentAction.WritingMemory, null);
                var buf = new byte[Math.Min(buffer.Length - pos, MaxBulkSize)];
                Array.Copy(buffer, pos, buf, 0, buf.Length);
                FelRequest(AWFELStandardRequest.RequestType.FEL_DOWNLOAD, (UInt32)(address + pos), (uint)buf.Length);
                FelWrite(buf);
                var status = new AWFELStatusResponse(FelRead(8));
                if (status.State != 0)
                {
                    throw new FelException("FEL write error");
                }
                pos += buf.Length;
            }
        }
Ejemplo n.º 2
0
        private byte[] ReadMemory(UInt32 address, UInt32 length, OnFelProgress callback = null)
        {
            if (address >= dram_base)
            {
                InitDram();
            }

            length = (length + 3) & ~((UInt32)3);

            var result = new List <byte>();

            while (length > 0)
            {
                if (callback != null)
                {
                    callback(CurrentAction.ReadingMemory, null);
                }
                var l = Math.Min(length, MaxBulkSize);
                FelRequest(AWFELStandardRequest.RequestType.FEL_UPLOAD, address, l);
                var r = FelRead((UInt32)l);
                result.AddRange(r);
                var status = new AWFELStatusResponse(FelRead(8));
                if (status.State != 0)
                {
                    throw new FelException("FEL read error");
                }
                length  -= l;
                address += l;
            }
            return(result.ToArray());
        }
Ejemplo n.º 3
0
        public void Exec(UInt32 address, int pause = 0)
        {
            FelRequest(AWFELStandardRequest.RequestType.FEL_RUN, address, 0);
            var status = new AWFELStatusResponse(FelRead(8));

            if (status.State != 0)
            {
                throw new FelException("FEL run error");
            }
            //Close();
            Thread.Sleep(pause * 1000);
            //int errorCount = 0;
            //while (true)
            //{
            //    try
            //    {
            //        Open(vid, pid);
            //        return;
            //    }
            //    catch (Exception ex)
            //    {
            //        errorCount++;
            //        if (errorCount >= 8)
            //            throw ex;
            //    }
            //}
        }
Ejemplo n.º 4
0
        public AWFELVerifyDeviceResponse VerifyDevice()
        {
            FelRequest(AWFELStandardRequest.RequestType.FEL_VERIFY_DEVICE);
            var resp   = FelRead(32);
            var status = new AWFELStatusResponse(FelRead(8));

            return(new AWFELVerifyDeviceResponse(resp));
        }
Ejemplo n.º 5
0
        public void Exec(UInt32 address)
        {
            FelRequest(AWFELStandardRequest.RequestType.FEL_RUN, address, 0);
            var status = new AWFELStatusResponse(FelRead(8));

            if (status.State != 0)
            {
                throw new FelException("FEL run error");
            }
        }
Ejemplo n.º 6
0
 public AWFELVerifyDeviceResponse VerifyDevice()
 {
     FelRequest(AWFELStandardRequest.RequestType.FEL_VERIFY_DEVICE);
     byte[] resp;
     try
     {
         resp = FelRead(32);
     }
     catch
     {
         resp = new byte[32];
     }
     var status = new AWFELStatusResponse(FelRead(8));
     return new AWFELVerifyDeviceResponse(resp);
 }
Ejemplo n.º 7
0
        public void WriteMemory(UInt32 address, byte[] buffer)
        {
            int pos = 0;

            while (pos < buffer.Length)
            {
                var buf = new byte[Math.Min(buffer.Length - pos, MaxBulkSize)];
                Array.Copy(buffer, pos, buf, 0, buf.Length);

                FelRequest(AWFELStandardRequest.RequestType.FEL_DOWNLOAD, (UInt32)(address + pos), (uint)buf.Length);
                FelWrite(buf);
                var status = new AWFELStatusResponse(FelRead(8));
                if (status.State != 0)
                {
                    throw new FelException("FEL write error");
                }
                pos += buf.Length;
            }
        }
Ejemplo n.º 8
0
        public byte[] ReadMemory(UInt32 address, UInt32 length)
        {
            var result = new List <byte>();

            while (length > 0)
            {
                var l = Math.Min(length, MaxBulkSize);
                Console.WriteLine("Reading {0:X8}, size: {1:X8}...", address, l);
                FelRequest(AWFELStandardRequest.RequestType.FEL_UPLOAD, address, l);
                var r = FelRead((UInt32)l);
                result.AddRange(r);
                var status = new AWFELStatusResponse(FelRead(8));
                if (status.State != 0)
                {
                    throw new FelException("FEL read error");
                }
                length  -= l;
                address += l;
            }
            return(result.ToArray());
        }