📄 flash_16x4.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 : flash_16x4.c//* Object : FLASH programmer for ://* AT49BV8011/AT49BV8011T//* AT49BV1604/AT49BV1604T//* AT49BV1614/AT49BV1614T//*//* Exported Resources : at91_flash_identify//* at91_erase_sector//* at91_write_flash//* Imported Resources ://*//*//* 1.0 23/04/99 JPP : Creation//* 1.1 26/04/00 EL : Clean up//*----------------------------------------------------------------------------#include "flash_16x4.h"//*----------------------------------------------------------------------------//* Function Name : at91_wait_flash_ready//* Object : check if data is written//* Input Parameters : Data and data address//* Output Parameters : TRUE or FALSE//* Functions called : none//*----------------------------------------------------------------------------static int at91_wait_flash_ready ( flash_word *address, flash_word data )//* Begin{ int count = 0 ; //* While two consecutive read don't give same value or timeout while (( *address != data ) && ( count++ < TIME_OUT )) ; //* If timeout if ( count < TIME_OUT ) { //* Return True return ( TRUE ) ; } //* Return False return ( FALSE );//* End}//*----------------------------------------------------------------------------//* Function Name : at91_flash_identify//* Object : Read the flash manufactured code and//* Input Parameters : flash_word *load_addr = Flash bass address//* Output Parameters : divice code and manufactured code//* Functions called : none//*----------------------------------------------------------------------------void at91_flash_identify ( flash_word *base_addr, flash_word *manuf_code,flash_word *device_code )//* Begin{ //* 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;//* End}//*----------------------------------------------------------------------------//* Function Name : at91_erase_sector//* Object : erase sector//* Input Parameters : Data and data address//* Output Parameters : TRUE or FALSE//* Functions called : at91_wait_flash_ready//*----------------------------------------------------------------------------int at91_erase_sector (flash_word *base_addr, flash_word *sector_addr)//* Begin{ //* Enter Sector Erase Sequence codes *(base_addr + FLASH_SEQ_ADD1) = FLASH_CODE1; *(base_addr + FLASH_SEQ_ADD2) = FLASH_CODE2; *(base_addr + FLASH_SEQ_ADD1) = ERASE_SECTOR_CODE1; *(base_addr + FLASH_SEQ_ADD1) = FLASH_CODE1; *(base_addr + FLASH_SEQ_ADD2) = FLASH_CODE2; *sector_addr = ERASE_SECTOR_CODE2 ; //* Wait for Flash Ready after Erase, if timeout if ( at91_wait_flash_ready ( sector_addr, (flash_word)0xFFFF ) == FALSE ) { //* Display Timeout and return False return ( FALSE ) ; } //* set this sector erased //* Return True return ( TRUE ) ;//* End}//*----------------------------------------------------------------------------//* Function Name : at91_write_flash//* Object : write a word in flash//* Input Parameters : flash_word *base_addr : Flash base address//* flash_word *load_addr : Flash data address//* flash_word data : Data value//* Output Parameters : error code : FLASH_WRITE_TIME_OUT, FLASH_WRITE_ERROR//* or OK : FLASH_OK//* Functions called : at91_wait_flash_ready//*----------------------------------------------------------------------------int at91_write_flash ( flash_word *base_addr, flash_word *load_addr, flash_word data ){ flash_word read_data ; //* Enter Programming code sequence *(base_addr + FLASH_SEQ_ADD1) = FLASH_CODE1 ; *(base_addr + FLASH_SEQ_ADD2) = FLASH_CODE2 ; *(base_addr + FLASH_SEQ_ADD1) = WRITE_CODE ; *load_addr = data ; //* Wait for Flash ready after erasing, if timeout if ( at91_wait_flash_ready ( load_addr, data ) != TRUE ) { return ( FLASH_WRITE_TIME_OUT ) ; } //* If Data written does not equal data if (( read_data = *load_addr ) != data ) { //* Return False return ( FLASH_WRITE_ERROR ); } //* Return OK return ( FLASH_OK ) ;//* End}//* End file
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -