?? sst39vf160.c
字號:
#include <stdio.h>#include "s3c4510.h"#include "SST39VF160.h"/*---------------------------------------------------------------- * brief : check the flash Manufacturer’s ID and Device ID * author: dailzh * param: none * retval: -1--------different 0---------the same * modify history: if you change the function please give the discription-----------------------------------------------------------------*/int sst_check_id( void ){ unsigned short SST_id1; unsigned short SST_id2; int ReturnStatus; //soft id entry //first bus write cycle access_bus( WRITE, SST39_CMD_ADDRESS1, SST39_READ_ID1, IP ); access_bus( SETUP, SST39_CMD_ADDRESS1, SST39_READ_ID1, IP ); //second bus write cycle access_bus( WRITE, SST39_CMD_ADDRESS2, SST39_READ_ID2, IP ); access_bus( SETUP, SST39_CMD_ADDRESS2, SST39_READ_ID2, IP ); //third bus write cycle access_bus( WRITE, SST39_CMD_ADDRESS1, SST39_READ_ID3, IP ); access_bus( SETUP, SST39_CMD_ADDRESS1, SST39_READ_ID3, IP ); //prepare to read access_bus( HOLD, SST39_CMD_ADDRESS1, SST39_READ_ID2, IP ); //read from bus-----Manufacturer’s ID access_bus( READ, 0x00000000, 0, IP ); SST_id1 = access_bus( READ, 0x00000000, 0 , RP ); //read from bus-----device ID access_bus( READ, 0x00000001, 0, IP ); SST_id2 = access_bus( READ, 0x00000001, 0 , RP ); //compare to sst39lv160 if( SST_id1 == SST_ID && SST_id2 == SST_39VF160 ) ReturnStatus = 0; else ReturnStatus = -1; //soft id exit //first bus write cycle access_bus( WRITE, SST39_CMD_ADDRESS1, SST39_READ_ID1, IP ); access_bus( SETUP, SST39_CMD_ADDRESS1, SST39_READ_ID1, IP ); //second bus write cycle access_bus( WRITE, SST39_CMD_ADDRESS2, SST39_READ_ID2, IP ); access_bus( SETUP, SST39_CMD_ADDRESS2, SST39_READ_ID2, IP ); //third bus write cycle access_bus( WRITE, SST39_CMD_ADDRESS1, SST39_EXIT_READ_ID, IP ); access_bus( SETUP, SST39_CMD_ADDRESS1, SST39_EXIT_READ_ID, IP ); return (ReturnStatus);}/*---------------------------------------------------------------- * brief : write a word to the flash * author: dailzh * param: addr------must a even addr(0x0~0x1ffffe) data------the write word * retval: none * modify history: 2003-12-3 Guo Jian first version-----------------------------------------------------------------*/void sst_write_word( unsigned int addr, unsigned short data ){ //first bus write cycle access_bus( WRITE, SST39_CMD_ADDRESS1, SST39_AUTO_PGRM1, IP ); access_bus( SETUP, SST39_CMD_ADDRESS1, SST39_AUTO_PGRM1, IP ); //second bus write cycle access_bus( WRITE, SST39_CMD_ADDRESS2, SST39_AUTO_PGRM2, IP ); access_bus( SETUP, SST39_CMD_ADDRESS2, SST39_AUTO_PGRM2, IP ); //third bus write cycle access_bus( WRITE, SST39_CMD_ADDRESS1, SST39_AUTO_PGRM3, IP ); access_bus( SETUP, SST39_CMD_ADDRESS1, SST39_AUTO_PGRM3, IP ); //forth bus write cycle access_bus( WRITE, addr/2, data, IP ); access_bus( SETUP, addr/2, data, IP ); sst_check_toggle_ready( addr ); return;}/*---------------------------------------------------------------- * brief : read a word on the flash * author: dailzh * param: addr------must a even addr(0x0~0x1ffffe) * retval: the word save on the flash * modify history: 2003-12-3 Guo Jian first version-----------------------------------------------------------------*/unsigned short sst_read_word( unsigned int addr ){ unsigned int tmp; access_bus(READ, addr/2, 0, IP); tmp = access_bus(READ, addr/2, 0 , RP); return tmp;}/*---------------------------------------------------------------- * brief : erase one block * author: dailzh * param: addr------the erase block first address * retval: none * modify history: 2003-12-3 Guo Jian first version-----------------------------------------------------------------*/void sst_erase_one_block( unsigned int addr ){ //first bus write cycle access_bus( WRITE, SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE1, IP ); access_bus( SETUP, SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE1, IP ); //second bus write cycle access_bus( WRITE, SST39_CMD_ADDRESS2, SST39_AUTO_PG_ERASE2, IP ); access_bus( SETUP, SST39_CMD_ADDRESS2, SST39_AUTO_PG_ERASE2, IP ); //third bus write cycle access_bus( WRITE, SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE3, IP ); access_bus( SETUP, SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE3, IP ); //forth bus write cycle access_bus( WRITE, SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE4, IP ); access_bus( SETUP, SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE4, IP ); //fifth bus write cycle access_bus( WRITE, SST39_CMD_ADDRESS2, SST39_AUTO_PG_ERASE5, IP ); access_bus( SETUP, SST39_CMD_ADDRESS2, SST39_AUTO_PG_ERASE5, IP ); //sixth bus write cycle access_bus( WRITE, addr, SST39_ERASE_BLOCK, IP ); access_bus( SETUP, addr, SST39_ERASE_BLOCK, IP ); sst_check_toggle_ready( addr ); return;}/*---------------------------------------------------------------- * brief : erase one sector * author: dailzh * param: addr------the first address of the erased addr * retval: none * modify history: 2003-12-3 Guo Jian first version-----------------------------------------------------------------*/void sst_erase_one_sector( unsigned int addr ){ //first bus write cycle access_bus( WRITE, SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE1, IP ); access_bus( SETUP, SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE1, IP ); //second bus write cycle access_bus( WRITE, SST39_CMD_ADDRESS2, SST39_AUTO_PG_ERASE2, IP ); access_bus( SETUP, SST39_CMD_ADDRESS2, SST39_AUTO_PG_ERASE2, IP ); //third bus write cycle access_bus( WRITE, SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE3, IP ); access_bus( SETUP, SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE3, IP ); //forth bus write cycle access_bus( WRITE, SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE4, IP ); access_bus( SETUP, SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE4, IP ); //fifth bus write cycle access_bus( WRITE, SST39_CMD_ADDRESS2, SST39_AUTO_PG_ERASE5, IP ); access_bus( SETUP, SST39_CMD_ADDRESS2, SST39_AUTO_PG_ERASE5, IP ); //sixth bus write cycle access_bus( WRITE, addr, SST39_ERASE_SECTOR, IP ); access_bus( SETUP, addr, SST39_ERASE_SECTOR, IP ); sst_check_toggle_ready( addr ); return;} /*---------------------------------------------------------------- * brief : erase the whole flash * author: dailzh * param: none * retval: none * modify history: 2003-12-3 Guo Jian first version-----------------------------------------------------------------*/void sst_erase_chip( void ){ //first bus write cycle access_bus( WRITE, SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE1, IP ); access_bus( SETUP, SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE1, IP ); //second bus write cycle access_bus( WRITE, SST39_CMD_ADDRESS2, SST39_AUTO_PG_ERASE2, IP ); access_bus( SETUP, SST39_CMD_ADDRESS2, SST39_AUTO_PG_ERASE2, IP ); //third bus write cycle access_bus( WRITE, SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE3, IP ); access_bus( SETUP, SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE3, IP ); //forth bus write cycle access_bus( WRITE, SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE4, IP ); access_bus( SETUP, SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE4, IP ); //fifth bus write cycle access_bus( WRITE, SST39_CMD_ADDRESS2, SST39_AUTO_PG_ERASE5, IP ); access_bus( SETUP, SST39_CMD_ADDRESS2, SST39_AUTO_PG_ERASE5, IP ); //sixth bus write cycle access_bus( WRITE, SST39_CMD_ADDRESS1, SST39_ERASE_CHIP, IP ); access_bus( SETUP, SST39_CMD_ADDRESS1, SST39_ERASE_CHIP, IP ); sst_check_toggle_ready( 0 ); printf( "erase ok\n" ); return;}/*---------------------------------------------------------------- * brief : check the toggle bit to confirm the internal operation finished * author: dailzh * param: addr------flash address * retval: the word save on the flash * modify history: 2003-12-3 Guo Jian first version-----------------------------------------------------------------*/void sst_check_toggle_ready( unsigned int addr ){ unsigned short pre_data; unsigned short cur_data; unsigned long time_out = 0; pre_data = sst_read_word( addr ); pre_data = pre_data & 0x4040; while( time_out < 0x7FFFFFFF ) { //get the current data on the bus cur_data = sst_read_word( addr ); cur_data = pre_data & 0x4040; //if finished internal operation return if( pre_data == cur_data ) return; pre_data = cur_data; time_out++; } printf( "time out in check toggle\n" ); return;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -