From 167a7dc6a753b5ba11c8c2ae2a365cec8656c171 Mon Sep 17 00:00:00 2001 From: Dave Hodder Date: Fri, 12 Feb 2016 18:06:50 +0000 Subject: single-page flash storage --- include/app.h | 36 +++++++++++++++++++++++++++++++++++- include/app_defs.h | 7 +++++++ 2 files changed, 42 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/app.h b/include/app.h index ed946d5..c26c131 100644 --- a/include/app.h +++ b/include/app.h @@ -43,7 +43,7 @@ /****************************************************************************** Button indexing is as follows - numbers in brackets do not correspond to real -buttons, but can be harmessly sent in hal_set_led. + buttons, but can be harmessly sent in hal_set_led. (90)91 92 93 94 95 96 97 98 (99) ....... @@ -92,6 +92,40 @@ void hal_send_midi(u8 port, u8 status, u8 data1, u8 data2); */ void hal_send_sysex(u8 port, const u8* data, u16 length); +/** + * Read some data from flash. + * + * Flash storage is in a single block, currently corresponding to one page. + * The block is always USER_AREA_SIZE bytes long. You can read/write any bytes + * within it - you do not need to worry about paging, that's handled by the HAL. + * + * The block size may increase to span multiple pages in future :) + * + * @param offset - how far into the USER_AREA_SIZE byte block to start reading + * @param data - buffer to receive data (must be at least length bytes long) + * @param length - bytes to read + * + * Attempts to read beyond the end of the block will fail silently. + * + * Note that your first ever read from a new device will contain 0xFF's until + * you overwrite them. + */ +void hal_read_flash(u32 offset, u8 *data, u32 length); + +/** + * Write data to flash + * + * Do take care to avoid thrashing it, as you can wear it out with excessive + * writes. The HAL does not currently do anything clever to mitigate this. + * + * @param offset - how far into the USER_AREA_SIZE byte block to start writing + * @param data - buffer to write (must be at least length bytes long) + * @param length - bytes to write + * + * Attempts to write beyond the end of the block will fail silently + */ +void hal_write_flash(u32 offset,const u8 *data, u32 length); + // ____________________________________________________________________________ // // Callbacks from the hardware (implemented in your app.c) diff --git a/include/app_defs.h b/include/app_defs.h index 829f8a6..7a3efa1 100644 --- a/include/app_defs.h +++ b/include/app_defs.h @@ -99,6 +99,13 @@ typedef unsigned char u8; #define MIDI_IN_CABLE 0 #define MIDI_OUT_CABLE 1 +// ____________________________________________________________________________ +// +// Flash storage +// ____________________________________________________________________________ + +#define USER_AREA_SIZE 1024 + // ____________________________________________________________________________ #endif -- cgit v1.2.1