/*! \brief Tests single-sector access functions. */ static void at45dbx_example_test_RAM_mem(void) { static U8 PatternTable[AT45DBX_SECTOR_SIZE]; static U8 ReceiveTable[AT45DBX_SECTOR_SIZE]; U8 Pattern = 0x55; memset(PatternTable, Pattern, AT45DBX_SECTOR_SIZE); memset(ReceiveTable, 0xA5, AT45DBX_SECTOR_SIZE); print_dbg("\tUsing Pattern 0x55"); // Perform write access. if (at45dbx_write_open(Pattern)) { at45dbx_write_sector_from_ram(PatternTable); at45dbx_write_close(); } // Perform read access. if (at45dbx_read_open(Pattern)) { at45dbx_read_sector_2_ram(ReceiveTable); at45dbx_read_close(); } // Check read and write operations. if (!memcmp(ReceiveTable, PatternTable, AT45DBX_SECTOR_SIZE)) { print_dbg(TEST_SUCCESS); } else { print_dbg(TEST_FAIL); } // Change the pattern used. Pattern = 0xAA; memset(PatternTable, Pattern, AT45DBX_SECTOR_SIZE); memset(ReceiveTable, 0xA5, AT45DBX_SECTOR_SIZE); print_dbg("\tUsing Pattern 0xAA"); // Perform write access. if (at45dbx_write_open(Pattern)) { at45dbx_write_sector_from_ram(PatternTable); at45dbx_write_close(); } // Perform read access. if (at45dbx_read_open(Pattern)) { at45dbx_read_sector_2_ram(ReceiveTable); at45dbx_read_close(); } // Check read and write operations. if (!memcmp(ReceiveTable, PatternTable, AT45DBX_SECTOR_SIZE)) { print_dbg(TEST_SUCCESS); } else { print_dbg(TEST_FAIL); } }
/*! \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); } }
/*! \brief Tests multiple-sector access functions. */ static void at45dbx_example_test_multiple_sector(void) { U32 position = 252; U32 nb_sector = 4; // Initialize counters. at45dbx_example_error_cnt = 0; // Write sectors. print_dbg("\tWriting sectors\r\n"); at45dbx_write_open(position); at45dbx_write_multiple_sector(nb_sector); at45dbx_write_close(); // Read written sectors. print_dbg("\tReading sectors\t"); at45dbx_read_open(position); at45dbx_read_multiple_sector(nb_sector); at45dbx_read_close(); if (!at45dbx_example_error_cnt) { print_dbg(TEST_SUCCESS); } else { print_dbg(TEST_FAIL "\t"); print_dbg_ulong(at45dbx_example_error_cnt); print_dbg(" errors\r\n"); } }
Ctrl_status at45dbx_ram_2_df(U32 addr, const void *ram) { if (addr + 1 > AT45DBX_MEM_CNT << (AT45DBX_MEM_SIZE - AT45DBX_SECTOR_BITS)) return CTRL_FAIL; at45dbx_write_open(addr); at45dbx_write_sector_from_ram(ram); at45dbx_write_close(); return CTRL_GOOD; }
Ctrl_status at45dbx_usb_write_10(U32 addr, U16 nb_sector) { if (addr + nb_sector > AT45DBX_MEM_CNT << (AT45DBX_MEM_SIZE - AT45DBX_SECTOR_BITS)) return CTRL_FAIL; at45dbx_write_open(addr); at45dbx_write_multiple_sector(nb_sector); at45dbx_write_close(); return CTRL_GOOD; }