Beispiel #1
0
void EraseFlashBuffer(void)
{
   /*Set the correct settings and store critical registers before NVM-workaround*/
#ifdef WORKAROUND
   Prepare_to_Sleep();
#endif
   /*Assembly "function" to erase flash buffer*/
    nvm_flash_flush_buffer();
}
Beispiel #2
0
/**
 * \brief Simulate corruption of a part of Flash
 *
 * This function simulates corruption of the Flash by modifying one of the
 * strings in the error insertion menu. More specifically it replaces the
 * "-- Error insertion --" menu title with "Out of cheese!". If called again,
 * the original string is reverted.
 */
static void oven_classb_flash_corrupter(void)
{
	/* Flash page base address of the menu title string */
	flash_addr_t page_addr = ((uintptr_t)error_menu_title / FLASH_PAGE_SIZE)
			* FLASH_PAGE_SIZE;
	/* Address within the page */
	uintptr_t string_addr = (uintptr_t)error_menu_title % FLASH_PAGE_SIZE;
	/* New string that we will replace it with */
	const char newstring[] = "    Out of cheese!   ";
	const char oldstring[] = "-- Error insertion --";

	/* Load page with strings from flash into our buffer */
	nvm_flash_flush_buffer();
	for (uint16_t addr = 0; addr < FLASH_PAGE_SIZE / 2; addr++) {
		flash_scramble_buf[addr] = nvm_flash_read_word((addr * 2)
				+ page_addr);
		oven_wdt_periodic_reset();
	}

	/* Check which string is the current and change it accordingly */
	if (strcmp((char *)flash_scramble_buf + string_addr, oldstring) == 0) {
		strcpy((char *)flash_scramble_buf + string_addr, newstring);
	} else {
		strcpy((char *)flash_scramble_buf + string_addr, oldstring);
	}

	oven_wdt_periodic_reset();

	/* Fill page buffer with our buffered data, then write it to flash */
	for (uint16_t addr = 0; addr < FLASH_PAGE_SIZE / 2; addr++) {
		nvm_flash_load_word_to_buffer(addr * 2,
				flash_scramble_buf[addr]);
		oven_wdt_periodic_reset();
	}
	nvm_flash_atomic_write_app_page(page_addr);
}