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

📄 fl_wrtphilips.c

📁 NXP需要外扩FLASH产品(比如LPC22XX)的外部FLASH烧写操作.
💻 C
📖 第 1 页 / 共 2 页
字号:
/* *  $Revision: 1.3 $ *    $Author: mechavar $ *      $Date: 2000/06/19 18:53:18 $ * *  Copyright (c) 1996 Advanced RISC Machines Limited *  All rights reserved * * *	This file contains the hardware independent portion of the ARM flash  * downloader. This version does not support placing ethernet cookies in the  * flash. * *//* Include Standard c Libraries to allow stand alone compiling and operation */#include <stdio.h>#include <stdlib.h>#include <time.h>#include <string.h>/* Include the specific files for the flash memory system */#include "mem.h"#include "config.h"#include "fl_AMphilips.h"/********************************************************************** *             P R E P R O C E S S O R   D E F I N E S **********************************************************************/#define	  BEEPCON  0x00000080        /* P0.7引脚控制B1,低电平蜂鸣 *//* Local routine defines for the flashwrt.c module */#define MIN_NO_OF_ARGS   2#define BYTE_MSBIT_MASK  0x80#define BYTE_ADD_OFFSET  1#define WORD_ADD_OFFSET  2#define WORD_SHIFT_OFFS  1#define FILL_PATTERN     0x5a#define WORD_SIZE        4#define WORD_TRUE         1typedef int bool;#ifndef TRUE#define TRUE (bool)1#endif#ifndef FALSE#define FALSE (bool)0#endif#define ASSERT(cond)   if (!cond) fprintf(stderr, "Assertion failed line %d\n", __LINE__);/* perform x/y, rounding upwards (i.e. 3/4 is 1, 5/2 is 3) */#define divroundup(x, y)   ((unsigned long)((x) + ((y)-1)) / (unsigned long)(y))/********************************************************************** *                    P R O G R A M   D A T A **********************************************************************/extern unsigned long base_address;/* Specify the host files for the flash transfer */FILE *image;unsigned long sector_size;unsigned long no_of_sectors;bool quiet;bool verbose;static bool interactive;int manuf_code, device_code;unsigned long filesize;unsigned long romsize;static enum operations{    op_writerom, op_verify,    op_blank, op_help, op_identify,op_back } mode;static bool start_defined;bool base_defined;bool file_defined;bool filesize_defined;bool rom_identified;unsigned long FL_RESET,FL_SEQ_ADD_1,FL_SEQ_ADD_2,FL_SEQ_ADD_3;unsigned long FL_WORD_COM_1,FL_WORD_COM_2,FL_AUTO_SELECT,FL_PROGRAM;unsigned long FL_ERASE_ADD_4,FL_ERASE_ADD_5,FL_CHIP_ERASE_ADD_6;unsigned long FL_ERASE_3,FL_ERASE_4,FL_ERASE_5,FL_SECTOR_ERASE_6;unsigned long FL_BLOCK_ERASE_6,FL_CHIP_ERASE_6;	unsigned long start_offset = 0;static char filename[512];extern unsigned int sector[MAX_SECTOR_SIZE];/********************************************************************** *          P R O T O T Y P E   D E C L A R A T I O N S **********************************************************************/extern bool IdentifyChip(void);extern bool SetDeviceParams( void );extern int write_sector (unsigned long, unsigned long, int, unsigned int []);extern bool checkFileSize(char *action);extern void DownloadFileToFlash( void );extern void BlankFlash( void );void needBaseAddress(void);void needFilename(void);void FileInfo(void);void openFile(void);void RomInfo(char *msg);//static void Pause(void);int verify_sector(unsigned long start_address, int sector_size,                   unsigned int sector_data[]);/********************************************************************** *                 L O C A L   F U N C T I O N S **********************************************************************/  /***************************************************************************** 名称:init()* 功能:初始化变量。* 入口参数:void	延时参数,值越大,延时越久* 出口参数:无****************************************************************************/ void init(void){sector_size = 0;no_of_sectors = -1;quiet = FALSE;verbose = FALSE;interactive = FALSE;filesize = 0;romsize = 0;mode = 6;// mode = op_writerom;start_defined = FALSE;base_defined = TRUE;file_defined = FALSE;filesize_defined = FALSE;rom_identified = FALSE;/********************************/	 FL_RESET		= 0x00F000F0;	 /* Generic command bus cycle addresses */	 FL_SEQ_ADD_1	= 0x5555;	 FL_SEQ_ADD_2	= 0x2AAA;	 FL_SEQ_ADD_3	= 0x5555;	 /* Generic command bus cycle data */	 FL_WORD_COM_1	= 0xAAAAAAAA;	 FL_WORD_COM_2	= 0x55555555;	 /* Command specific data for cycle 3 */	 FL_AUTO_SELECT	= 0x00900090;	 FL_PROGRAM	= 0x00A000A0;/********************************/ start_offset = 0;}  /***************************************************************************** 名称:DelayNS()* 功能:长软件延时。* 入口参数:dly		延时参数,值越大,延时越久* 出口参数:无****************************************************************************/void  DelayNS(uint32  dly){  uint32  i;   for(; dly>0; dly--)       for(i=0; i<5000; i++);}            /* *       Function: getYesOrNo *        Purpose: Print out the given message and wait for the user to enter 'y' or 'n'.. * *  PreConditions: none. *  *         Params: msg - prompt to write out *                 def - default value if just a carriage return entered. * *        Returns: none *  * PostConditions: none. */bool getYesOrNo(char *msg, bool def){    bool ans = def;    char c;//int c;    printf(msg);    c = getchar();    c = getchar();    while(c != EOF)//(c = getchar())    {        if (c == 'y' || c == 'Y')        {            ans = 1;            break;        }        else if (c == 'n' || c == 'N')        {            ans = 0;            break;        }        else if (c == '\n')        {            ans = def;            break;        }        else            printf(msg);    }    /* Now consume the rest of the line (as we don't unset line editing     * mode, the only way we get any char is if the user enters a whole line.     */    while( c != '\n' && (c = getchar()) != EOF)        continue;        return ans;}/* *       Function: getLong *        Purpose: Print out the given message and wait for the user to enter a valid number * *  PreConditions: none. *  *         Params: msg - prompt to write out (should include a %ld for the default) *                 def - default value if just a carriage return entered. * *        Returns: none *  * PostConditions: none. *//*static unsigned long getLong(char *msg, unsigned long def){    unsigned long ans,instring;    //char instring[32];        while (TRUE)    {        printf(msg, def);        //fgets(instring,sizeof(instring),stdin);        scanf("%lx",&instring);        if ((char)ans=='\n')//instring[0] == '\n')        {            ans = def;            break;        }        else            ans = instring;//if (sscanf(instring,"%lx",&ans) == 1)                break;    }    return ans;}*//* *       Function: getString *        Purpose: Print out the given message and wait for the user to enter a string * *  PreConditions: none. *  *         Params: msg - prompt to write out (should include a %s for the default) *                 def - default value if just a carriage return entered. * *        Returns: char * - a pointer to the string retrieved. *  * PostConditions: none. */static char *getString(char *msg, char *def){    static char instring[512];//;    char *p;        printf(msg, def);     scanf("%s",&instring);//[0]);//fgets(instring,sizeof(instring),stdin);        if (instring[0] == '\n')//        strcpy(instring, def);    else if ((p = strchr(instring, '\n')) != NULL)        *p = '\0';        return instring;}/* *       Function: DisplayHelp *        Purpose: Print out the usage message. * *  PreConditions: none. *  *         Params: none. * *        Returns: none *  * PostConditions: none. */static void DisplayHelp(void){#ifdef SHORT_HELP    printf("usage: flash [-w|-v|-B|-h|-I] [-qvp] [-b addr] [-s sector] [file]\n");#else    printf("Usage:\n"           "  [-w] [-qvp] [-b addr] [-s offset] [file]\n"           "  -v [-qvp] [-b addr] [-s offset] [file]\n"           "  -B [-qvp] [-b addr] [-s offset]\n"           "  -h\n"           "  -I\n");#endif#ifdef  LONG_HELP    printf("\n"           " Modes:\n"           "  w       write and verify named file to ROM (default mode,\n"           "           the \'-w\' is optional if a filename is specified)\n"           "  v       verify named file matches ROM contents.\n"           "  B       blank the ROM from the start offset to the end.\n"           "  h       print the usage message\n"           "  I       identify the ROM type \n"           "  e		  quit\n"           "\n");   #endif}/* *       Function: needStartOffset *        Purpose: if the sector start is not currently defined (as indicated by *                 'start_defined' or interactive mode is enabled then prompt *                 the user for a starting sector, indicating the current value. * *  PreConditions:  *  *         Params: *            Input: start_defined - global indicating if the filename is set *                   interactive - global indicating if info should be prompted *                                 for even if set on the command line. * *        Returns: none. *  * PostConditions: global startsector and start_defined set */void needStartOffset( void ){    if (start_defined == FALSE || interactive == TRUE)    {    	printf("Starting address offset:[in hex, default %lx]: \n",start_offset);        scanf("%lx",&start_offset);        //start_offset = getLong("Starting address offset [in hex, default %lx]:\n ", start_offset);        start_defined = TRUE;    }}/* *       Function: needBaseAddress *        Purpose: if the ROM base is not currently defined (as indicated by *                 'base_defined' or interactive mode is enabled then prompt *                 the user for a base address, indicating the current value. * *  PreConditions:  *  *         Params: *            Input: start_defined - global indicating if the filename is set *                   interactive - global indicating if info should be prompted *                                 for even if set on the command line. * *        Returns: none. *  * PostConditions: global startsector and start_defined set */void needBaseAddress(void){    if (base_defined == FALSE || interactive == TRUE)    {        printf("Base Address [in hex, default %lx]: \n",base_address);        scanf("%lx",&base_address);        //base_address = getLong("Base Address [in hex, default %lx]: \n", base_address);        base_defined = TRUE;    }}/* *       Function: needFilename *        Purpose: if the filename is not currently defined (as indicated by *                 'file_defined' or interactive mode is enabled then prompt *                 the user for a filename, indicating the current value. * *  PreConditions:  *  *         Params: *            Input: file_defined - global indicating if the filename is set *                   interactive - global indicating if info should be prompted *                                 for even if set on the command line. * *        Returns: none.

⌨️ 快捷键说明

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