[PATCH 08/11] Add code to write rom of the OSTC3

Anton Lundin glance at acc.umu.se
Fri Nov 21 12:28:35 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 | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/src/hw_ostc3.c b/src/hw_ostc3.c
index d8ee534..df537be 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
@@ -900,3 +901,58 @@ 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);
+#if 0
+	// FIXME: This variant doens't work
+	// Things doesn't get written to memory. Timing issues?
+	// Version below works, serial_sleep (2) is probably the thing.
+	unsigned char buffer[4 + block_size];
+	buffer[0] = WRITE_BLOCK;
+	uint24_be_array(addr, buffer + 1);
+	memcpy(buffer + 4, block, block_size);
+
+	rc = hw_ostc3_transfer(device, NULL, WRITE_BLOCK, buffer, sizeof(buffer), NULL, 0);
+	serial_sleep (device->port, 1100);
+	return rc;
+#else
+	int n;
+	unsigned char response;
+	unsigned char buffer[4];
+	buffer[0] = WRITE_BLOCK;
+	uint24_be_array(addr, buffer + 1);
+
+	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;
+#endif
+}
-- 
1.9.1



More information about the devel mailing list