[RFC PATCH 07/10] Add code to write rom of the OSTC3

Anton Lundin glance at acc.umu.se
Fri Nov 14 09:01:36 PST 2014


This is now you transfer a new firmware to the OSTC3.

This code is inspired by JeanDo ostc-companion.

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

diff --git a/src/hw_ostc3.c b/src/hw_ostc3.c
index 117a4bb..ff65677 100644
--- a/src/hw_ostc3.c
+++ b/src/hw_ostc3.c
@@ -53,6 +53,7 @@
 #define RB_LOGBOOK_COUNT 256
 
 #define READ_BLOCK 0x20
+#define WRITE_BLOCK 0x30
 #define ERASE_RANGE 0x42
 #define S_READY    0x4C
 #define READY      0x4D
@@ -836,3 +837,57 @@ hw_ostc3_device_read_block (hw_ostc3_device_t *device, unsigned int addr, unsign
 
 	return hw_ostc3_transfer (device, NULL, READ_BLOCK, buffer, sizeof(buffer), block, block_size);
 }
+
+static dc_status_t
+hw_ostc3_device_write_block (dc_device_t *abstract, unsigned int addr, unsigned char block[], unsigned int block_size)
+{
+	dc_status_t rc = DC_STATUS_SUCCESS;
+	hw_ostc3_device_t *device = (hw_ostc3_device_t *) abstract;
+	dc_context_t *context = (abstract ? abstract->context : NULL);
+	int n;
+	unsigned char response;
+	unsigned char buffer[4];
+	buffer[0] = WRITE_BLOCK;
+	uint24_be_array(addr, buffer + 1);
+
+	// Make sure everything is in a sane state.
+	serial_sleep (device->port, 100);
+	serial_flush (device->port, SERIAL_QUEUE_BOTH);
+
+	// Send initial write block command.
+	/* FIXME: we can't use hw_ostc3_transfer here, for some odd reason
+	 * Here shit goes sideways. The device reboots probably due
+	 * to that it thinks it doesn't have any data
+	rc = hw_ostc3_transfer(device, NULL, WRITE_BLOCK, buffer, sizeof(buffer), NULL, 0);
+	if (rc != DC_STATUS_SUCCESS) {
+		ERROR (context, "Failed to send write block command");
+		return rc;
+	}*/
+	n = serial_write (device->port, buffer, sizeof(buffer));
+	if (n != sizeof(buffer)) {
+		ERROR (context, "failed to send address to device");
+		return EXITCODE (n);
+	}
+
+	serial_flush (device->port, SERIAL_QUEUE_BOTH);
+	serial_sleep (device->port, 2);
+
+	// Send the new block
+	n = serial_write (device->port, block, block_size);
+	if (n != block_size) {
+		ERROR (context, "failed to send block to device");
+		return EXITCODE (n);
+	}
+
+	serial_flush (device->port, SERIAL_QUEUE_BOTH);
+
+	// A sleep lenght copied from ostc-companion
+	// Feels a bit slower than that what that does?
+	serial_sleep (device->port, 1100);
+
+	n = serial_read (device->port, &response, sizeof (response));
+	if (n != sizeof (response) || response != S_READY)
+		return EXITCODE (n);
+
+	return DC_STATUS_SUCCESS;
+}
-- 
1.9.1



More information about the devel mailing list