Permalink
Browse files

Add support for 1-Wire overdrive mode

Some 1-Wire devices, such as the DS28E15 authenticator, do not operate
at the standard speed which the BP currently supports. They require the
faster variant known as "overdrive" in order to even acknowledge their
presence. This changeset adds support for this mode, including the
ability to select it via the binary command mode.
  • Loading branch information...
1 parent 3c6ca90 commit 07c8be981fac9cfc633195c55959ca4c968ba4e1 @u1f35c u1f35c committed Dec 24, 2016
View
@@ -46,6 +46,7 @@
#include "base.h"
#include "binary_io.h"
+#include "proc_menu.h"
/**
* Size of a 1-Wire ROM number identifier, in bytes.
@@ -358,13 +359,34 @@ void onewire_data_high(void) {
}
void onewire_setup(void) {
+ int speed;
/* Always start in high-impedance mode. */
mode_configuration.high_impedance = true;
+ /* Assume standard speed. */
+ consumewhitechars();
+ speed = getint();
+ if ((speed > 0) && (speed <= 2)) {
+ mode_configuration.speed = speed - 1;
+ } else {
+ speed = 0;
+ }
+
+ if (speed == 0) {
+ command_error = false;
+ }
+
+ if (speed == 0) {
+ MSG_1WIRE_SPEED_PROMPT;
+ mode_configuration.speed = (getnumber(1, 1, 2, 0) - 1);
+ }
+
/* Clear the saved device roster entries. */
onewire_state.used_roster_entries = 0;
+}
+void onewire_setup_exc(void) {
/* Set up pins. */
ONEWIRE_DATA_DIRECTION = INPUT;
ONEWIRE_DATA_LINE = LOW;
@@ -568,27 +590,45 @@ onewire_bus_reset_result_t perform_bus_reset(void) {
/* Pull the bus line LOW. */
ONEWIRE_DATA_DIRECTION = INPUT;
+ if (mode_configuration.speed == 1) {
+ /* AN126: Parameter G */
+ bp_delay_us(1);
+ }
ONEWIRE_DATA_LINE = LOW;
ONEWIRE_DATA_DIRECTION = OUTPUT;
/*
* According to specification a minimum of 480us need to be waited before
- * reading the line.
+ * reading the line in standard mode, or no more than 70us for overdrive.
+ * AN126: Parameter H
*/
- bp_delay_us(500);
+ if (mode_configuration.speed == 0) {
+ bp_delay_us(500);
+ } else {
+ bp_delay_us(70);
+ }
/* Release the bus. */
ONEWIRE_DATA_DIRECTION = INPUT;
- bp_delay_us(65);
+ /* AN126: Parameter I */
+ if (mode_configuration.speed == 0) {
+ bp_delay_us(65);
+ } else {
+ bp_delay_us(6);
+ }
/* Read the data line. */
if (ONEWIRE_DATA_LINE) {
/* If the data line is still high, no device is available on the bus. */
result = ONEWIRE_BUS_RESET_NO_DEVICE;
}
- /* Wait for 500us. */
- bp_delay_us(500);
+ /* AN126: Parameter J */
+ if (mode_configuration.speed == 0) {
+ bp_delay_us(500);
+ } else {
+ bp_delay_us(32);
+ }
/* Read the data line. */
if (ONEWIRE_DATA_LINE == LOW) {
@@ -856,6 +896,31 @@ uint8_t update_crc8(uint8_t value) {
#define BINARY_IO_ONEWIRE_COMMAND_BULK_TRANSFER 0x01
/**
+ * Binary I/O 1-Wire configuration command.
+ *
+ * Once this command is received by the board, it will configure the 1-Wire
+ * parameters to those provided. At present this simply controls whether the
+ * bus speed is Standard or Overdrive.
+ *
+ * Current command format is as follows:
+ *
+ * MSB
+ * 0010xxss
+ * ||||
+ * ||++--> The speed to be configured.
+ * || 00 = Standard
+ * || 01 = Overdrive
+ * || 1x = Reserved
+ * ++----> Ignored. Should be set to 0 to allow for future use.
+ *
+ * Interaction flow is as follows:
+ *
+ * PC -> 0b001000ss
+ * Bus Pirate <- 0b00000001 (SUCCESS)
+ */
+#define BINARY_IO_ONEWIRE_COMMAND_CONFIGURE 0x02
+
+/**
* Binary I/O 1-Wire Peripherals configuration command.
*
* This command will set up the board in a particular fashion to accommodate the
@@ -1125,6 +1190,11 @@ void binary_io_enter_1wire_mode(void) {
break;
}
+ case BINARY_IO_ONEWIRE_COMMAND_CONFIGURE:
+ mode_configuration.speed = (input_byte & 1);
+ UART1TX(BP_BINARY_IO_RESULT_SUCCESS);
+ break;
+
case BINARY_IO_ONEWIRE_COMMAND_CONFIGURE_PERIPHERALS:
bp_binary_io_peripherals_set(input_byte);
REPORT_IO_SUCCESS();
@@ -1148,11 +1218,19 @@ bool onewire_internal_bit_io(bool bit_value) {
ONEWIRE_DATA_LINE = LOW;
ONEWIRE_DATA_DIRECTION = OUTPUT;
- bp_delay_us(4);
+ /* AN126: Parameter A */
+ if (mode_configuration.speed == 0) {
+ bp_delay_us(4);
+ } else {
+ bp_delay_us(1);
+ }
if (bit_value) {
ONEWIRE_DATA_DIRECTION = INPUT;
}
- bp_delay_us(8);
+ /* AN126: Parameter E */
+ if (mode_configuration.speed == 0) {
+ bp_delay_us(8);
+ }
/*
* This is where the magic happens. If a bit_value value of 1 is sent to this
@@ -1165,16 +1243,33 @@ bool onewire_internal_bit_io(bool bit_value) {
if (bit_value) {
bit_value = ONEWIRE_DATA_LINE;
- bp_delay_us(32);
+ /* AN126: Parameter F */
+ if (mode_configuration.speed == 0) {
+ bp_delay_us(32);
+ } else {
+ bp_delay_us(6);
+ }
} else {
- bp_delay_us(25);
+ /* AN126: Parameter C */
+ if (mode_configuration.speed == 0) {
+ bp_delay_us(25);
+ } else {
+ bp_delay_us(4);
+ }
ONEWIRE_DATA_DIRECTION = INPUT;
- bp_delay_us(7);
+ /* AN126: Parameter D */
+ if (mode_configuration.speed == 0) {
+ bp_delay_us(7);
+ } else {
+ bp_delay_us(2);
+ }
}
- /* Adjust timing to take 70us per bit. */
+ /* Adjust timing to take 70us per bit for standard mode. */
- bp_delay_us(5);
+ if (mode_configuration.speed == 0) {
+ bp_delay_us(5);
+ }
return bit_value;
}
@@ -1202,7 +1297,9 @@ uint8_t onewire_internal_byte_io(uint8_t byte_value) {
}
}
- bp_delay_us(8);
+ if (mode_configuration.speed == 0) {
+ bp_delay_us(8);
+ }
return byte_value;
}
View
@@ -78,14 +78,20 @@ void onewire_data_low(void);
void onewire_data_high(void);
/**
- * Prepares the protocol for operating on the bus.
+ * Configures the protocol for operating on the bus.
*
* @see bus_pirate_protocol_t.protocol_setup
- * @see bus_pirate_protocol_t.protocol_get_ready
*/
void onewire_setup(void);
/**
+ * Prepares the protocol ready to operate on the bus.
+ *
+ * @see bus_pirate_protocol_t.protocol_get_ready
+ */
+void onewire_setup_exc(void);
+
+/**
* Runs the macro identified by the given marker.
*
* @param[in] macro the macro identifier.
@@ -117,4 +123,4 @@ void onewire_reset(void);
#endif /* BP_ENABLE_1WIRE_SUPPORT */
-#endif /* !BP_1WIRE_H */
+#endif /* !BP_1WIRE_H */
View
@@ -225,7 +225,7 @@ bus_pirate_protocol_t enabled_protocols[ENABLED_PROTOCOLS_COUNT] = {
/* setup */
onewire_setup,
/* get_ready */
- onewire_setup,
+ onewire_setup_exc,
/* cleanup */
reset_mode_to_8_bits,
/* print_pins_state */
@@ -509,4 +509,4 @@ void reset_mode_to_8_bits(void) {
mode_configuration.numbits = 8;
mode_configuration.int16 = 0;
-}
+}
@@ -245,36 +245,37 @@
#define HLP1021 bp_message_write_line(5457, 54)
#define HLP1022 bp_message_write_line(5511, 62)
#define MSG_1WIRE_MODE_IDENTIFIER bp_message_write_buffer(5573, 4)
-#define MSG_ACK bp_message_write_buffer(5577, 3)
-#define MSG_BASE_CONVERTER_EQUAL_SIGN bp_message_write_buffer(5580, 3)
-#define MSG_BBIO_MODE_IDENTIFIER bp_message_write_buffer(5583, 5)
-#define MSG_CHIP_IDENTIFIER_CLONE bp_message_write_buffer(5588, 22)
-#define MSG_CHIP_REVISION_A3 bp_message_write_buffer(5610, 2)
-#define MSG_CHIP_REVISION_B4 bp_message_write_buffer(5612, 2)
-#define MSG_CHIP_REVISION_B5 bp_message_write_buffer(5614, 2)
-#define MSG_CHIP_REVISION_B8 bp_message_write_buffer(5616, 2)
-#define MSG_CHIP_REVISION_ID_BEGIN bp_message_write_buffer(5618, 13)
-#define MSG_CHIP_REVISION_ID_END_2 bp_message_write_buffer(5631, 2)
-#define MSG_CHIP_REVISION_ID_END_4 bp_message_write_buffer(5633, 2)
-#define MSG_CHIP_REVISION_UNKNOWN bp_message_write_buffer(5635, 3)
-#define MSG_CLUTCH_DISENGAGED bp_message_write_line(5638, 20)
-#define MSG_CLUTCH_ENGAGED bp_message_write_line(5658, 17)
-#define MSG_FINISH_SETUP_PROMPT bp_message_write_line(5675, 61)
-#define MSG_I2C_MODE_IDENTIFIER bp_message_write_buffer(5736, 4)
-#define MSG_I2C_START_BIT bp_message_write_line(5740, 13)
-#define MSG_I2C_STOP_BIT bp_message_write_line(5753, 12)
-#define MSG_NACK bp_message_write_buffer(5765, 4)
-#define MSG_NO_VOLTAGE_ON_PULLUP_PIN bp_message_write_line(5769, 34)
-#define MSG_OPENOCD_MODE_IDENTIFIER bp_message_write_buffer(5803, 4)
-#define MSG_PIC_MODE_IDENTIFIER bp_message_write_buffer(5807, 4)
-#define MSG_PIC_UNKNOWN_MODE bp_message_write_line(5811, 12)
-#define MSG_PWM_FREQUENCY_TOO_LOW bp_message_write_line(5823, 36)
-#define MSG_PWM_HZ_MARKER bp_message_write_line(5859, 3)
-#define MSG_RAW_BRG_VALUE_INPUT bp_message_write_line(5862, 23)
-#define MSG_RAW_MODE_IDENTIFIER bp_message_write_buffer(5885, 4)
-#define MSG_SPI_COULD_NOT_KEEP_UP bp_message_write_line(5889, 16)
-#define MSG_SPI_MODE_IDENTIFIER bp_message_write_buffer(5905, 4)
-#define MSG_UART_MODE_IDENTIFIER bp_message_write_buffer(5909, 4)
-#define MSG_VREG_TOO_LOW bp_message_write_line(5913, 31)
+#define MSG_1WIRE_SPEED_PROMPT bp_message_write_line(5577, 62)
+#define MSG_ACK bp_message_write_buffer(5639, 3)
+#define MSG_BASE_CONVERTER_EQUAL_SIGN bp_message_write_buffer(5642, 3)
+#define MSG_BBIO_MODE_IDENTIFIER bp_message_write_buffer(5645, 5)
+#define MSG_CHIP_IDENTIFIER_CLONE bp_message_write_buffer(5650, 22)
+#define MSG_CHIP_REVISION_A3 bp_message_write_buffer(5672, 2)
+#define MSG_CHIP_REVISION_B4 bp_message_write_buffer(5674, 2)
+#define MSG_CHIP_REVISION_B5 bp_message_write_buffer(5676, 2)
+#define MSG_CHIP_REVISION_B8 bp_message_write_buffer(5678, 2)
+#define MSG_CHIP_REVISION_ID_BEGIN bp_message_write_buffer(5680, 13)
+#define MSG_CHIP_REVISION_ID_END_2 bp_message_write_buffer(5693, 2)
+#define MSG_CHIP_REVISION_ID_END_4 bp_message_write_buffer(5695, 2)
+#define MSG_CHIP_REVISION_UNKNOWN bp_message_write_buffer(5697, 3)
+#define MSG_CLUTCH_DISENGAGED bp_message_write_line(5700, 20)
+#define MSG_CLUTCH_ENGAGED bp_message_write_line(5720, 17)
+#define MSG_FINISH_SETUP_PROMPT bp_message_write_line(5737, 61)
+#define MSG_I2C_MODE_IDENTIFIER bp_message_write_buffer(5798, 4)
+#define MSG_I2C_START_BIT bp_message_write_line(5802, 13)
+#define MSG_I2C_STOP_BIT bp_message_write_line(5815, 12)
+#define MSG_NACK bp_message_write_buffer(5827, 4)
+#define MSG_NO_VOLTAGE_ON_PULLUP_PIN bp_message_write_line(5831, 34)
+#define MSG_OPENOCD_MODE_IDENTIFIER bp_message_write_buffer(5865, 4)
+#define MSG_PIC_MODE_IDENTIFIER bp_message_write_buffer(5869, 4)
+#define MSG_PIC_UNKNOWN_MODE bp_message_write_line(5873, 12)
+#define MSG_PWM_FREQUENCY_TOO_LOW bp_message_write_line(5885, 36)
+#define MSG_PWM_HZ_MARKER bp_message_write_line(5921, 3)
+#define MSG_RAW_BRG_VALUE_INPUT bp_message_write_line(5924, 23)
+#define MSG_RAW_MODE_IDENTIFIER bp_message_write_buffer(5947, 4)
+#define MSG_SPI_COULD_NOT_KEEP_UP bp_message_write_line(5951, 16)
+#define MSG_SPI_MODE_IDENTIFIER bp_message_write_buffer(5967, 4)
+#define MSG_UART_MODE_IDENTIFIER bp_message_write_buffer(5971, 4)
+#define MSG_VREG_TOO_LOW bp_message_write_line(5975, 31)
#endif /* BP_MESSAGES_V3_H */
@@ -734,6 +734,9 @@ _bp_messages:
; MSG_1WIRE_MODE_IDENTIFIER
.pascii "1W01"
+ ; MSG_1WIRE_SPEED_PROMPT
+ .pascii "Set speed:\r\n 1. Standard (~16.3kbps) \r\n 2. Overdrive (~160kps)"
+
; MSG_ACK
.pascii "ACK"
Oops, something went wrong.

0 comments on commit 07c8be9

Please sign in to comment.