aboutsummaryrefslogtreecommitdiff
path: root/fsm
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--fsm/eeprom.h49
-rw-r--r--fsm/tk.h14
2 files changed, 41 insertions, 22 deletions
diff --git a/fsm/eeprom.h b/fsm/eeprom.h
index 440d2b3..1e10fd2 100644
--- a/fsm/eeprom.h
+++ b/fsm/eeprom.h
@@ -7,44 +7,49 @@
#include <avr/eeprom.h>
// set this higher to enable normal eeprom functions
+// TODO: rename to EEPROM_BYTES_NEEDED or similar, to make purpose clearer
#ifndef EEPROM_BYTES
#define EEPROM_BYTES 0
#endif
// set this higher to enable wear-levelled eeprom functions
+// TODO: rename to EEPROM_WL_BYTES_NEEDED or similar, to make purpose clearer
#ifndef EEPROM_WL_BYTES
#define EEPROM_WL_BYTES 0
#endif
#ifdef USE_EEPROM
-// this fails when EEPROM_BYTES is a sizeof()
-//#if EEPROM_BYTES >= (EEPSIZE/2)
-//#error Requested EEPROM_BYTES too big.
-//#endif
-#ifdef EEPROM_OVERRIDE
-uint8_t *eeprom;
-#else
-uint8_t eeprom[EEPROM_BYTES];
-#endif
-uint8_t load_eeprom(); // returns 1 for success, 0 for no data found
-void save_eeprom();
-#define EEP_START (EEPSIZE/2)
+ #ifdef USE_EEPROM_WL
+ // split eeprom in half
+ #define EEP_START (EEPROM_SIZE/2)
+ BUILD_ASSERT(eep_less_than_half, EEPROM_BYTES <= (EEPROM_SIZE/2));
+ #else
+ // use entire eeprom
+ #define EEP_START 0
+ BUILD_ASSERT(eep_data_fits, EEPROM_BYTES <= EEPROM_SIZE);
+ #endif
+ #ifdef EEPROM_OVERRIDE
+ uint8_t *eeprom;
+ #else
+ uint8_t eeprom[EEPROM_BYTES];
+ #endif
+ uint8_t load_eeprom(); // returns 1 for success, 0 for no data found
+ void save_eeprom();
#endif
#ifdef USE_EEPROM_WL
-#if EEPROM_WL_BYTES >= (EEPSIZE/4)
-#error Requested EEPROM_WL_BYTES too big.
-#endif
-uint8_t eeprom_wl[EEPROM_WL_BYTES];
-uint8_t load_eeprom_wl(); // returns 1 for success, 0 for no data found
-void save_eeprom_wl();
-#define EEP_WL_SIZE (EEPSIZE/2)
+ #define EEP_WL_SIZE (EEPROM_SIZE/2)
+ // ensure space for at least 2 slots for wear levelling
+ BUILD_ASSERT(eepwl_two_slots_minimum, EEPROM_WL_BYTES <= (EEP_WL_SIZE/2));
+ uint8_t eeprom_wl[EEPROM_WL_BYTES];
+ uint8_t load_eeprom_wl(); // returns 1 for success, 0 for no data found
+ void save_eeprom_wl();
#endif
-#if EEPSIZE > 256
-#define EEP_OFFSET_T uint16_t
+#if EEPROM_SIZE > 256
+ #define EEP_OFFSET_T uint16_t
#else
-#define EEP_OFFSET_T uint8_t
+ #define EEP_OFFSET_T uint8_t
#endif
// if this marker isn't found, the eeprom is assumed to be blank
diff --git a/fsm/tk.h b/fsm/tk.h
index 785808d..f2e7efe 100644
--- a/fsm/tk.h
+++ b/fsm/tk.h
@@ -24,3 +24,17 @@
// use it like this:
//#include incfile(CONFIGFILE)
+
+// cause a build failure if `condition` is true
+// (gcc compile trick taken from an old version of include/linux/kernel.h)
+// more info here:
+// https://scaryreasoner.wordpress.com/2009/02/28/checking-sizeof-at-compile-time/
+#define BUILD_FAIL_IF(name, condition) \
+ __attribute__((unused)) static void name() \
+ { ((void)sizeof(char[1 - 2*!!(condition)])); }
+
+// cause a build failure if `condition` is false
+#define BUILD_ASSERT(name, condition) \
+ __attribute__((unused)) static void name() \
+ { ((void)sizeof(char[1 - 2*!(condition)])); }
+
If you find this content useful please consider a small donation via bitcoin: bitcoin:1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2?amount=0.001&message=Donation Scraping git contents via cgit is very resource intensive. The continued hosting of these git repositories is entirely financed by your bitcoin contributions. For donations of a least 1 mBTC you include your IP address in the message of your bitcoin donation. This will remove this message in the future for requests from your IP, which will significantly reduce token usage. In any case, any contributions to bitcoin address 1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2 are very welcome. Thanks in advance for you contribution to a self-sustaining ecosystem.