comparison 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
comparison
equal deleted inserted replaced
69:cf9eb08b8b23 70:aaf0603d7f88
118 /* Local variable declarations */ 118 /* Local variable declarations */
119 119
120 /* Local function prototypes */ 120 /* Local function prototypes */
121 static void tempctrl_load_or_init_settings(void); 121 static void tempctrl_load_or_init_settings(void);
122 static void tempctrl_default_settings(void); 122 static void tempctrl_default_settings(void);
123 static void tempctrl_write_settings(void); 123 static int tempctrl_write_settings(void);
124 static void setstate(char state); 124 static void setstate(char state);
125 static const char * state2long(char s); 125 static const char * state2long(char s);
126 static int fmttemp(char *buf, const char *name, int tmp, const char *trailer); 126 static int fmttemp(char *buf, const char *name, int tmp, const char *trailer);
127 static GPIO_TypeDef *char2port(char port); 127 static GPIO_TypeDef *char2port(char port);
128 128
340 static void 340 static void
341 tempctrl_load_or_init_settings(void) { 341 tempctrl_load_or_init_settings(void) {
342 if (!flashreadblock(TEMPCTRL_FLASH_ADDRESS, sizeof(tc_settings), &tc_settings)) { 342 if (!flashreadblock(TEMPCTRL_FLASH_ADDRESS, sizeof(tc_settings), &tc_settings)) {
343 fputs("CRC fails, loading defaults\n", stdout); 343 fputs("CRC fails, loading defaults\n", stdout);
344 tempctrl_default_settings(); 344 tempctrl_default_settings();
345 tempctrl_write_settings(); 345 if (tempctrl_write_settings())
346 fputs("Failed to write settings\n", stdout);
346 } 347 }
347 } 348 }
348 349
349 /* Load in the defaults from flash */ 350 /* Load in the defaults from flash */
350 static void 351 static void
351 tempctrl_default_settings(void) { 352 tempctrl_default_settings(void) {
352 memcpy(&tc_settings, &default_tc_settings, sizeof(tc_settings_t)); 353 memcpy(&tc_settings, &default_tc_settings, sizeof(tc_settings_t));
353 } 354 }
354 355
355 /* Write the current settings out to SPI flash */ 356 /* Write the current settings out to SPI flash */
356 static void 357 static int
357 tempctrl_write_settings(void) { 358 tempctrl_write_settings(void) {
358 flashwriteblock(TEMPCTRL_FLASH_ADDRESS, sizeof(tc_settings), &tc_settings); 359 return flashwriteblock(TEMPCTRL_FLASH_ADDRESS, sizeof(tc_settings), &tc_settings);
359 } 360 }
360 361
361 /* Set the relays to match the desired state */ 362 /* Set the relays to match the desired state */
362 static void 363 static void
363 setstate(char state) { 364 setstate(char state) {
438 ); 439 );
439 return; 440 return;
440 } 441 }
441 442
442 if (!strcasecmp(argv[0], "save")) { 443 if (!strcasecmp(argv[0], "save")) {
443 tempctrl_write_settings(); 444 if (tempctrl_write_settings())
445 fputs("Failed to write settings\n", stdout);
444 return; 446 return;
445 } 447 }
446 if (!strcasecmp(argv[0], "load")) { 448 if (!strcasecmp(argv[0], "load")) {
447 tempctrl_load_or_init_settings(); 449 tempctrl_load_or_init_settings();
448 return; 450 return;