Пример #1
0
/*!
    \brief Writes data to the data flash block

    No data is written if the data to be written will cross data flash block
    boundries.    

    \param[in] ADDR The data flash address to start the write from
    \param[in] DATA The data to be written
    \param[in] LEN The number of bytes to write

    \return The number of bytes written
*/
UInt16 write_data_flash(const UInt16 ADDR, const UInt8 * DATA, const UInt8 LEN)
{
    UInt16 written = 0;
    
    if(!DATA || ADDR < DF_BLOCK_START || ADDR >= DF_BLOCK_END)
    {
        return 0;
    } // if the parameters are invalid //
    
    if(ADDR + LEN >= DF_BLOCK_END)
    {
        return 0;
    } // if not enough room //

    enable_df_write();

    while(written < LEN)
    {
        ((UInt8 *)ADDR)[written] = PROGRAM;
        ((UInt8 *)ADDR)[written++] = *DATA++;
        while(!COMPLETE());
        if(!WRITE_SUCCESS())
        {
            clr_status_reg(&(((UInt8 *)ADDR)[written]));
            written--;              // since it failed
            break;
        } // if the write was not successful //
    } // loop to read the data flash //

    disable_df_write();

    return written;
} // write_data_flash //
Пример #2
0
/*!
    \brief Erase a data flash block.

    \param[in] ADDR Address in the block to erase.

    \return TRUE if erase was successful
            FALSE if erase was not successful
*/
BOOL erase_data_flash(const UInt16 ADDR)
{
    BOOL rv = TRUE;

    if(ADDR < DF_BLOCK_START || ADDR >= DF_BLOCK_END)
    {
        return 0;
    } // if the parameters are invalid //

    enable_df_write();

    *((UInt8 *)ADDR) = ERASE_CYCLE1;
    *((UInt8 *)ADDR) = ERASE_CYCLE2;
    while(!COMPLETE());
    if(!ERASE_SUCCESS())
    {
        clr_status_reg((UInt8 *)ADDR);
        rv = FALSE;
    } // if the write was not successful //

    disable_df_write();

    return rv;
} // erase_data_flash //
Пример #3
0
void prog_flash(int dev, char* bin_file, char flash_id)
{
	FILE *file;
	unsigned int addr;
	unsigned int base_addr;
	unsigned int elec_sig = 0;
	int i;

	// Open bin_file
	file = fopen(bin_file, "rb");
	if (!file)
	{
		fprintf(stderr, "Unable to open file %s.\r\n", bin_file);
		return;
	}

	// Select flash
	if (flash_id == 'a' || flash_id == 'A')
		base_addr = XFL_CONFIG_BASE_ADDR_A;
	else if (flash_id == 'b' || flash_id == 'B')
		base_addr = XFL_CONFIG_BASE_ADDR_B;
	else
	{
		fprintf(stderr, "Invalid target flash '%c'!\r\n", flash_id);
		return;
	}

	clr_status_reg(dev, base_addr);

	printf("Flash image: %s\r\n", bin_file);

	elec_sig = rd_elec_sig(dev, base_addr);
	printf("Manufacturer ID: %x\r\n", elec_sig);

	if (elec_sig != XFL_ELEC_SIG)
	{
		fprintf(stderr, "Invalid electronic signature! Please verify that the CPLD is configured properly.\r\n");
		return;
	}

	clr_status_reg(dev, base_addr);

	printf("Programming flash '%c'.\r\n", flash_id);
	printf("[", flash_id);

	for (i = 0; i < XFL_CONFIG_TOTAL_BLKS; i++)
	{
		addr = base_addr + (XFL_CONFIG_BLOCK_SIZE * i);
		printf("."); fflush(stdout);
		unlock_single_block(dev, addr);
		erase_single_block(dev, addr);
	}

	clr_status_reg(dev, base_addr);

	flash_wr_binfile_B(dev, base_addr, file);

	printf("]\r\n", flash_id);
	
        // Close bin_file
        fclose(file);
}