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++; }
public void WriteEfb(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 < offset + count) { 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.EfbWrite); stream.WriteByte((byte)(count - 1)); stream.Write(data, offset, count); 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 (WriteEfb)"); } if (bytesWritten != bytes.Length) { throw new Exception("Wrong number of bytes written (WriteEfb)"); } }
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++; }