[PATCH 04/11] Add a helper to put the OSTC3 into servicemode

Anton Lundin glance at acc.umu.se
Fri Nov 21 12:28:31 PST 2014


This code is inspired by JeanDo ostc-companion.

Signed-off-by: Anton Lundin <glance at acc.umu.se>
---
 src/hw_ostc3.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 47 insertions(+), 2 deletions(-)

diff --git a/src/hw_ostc3.c b/src/hw_ostc3.c
index 7fa38f8..4d6bf83 100644
--- a/src/hw_ostc3.c
+++ b/src/hw_ostc3.c
@@ -50,6 +50,7 @@
 #define RB_LOGBOOK_SIZE  256
 #define RB_LOGBOOK_COUNT 256
 
+#define S_READY    0x4C
 #define READY      0x4D
 #define HEADER     0x61
 #define CLOCK      0x62
@@ -71,6 +72,7 @@ typedef struct hw_ostc3_device_t {
 		NONE,
 		OPEN,
 		DOWNLOAD,
+		SERVICE,
 	} state;
 } hw_ostc3_device_t;
 
@@ -196,7 +198,7 @@ hw_ostc3_transfer (hw_ostc3_device_t *device,
 		}
 
 		// Verify the ready byte.
-		if (ready[0] != READY) {
+		if (!(ready[0] == READY || ready[0] == S_READY)) {
 			ERROR (abstract->context, "Unexpected ready byte.");
 			return DC_STATUS_PROTOCOL;
 		}
@@ -294,7 +296,7 @@ hw_ostc3_check_state_or_init(dc_device_t *abstract)
 	if (device->state == OPEN) {
 		if ((rc = hw_ostc3_device_init(abstract)) != DC_STATUS_SUCCESS)
 			return rc;
-	} else if (device->state != DOWNLOAD) {
+	} else if (device->state != DOWNLOAD && device->state != SERVICE) {
 		return DC_STATUS_INVALIDARGS;
 	}
 	return DC_STATUS_SUCCESS;
@@ -826,3 +828,46 @@ hw_ostc3_firmware_readfile (hw_ostc3_firmware_t *firmware, dc_context_t *context
 
 	return DC_STATUS_SUCCESS;
 }
+
+
+static dc_status_t
+hw_ostc3_device_service_mode (dc_device_t *abstract)
+{
+	hw_ostc3_device_t *device = (hw_ostc3_device_t *) abstract;
+	unsigned char command[] = {0xAA, 0xAB, 0xCD, 0xEF};
+	unsigned char output[5];
+	dc_status_t rc;
+	int n;
+
+	if (device->state != OPEN)
+		return DC_STATUS_INVALIDARGS;
+
+	// We cant use hw_ostc3_transfer here, due to the different echos
+	n = serial_write (device->port, command, sizeof (command));
+	if (n != sizeof (command)) {
+		ERROR (abstract->context, "Failed to send the command.");
+		return EXITCODE (n);
+	}
+
+	// Give the device some time to enter service mode
+	serial_sleep(device->port, 100);
+
+	// Read the response
+	n = serial_read (device->port, output, sizeof (output));
+	if (n != sizeof (output)) {
+		ERROR (abstract->context, "Failed to receive the echo.");
+		return EXITCODE (n);
+	}
+
+	// Verify the response to service mode
+	if (output[0] != 0x4B || output[1] != 0xAB ||
+			output[2] != 0xCD || output[3] != 0xEF ||
+			output[4] != S_READY) {
+		ERROR (abstract->context, "Failed to verify echo.");
+		return DC_STATUS_IO;
+	}
+
+	device->state = SERVICE;
+
+	return DC_STATUS_SUCCESS;
+}
-- 
1.9.1



More information about the devel mailing list