Skip to content

Commit

Permalink
Fixed timing issues with Read Multiple Blocks
Browse files Browse the repository at this point in the history
ISO15693 CRC calculation is slow and it delayed too much transmission of long
frames. Some readers marked transmission as unsuccesfull and ignored data.
Moving CRC calculation inside the codec allows to start modulating the field
while the CRC is not yet ready but, by the time it has to be trasmitted,
calculation will be done.
This fixes emsec#262

In EM4233, there still are issues with Read Multiple command when block
locking status is requested for more than 0x1F blocks

Implemented a check in ISO15693 codec to avoid out of bound CRC writes.
  • Loading branch information
ceres-c committed Sep 10, 2020
1 parent d439424 commit ebd6ab5
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 27 deletions.
10 changes: 2 additions & 8 deletions Firmware/Chameleon-Mini/Application/EM4233.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ uint16_t EM4233_Read_Single(uint8_t *FrameBuf, uint16_t FrameBytes) {
if (BlockAddress >= EM4233_NUMBER_OF_BLCKS) { /* check if the reader is requesting a sector out of bound */
if (FrameInfo.Addressed) { /* If the request is addressed */
FrameBuf[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_ERROR;
FrameBuf[ISO15693_RES_ADDR_PARAM] = 0x0F; /* Magic number from real tag */
FrameBuf[ISO15693_RES_ADDR_PARAM] = ISO15693_RES_ERR_GENERIC;
ResponseByteCount += 2; /* Copied this behaviour from real tag, not specified in ISO documents */
}
return ResponseByteCount; /* If not addressed real tag does not respond */
Expand Down Expand Up @@ -178,7 +178,7 @@ uint16_t EM4233_Read_Multiple(uint8_t *FrameBuf, uint16_t FrameBytes) {
if (BlockAddress >= EM4233_NUMBER_OF_BLCKS) { /* the reader is requesting a block out of bound */
if (FrameInfo.Addressed) { /* If the request is addressed */
FrameBuf[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_ERROR;
FrameBuf[ISO15693_RES_ADDR_PARAM] = 0x0F; /* Magic number from real tag */
FrameBuf[ISO15693_RES_ADDR_PARAM] = ISO15693_RES_ERR_GENERIC;
ResponseByteCount += 2; /* Copied this behaviour from real tag, not specified in ISO documents */
}
return ResponseByteCount; /* If not addressed real tag does not respond */
Expand Down Expand Up @@ -669,12 +669,6 @@ uint16_t EM4233AppProcess(uint8_t *FrameBuf, uint16_t FrameBytes) {
}
}

if (ResponseByteCount > 0) {
/* There is data to send. Append CRC */
ISO15693AppendCRC(FrameBuf, ResponseByteCount);
ResponseByteCount += ISO15693_CRC16_SIZE;
}

return ResponseByteCount;
}

Expand Down
6 changes: 0 additions & 6 deletions Firmware/Chameleon-Mini/Application/Sl2s2002.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,6 @@ uint16_t Sl2s2002AppProcess(uint8_t *FrameBuf, uint16_t FrameBytes) {
break;
}

if (ResponseByteCount > 0) {
/* There is data to be sent. Append CRC */
ISO15693AppendCRC(FrameBuf, ResponseByteCount);
ResponseByteCount += ISO15693_CRC16_SIZE;
}

return ResponseByteCount;

} else { // Invalid CRC
Expand Down
6 changes: 0 additions & 6 deletions Firmware/Chameleon-Mini/Application/TITagitstandard.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,6 @@ uint16_t TITagitstandardAppProcess(uint8_t *FrameBuf, uint16_t FrameBytes) {
break;
}

if (ResponseByteCount > 0) {
/* There is data to be sent. Append CRC */
ISO15693AppendCRC(FrameBuf, ResponseByteCount);
ResponseByteCount += ISO15693_CRC16_SIZE;
}

return ResponseByteCount;
}

Expand Down
6 changes: 0 additions & 6 deletions Firmware/Chameleon-Mini/Application/Vicinity.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,6 @@ uint16_t VicinityAppProcess(uint8_t *FrameBuf, uint16_t FrameBytes) {
break;
}

if (ResponseByteCount > 0) {
/* There is data to be sent. Append CRC */
ISO15693AppendCRC(FrameBuf, ResponseByteCount);
ResponseByteCount += ISO15693_CRC16_SIZE;
}

return ResponseByteCount;

} else { // Invalid CRC
Expand Down
13 changes: 12 additions & 1 deletion Firmware/Chameleon-Mini/Codec/ISO15693.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,13 @@ void ISO15693CodecTask(void) {

/* This is only reached when we've received a valid frame */
if (AppReceivedByteCount != ISO15693_APP_NO_RESPONSE) {
LogEntry(LOG_INFO_CODEC_TX_DATA, CodecBuffer, AppReceivedByteCount);
if (AppReceivedByteCount > CODEC_BUFFER_SIZE - ISO15693_CRC16_SIZE) { /* CRC would be written outside codec buffer */
CodecBuffer[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_ERROR;
CodecBuffer[ISO15693_RES_ADDR_PARAM] = ISO15693_RES_ERR_NOT_SUPP;
AppReceivedByteCount = 2;
LogEntry(LOG_INFO_GENERIC, "Too much data requested - See PR #274", 38);
}

LEDHook(LED_CODEC_TX, LED_PULSE);

ByteCount = AppReceivedByteCount;
Expand All @@ -653,6 +659,11 @@ void ISO15693CodecTask(void) {
StateRegister = LOADMOD_START_SINGLE;
}

/* Calculate the CRC while modulation is already ongoing */
ISO15693AppendCRC(CodecBuffer, AppReceivedByteCount);
ByteCount += ISO15693_CRC16_SIZE; /* Increase this variable as it will be read by the codec during loadmodulation */
LogEntry(LOG_INFO_CODEC_TX_DATA, CodecBuffer, AppReceivedByteCount + ISO15693_CRC16_SIZE);

} else {
/* Overwrite the PERBUF register, which was configured in ISO15693_EOC, with the new appropriate value.
* This is expecially needed because, since load modulation has not been performed, we're jumping here straight after
Expand Down

0 comments on commit ebd6ab5

Please sign in to comment.