Add a function to erase the memory of the OSTC3
This is the fist step in the firmware upgrade process. This code is inspired by JeanDo ostc-companion. Reviewed-by: Jef Driesen <jef@libdivecomputer.org> Signed-off-by: Anton Lundin <glance@acc.umu.se>
This commit is contained in:
parent
08dda98c29
commit
5c71ff34c4
@ -46,10 +46,13 @@
|
||||
#define SZ_MEMORY 0x200000
|
||||
#define SZ_CONFIG 4
|
||||
#define SZ_FIRMWARE 0x01E000 // 120KB
|
||||
#define SZ_FIRMWARE_BLOCK 0x1000 // 4KB
|
||||
#define FIRMWARE_AREA 0x3E0000
|
||||
|
||||
#define RB_LOGBOOK_SIZE 256
|
||||
#define RB_LOGBOOK_COUNT 256
|
||||
|
||||
#define S_ERASE 0x42
|
||||
#define S_READY 0x4C
|
||||
#define READY 0x4D
|
||||
#define HEADER 0x61
|
||||
@ -872,3 +875,18 @@ hw_ostc3_firmware_readfile (hw_ostc3_firmware_t *firmware, dc_context_t *context
|
||||
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static dc_status_t
|
||||
hw_ostc3_firmware_erase (hw_ostc3_device_t *device, unsigned int addr, unsigned int size)
|
||||
{
|
||||
// Convert size to number of pages, rounded up.
|
||||
unsigned char blocks = ((size + SZ_FIRMWARE_BLOCK - 1) / SZ_FIRMWARE_BLOCK);
|
||||
|
||||
// Erase just the needed pages.
|
||||
unsigned char buffer[4];
|
||||
array_uint24_be_set (buffer, addr);
|
||||
buffer[3] = blocks;
|
||||
|
||||
return hw_ostc3_transfer (device, NULL, S_ERASE, buffer, sizeof (buffer), NULL, 0);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user