C-Netz-SIM: Added delay before answering to messages

This delay is required, so that the card reader has enough time to
release the I/O line. The AEG OLYMPIA now works.
This commit is contained in:
Andreas Eversberg
2023-08-27 20:28:43 +02:00
parent abe449bd0e
commit 4252ca1f82
3 changed files with 22 additions and 5 deletions

View File

@@ -1212,8 +1212,11 @@ static int rx_char(sim_sim_t *sim, uint8_t c)
sim->block_rx_data[sim->block_count++] = c; sim->block_rx_data[sim->block_count++] = c;
return 0; return 0;
} }
sim->l1_state = L1_STATE_IDLE; sim->l1_state = L1_STATE_COMPLETE;
rx_block(sim); /* Waiting for timeout, then process the received PDU.
* This way we detect garbage after the message.
* Also we wait for the card reader to release the I/O line. (22 bit durations minimum) */
return 0;
} }
return -1; return -1;
@@ -1395,6 +1398,9 @@ int sim_rx(sim_sim_t *sim, uint8_t c)
case L1_STATE_RECEIVE: case L1_STATE_RECEIVE:
rc = rx_char(sim, c); rc = rx_char(sim, c);
break; break;
case L1_STATE_COMPLETE:
PDEBUG(DSIM1, DEBUG_NOTICE, "Received garbage after message!\n");
sim->l1_state = L1_STATE_GARBAGE;
default: default:
break; break;
} }
@@ -1434,10 +1440,19 @@ void sim_timeout(sim_sim_t *sim)
PDEBUG(DSIM1, DEBUG_NOTICE, "Timeout while receiving message!\n"); PDEBUG(DSIM1, DEBUG_NOTICE, "Timeout while receiving message!\n");
sim->block_state = BLOCK_STATE_ADDRESS; sim->block_state = BLOCK_STATE_ADDRESS;
break; break;
case L1_STATE_GARBAGE:
PDEBUG(DSIM1, DEBUG_NOTICE, "Timeout after skipping garbage!\n");
sim->l1_state = L1_STATE_IDLE;
break;
case L1_STATE_SEND: case L1_STATE_SEND:
PDEBUG(DSIM1, DEBUG_NOTICE, "Timeout while sending message!\n"); PDEBUG(DSIM1, DEBUG_NOTICE, "Timeout while sending message!\n");
sim->l1_state = L1_STATE_IDLE; sim->l1_state = L1_STATE_IDLE;
break; break;
case L1_STATE_COMPLETE:
/* We did not receive garbage after message, so we process it now. */
sim->l1_state = L1_STATE_IDLE;
rx_block(sim);
break;
default: default:
break; break;
} }

View File

@@ -13,6 +13,8 @@ enum l1_state {
L1_STATE_IDLE, /* waiting for message or reset */ L1_STATE_IDLE, /* waiting for message or reset */
L1_STATE_SEND, /* sending reply */ L1_STATE_SEND, /* sending reply */
L1_STATE_RECEIVE, /* receiving message */ L1_STATE_RECEIVE, /* receiving message */
L1_STATE_COMPLETE, /* received message complete, waiting for card reader to release */
L1_STATE_GARBAGE, /* received garbage right after frame, waiting for timeout */
}; };
enum block_state { enum block_state {

View File

@@ -1,4 +1,4 @@
/* SIM card for ATMEL /* SIM card for ATMEL
* *
* (C) 2020 by Andreas Eversberg <jolly@eversberg.eu> * (C) 2020 by Andreas Eversberg <jolly@eversberg.eu>
* All Rights Reserved * All Rights Reserved
@@ -27,14 +27,14 @@ extern "C"
#if defined(__AVR_ATtiny85__) #if defined(__AVR_ATtiny85__)
#define SERIAL_DATA 4 #define SERIAL_DATA 4
#define SERIAL_DELAY 124 #define SERIAL_DELAY 124
#define SERIAL_TIMEOUT 1200 /* > two bytes */ #define SERIAL_TIMEOUT 800 /* > more than two bytes */
#else #else
/* settings for Arduino UNO with 16 MHz */ /* settings for Arduino UNO with 16 MHz */
#define STATUS_LED LED_BUILTIN #define STATUS_LED LED_BUILTIN
#define RESET_PIN 6 #define RESET_PIN 6
#define SERIAL_DATA 7 #define SERIAL_DATA 7
#define SERIAL_DELAY 410 #define SERIAL_DELAY 410
#define SERIAL_TIMEOUT 2500 /* > two bytes */ #define SERIAL_TIMEOUT 1600 /* > more than two bytes */
#endif #endif
/* to set fused for ATTINY85: /* to set fused for ATTINY85:
* avrdude -c usbasp-clone -p t85 -U lfuse:w:0xc0:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m * avrdude -c usbasp-clone -p t85 -U lfuse:w:0xc0:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m