AllJoyn/Samples/BACnetAdapter/bacnet-stack-0.8.2/ports/xplained/ASF/xmega/drivers/nvm/nvm.c
void nvm_issue_flash_range_crc(flash_addr_t start_addr,
    flash_addr_t end_addr)
{
    uint8_t old_cmd;
    // Save current nvm command
    old_cmd = NVM.CMD;

    // Load the NVM CMD register with the Flash Range CRC command
    NVM.CMD = NVM_CMD_FLASH_RANGE_CRC_gc;

    // Load the start byte address in the NVM Address Register
    NVM.ADDR0 = start_addr & 0xFF;
    NVM.ADDR1 = (start_addr >> 8) & 0xFF;
#if (FLASH_SIZE >= 0x10000UL)
    NVM.ADDR2 = (start_addr >> 16) & 0xFF;
#endif

    // Load the end byte address in NVM Data Register
    NVM.DATA0 = end_addr & 0xFF;
    NVM.DATA1 = (end_addr >> 8) & 0xFF;
#if (FLASH_SIZE >= 0x10000UL)
    NVM.DATA2 = (end_addr >> 16) & 0xFF;
#endif

    // Execute command
    ccp_write_io((uint8_t *) & NVM.CTRLA, NVM_CMDEX_bm);

    // Restore command register
    NVM.CMD = old_cmd;
}
/**
 * \brief Issue flash range CRC command
 *
 * This function sets the FLASH range CRC command in the NVM.CMD register.
 * It then loads the start and end byte address of the part of FLASH to
 * generate a CRC-32 for into the ADDR and DATA registers and finally performs
 * the execute command.
 *
 * \note Should only be called from the CRC module. The function saves and
 *       restores the NVM.CMD register, but if this
 *       function is called from an interrupt, interrupts must be disabled
 *       before this function is called.
 *
 * \param start_addr  end byte address
 * \param end_addr    start byte address
 */
\brief Issue flash range CRC command
This function sets the FLASH range CRC command in the NVM.CMD register.
It then loads the start and end byte address of the part of FLASH to
generate a CRC-32 for into the ADDR and DATA registers and finally performs
the execute command.

\note Should only be called from the CRC module. The function saves and
restores the NVM.CMD register, but if this
function is called from an interrupt, interrupts must be disabled
before this function is called.

\param start_addr  end byte address
\param end_addr    start byte address
\ brief Issue flash range CRC command This function sets the FLASH range CRC command in the NVM . CMD register . It then loads the start and end byte address of the part of FLASH to generate a CRC - 32 for into the ADDR and DATA registers and finally performs the execute command . \ note Should only be called from the CRC module . The function saves and restores the NVM . CMD register but if this function is called from an interrupt interrupts must be disabled before this function is called . \ param start_addr end byte address \ param end_addr start byte address
void nvm_issue_flash_range_crc(flash_addr_t start_addr,
    flash_addr_t end_addr)
{
    uint8_t old_cmd;
    old_cmd = NVM.CMD;
    NVM.CMD = NVM_CMD_FLASH_RANGE_CRC_gc;
    NVM.ADDR0 = start_addr & 0xFF;
    NVM.ADDR1 = (start_addr >> 8) & 0xFF;
#if (FLASH_SIZE >= 0x10000UL)
    NVM.ADDR2 = (start_addr >> 16) & 0xFF;
#endif
    NVM.DATA0 = end_addr & 0xFF;
    NVM.DATA1 = (end_addr >> 8) & 0xFF;
#if (FLASH_SIZE >= 0x10000UL)
    NVM.DATA2 = (end_addr >> 16) & 0xFF;
#endif
    ccp_write_io((uint8_t *) & NVM.CTRLA, NVM_CMDEX_bm);
    NVM.CMD = old_cmd;
}
void nvm_issue_flash_range_crc ( flash_addr_t start_addr , flash_addr_t end_addr ) { uint8_t old_cmd ; old_cmd = NVM . CMD ; NVM . CMD = NVM_CMD_FLASH_RANGE_CRC_gc ; NVM . ADDR0 = start_addr & 0xFF ; NVM . ADDR1 = ( start_addr >> 8 ) & 0xFF ; #if ( FLASH_SIZE >= 0x10000UL ) NVM . ADDR2 = ( start_addr >> 16 ) & 0xFF ; #endif NVM . DATA0 = end_addr & 0xFF ; NVM . DATA1 = ( end_addr >> 8 ) & 0xFF ; #if ( FLASH_SIZE >= 0x10000UL ) NVM . DATA2 = ( end_addr >> 16 ) & 0xFF ; #endif ccp_write_io ( ( uint8_t * ) & NVM . CTRLA , NVM_CMDEX_bm ) ; NVM . CMD = old_cmd ; }
\brief Issue flash range CRC command
 This function sets the FLASH range CRC command in the NVM.CMD register.
\ brief Issue flash range CRC command This function sets the FLASH range CRC command in the NVM . CMD register .
// Save current nvm command // Load the NVM CMD register with the Flash Range CRC command // Load the start byte address in the NVM Address Register // Load the end byte address in NVM Data Register // Execute command // Restore command register