Skip to content

Commit b70710c

Browse files
committed
OSTC 4/5: Add 0x20 'read memory' and 0x80 'write hardware info'.
Signed-off-by: Michael Keller <[email protected]>
1 parent 64ecef5 commit b70710c

File tree

2 files changed

+52
-15
lines changed

2 files changed

+52
-15
lines changed

include/libdivecomputer/hw_ostc3.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ hw_ostc3_device_display (dc_device_t *device, const char *text);
4747
dc_status_t
4848
hw_ostc3_device_customtext (dc_device_t *device, const char *text);
4949

50+
dc_status_t hw_ostc3_device_hwinfo_write (dc_device_t *abstract, unsigned char hwinfo[52]);
51+
5052
dc_status_t
5153
hw_ostc3_device_config_read (dc_device_t *abstract, unsigned int config, unsigned char data[], unsigned int size);
5254

src/hw_ostc3.c

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
#define S_UPLOAD 0x73
7777
#define WRITE 0x77
7878
#define RESET 0x78
79+
#define HWINFO_WRITE 0x80
7980
#define S_INIT 0xAA
8081
#define INIT 0xBB
8182
#define EXIT 0xFF
@@ -1019,6 +1020,27 @@ hw_ostc3_device_customtext (dc_device_t *abstract, const char *text)
10191020
return DC_STATUS_SUCCESS;
10201021
}
10211022

1023+
dc_status_t hw_ostc3_device_hwinfo_write (dc_device_t *abstract, unsigned char hwinfo[52])
1024+
{
1025+
hw_ostc3_device_t *device = (hw_ostc3_device_t *) abstract;
1026+
1027+
if (!ISINSTANCE (abstract))
1028+
return DC_STATUS_INVALIDARGS;
1029+
1030+
dc_status_t rc = hw_ostc3_device_init (device, SERVICE);
1031+
if (rc != DC_STATUS_SUCCESS)
1032+
return rc;
1033+
1034+
if (device->hardware == OSTC3)
1035+
return DC_STATUS_UNSUPPORTED;
1036+
1037+
rc = hw_ostc3_transfer(device, NULL, HWINFO_WRITE, hwinfo, 52, NULL, 0, NULL, NODELAY);
1038+
if (rc != DC_STATUS_SUCCESS)
1039+
return rc;
1040+
1041+
return DC_STATUS_SUCCESS;
1042+
}
1043+
10221044
dc_status_t
10231045
hw_ostc3_device_config_read (dc_device_t *abstract, unsigned int config, unsigned char data[], unsigned int size)
10241046
{
@@ -1641,32 +1663,45 @@ hw_ostc3_device_read (dc_device_t *abstract, unsigned int address, unsigned char
16411663
dc_status_t status = DC_STATUS_SUCCESS;
16421664
hw_ostc3_device_t *device = (hw_ostc3_device_t *) abstract;
16431665

1644-
if ((address % SZ_FIRMWARE_BLOCK != 0) ||
1645-
(size % SZ_FIRMWARE_BLOCK != 0)) {
1646-
ERROR (abstract->context, "Address or size not aligned to the page size!");
1647-
return DC_STATUS_INVALIDARGS;
1648-
}
1649-
16501666
// Make sure the device is in service mode.
16511667
status = hw_ostc3_device_init (device, SERVICE);
16521668
if (status != DC_STATUS_SUCCESS) {
16531669
return status;
16541670
}
16551671

1656-
if (device->hardware == OSTC4) {
1657-
return DC_STATUS_UNSUPPORTED;
1658-
}
1672+
if (device->hardware == OSTC3) {
1673+
if ((address % SZ_FIRMWARE_BLOCK != 0) ||
1674+
(size % SZ_FIRMWARE_BLOCK != 0)) {
1675+
ERROR (abstract->context, "Address or size not aligned to the page size!");
1676+
return DC_STATUS_INVALIDARGS;
1677+
}
16591678

1660-
unsigned int nbytes = 0;
1661-
while (nbytes < size) {
1662-
// Read a memory page.
1663-
status = hw_ostc3_firmware_block_read (device, address + nbytes, data + nbytes, SZ_FIRMWARE_BLOCK);
1679+
unsigned int nbytes = 0;
1680+
while (nbytes < size) {
1681+
// Read a memory page.
1682+
status = hw_ostc3_firmware_block_read (device, address + nbytes, data + nbytes, SZ_FIRMWARE_BLOCK);
1683+
if (status != DC_STATUS_SUCCESS) {
1684+
ERROR (abstract->context, "Failed to read block.");
1685+
1686+
return status;
1687+
}
1688+
1689+
nbytes += SZ_FIRMWARE_BLOCK;
1690+
}
1691+
} else {
1692+
if (address % 0x100 != 0) {
1693+
ERROR(abstract->context, "Address not aligned to the page size (0x100)!");
1694+
1695+
return DC_STATUS_INVALIDARGS;
1696+
}
1697+
1698+
status = hw_ostc3_firmware_block_read(device, address >> 8, data, size);
16641699
if (status != DC_STATUS_SUCCESS) {
1665-
ERROR (abstract->context, "Failed to read block.");
1700+
ERROR(abstract->context, "Failed to read block.");
1701+
16661702
return status;
16671703
}
16681704

1669-
nbytes += SZ_FIRMWARE_BLOCK;
16701705
}
16711706

16721707
return DC_STATUS_SUCCESS;

0 commit comments

Comments
 (0)