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:
@@ -1212,8 +1212,11 @@ static int rx_char(sim_sim_t *sim, uint8_t c)
|
||||
sim->block_rx_data[sim->block_count++] = c;
|
||||
return 0;
|
||||
}
|
||||
sim->l1_state = L1_STATE_IDLE;
|
||||
rx_block(sim);
|
||||
sim->l1_state = L1_STATE_COMPLETE;
|
||||
/* 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;
|
||||
@@ -1395,6 +1398,9 @@ int sim_rx(sim_sim_t *sim, uint8_t c)
|
||||
case L1_STATE_RECEIVE:
|
||||
rc = rx_char(sim, c);
|
||||
break;
|
||||
case L1_STATE_COMPLETE:
|
||||
PDEBUG(DSIM1, DEBUG_NOTICE, "Received garbage after message!\n");
|
||||
sim->l1_state = L1_STATE_GARBAGE;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -1434,10 +1440,19 @@ void sim_timeout(sim_sim_t *sim)
|
||||
PDEBUG(DSIM1, DEBUG_NOTICE, "Timeout while receiving message!\n");
|
||||
sim->block_state = BLOCK_STATE_ADDRESS;
|
||||
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:
|
||||
PDEBUG(DSIM1, DEBUG_NOTICE, "Timeout while sending message!\n");
|
||||
sim->l1_state = L1_STATE_IDLE;
|
||||
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:
|
||||
break;
|
||||
}
|
||||
|
@@ -13,6 +13,8 @@ enum l1_state {
|
||||
L1_STATE_IDLE, /* waiting for message or reset */
|
||||
L1_STATE_SEND, /* sending reply */
|
||||
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 {
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/* SIM card for ATMEL
|
||||
/* SIM card for ATMEL
|
||||
*
|
||||
* (C) 2020 by Andreas Eversberg <jolly@eversberg.eu>
|
||||
* All Rights Reserved
|
||||
@@ -27,14 +27,14 @@ extern "C"
|
||||
#if defined(__AVR_ATtiny85__)
|
||||
#define SERIAL_DATA 4
|
||||
#define SERIAL_DELAY 124
|
||||
#define SERIAL_TIMEOUT 1200 /* > two bytes */
|
||||
#define SERIAL_TIMEOUT 800 /* > more than two bytes */
|
||||
#else
|
||||
/* settings for Arduino UNO with 16 MHz */
|
||||
#define STATUS_LED LED_BUILTIN
|
||||
#define RESET_PIN 6
|
||||
#define SERIAL_DATA 7
|
||||
#define SERIAL_DELAY 410
|
||||
#define SERIAL_TIMEOUT 2500 /* > two bytes */
|
||||
#define SERIAL_TIMEOUT 1600 /* > more than two bytes */
|
||||
#endif
|
||||
/* 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
|
||||
|
Reference in New Issue
Block a user