/** * \brief Fill the specified pattern to AT24CXX. * * \param u32_start_address The first address to be filled. * \param u32_end_address The last address to be filled. * \param u8_pattern The pattern to be filled. * * \return AT24C_WRITE_SUCCESS if the pattern was filled, AT24C_WRITE_FAIL * otherwise. */ uint32_t at24cxx_fill_pattern(uint32_t u32_start_address, uint32_t u32_end_address, uint8_t u8_pattern) { uint32_t addr; for (addr = u32_start_address; addr < u32_end_address + 1; addr++) { if (at24cxx_write_byte((uint16_t)addr, u8_pattern) != AT24C_WRITE_SUCCESS) { return AT24C_WRITE_FAIL; } } return AT24C_WRITE_SUCCESS; }
/** * \brief Test data read/write API functions. * * This test calls the data read/write API functions and check the data consistency. * * \param test Current test case. */ static void run_test_data_read_write(const struct test_case *test) { twi_options_t opt; uint8_t data; /* Configure the options of TWI driver */ opt.master_clk = sysclk_get_main_hz(); opt.speed = AT24C_TWI_CLK; if (twi_master_init(BOARD_AT24C_TWI_INSTANCE, &opt) != TWI_SUCCESS) { puts("AT24CXX initialization is failed.\r"); } if (at24cxx_write_byte(AT24C_MEM_ADDR, 0xA5) != AT24C_WRITE_SUCCESS) { puts("AT24CXX write packet is failed.\r"); } mdelay(10); if (at24cxx_read_byte(AT24C_MEM_ADDR, &data) != AT24C_READ_SUCCESS) { puts("AT24CXX read packet is failed.\r"); } test_assert_true(test, data == 0xA5, "Data is not consistent!"); }