/* load_flash_altera.c Load Flash Ram from Altera generated file Written by: Rod Klein Date: July 23, 1998 Rev. History: */ /* Include Files */ #include #include "VISION.h" #include "tracker.h" #include "functions.h" /* Start program */ void load_flash_altera() { unsigned int seq_addr[] = {0x555, 0x2AA, 0x555}; unsigned int seq_data[] = {0xAA, 0x55, 0xA0}; unsigned int byte_count; unsigned int rec_type; unsigned int fl_data; unsigned int fl_addr; unsigned int fl_cmd; unsigned int status; unsigned int bytes; unsigned int data; unsigned int addr; char data_array[200]; char altera[200]; char f_name[64]; char s1[3]; char s2[3]; int write_count; int i, j, k; int count; int adr; int num; int len; FILE *data_file; i = 0; j = 0; k = 0; len = 0; adr = 0; num = 0; data = 0; count = 0; fl_cmd = 0; fl_addr = 0; fl_data = 0; rec_type = 0; data_file = 0; byte_count = 0; write_count = 0; printf("\n Enter filename of input file (full path name) - "); gets( f_name); data_file = fopen( f_name, "r"); if( data_file == NULL ) { printf("\n Unable to open %s\n", f_name); return; } erase_flash_ram(); while( !feof( data_file) ) { if( fgets( altera, 200, data_file) != NULL) { sscanf( altera, ":%02X%04X%02X%s", &byte_count, &addr, &rec_type, data_array); if( rec_type == 0 ) { i = 0; while( i<(byte_count*2)) { s1[0] = data_array[i++]; s2[0] = data_array[i++]; s1[1] = '\0'; s2[1] = '\0'; strcat( s1, s2); sscanf( s1, "%02X", &data); for( k=0; k<3; k++ ) { fl_addr = FLASH_RAM | (seq_addr[k] << 2); fl_cmd = (seq_data[k] << 24) | seq_data[k]; status = VISIONwrite( finder, fl_addr, WORD_LEN, &bytes, &fl_cmd); if( status != 0 ) perror(" load_flash_altera: VISIONwrite"); } fl_addr = FLASH_RAM | (adr << 2); data = data << 24; status = VISIONwrite( finder, fl_addr, WORD_LEN, &bytes, &data); if( status != 0 ) perror(" load_flash_altera: VISIONwrite"); status = VISIONread( finder, fl_addr, WORD_LEN, &bytes, &fl_data); if( status != 0 ) perror(" load_flash_altera: VISIONread"); fl_data = fl_data & 0xFF000000; while( fl_data != data ) { for( k=0; k<3; k++ ) { fl_addr = FLASH_RAM | (seq_addr[k] << 2); fl_cmd = (seq_data[k] << 24) | seq_data[k]; status = VISIONwrite( finder, fl_addr, WORD_LEN, &bytes, &fl_cmd); if( status != 0 ) perror(" load_flash_altera: VISIONwrite"); } fl_addr = FLASH_RAM | (adr << 2); data = data << 24; status = VISIONwrite( finder, fl_addr, WORD_LEN, &bytes, &data); if( status != 0 ) perror(" load_flash_altera: VISIONwrite"); status = VISIONread( finder, fl_addr, WORD_LEN, &bytes, &fl_data); if( status != 0 ) perror(" load_flash_altera: VISIONread"); fl_data = fl_data & 0xFF000000; write_count++; if( write_count > 100 ) { printf("\n After 100 attempts, unable to load address %06X with %02X\n", adr, data>>24); return; } } if( count == 1000 ) { printf("\n Loading Flash RAM Address = %06X", adr); count = 0; } else count++; adr++; } } } } fclose( data_file); }