diff tempctrl.c @ 70:aaf0603d7f88

Add routine to CRC a block of flash. Use it to verify a flash block write.
author Daniel O'Connor <darius@dons.net.au>
date Sun, 14 Apr 2013 22:53:50 +0930
parents 0916bfe3f418
children 05ba84c7da97
line wrap: on
line diff
--- a/tempctrl.c	Sun Apr 14 22:52:21 2013 +0930
+++ b/tempctrl.c	Sun Apr 14 22:53:50 2013 +0930
@@ -120,7 +120,7 @@
 /* Local function prototypes */
 static void		tempctrl_load_or_init_settings(void);
 static void		tempctrl_default_settings(void);
-static void		tempctrl_write_settings(void);
+static int		tempctrl_write_settings(void);
 static void		setstate(char state);
 static const char *	state2long(char s);
 static int		fmttemp(char *buf, const char *name, int tmp, const char *trailer);
@@ -342,7 +342,8 @@
     if (!flashreadblock(TEMPCTRL_FLASH_ADDRESS, sizeof(tc_settings), &tc_settings)) {
 	fputs("CRC fails, loading defaults\n", stdout);
 	tempctrl_default_settings();
-	tempctrl_write_settings();
+	if (tempctrl_write_settings())
+	    fputs("Failed to write settings\n", stdout);
     }
 }
 
@@ -353,9 +354,9 @@
 }
 
 /* Write the current settings out to SPI flash */
-static void
+static int
 tempctrl_write_settings(void) {
-    flashwriteblock(TEMPCTRL_FLASH_ADDRESS, sizeof(tc_settings), &tc_settings);
+    return flashwriteblock(TEMPCTRL_FLASH_ADDRESS, sizeof(tc_settings), &tc_settings);
 }
 
 /* Set the relays to match the desired state */
@@ -440,7 +441,8 @@
     }
 	
     if (!strcasecmp(argv[0], "save")) {
-	tempctrl_write_settings();
+	if (tempctrl_write_settings())
+	    fputs("Failed to write settings\n", stdout);
 	return;
     }
     if (!strcasecmp(argv[0], "load")) {