Beispiel #1
0
/*! \brief Tests single-byte access functions.
 */
static void at45dbx_example_test_byte_mem(void)
{
  U8 Pattern = 0x55;
  U8 j = 0xA5;
  print_dbg("\tUsing Pattern 0x55");
  // Perform write access.
  if (at45dbx_write_open(Pattern))
  {
    at45dbx_write_byte(Pattern);
    at45dbx_write_close();
  }
  // Perform read access.
  if (at45dbx_read_open(Pattern))
  {
    j = at45dbx_read_byte();
    at45dbx_read_close();
  }
  // Check read and write operations.
  if (j == Pattern)
  {
    print_dbg(TEST_SUCCESS);
  }
  else
  {
    print_dbg(TEST_FAIL);
  }

  // Change the pattern used.
  Pattern = 0xAA;
  j = 0xA5;
  print_dbg("\tUsing Pattern 0xAA");
  // Perform write access.
  if (at45dbx_write_open(Pattern))
  {
    at45dbx_write_byte(Pattern);
    at45dbx_write_close();
  }
  // Perform read access.
  if (at45dbx_read_open(Pattern))
  {
    j = at45dbx_read_byte();
    at45dbx_read_close();
  }
  // Check read and write operations.
  if (j == Pattern)
  {
    print_dbg(TEST_SUCCESS);
  }
  else
  {
    print_dbg(TEST_FAIL);
  }
}
status_code_t nvm_read_char(mem_type_t mem, uint32_t address, uint8_t *data)
{
	switch (mem) {
	case INT_FLASH:
	case INT_USERPAGE:
		*data = *((uint8_t *)(address));
		break;

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

		*data = at45dbx_read_byte();
		at45dbx_read_close();
		break;
#endif

	default:
		return ERR_INVALID_ARG;
	}

	return STATUS_OK;
}
Beispiel #3
0
status_code_t nvm_read_char(mem_type_t mem, uint32_t address, uint8_t *data)
{
	switch (mem) {
	case INT_FLASH:
		*data = nvm_flash_read_byte((flash_addr_t)address);
		break;

	case INT_USERPAGE:
		nvm_user_sig_read_buffer((flash_addr_t)address, (void *)data,
				1);
		break;

	case INT_EEPROM:
		*data = nvm_eeprom_read_byte((eeprom_addr_t)address);
		break;

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

		*data = at45dbx_read_byte();
		at45dbx_read_close();
		break;
#endif

	default:
		return ERR_INVALID_ARG;
	}

	return STATUS_OK;
}
Beispiel #4
0
/**
 * \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();
}
Beispiel #5
0
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;
}
Beispiel #6
0
status_code_t nvm_read_char(mem_type_t mem, uint32_t address, uint8_t *data)
{
	switch (mem) {
	case INT_FLASH:
		*data = *((uint8_t *)(address));
		break;

#if SAM4S
	case INT_USERPAGE:
	{
		/*! This function creates a buffer of IFLASH_PAGE_SIZE to
		 * read the data from starting of user signature */
		uint32_t buffer[IFLASH_PAGE_SIZE];
		uint32_t offset = address - IFLASH_ADDR;
		if (offset < 0) {
			return ERR_INVALID_ARG;
		}

		flash_read_user_signature(buffer, offset);
		*data = buffer[offset];
		break;
	}
#endif

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

		*data = at45dbx_read_byte();
		at45dbx_read_close();
		break;
#endif

	default:
		return ERR_INVALID_ARG;
	}

	return STATUS_OK;
}