[PATCH v2 10/15] Add code to write rom of the OSTC3

Anton Lundin glance at acc.umu.se
Wed Dec 17 14:11:07 PST 2014


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

This code is inspired by JeanDo ostc-companion.

Reviewed-by: Jef Driesen <jef at libdivecomputer.org>
Signed-off-by: Anton Lundin <glance at acc.umu.se>
---
 src/hw_ostc3.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/src/hw_ostc3.c b/src/hw_ostc3.c
index 5584f31..35df0c7 100644
--- a/src/hw_ostc3.c
+++ b/src/hw_ostc3.c
@@ -53,6 +53,7 @@
 #define RB_LOGBOOK_COUNT 256
 
 #define S_BLOCK_READ 0x20
+#define S_BLOCK_WRITE 0x30
 #define S_ERASE    0x42
 #define S_READY    0x4C
 #define READY      0x4D
@@ -902,3 +903,17 @@ hw_ostc3_firmware_block_read (hw_ostc3_device_t *device, unsigned int addr, unsi
 
 	return hw_ostc3_transfer (device, NULL, S_BLOCK_READ, buffer, sizeof(buffer), block, block_size);
 }
+
+static dc_status_t
+hw_ostc3_firmware_block_write (hw_ostc3_device_t *device, unsigned int addr, unsigned char block[], unsigned int block_size)
+{
+	unsigned char buffer[3 + SZ_FIRMWARE_BLOCK];
+	// We currenty only support writing SZ_FIRMWARE_BLOCK sized blocks.
+	if (block_size > SZ_FIRMWARE_BLOCK)
+		return DC_STATUS_INVALIDARGS;
+
+	array_uint24_be_set(buffer, addr);
+	memcpy(buffer + 3, block, block_size);
+
+	return hw_ostc3_transfer (device, NULL, S_BLOCK_WRITE, buffer, sizeof(buffer), NULL, 0);
+}
-- 
2.1.0



More information about the devel mailing list