/** * \brief Erase bytes from all EEPROM pages. * * This function erases bytes from all EEPROM pages, so that every location * written to in the page buffer reads 0xFF. */ void nvm_eeprom_erase_bytes_in_all_pages(void) { // Wait until NVM is ready nvm_wait_until_ready(); // Issue EEPROM Erase All command nvm_issue_command(NVM_CMD_ERASE_EEPROM_gc); }
/** * \brief Read a fuse byte. * * This function reads and returns the value of a given fuse byte. * * \param fuse Fuse byte to read. * * \return Byte value of fuse. */ uint8_t nvm_fuses_read(enum fuse_byte_t fuse) { // Wait until NVM is ready nvm_wait_until_ready(); // Set address NVM.ADDR0 = fuse; // Issue READ_FUSES command nvm_issue_command(NVM_CMD_READ_FUSES_gc); return NVM.DATA0; }
/** * \brief Read one byte from EEPROM using IO mapping. * * This function reads one byte from EEPROM using IO-mapped access. * If memory mapped EEPROM is enabled, this function will not work. * * \param addr EEPROM address, between 0 and EEPROM_SIZE * * \return Byte value read from EEPROM. */ uint8_t nvm_eeprom_read_byte(eeprom_addr_t addr) { Assert(addr <= EEPROM_SIZE); /* Wait until NVM is ready */ nvm_wait_until_ready(); /* Set address to read from */ NVM.ADDR2 = 0x00; NVM.ADDR1 = (addr >> 8) & 0xFF; NVM.ADDR0 = addr & 0xFF; /* Issue EEPROM Read command */ nvm_issue_command(NVM_CMD_READ_EEPROM_gc); return NVM.DATA0; }
/** * \brief Erase bytes from EEPROM page. * * This function erases bytes from one EEPROM page, so that every location * written to in the page buffer reads 0xFF. * * \param page_addr EEPROM Page address, between 0 and EEPROM_SIZE/EEPROM_PAGE_SIZE */ void nvm_eeprom_erase_bytes_in_page(uint8_t page_addr) { // Wait until NVM is ready nvm_wait_until_ready(); // Calculate page address uint16_t address = (uint16_t)(page_addr * EEPROM_PAGE_SIZE); Assert(address <= EEPROM_SIZE); // Set address NVM.ADDR2 = 0x00; NVM.ADDR1 = (address >> 8) & 0xFF; NVM.ADDR0 = address & 0xFF; // Issue EEPROM Erase command nvm_issue_command(NVM_CMD_ERASE_EEPROM_PAGE_gc); }