/** * \brief Read buffer within the eeprom * * \param address the address to where to read * \param buf pointer to the data * \param len the number of bytes to read */ void nvm_eeprom_read_buffer(eeprom_addr_t address, void *buf, uint16_t len) { nvm_wait_until_ready(); eeprom_enable_mapping(); memcpy( buf,(void*)(address+MAPPED_EEPROM_START), len ); eeprom_disable_mapping(); }
/** * \brief Load single byte into temporary page buffer. * * This function loads one byte into the temporary EEPROM page buffers. * If memory mapped EEPROM is enabled, this function will not work. * Make sure that the buffer is flushed before starting to load bytes. * Also, if multiple bytes are loaded into the same location, they will * be ANDed together, thus 0x55 and 0xAA will result in 0x00 in the buffer. * * \note Only one page buffer exist, thus only one page can be loaded with * data and programmed into one page. If data needs to be written to * different pages, the loading and writing needs to be repeated. * * \param byte_addr EEPROM Byte address, between 0 and EEPROM_PAGE_SIZE. * \param value Byte value to write to buffer. */ void nvm_eeprom_load_byte_to_buffer(uint8_t byte_addr, uint8_t value) { // Wait until NVM is ready nvm_wait_until_ready(); eeprom_enable_mapping(); *(uint8_t*)(byte_addr + MAPPED_EEPROM_START) = value; eeprom_disable_mapping(); }
/** * \brief Read one byte from EEPROM using mapped access. * * This function reads one byte from EEPROM using mapped access. * * \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) { uint8_t data; Assert(addr <= EEPROM_SIZE); /* Wait until NVM is ready */ nvm_wait_until_ready(); eeprom_enable_mapping(); data = *(uint8_t*)(addr + MAPPED_EEPROM_START), eeprom_disable_mapping(); return data; }
int main(void) { ADDR_T address = 0; unsigned int temp_int=0; unsigned char val; /* Initialization */ void (*funcptr)( void ) = 0x0000; // Set up function pointer to RESET vector. PMIC_SetVectorLocationToBoot(); eeprom_disable_mapping(); PROGPORT |= (1<<PROG_NO); // Enable pull-up on PROG_NO line on PROGPORT. /* Branch to bootloader or application code? */ if( /*!(PROGPIN & (1<<PROG_NO))*/1 ) // If PROGPIN is pulled low, enter programmingmode. { initbootuart(); // Initialize UART. /* Main loop */ for(;;) { val = recchar(); // Wait for command character. // Check autoincrement status. if(val=='a') { sendchar('Y'); // Yes, we do autoincrement. } // Set address (2 bytes). else if(val == 'A') { // NOTE: Flash addresses are given in words, not bytes. address = recchar(); address <<= 8; address |= recchar(); // Read address high and low byte. sendchar('\r'); // Send OK back. } // Set extended address (3 bytes). else if(val == 'H') { // NOTE: Flash addresses are given in words, not bytes. address = (uint32_t)recchar() << 16; address |= (uint16_t)recchar() << 8; address |= recchar(); sendchar('\r'); // Send OK back. } // Chip erase. else if(val=='e') { for(address = 0; address < APP_END; address += PAGESIZE) { // NOTE: Here we use address as a byte-address, not word-address, for convenience. nvm_wait_until_ready(); #ifdef __ICCAVR__ #pragma diag_suppress=Pe1053 // Suppress warning for conversion from long-type address to flash ptr. #endif EraseApplicationPage( address ); #ifdef __ICCAVR__ #pragma diag_default=Pe1053 // Back to default. #endif } nvm_eeprom_erase_all(); sendchar('\r'); // Send OK back. } #ifndef REMOVE_BLOCK_SUPPORT // Check block load support. else if(val=='b') { sendchar('Y'); // Report block load supported. sendchar((BLOCKSIZE>>8) & 0xFF); // MSB first. sendchar(BLOCKSIZE&0xFF); // Report BLOCKSIZE (bytes). } // Start block load. else if(val=='B')