⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fl_wrtphilips.c

📁 NXP需要外扩FLASH产品(比如LPC22XX)的外部FLASH烧写操作.
💻 C
📖 第 1 页 / 共 2 页
字号:
 *  * PostConditions: global filename and file_defined set */void needFilename(void){    if (file_defined == FALSE || interactive == TRUE)    {        strcpy(filename, getString("Filename [default \"%s\"]: ", filename));        file_defined = TRUE;    }}/* *       Function: RomInfo *        Purpose: Print standard info about the ROM to stdout, if not *                 in "quiet" mode. * *  PreConditions:  *  *         Params: *            Input: filename - the pathname in host form containing the PROM image *                   base - the base address of the Flash PROM in memory *                   sector - the sector to start at; a sector is a block (e.g. of 256 *                            bytes) in the PROM * *        Returns: none. *  * PostConditions: */void RomInfo(char *msg){    IdentifyChip();        if (!quiet)    {        printf(msg);            if (file_defined)            FileInfo();                printf("ROM Sector size : 0x%lx\n", sector_size);        printf("ROM Total Length    : %ldKB\n",               divroundup((no_of_sectors * sector_size), 1024));                if (start_defined)            printf("Start Offset    : 0x%lx\n", start_offset);        if (base_defined)            printf("Base Address    : 0x%lx\n", base_address);    }}/* *       Function: FileInfo *        Purpose: Print the filename and file size in Kb and sectros *                 if not quiet mode. * *  PreConditions: file_defined TRUE, openFile called, sector_size set. *  *         Params: *            Input: filename - global containing a pointer to the filename. *                   filesize - global containing the file size in bytes. * *        Returns: none. *  * PostConditions: */void FileInfo(void){    if (!quiet)    {        printf("Input File      : \"%s\"\n", filename);        printf("File size       : %luKb (%lu sectors)\n",               divroundup(filesize, 1024),               divroundup(filesize, sector_size));    }}void openFile(void){    /* open the external FLASH Image file - any failure then exit */    if ((image = fopen(filename,"rb")) == NULL)    {        printf("Error: Cannot open file \"%s\"\n", filename);        exit(1);    }        if (fseek(image, 0, SEEK_END) == 0)    {        filesize = ftell(image);        fseek(image, 0, SEEK_SET);        filesize_defined = TRUE;    }}void ShowProgress(int sectors_done){    if (!quiet && ((sectors_done & 0xF) == 0))    {        printf("%d ", sectors_done);        if ((sectors_done & 0xFF) == 0)            putchar('\n');        fflush(stdout);    }}/* *       Function: VerifyFileInFlash *        Purpose: Verify the named file matches the data in flash ROM * *  PreConditions:  *  *         Params: *            Input: none. * *        Returns: none. *  * PostConditions: */static void VerifyFileInFlash(){    int sectors_done;    int endflag = 0,value_read = 0, offset;    int errors=0;        if (file_defined)        openFile();        RomInfo("Verifying Flash ROM\n");    needBaseAddress();    needStartOffset();    if (!file_defined)    {        needFilename();        openFile();        FileInfo();    }    romsize = no_of_sectors * sector_size;        if (!checkFileSize("verified"))        return;        if (!quiet)        printf("Now verifying flash from sector 0x%lx - please wait\n",               start_offset);    /* Check the Image file to the FLASH Device in the required sector sizes */    offset = sector_size * start_offset;    sectors_done=0;    endflag = 0;    while (!endflag && offset < romsize && errors < 20)    {        int finish_sector;        /* read Image file and write in sector sizes until not enough data         * to fill sector         */        if ((value_read = fread(sector, 1, sector_size, image)) != sector_size)        {            /* fill remaining sector data with fill pattern 0x5a */            for (finish_sector = value_read; finish_sector < sector_size ; finish_sector++)            {                ((char *)sector)[finish_sector] = FILL_PATTERN;                endflag++;            }        }        /* Verify the image file to the specified device at the offset required */        errors += verify_sector(base_address + offset, sector_size, sector);                        sectors_done++;        ShowProgress(sectors_done);                /* increment the offset for the address write - increment is the         * sector size         */        offset += sector_size;    }    /* Close the external file and return */    fclose(image);        if (errors==0)        printf("\nFlash verified successfully\n");    else if (errors == 20)        printf("\nFlash write aborted: too many errors.\n");    else        printf("\nFlash failed with %i verify errors\n",errors);}int verify_sector(unsigned long start_address, int sector_size,                   unsigned int sector_data[]){    int verify_errors = 0;    int i;    ASSERT(rom_identified);        /* check that the sector size is not greater than the maximum */    if (sector_size > MAX_SECTOR_SIZE) {        printf ("Error: Sector size too large\n");        return 1;    }            for (i = 0; i < (sector_size/4) && verify_errors < 10; i++)    {         if ((((volatile int *) start_address)[i] != sector_data[i])&&((start_address + WORD_SIZE*i)<(base_address+filesize)))        //change by barry        {            printf("\nError: Verify Failed at address %lx\n",                   start_address + (WORD_SIZE*i));            verify_errors++;        }    }    /* Return the number of cycles required to write the data */    return verify_errors;}static void ShowROMIdentity(){    IdentifyChip();    if (rom_identified)    {        printf ("Manufacturer:  ");        if (manuf_code == MAN_ATMEL)            printf ("ATMEL\n");        else        if (manuf_code == MAN_AMD)            printf ("AMD\n");        else        if (manuf_code == MAN_STM)            printf ("ST\n");        else        if (manuf_code == MAN_SST)            printf ("SST\n");        else            printf ("(unknown)\n");            printf ("Device type:   ");        switch (device_code)        {            case  ATMEL_AT29C040A_ID:                printf ("AT29C040A\n");                break;            case  ATMEL_AT29C1024_ID:                printf ("AT29C1024\n");                break;	   case AMD_AM29LV400B_ID:                printf ("AM29LV400B\n");                break;	   case AMD_AM29LV800B_ID:                printf ("AM29LV800B\n");                break;                       case AMD_AM29D800B_ID:                printf ("AM29D800B\n");                break;	   case STM_M29W400B_ID:                printf ("M29W400B\n");                break;	   case STM_M29W800B_ID:                printf ("M29W800B\n");                break;                       case SST_SST39VF160_ID:                printf ("SST39VF160\n");                break;                     default :                printf ("(unknown)\n");                break;        }        printf ("Sector size:   %lu bytes\n", sector_size);        printf ("Total sectors: %lu\n", no_of_sectors);           printf ("ROM size:      %lu bytes\n", sector_size * no_of_sectors);        printf ("Base Address:  0x%lx\n", base_address);    }}/* main  * * This is the c library entry point and controlling function for * the whole  program. It checks that there is a specified file for * download and then  checks the identity of the flash device on * board.. The external file is then  opened and transferred to the * flash memory in the required sectors */int main(void){    int i;    char param,character;     BCFG1=BCFG1|0x20000400;   PINSEL0 = 0x00000000;			// 设置管脚连接GPIO      IO0DIR = BEEPCON; 				// 设置I/O为输出   for(i=0;i<2;i++)   {        IO0CLR = BEEPCON;				// BEEPCON = 0      DelayNS(10);      IO0SET = BEEPCON;				// BEEPCON = 1      DelayNS(10);   }   do{    init();   printf("begin...\n Please input parameter:\n");  do{  character = getchar();  }while(character == 0x0a);  printf("%c\n",  character);          switch(character)         {            case 'v':                mode = op_verify;                break;                            case 'w':                mode = op_writerom;                break;                            case 'B':                mode = op_blank;                break;                            case 'h':                mode = op_help;                break;                            case 'I':                mode = op_identify;                break;                            case 'V':                verbose = TRUE;                break;                            case 't':                device_code = AMD_AM29LV800B_ID;                manuf_code = MAN_STM;                SetDeviceParams();                break;                            case 'e':            	exit(1);                            default:               printf("Error: unknown option letter \"%c\"\n",param);// argv[i][1]);                DisplayHelp();                mode = op_back;                   }        if (!quiet)       printf("ARM Flash Programming Utility\n\n");          filename[0] = 0;    switch(mode)    {        case op_writerom:            DownloadFileToFlash();            break;        case op_blank:            BlankFlash();            break;        case op_verify:            VerifyFileInFlash();            break;        case op_help:            DisplayHelp();            break;        case op_identify:            ShowROMIdentity();            break;        case op_back:        	break;               }         }while(1); return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -