private byte[] ReadFromDevice(ISPIPeripheral device, int count) { var result = new byte[count]; for (var i = 0; i < result.Length; i++) { // send a dummy byte result[i] = device.Transmit(0); } return(result); }
private bool HandleCommand(IPCommandDescriptor cmd, ISPIPeripheral device) { var result = true; parent.Log(LogLevel.Debug, "About to execute command {0}", cmd); switch (cmd.Command) { case IPCommand.TransmitCommand_SDR: device.Transmit(cmd.Operand); break; case IPCommand.ReceiveReadData_SDR: { var dataCount = (parent.dataSize.Value == 0) ? cmd.Operand : parent.dataSize.Value; var data = ReadFromDevice(device, (int)dataCount); var count = parent.rxQueue.Enqueue(data); if (count != data.Length) { parent.Log(LogLevel.Warning, "There is no more space left in the RX queue. {0} bytes were dropped", data.Length - count); } } break; case IPCommand.Stop: { device.FinishTransmission(); parent.ipCommandDone.Value = true; parent.UpdateInterrupts(); } break; case IPCommand.TransmitProgrammingData_SDR: { parent.isInTransmit = true; // note: parent operation breaks execution of the command // waiting for the data to be written to FIFO result = false; } break; case IPCommand.TransmitRowAddress_SDR: { var a0 = (byte)(parent.serialFlashAddress.Value); var a1 = (byte)(parent.serialFlashAddress.Value >> 8); var a2 = (byte)(parent.serialFlashAddress.Value >> 16); device.Transmit(a2); device.Transmit(a1); device.Transmit(a0); } break; default: parent.Log(LogLevel.Info, "Unsupported IP command: {0}", cmd); break; } return(result); }