adjust LFSim to download lf fpga prior to setting emulation buffer

to prevent buffer overwrite condition if you are coming from HF fpga.
This commit is contained in:
marshmellow42 2017-09-11 12:38:01 -04:00
commit e8defa30f7
2 changed files with 11 additions and 7 deletions

View file

@ -1304,7 +1304,7 @@ void UsbPacketReceived(uint8_t *packet, int len)
break;
case CMD_SET_LF_DIVISOR:
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, c->arg[0]);
break;

View file

@ -410,28 +410,32 @@ int CmdLFSim(const char *Cmd)
sscanf(Cmd, "%i", &gap);
// convert to bitstream if necessary
//prep fpga to lf (divisor is not important)
UsbCommand c = {CMD_SET_LF_DIVISOR, {89,0,0}};
clearCommandBuffer();
SendCommand(&c);
// convert to bitstream if necessary
ChkBitstream(Cmd);
//can send only 512 bits at a time (1 byte sent per bit...)
printf("Sending [%d bytes]", GraphTraceLen);
for (i = 0; i < GraphTraceLen; i += USB_CMD_DATA_SIZE) {
UsbCommand c={CMD_DOWNLOADED_SIM_SAMPLES_125K, {i, 0, 0}};
UsbCommand c2 = {CMD_DOWNLOADED_SIM_SAMPLES_125K, {i, 0, 0}};
for (j = 0; j < USB_CMD_DATA_SIZE; j++) {
c.d.asBytes[j] = GraphBuffer[i+j];
c2.d.asBytes[j] = GraphBuffer[i+j];
}
SendCommand(&c);
SendCommand(&c2);
WaitForResponse(CMD_ACK,NULL);
printf(".");
}
printf("\n");
PrintAndLog("Starting to simulate");
UsbCommand c = {CMD_SIMULATE_TAG_125K, {GraphTraceLen, gap, 0}};
UsbCommand c3 = {CMD_SIMULATE_TAG_125K, {GraphTraceLen, gap, 0}};
clearCommandBuffer();
SendCommand(&c);
SendCommand(&c3);
return 0;
}