예제 #1
0
        public void WriteSram(int pageAddr, byte[] data)
        {
            if ((pageAddr % 1) != 0)
            {
                throw new ArgumentException("pageAddr must be word aligned");
            }

            StxEtxMemoryStream stream = new StxEtxMemoryStream();

            int addr = pageAddr / 2;

            stream.StartPacket();
            stream.WriteByte((byte)Commands.SetAddr);
            WriteIntBe(stream, addr);
            stream.EndPacket();

            stream.StartPacket();
            stream.WriteByte((byte)Commands.SramWrite);
            stream.Write(data, 0, data.Length);
            stream.EndPacket();

            byte[]    bytes        = stream.GetBytes();
            uint      bytesWritten = 0;
            FT_STATUS status       = _Ftdi.Write(bytes, bytes.Length, ref bytesWritten);

            if (status != FT_STATUS.FT_OK)
            {
                throw new Exception("Error writing data (WriteSram)");
            }
            if (bytesWritten != bytes.Length)
            {
                throw new Exception("Wrong number of bytes written (WriteSram)");
            }
            _PendingAck++;
        }
예제 #2
0
        public void EraseSector(int sectorAddr)
        {
            Console.WriteLine(String.Format("Erase sector: 0x{0:X8}", sectorAddr));

            StxEtxMemoryStream stream = new StxEtxMemoryStream();

            int addr = sectorAddr / 4;

            stream.StartPacket();
            stream.WriteByte((byte)Commands.SetAddr);
            WriteIntBe(stream, addr);
            stream.EndPacket();

            stream.StartPacket();
            stream.WriteByte((byte)Commands.FlashErase);
            stream.EndPacket();

            byte[]    bytes        = stream.GetBytes();
            uint      bytesWritten = 0;
            FT_STATUS status       = _Ftdi.Write(bytes, bytes.Length, ref bytesWritten);

            if (status != FT_STATUS.FT_OK)
            {
                throw new Exception("Error writing data (EraseSector)");
            }
            if (bytesWritten != bytes.Length)
            {
                throw new Exception("Wrong number of bytes written (EraseSector)");
            }
            _PendingAck++;
        }
예제 #3
0
        public void SetFlashSelect(FlashType flashType)
        {
            byte flashSel;

            if (flashType == FlashType.Rom)
            {
                flashSel = 0;
            }
            else
            {
                flashSel = 1;
            }
            Console.WriteLine(String.Format("Set FlashSel: {0}", flashSel));

            StxEtxMemoryStream stream = new StxEtxMemoryStream();

            stream.StartPacket();
            stream.WriteByte((byte)Commands.FlashSelect);
            stream.WriteByte(flashSel);
            stream.EndPacket();

            byte[]    bytes        = stream.GetBytes();
            uint      bytesWritten = 0;
            FT_STATUS status       = _Ftdi.Write(bytes, bytes.Length, ref bytesWritten);

            if (status != FT_STATUS.FT_OK)
            {
                throw new Exception("Error writing data (SetFlashSelect)");
            }
            if (bytesWritten != bytes.Length)
            {
                throw new Exception("Wrong number of bytes written (SetFlashSelect)");
            }
        }
예제 #4
0
 private void WriteIntBe(StxEtxMemoryStream stream, int value)
 {
     stream.WriteByte((byte)(value >> 24));
     stream.WriteByte((byte)(value >> 16));
     stream.WriteByte((byte)(value >> 8));
     stream.WriteByte((byte)(value >> 0));
 }
예제 #5
0
        public void SetRtc(DateTime rtcTime)
        {
            StxEtxMemoryStream stream = new StxEtxMemoryStream();

            stream.StartPacket();
            stream.WriteByte((byte)Commands.SetRtc);
            stream.WriteByte(ConvertToBcd(rtcTime.Second));
            stream.WriteByte(ConvertToBcd(rtcTime.Minute));
            stream.WriteByte(ConvertToBcd(rtcTime.Hour));
            byte dayOfWeek = (byte)rtcTime.DayOfWeek;

            if (rtcTime.DayOfWeek == DayOfWeek.Sunday)
            {
                dayOfWeek = 7;
            }
            stream.WriteByte(dayOfWeek);
            stream.WriteByte(ConvertToBcd(rtcTime.Day));
            stream.WriteByte(ConvertToBcd(rtcTime.Month));
            stream.WriteByte(ConvertToBcd((rtcTime.Year - 2000)));
            stream.EndPacket();
            byte[]    bytes        = stream.GetBytes();
            uint      bytesWritten = 0;
            FT_STATUS status       = _Ftdi.Write(bytes, bytes.Length, ref bytesWritten);

            if (status != FT_STATUS.FT_OK)
            {
                throw new Exception("Error writing data (SetRtc)");
            }
            if (bytesWritten != bytes.Length)
            {
                throw new Exception("Wrong number of bytes written (SetRtc)");
            }
        }
예제 #6
0
        public void ReadEfb(int addr, byte[] data, int offset, int count)
        {
            if (addr > 0xff)
            {
                throw new ArgumentException("addr");
            }
            if ((count > 0xff) || (count < 1))
            {
                throw new ArgumentException("count");
            }
            if (data.Length < count + offset)
            {
                throw new ArgumentException("data to small");
            }

            StxEtxMemoryStream stream = new StxEtxMemoryStream();

            stream.StartPacket();
            stream.WriteByte((byte)Commands.SetAddr);
            WriteIntBe(stream, addr);
            stream.EndPacket();

            stream.StartPacket();
            stream.WriteByte((byte)Commands.EfbRead);
            stream.WriteByte((byte)(count - 1));
            stream.EndPacket();

            byte[]    bytes        = stream.GetBytes();
            uint      bytesWritten = 0;
            FT_STATUS status       = _Ftdi.Write(bytes, bytes.Length, ref bytesWritten);

            if (status != FT_STATUS.FT_OK)
            {
                throw new Exception("Error writing data (ReadEfb)");
            }
            if (bytesWritten != bytes.Length)
            {
                throw new Exception("Wrong number of bytes written (ReadEfb)");
            }

            byte[] result = ReceiveResponse();
            result.CopyTo(data, offset);
        }
예제 #7
0
        public void WritePage(int pageAddr, byte[] data)
        {
            Console.WriteLine(String.Format("Write page: 0x{0:X8}", pageAddr));

            if ((pageAddr % 2) != 0)
            {
                throw new ArgumentException("pageAddr must be dword aligned");
            }

            StxEtxMemoryStream stream = new StxEtxMemoryStream();

            int addr = pageAddr / 4;

            stream.StartPacket();
            stream.WriteByte((byte)Commands.SetAddr);
            WriteIntBe(stream, addr);
            stream.EndPacket();

            stream.StartPacket();
            stream.WriteByte((byte)Commands.FlashWrite);
            stream.Write(data, 0, data.Length);
            stream.EndPacket();

            byte[]    bytes        = stream.GetBytes();
            uint      bytesWritten = 0;
            FT_STATUS status       = _Ftdi.Write(bytes, bytes.Length, ref bytesWritten);

            if (status != FT_STATUS.FT_OK)
            {
                throw new Exception("Error writing data (WritePage)");
            }
            if (bytesWritten != bytes.Length)
            {
                throw new Exception("Wrong number of bytes written (WritePage)");
            }
            _PendingAck++;
        }