示例#1
0
/**
 * \brief Test EEPROM write buffer
 *
 * This test erases test page \ref TEST_WRITE_BUFFER_PAGE then writes a buffer
 * to the test page, and then overwrites this with the another buffer and checks
 * that the last buffer written is what the page is containing.
 *
 * \param test Current test case.
 */
static void run_eeprom_write_buffer_test(const struct test_case *test)
{
	uint8_t buffer[EEPROM_PAGE_SIZE];
	bool    success;

	set_buffer(buffer, EEPROM_ERASED);
	buffer[0] = 0x11;
	buffer[1] = 0xaa;
	buffer[2] = 0xee;
	buffer[3] = 0x22;

	// Erase page
	nvm_eeprom_erase_bytes_in_page(TEST_WRITE_BUFFER_PAGE);
	// Write buffer to EEPROM
	nvm_eeprom_erase_and_write_buffer(TEST_WRITE_BUFFER_PAGE *
			EEPROM_PAGE_SIZE, &buffer, EEPROM_PAGE_SIZE);
	/* Write another buffer to EEPROM to make sure EEPROM is deleted before
	 * written to.
	*/
	buffer[0] = 0x33;
	buffer[1] = 0x11;
	buffer[2] = 0xee;
	buffer[3] = 0xaa;
	nvm_eeprom_erase_and_write_buffer(TEST_WRITE_BUFFER_PAGE *
			EEPROM_PAGE_SIZE, &buffer, EEPROM_PAGE_SIZE);

	// Check that what we have written is in EEPROM.
	success = is_eeprom_page_equal_to_buffer(TEST_WRITE_BUFFER_PAGE, buffer);

	test_assert_true(test, success, "Write buffer failed");
}
示例#2
0
void system_config_save(char* command)
{
	UNUSED(command);
	
	system_config_check();
	
	nvm_eeprom_erase_and_write_buffer((eeprom_addr_t) &EEPROM_PDICLOCK, &(systemconfig.pdiclock), sizeof(EEPROM_PDICLOCK));
	nvm_eeprom_erase_and_write_buffer((eeprom_addr_t) &EEPROM_TPICLOCK, &(systemconfig.tpiclock), sizeof(EEPROM_TPICLOCK));
	nvm_eeprom_erase_and_write_buffer((eeprom_addr_t) &EEPROM_VERSION, &(systemconfig.version), sizeof(EEPROM_VERSION));
	nvm_eeprom_erase_and_write_buffer((eeprom_addr_t) &EEPROM_DRIVER, &(systemconfig.driver), sizeof(EEPROM_DRIVER));
}
示例#3
0
/**
 * \brief  Copy a RAM buffer to a eeprom memory section
 *
 * \param dst    Pointer to flash destination.
 * \param src    Pointer to source data.
 * \param nbytes Number of bytes to transfer.
 */
static void mem_eeprom_write(isp_addr_t dst, const void *src, uint16_t nbytes)
{
#if (FLASH_SIZE==0x10000)
	// Optimize CODE space (150B), but decrease the speed
   	// 24s to program 2KB instead of 1s
	while (nbytes--) {
		nvm_eeprom_write_byte(dst++, *(uint8_t*)src);
		src = (uint8_t*)src + 1;
	}
#else
	nvm_eeprom_erase_and_write_buffer(dst, src, nbytes);
#endif
}
示例#4
0
status_code_t nvm_write(mem_type_t mem, uint32_t address, void *buffer,
		uint32_t len)
{
	switch (mem) {
	case INT_FLASH:
		nvm_flash_erase_and_write_buffer((flash_addr_t)address,
				(const void *)buffer, len, true);
		break;

	case INT_USERPAGE:
		nvm_user_sig_write_buffer((flash_addr_t)address,
				(const void *)buffer, len, true);
		break;

	case INT_EEPROM:
		nvm_eeprom_erase_and_write_buffer((eeprom_addr_t)address,
				(const void *)buffer, len);
		break;

#if defined(USE_EXTMEM) && defined(CONF_BOARD_AT45DBX)
	case AT45DBX:
	{
		uint32_t sector = address / AT45DBX_SECTOR_SIZE;
		if (!at45dbx_write_sector_open(sector)) {
			return ERR_BAD_ADDRESS;
		}

		at45dbx_write_sector_from_ram((const void *)buffer);
		at45dbx_write_close();
	}
	break;
#endif

	default:
		return ERR_INVALID_ARG;
	}

	return STATUS_OK;
}