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

📄 flash_8011_ghs.c

📁 ARM入门的好帮手.包含了从简单到相对较复杂的程序.
💻 C
📖 第 1 页 / 共 2 页
字号:
//*-----------------------------------------------------------------------------//*      ATMEL Microcontroller Software Support  -  ROUSSET  -//*-----------------------------------------------------------------------------//* The software is delivered "AS IS" without warranty or condition of any//* kind, either express, implied or statutory. This includes without//* limitation any warranty or condition with respect to merchantability or//* fitness for any particular purpose, or against the infringements of//* intellectual property rights of others.//*-----------------------------------------------------------------------------//* File Name               : flash_8011_ghs.c//* Object                  : FLASH programmer for ://*                             AT49BV8011/AT49BV8011T//*                             AT49BV8011/AT49BV8011T//*//* Translator              : Green Hills Multi2K Software Development Toolkit V3.01//*//* 1.0 23/04/99 JCZ        : Creation//* 1.1 10/01/02 PFi        : Speed improved version. The file to download//*                         : is copied in SRAM and then into flash.//*//*-----------------------------------------------------------------------------/* Include Standard c Libraries to allow stand alone compiling and operation */#include <stdio.h>#include <stdlib.h>#define TRUE    1#define FALSE   0typedef volatile unsigned short flash_word ;typedef unsigned short RAM_flash_word ;/* Target Identification */#define TARGET_ID           "Flash 8011 "/* Trials Number to erase a sector */#define NB_TRIAL_ERASE      10#define MIN_NO_OF_ARGS      3/* Timeout loop count */#define TIME_OUT            1000000/* Loop count for delay after sequence */#define DELAY               10000#define MAX_WORDS_IN_SECTOR 32*1024/* Wait for flash ready by poliing RDY/BUSY pin selection *///#define   POLL_RDY_NBUSY/* PIO connected to RDY/BUSY pin of the flash *//* used only if POLL_RDY_NBUSY is defined */#define RDY_PIO_BUSY        (1<<25)/* Define Flash Codes */#define FLASH_SEQ_ADD1      (0x5555)#define FLASH_SEQ_ADD2      (0x2AAA)#define FLASH_CODE1         ((flash_word)(0xAA))#define FLASH_CODE2         ((flash_word)(0x55))#define ID_IN_CODE          ((flash_word)(0x90))#define ID_OUT_CODE         ((flash_word)(0xF0))#define WRITE_CODE          ((flash_word)(0xA0))#define ERASE_SECTOR_CODE1  ((flash_word)(0x80))#define CHIP_SECTOR_CODE1   ((flash_word)(0x10))#define ERASE_SECTOR_CODE2  ((flash_word)(0x30))/* Defines organization structure */typedef struct OrgDef{    unsigned int    sector_number ;    unsigned int    sector_size ;} OrgDef ;/* Defines supported flash organizations */const OrgDef OrgAT49BV8011[] ={    /* 1 x 16kbytes sectors */    {        1,        16*1024    },    /* 1 x 32 kbytes sectors */    {        1,        32*1024,    },    /* 4 x 8 kbytes sectors */    {        4,        8*1024,    },    /* 1 x 32 kbytes sectors */    {        1,        32*1024,    },    /* 1 x 16kbytes sectors */    {        1,        16*1024    },    /* 14 x 64 kbytes sectors */    {        14,        64*1024,    }};const OrgDef OrgAT49BV8011T[] ={    /* 14 x 64 kbytes sectors */    {        14,        64*1024,    },    /* 1 x 16kbytes sectors */    {        1,        16*1024    },    /* 1 x 32 kbytes sectors */    {        1,        32*1024,    },    /* 4 x 8 kbytes sectors */    {        4,        8*1024,    },    /* 1 x 32 kbytes sectors */    {        1,        32*1024,    },    /* 1 x 16kbytes sectors */    {        1,        16*1024    }};/* Defines Flash device definition structure */typedef struct FlashDef{    unsigned int    flash_size;    char            *flash_name;    unsigned int    flash_manuf_id;    unsigned int    flash_id;    unsigned int    flash_mask;    const OrgDef    *flash_org;    unsigned int    flash_block_nb;}FlashDef;/* Define supported flash Table */const FlashDef FlashTable[] ={    {        1024*1024,        "AT49BV8011",        0x001F,        0x00CB,        0x000FFFFF,        OrgAT49BV8011,        sizeof(OrgAT49BV8011)/sizeof(OrgDef)    },    {        1024*1024,        "AT49BV8011",        0x001F,        0x004A,        0x000FFFFF,        OrgAT49BV8011T,        sizeof(OrgAT49BV8011T)/sizeof(OrgDef)    }};/* Defines number of flash supported */#define NB_FLASH_SUPPORTED  sizeof(FlashTable)/sizeof(FlashDef)RAM_flash_word RAMSectorData[MAX_WORDS_IN_SECTOR];void wait ( int count ){    int     i ;    for ( i = count ; i > 0 ; i -- ) ;}//*--------------------------------------------------------------------------------------//* Function Name       : display_help//* Object              : Display help when an error occures//* Input Parameters    : none//* Output Parameters   : none//* Functions called    : none//*--------------------------------------------------------------------------------------void display_help ( void ){    // Display Error    printf ( "\n" ) ;    printf ( "Erro in arguments, correct syntax is :\n" ) ;    // Dispaly Syntax    printf ( "\tload flash <filename> <address>\n" ) ;    printf ( "\twhere:\n" ) ;    // Display arguments    printf ( "\t\t<filename> - binary file to program into flash\n" ) ;    printf ( "\t\t<address>  - beginning address to download\n" ) ;    printf ( "\n" ) ;}//*--------------------------------------------------------------------------------------//* Function Name       : flash_identify//* Object              : Read the flash manufacturer code and Flash ID code//* Input Parameters    : flash_word *load_addr = Flash bass address//* Output Parameters   : Pointer to the Flash identified//* Functions called    : none//*--------------------------------------------------------------------------------------const FlashDef *flash_identify ( flash_word *load_addr ){    flash_word      manuf_code ;    flash_word      device_code ;    const FlashDef  *flash_pt ;    flash_word      *base_addr ;    int             exit = FALSE ;    // Initialize Flash Table pointer    flash_pt = FlashTable ;    // Look for the  device in the known flash table    while ( exit == FALSE )    {        // Initialize Flash Base Address        base_addr = (flash_word *) ((int)load_addr & ~(flash_pt->flash_mask)) ;        // Display Flash Identification Header        printf ( "Trying to identify Flash at base address (0x%x)\n", (int)base_addr) ;        // Display Flash Tested        printf ( "Trying %s\n", flash_pt->flash_name ) ;        // Enter Software Product Identification Mode        *(base_addr + FLASH_SEQ_ADD1) = FLASH_CODE1;        *(base_addr + FLASH_SEQ_ADD2) = FLASH_CODE2;        *(base_addr + FLASH_SEQ_ADD1) = ID_IN_CODE;        // Read Manufacturer and device code from the device        manuf_code  = *base_addr ;        device_code = *(base_addr + 1) ;        // Exit Software Product Identification Mode        *(base_addr + FLASH_SEQ_ADD1) = FLASH_CODE1;        *(base_addr + FLASH_SEQ_ADD2) = FLASH_CODE2;        *(base_addr + FLASH_SEQ_ADD1) = ID_OUT_CODE;        // If both manufacturer and device codes corresponds        if (( flash_pt->flash_id == device_code ) &&            ( flash_pt->flash_manuf_id == manuf_code ))        {            // Exit the search loop            exit = TRUE ;        }        else        {            // Next Flash, If end of table            if ( ++flash_pt >= FlashTable + NB_FLASH_SUPPORTED )            {                // Return 0, Display Error and Exit loop                flash_pt = (const FlashDef *)0 ;                printf ( "Error - Unknown device: manufacturer %02x / device %02x \n",                        manuf_code, device_code );                exit = TRUE ;            }        }    }    // Return pointer to Flash found    return ( flash_pt ) ;}//*--------------------------------------------------------------------------------------//* Function Name       : init_flash_ready//* Object              : Setup the PIO line connected to the RDY/BUSY line of the flash//* Input Parameters    : none//* Output Parameters   : none//* Functions called    : none//*--------------------------------------------------------------------------------------void init_flash_ready ( void ){#ifdef POLL_RDY_NBUSY    *(( volatile unsigned int *) 0xFFFF0000 ) = RDY_PIO_BUSY ;    *(( volatile unsigned int *) 0xFFFF0014 ) = RDY_PIO_BUSY ;#endif}//*--------------------------------------------------------------------------------------//* Function Name       : wait_flash_ready//* Object              : check if data is written by software polling//* Input Parameters    : Data and address of the data.//* Output Parameters   : TRUE or FALSE//* Functions called    : none//*--------------------------------------------------------------------------------------int wait_flash_ready ( flash_word *address, flash_word data ){    int i = 0 ;#ifdef POLL_RDY_NBUSY    // While RDY/BUSY is not set    while (((*(( volatile unsigned int *) 0xFFFF0024 ) & RDY_PIO_BUSY ) == 0 ) &&           ( i++ < TIME_OUT )) ;#else    // While two consecutive read don't give same value or timeout    while (( *address != data ) && ( i++ < TIME_OUT )) ;#endif    // If timeout    if ( i < TIME_OUT )    {        //printf ( "Counter = %d\n", i ) ;        return ( TRUE ) ;    }    else    {        //printf ( "Timeout\n" ) ;        return ( FALSE ) ;    }}//*--------------------------------------------------------------------------------------//* Function Name       : check_sector_erased//* Object              : check if sector is erased. If not erase it.//*//* Input Parameters    : <sector_addr> base sector address//*                       <size> sector size in byte//*                       <sector_id> sector ID//*//* Output Parameters   : If data sector erase TRUE, else FALSE//*--------------------------------------------------------------------------------------int check_sector_erased ( flash_word *sector_addr, int size, int sector_id )

⌨️ 快捷键说明

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