?? lib_flash_at49.c
字號:
//*-----------------------------------------------------------------------------//* 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 : lib_flash_at49.c//* Object : FLASH programmer for ://* - AT49BV1604/AT49BV1604T//* - AT49BV1614/AT49BV1604T//* - AT49BV8011/AT49BV8011T//* - AT49BV8011/AT49BV8011T//*//* 1.1 06/11/00 JPP : Creation//*-----------------------------------------------------------------------------//* --------------------------- include file ----------------------------------#include "lib_flash_at49.h"/* Defines supported flash organizations */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 }};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 }};OrgDef OrgAT49BV16x4[] ={ /* 8 x 8kbytes sectors */ { 8, 8*1024 }, /* 2 x 32 kbytes sectors */ { 2, 32*1024 }, /* 30 x 64 kbytes sectors */ { 30, 64*1024 }};OrgDef OrgAT49BV16x4T[] ={ /* 30 x 64 kbytes sectors */ { 30, 64*1024 }, /* 2 x 32 kbytes sectors */ { 2, 32*1024 }, /* 8 x 8kbytes sectors */ { 8, 8*1024 }};/* Define supported flash Table */FlashAt49BVDef FlashTable[NB_FLASH_SUPPORTED] ={ { 1024*1024, /* 1 M Bytes */ FLASH_AT49BV8011, OrgAT49BV8011, sizeof(OrgAT49BV8011)/sizeof(OrgDef) }, { 1024*1024, /* 1 M Bytes */ FLASH_AT49BV8011T, OrgAT49BV8011T, sizeof(OrgAT49BV8011T)/sizeof(OrgDef) }, { 2*1024*1024, /* 2 M Bytes */ FLASH_AT49BV16x4, OrgAT49BV16x4, sizeof(OrgAT49BV16x4)/sizeof(OrgDef) }, { 2*1024*1024, /* 2 M Bytes */ FLASH_AT49BV16x4T, OrgAT49BV16x4T, sizeof(OrgAT49BV16x4T)/sizeof(OrgDef) }};//* Static data for AT49static flash_word *addr_base = (flash_word *)0x01000000;static flash_word *addr_load;static FlashAt49BVDef *flash;//* Static Variable for AT49static flash_word *addr_prg_sector = (flash_word *)0x01000000; //* base_addr;static unsigned int block = 0 ;static int nb_sector = 0 ;static int first = TRUE;static int erase = FALSE ;//* --------------------------- Static function -------------------------------#define LED_3 1<<3#define LED_4 1<<4#define LED_5 1<<5#define LED_6 1<<6#define LED_16 1<<16#define LED_17 1<<17#define LED_18 1<<18#define LED_19 1<<19//* testvoid led_on(int state, int led){ int *pt=(int *)0xFFFF0030; if (state) pt++; *pt = led;}//*----------------------------------------------------------------------------//* Function Name : read_dbg_data//* Object : read debug communication data register//* Input Parameters ://* Output Parameters : R0//*----------------------------------------------------------------------------extern u_int read_dbg_data(void);//*----------------------------------------------------------------------------//* Function Name : read_dbg_control//* Object : read debug communication data register//* Input Parameters ://* Output Parameters : R0//*----------------------------------------------------------------------------extern u_int read_dbg_control(void);//*----------------------------------------------------------------------------//* Function Name : write_dbg_data//* Object : read debug communication data register//* Input Parameters : Val = R0//* Output Parameters ://*----------------------------------------------------------------------------extern void write_dbg_data(u_int val);//*----------------------------------------------------------------------------//* Function Name : Pause//* Object : wait flash response//* Input Parameters : none//* Output Parameters : none//*----------------------------------------------------------------------------/*static void Pause(void){ int count; for (count=0;count < TIME_OUT/10 ;count++) {*/ /* Do nothing - just wait *///* }//* }//* --------------------------- Export function -------------------------------//*----------------------------------------------------------------------------//* Function Name : flash_at49_identify//* Object : Get the device id//* Input Parameters : <sart_addr> Flash base address//* Output Parameters : device_code or 0xFFFF if bad manuf code//*----------------------------------------------------------------------------/*flash_word flash_at49_identify ( flash_word *base_addr )//* Begin{ flash_word manuf_code ; flash_word device_code ; Pause(); //* 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 ( manuf_code != ATMEL_MANUFACTURED ) { return (FLASH_AT49BV_UNKNOW); } //* Return pointer to Flash found return ( device_code ) ;}*///*----------------------------------------------------------------------------//* Function Name : flash_at49_init_write//* Object : check if sector is erased if not erase//* Input Parameters ://* Output Parameters : if data sector erase TRUE or FALSE//*----------------------------------------------------------------------------/* void flash_at49_init_write ( flash_word *address_base,flash_word *address_load,FlashAt49BVDef *flash_type)//* Begin{ addr_prg_sector = address_base; addr_base = address_base; addr_load = address_load; block = 0; nb_sector = 0; first = TRUE; erase = FALSE; flash = flash_type;}*///*----------------------------------------------------------------------------//* Function Name : Get_Flash_Type//* Object : return pointer towards flash type structure//* Input Parameters : flash_type//* Output Parameters : pointer towards flash structure//*----------------------------------------------------------------------------FlashAt49BVDef *Get_Flash_Type(u_int flash_type){ FlashAt49BVDef *type; switch (flash_type){ case FLASH_AT49BV8011 : type = &FlashTable[0]; break; case FLASH_AT49BV8011T : type = &FlashTable[1]; break; case FLASH_AT49BV16x4 : type = &FlashTable[2]; break; case FLASH_AT49BV16x4T : type = &FlashTable[3]; break; default : type = (FlashAt49BVDef *)0x0; break; } return type;}//*----------------------------------------------------------------------------//* Function Name : flash_wait_flash_ready//* Object : wait the end of write//* Input Parameters : <address> Adress to write//* <data> data write at the <address>//* Output Parameters : if data write TRUE or FALSE if time out//*----------------------------------------------------------------------------int flash_wait_flash_ready ( flash_word *address, flash_word data ){//* Begin int i = 0 ; //* While two consecutive read don't give same value or timeout while (( *address != data ) && ( i++ < TIME_OUT )) ; //* If timeout if ( i < TIME_OUT ) { return ( TRUE ) ; } //* Else else { return ( FALSE ) ; } //* Endif}//* End//*----------------------------------------------------------------------------//* Function Name : erase_sector//* Object : check if sector is erased if not erase//* Input Parameters : <base_addr> Flash base address//* <sector_addr> base sector address//* <size> sector size in byte//* Output Parameters : if data sector erase TRUE or FALSE//*----------------------------------------------------------------------------static int erase_sector ( flash_word *base_addr,flash_word *sector_addr,int size )//* Begin{ int trial = 0 ; //* While flash is not erased or too much erasing performed while (( flash_at49_check_sector_erased ( sector_addr, size ) == FALSE ) && ( trial++ < NB_TRIAL_ERASE )) { if ( flash_at49_erase_sector(base_addr,sector_addr) == FALSE ) { //* return False return ( FALSE ) ; } //* Endif }//* EndWhile //* Return True return ( TRUE ) ;}//* End//*----------------------------------------------------------------------------//* Function Name : flash_at49_check_sector_erased//* Object : check if sector is erased//* Input Parameters : <sector_addr> base sector address//* <size> sector size in byte//* Output Parameters : if data sector erase TRUE or FALSE
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -