diff --git a/armsrc/em4x70.c b/armsrc/em4x70.c index 68025dcdd..6f962fe40 100644 --- a/armsrc/em4x70.c +++ b/armsrc/em4x70.c @@ -30,43 +30,50 @@ static em4x70_tag_t tag = { 0 }; // EM4170 requires a parity bit on commands, other variants do not. static bool command_parity = true; -// Conversion from Ticks to RF periods -// 1 us = 1.5 ticks -// 1RF Period = 8us = 12 Ticks -#define TICKS_PER_FC 12 -// Chip timing from datasheet -// Converted into Ticks for timing functions -#define EM4X70_T_TAG_QUARTER_PERIOD (8 * TICKS_PER_FC) -#define EM4X70_T_TAG_HALF_PERIOD (16 * TICKS_PER_FC) -#define EM4X70_T_TAG_THREE_QUARTER_PERIOD (24 * TICKS_PER_FC) -#define EM4X70_T_TAG_FULL_PERIOD (32 * TICKS_PER_FC) // 1 Bit Period -#define EM4X70_T_TAG_TWA (128 * TICKS_PER_FC) // Write Access Time -#define EM4X70_T_TAG_DIV (224 * TICKS_PER_FC) // Divergency Time -#define EM4X70_T_TAG_AUTH (4224 * TICKS_PER_FC) // Authentication Time -#define EM4X70_T_TAG_WEE (3072 * TICKS_PER_FC) // EEPROM write Time -#define EM4X70_T_TAG_TWALB (672 * TICKS_PER_FC) // Write Access Time of Lock Bits -#define EM4X70_T_TAG_BITMOD (4 * TICKS_PER_FC) // Initial time to stop modulation when sending 0 -#define EM4X70_T_TAG_TOLERANCE (8 * TICKS_PER_FC) // Tolerance in RF periods for receive/LIW +#if 1 // Calculation of ticks for timing functions + // Conversion from Ticks to RF periods + // 1 us = 1.5 ticks + // 1RF Period = 8us = 12 Ticks + #define TICKS_PER_FC 12 -#define EM4X70_T_TAG_TIMEOUT (4 * EM4X70_T_TAG_FULL_PERIOD) // Timeout if we ever get a pulse longer than this -#define EM4X70_T_WAITING_FOR_LIW 50 // Pulses to wait for listen window -#define EM4X70_T_READ_HEADER_LEN 16 // Read header length (16 bit periods) + // Chip timing from datasheet + // Converted into Ticks for timing functions + #define EM4X70_T_TAG_QUARTER_PERIOD (8 * TICKS_PER_FC) + #define EM4X70_T_TAG_HALF_PERIOD (16 * TICKS_PER_FC) + #define EM4X70_T_TAG_THREE_QUARTER_PERIOD (24 * TICKS_PER_FC) + #define EM4X70_T_TAG_FULL_PERIOD (32 * TICKS_PER_FC) // 1 Bit Period + #define EM4X70_T_TAG_TWA (128 * TICKS_PER_FC) // Write Access Time + #define EM4X70_T_TAG_DIV (224 * TICKS_PER_FC) // Divergency Time + #define EM4X70_T_TAG_AUTH (4224 * TICKS_PER_FC) // Authentication Time + #define EM4X70_T_TAG_WEE (3072 * TICKS_PER_FC) // EEPROM write Time + #define EM4X70_T_TAG_TWALB (672 * TICKS_PER_FC) // Write Access Time of Lock Bits + #define EM4X70_T_TAG_BITMOD (4 * TICKS_PER_FC) // Initial time to stop modulation when sending 0 + #define EM4X70_T_TAG_TOLERANCE (8 * TICKS_PER_FC) // Tolerance in RF periods for receive/LIW -#define EM4X70_COMMAND_RETRIES 5 // Attempts to send/read command -#define EM4X70_MAX_RECEIVE_LENGTH 96 // Maximum bits to expect from any command + #define EM4X70_T_TAG_TIMEOUT (4 * EM4X70_T_TAG_FULL_PERIOD) // Timeout if we ever get a pulse longer than this + #define EM4X70_T_WAITING_FOR_LIW 50 // Pulses to wait for listen window + #define EM4X70_T_READ_HEADER_LEN 16 // Read header length (16 bit periods) -/** - * These IDs are from the EM4170 datasheet - * Some versions of the chip require a - * (even) parity bit, others do not - */ -#define EM4X70_COMMAND_ID 0x01 -#define EM4X70_COMMAND_UM1 0x02 -#define EM4X70_COMMAND_AUTH 0x03 -#define EM4X70_COMMAND_PIN 0x04 -#define EM4X70_COMMAND_WRITE 0x05 -#define EM4X70_COMMAND_UM2 0x07 + #define EM4X70_COMMAND_RETRIES 5 // Attempts to send/read command + #define EM4X70_MAX_RECEIVE_LENGTH 96 // Maximum bits to expect from any command +#endif // Calculation of ticks for timing functions + +#if 1 // EM4x70 Command IDs + /** + * These IDs are from the EM4170 datasheet. + * Some versions of the chip require a + * (even) parity bit, others do not. + * The command is thus stored only in the + * three least significant bits (mask 0x07). + */ + #define EM4X70_COMMAND_ID 0x01 + #define EM4X70_COMMAND_UM1 0x02 + #define EM4X70_COMMAND_AUTH 0x03 + #define EM4X70_COMMAND_PIN 0x04 + #define EM4X70_COMMAND_WRITE 0x05 + #define EM4X70_COMMAND_UM2 0x07 +#endif // EM4x70 Command IDs // Constants used to determine high/low state of signal #define EM4X70_NOISE_THRESHOLD 13 // May depend on noise in environment