Beispiel #1
0
/************************************************************************
* Function: BYTE SST39WriteByte(DWORD address, BYTE data)
*                                                                       
* Overview: this function writes one byte
*                                                                       
* Input: address and byte to be written
*                                                                       
* Output: non-zero if it's successful
*
* Notes: none
*                                                                       
************************************************************************/
BYTE SST39WriteByte(DWORD address, BYTE data)
{
    SST39SetAddress(0x55555555);
    SST39_CS_LAT = 0;
    PMDIN1 = 0xaa;
    SST39PMPWaitBusy();
    SST39_CS_LAT = 1;

    SST39SetAddress(0xaaaaaaaa);
    SST39_CS_LAT = 0;
    PMDIN1 = 0x55;
    SST39PMPWaitBusy();
    SST39_CS_LAT = 1;

    SST39SetAddress(0x55555555);
    SST39_CS_LAT = 0;
    PMDIN1 = 0xa0;
    SST39PMPWaitBusy();
    SST39_CS_LAT = 1;

    SST39SetAddress(address);
    SST39_CS_LAT = 0;
    PMDIN1 = data;
    SST39PMPWaitBusy();
    SST39_CS_LAT = 1;

    SST39WaitProgram();

    if(SST39ReadByte(address) == data)
        if(SST39ReadByte(address) == data)
            return (1);

    return (0); // failed
}
/************************************************************************
* Function: WORD SST39ReadWord(DWORD address)             
*                                                                       
* Overview: this function reads a 16-bit word from address specified         
*                                                                       
* Input: address                                                     
*                                                                       
* Output: data read
*                                                                       
************************************************************************/
WORD SST39ReadWord(DWORD address){
WORD_VAL temp;

    temp.v[0] = SST39ReadByte(address);
    temp.v[1] = SST39ReadByte(address+1);

    return temp.Val;
}
/************************************************************************
* Function: BYTE SST39WriteArray(DWORD address, BYTE* pData, nCount)
*                                                                       
* Overview: this function writes data array at the address specified
*                                                                       
* Input: flash memory address, pointer to the data array, data number
*                                                                       
* Output: return 1 if the operation was successfull
*
* Notes: none
*                                                                       
************************************************************************/
BYTE SST39WriteArray(DWORD address, BYTE* pData, WORD nCount)
{
	WORD    counter;
	BYTE*   pD;
	DWORD   addr;

    pD = pData;
    addr = address;

    // write
    for(counter=0; counter<nCount; counter++){
       while(0 == SST39WriteByte(addr,*pD));
       addr++; pD++;
    }

    pD = pData;
    addr = address;

    // verify
    for(counter=0; counter<nCount; counter++){
        if(*pD++ != SST39ReadByte(addr++))
            return 0;
    }

    return 1;
}
/************************************************************************
* Function: BYTE SST39WriteByte(DWORD address, BYTE data)
*                                                                       
* Overview: this function writes one byte
*                                                                       
* Input: address and byte to be written
*                                                                       
* Output: non-zero if it's successful
*
* Notes: none
*                                                                       
************************************************************************/
BYTE SST39WriteByte(DWORD address, BYTE data)
{
	BYTE d1, d2;
	
    SST39SetAddress(0x00005555);
    SST39_CS_LAT = 0;
    PMDIN1 = 0xAA;
    SST39PMPWaitBusy();
    SST39_CS_LAT = 1;

    SST39SetAddress(0x00002AAA);
    SST39_CS_LAT = 0;
    PMDIN1 = 0x55;
    SST39PMPWaitBusy();
    SST39_CS_LAT = 1;
    
    SST39SetAddress(0x00005555);
    SST39_CS_LAT = 0;
    PMDIN1 = 0xA0;
    SST39PMPWaitBusy();
    SST39_CS_LAT = 1;
    
    SST39SetAddress(address);
    SST39_CS_LAT = 0;
    PMDIN1 = data;
    SST39PMPWaitBusy();
    SST39_CS_LAT = 1;
    
	dwWriteAddr++;
    SST39WaitProgram();

	d1 = SST39ReadByte(address);
	d2 = SST39ReadByte(address);
	if ((d1 == data) && (d2 == data))
		return 1;
 
    return 0; // failed
}