Example #1
0
/*
 * Writing the config is done to the next unwritten slot in the
 * flash.  If all slots have been written, erase whole block and
 * start from the first slot.
 * We calculate the config CRC just before writing.
 */
void write_config(void)
{
#if 0
	config.crc = calc_block_crc(sizeof(config) - sizeof(unsigned),
								(void *)&config);
	/* This might take a long time, so take the risk. */
	watchdog_disable();
	eeprom_write_block(&config, (void *)EE_CONFIG_ADDRESS, sizeof(config));
	watchdog_enable();
#endif
}
Example #2
0
//==============================================================================
bool CC_UnitDriver::flash_verify_by_crc(const DataSectionStore &section_store)
{
    // Channel 0: Flash mapped to Xdata -> CRC shift register
    uint8_t dma_desc[8] = {
        HIBYTE(reg_info_.xbank_offset),   // src[15:8]
        LOBYTE(reg_info_.xbank_offset),   // src[7:0]
        HIBYTE(reg_info_.rndh),    		// dest[15:8]
        LOBYTE(reg_info_.rndh),      		// dest[7:0]
        HIBYTE(reg_info_.verify_block_size),// block size[15:8]
        LOBYTE(reg_info_.verify_block_size),// block size[7:0]
        0x20,                     		// no trigger event, block mode
        0x42,                   			// increment source
    };

    write_xdata_memory(reg_info_.dma_arm, 0x00);

    // set the pointer to the DMA descriptors
    write_xdata_memory(reg_info_.dma0_cfgl, LOBYTE(reg_info_.dma0_cfg_offset));
    write_xdata_memory(reg_info_.dma0_cfgh, HIBYTE(reg_info_.dma0_cfg_offset));

    size_t flash_bank = 0xFF; // correct flash bank will be set later

    pw_.read_start(section_store.actual_size());

    foreach (const DataSection &section, section_store.sections())
    {
        size_t section_offset = section.address;
        size_t total_size = section.size();
        size_t bank_offset = section_offset % FLASH_BANK_SIZE;
        while (total_size)
        {
            size_t count = std::min(total_size, reg_info_.verify_block_size);
            size_t flash_bank_0 = section_offset / FLASH_BANK_SIZE;
            size_t flash_bank_1 = (section_offset + count) / FLASH_BANK_SIZE;

            if (flash_bank_0 != flash_bank_1)
                count = FLASH_BANK_SIZE - (section_offset % FLASH_BANK_SIZE);

            if (flash_bank != flash_bank_0)
            {
                flash_bank = flash_bank_0;
                if (reg_info_.memctr)
                    write_xdata_memory(reg_info_.memctr, flash_bank);
                bank_offset = section_offset % FLASH_BANK_SIZE;
            }

            dma_desc[0] = HIBYTE(bank_offset + reg_info_.xbank_offset);
            dma_desc[1] = LOBYTE(bank_offset + reg_info_.xbank_offset);
            dma_desc[4] = HIBYTE(count);
            dma_desc[5] = LOBYTE(count);
            write_xdata_memory(reg_info_.dma0_cfg_offset, dma_desc, sizeof(dma_desc));

            CrcCalculator crc_calc;
            crc_calc.process_bytes(&section.data[section.size() - total_size], count);
            if (calc_block_crc() != crc_calc.checksum())
                return false;

            total_size -= count;
            section_offset += count;
            bank_offset += count;

            pw_.read_progress(count);
        }
    }
    pw_.read_finish();
    return true;
}