/** * \brief Performs out of range memory test on DataFlash memory * * This function will simply test the output of the function * \ref at45dbx_mem_check and returns an error in case of failure. * * \param test Current test case. */ static void run_memory_range_check_test(const struct test_case *test) { bool status; status = at45dbx_read_byte_open( (((uint32_t)1<<AT45DBX_MEM_SIZE)*AT45DBX_MEM_CNT)); test_assert_true(test, status == true, "Error memory range check failed"); status = at45dbx_read_byte_open( (((uint32_t)1<<AT45DBX_MEM_SIZE)*AT45DBX_MEM_CNT)+1); test_assert_true(test, status == false, "Error memory range check failed"); }
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; }
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; }
/** * \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(); }
bool at45dbx_read_sector_open(uint32_t sector) { if (at45dbx_check_address(sector << AT45DBX_SECTOR_BITS) == false) { return false; } else { return at45dbx_read_byte_open(sector << AT45DBX_SECTOR_BITS); } }
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; }
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; }