예제 #1
0
status_code_t nvm_write_char(mem_type_t mem, uint32_t address, uint8_t data)
{
	switch (mem) {
	case INT_FLASH:
		nvm_flash_erase_and_write_buffer((flash_addr_t)address,
				(const void *)&data, 1, true);
		break;

	case INT_USERPAGE:
		nvm_user_sig_write_buffer((flash_addr_t)address,
				(const void *)&data, 1, true);
		break;

	case INT_EEPROM:
		nvm_eeprom_write_byte((eeprom_addr_t)address, data);
		break;

#if defined(USE_EXTMEM) && defined(CONF_BOARD_AT45DBX)
	case AT45DBX:
		if (!at45dbx_write_byte_open(address)) {
			return ERR_BAD_ADDRESS;
		}

		at45dbx_write_byte(data);
		at45dbx_write_close();
#endif

	default:
		return ERR_INVALID_ARG;
	}

	return STATUS_OK;
}
예제 #2
0
status_code_t nvm_write_char(mem_type_t mem, uint32_t address, uint8_t data)
{
	switch (mem) {
	case INT_FLASH:
	case INT_USERPAGE:
		flash_api_memcpy((volatile void *)address, (const void *)&data,
				1, true);
		break;

#if defined(USE_EXTMEM) && defined(CONF_BOARD_AT45DBX)
	case AT45DBX:
		if (!at45dbx_write_byte_open(address)) {
			return ERR_BAD_ADDRESS;
		}

		at45dbx_write_byte(data);
		at45dbx_write_close();
#endif

	default:
		return ERR_INVALID_ARG;
	}

	return STATUS_OK;
}
예제 #3
0
파일: unit_tests.c 프로젝트: InSoonPark/asf
/**
 * \brief Test the read and write byte operations on the DataFlash
 *
 * This function will test the read and write functionalities of the DataFlash
 * using byte access. It will first write a known pattern on the 2 first
 * consecutive sectors and read it back by testing each value read.\n
 * In addition to test the data integrity and the byte read / write
 * functions, this will also test the continuity of the sectors as well as the
 * auto-incrementation of the DataFlash address.
 *
 * \param test Current test case.
 */
static void run_byte_access_test(const struct test_case *test)
{
	uint32_t i;
	bool status;
	uint8_t byte;

	/* Write bytes one by one to the 2 first continuous sectors
	 */
	status = at45dbx_write_byte_open(0);
	test_assert_true(test, status == true,
			"Cannot open the DataFlash memory for write access");
	for (i=0; i<AT45DBX_SECTOR_SIZE * 2; i++) {
		status = at45dbx_write_byte(BYTE_PATTERN1(i));
		test_assert_true(test, status == true,
				"Write byte operation error @ 0x%08x", i);
	}
	at45dbx_write_close();

	/* Read back the 2 first sectors of the DataFlash and check the values
	 */
	status = at45dbx_read_byte_open(0);
	test_assert_true(test, status == true,
			"Cannot open the DataFlash memory for read access");
	for (i=0; i<AT45DBX_SECTOR_SIZE * 2; i++) {
		byte = at45dbx_read_byte();
		test_assert_true(test, byte == BYTE_PATTERN1(i),
				"Read byte operation error @ 0x%08x"
				" (read: 0x%02x, expected: 0x%02x)", i,
				byte, BYTE_PATTERN1(i));
	}
	at45dbx_read_close();
}
예제 #4
0
파일: sam_nvm.c 프로젝트: kerichsen/asf
status_code_t nvm_write_char(mem_type_t mem, uint32_t address, uint8_t data)
{
	switch (mem) {
	case INT_FLASH:
#if SAM4S
		/*! This erases 8 pages of flash before writing */
		if (flash_erase_page(address, IFLASH_ERASE_PAGES_8)) {
			return ERR_INVALID_ARG;
		} else if (flash_write(address, (const void *)&data, 1,
				false)) {
			return ERR_INVALID_ARG;
		}

#else
		if (flash_write(address, (const void *)&data, 1, true)) {
			return ERR_INVALID_ARG;
		}

#endif
		break;

#if SAM4S
	case INT_USERPAGE:
		if (flash_write_user_signature((const void *)&data,	1)) {
			return ERR_INVALID_ARG;
		}
		break;
#endif

#if defined(USE_EXTMEM) && defined(CONF_BOARD_AT45DBX)
	case AT45DBX:
		if (!at45dbx_write_byte_open() address) {
			return ERR_BAD_ADDRESS;
		}

		at45dbx_write_byte(data);
		at45dbx_write_close();
		at45dbx_read_byte_open(address);
		read = at45dbx_read_byte();
		at45dbx_read_close();
		break;
#endif

	default:
		return ERR_INVALID_ARG;
	}

	return STATUS_OK;
}