Skip to content

Commit

Permalink
New functions xnvm_erase_eeprom(), xnvm_program_flash_page()
Browse files Browse the repository at this point in the history
and xnvm_write_lock_byte()


git-svn-id: http://svn.code.sf.net/p/xc3sprog/code/trunk@599 5e3be8be-922f-45f9-ad52-57b51d30232e
  • Loading branch information
u_bonnes committed Mar 11, 2011
1 parent 7563103 commit 9f35ded
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
4 changes: 4 additions & 0 deletions progalgnvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,12 @@ class ProgAlgNVM
enum PDI_STATUS_CODE xnvm_chip_erase(void);
enum PDI_STATUS_CODE xnvm_application_erase(void);
enum PDI_STATUS_CODE xnvm_boot_erase(uint32_t address);
enum PDI_STATUS_CODE xnvm_erase_eeprom(void);
uint16_t xnvm_read_memory(uint32_t address, uint8_t *data, uint32_t length);
enum PDI_STATUS_CODE xnvm_erase_program_flash_page
(uint32_t address, uint8_t *dat_buf, uint16_t length);
enum PDI_STATUS_CODE xnvm_program_flash_page
(uint32_t address, uint8_t *dat_buf, uint16_t length);
enum PDI_STATUS_CODE xnvm_put_dev_in_reset (void);
enum PDI_STATUS_CODE xnvm_pull_dev_out_of_reset(void);
enum PDI_STATUS_CODE xnvm_erase_program_eeprom_page
Expand All @@ -139,6 +142,7 @@ class ProgAlgNVM
(uint32_t address, uint8_t *dat_buf, uint16_t length);
enum PDI_STATUS_CODE xnvm_write_fuse_byte
(uint32_t address, uint8_t value);
enum PDI_STATUS_CODE xnvm_write_lock_byte(uint8_t value);
};

#endif //PROGALGNVM_H
66 changes: 66 additions & 0 deletions xmega_pdi_nvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,22 @@ enum PDI_STATUS_CODE ProgAlgNVM::xnvm_boot_erase(uint32_t address)
return xnvm_ctrl_wait_nvmbusy(WAIT_RETRIES_NUM);
}

/**
* \brief Erase the eeprom section chip
*
* \retval STATUS_OK erase chip succussfully.
* \retval ERR_TIMEOUT Time out.
*/
enum PDI_STATUS_CODE ProgAlgNVM::xnvm_erase_eeprom(void)
{
/* Write the chip erase command to the NVM command reg */
xnvm_ctrl_cmd_write(XNVM_CMD_ERASE_EEPROM);
/* Write the CMDEX to execute command */
xnvm_st_ptr(XNVM_EEPROM_BASE);
xnvm_st_star_ptr_postinc(DUMMY_BYTE);
return xnvm_ctrl_wait_nvmbusy(WAIT_RETRIES_NUM);
}

/**
* \internal
* \brief Load the flash page buffer
Expand Down Expand Up @@ -406,6 +422,30 @@ enum PDI_STATUS_CODE ProgAlgNVM::xnvm_erase_flash_buffer(uint32_t retries)
return xnvm_ctrl_wait_nvmbusy(retries);
}

/**
* \internal
* \brief Program the flash page buffer with NVM controller.
*
* \param address the address of the flash IN PDI address space
* \param dat_buf the pointer which points to the data buffer.
* \param length the data length.
* \retval STATUS_OK program succussfully.
* \retval ERR_TIMEOUT Time out.
*/
enum PDI_STATUS_CODE ProgAlgNVM::xnvm_program_flash_page(
uint32_t address, uint8_t *dat_buf, uint16_t length)
{
xnvm_erase_flash_buffer(WAIT_RETRIES_NUM);
xnvm_load_flash_page_buffer(address, dat_buf, length);
xnvm_ctrl_cmd_write(XNVM_CMD_WRITE_FLASH_PAGE);

/* Dummy write for starting the erase and write command */
xnvm_st_ptr(address);
xnvm_st_star_ptr_postinc(DUMMY_BYTE);

return xnvm_ctrl_wait_nvmbusy(WAIT_RETRIES_NUM);
}

/**
* \internal
* \brief Erase and program the flash page buffer with NVM controller.
Expand Down Expand Up @@ -702,6 +742,32 @@ enum PDI_STATUS_CODE ProgAlgNVM::xnvm_write_fuse_byte(uint32_t address, uint8_t
return xnvm_ctrl_wait_nvmbusy(WAIT_RETRIES_NUM);
}

/**
* \brief Write the lock byte with NVM controller
*
* \param value which should be write into the lock byte.
* \retval STATUS_OK write succussfully.
* \retval ERR_TIMEOUT time out.
*/
enum PDI_STATUS_CODE ProgAlgNVM::xnvm_write_lock_byte(uint8_t value)
{
uint32_t register_address;

xnvm_ctrl_cmd_write(XNVM_CMD_WRITE_LOCK_BITS);

cmd_buffer[0] = XNVM_PDI_STS_INSTR | XNVM_PDI_LONG_ADDRESS_MASK |
XNVM_PDI_BYTE_DATA_MASK;

register_address = XNVM_FUSE_BASE + NVM_LOCKBIT_ADDR;

memmove((cmd_buffer + 1), (uint8_t*)&register_address, 4);
cmd_buffer[5] = value;

prot->pdi_write(cmd_buffer, 6);

return xnvm_ctrl_wait_nvmbusy(WAIT_RETRIES_NUM);
}

/**
* \internal
* \brief Wait until the NVM Controller is ready.
Expand Down

0 comments on commit 9f35ded

Please sign in to comment.