Exemplo n.º 1
0
/************************************************************************
* Function: void SST39WaitProgram()
*                                                                       
* Overview: this function waits for program/erase operation completion
*                                                                       
* Input: none                                                          
*                                                                       
* Output: 1 if it was successfull 0 - if not
*                                                                       
************************************************************************/
void SST39WaitProgram()
{
	SST39STATUS stat;
	SST39STATUS prevStat;

    // enable
    SST39_CS_LAT = 0;

    prevStat.Val = PMDIN1;
    SST39PMPWaitBusy();

    prevStat.Val = PMDIN1;
    SST39PMPWaitBusy();

    stat.Val = PMDIN1;
    SST39PMPWaitBusy();


    while(stat.Bits.TOGGLE != prevStat.Bits.TOGGLE){

        prevStat.Val = stat.Val;
        stat.Val = PMDIN1;
        SST39PMPWaitBusy();
        
    }// end of while

    // disable
    SST39_CS_LAT = 1;
}
Exemplo n.º 2
0
/************************************************************************
* Function: BYTE SST39ReadByte(DWORD address)
*                                                                       
* Overview: this function reads a byte from address specified         
*                                                                       
* Input: address                                                     
*                                                                       
* Output: data read
*                                                                       
************************************************************************/
BYTE SST39ReadByte(DWORD address)
{
    BYTE    temp;

    SST39SetAddress(address);

    // enable
    SST39_CS_LAT = 0;

    temp = PMDIN1;

    // wait for reading cycle is completed
    SST39PMPWaitBusy();

    // disable
    SST39_CS_LAT = 1;

    // read result
    temp = PMDIN1;

    // wait for dummy reading cycle is completed
    SST39PMPWaitBusy();

    return (temp);
}
Exemplo n.º 3
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
}
Exemplo n.º 4
0
/************************************************************************
* Function: void SST39ReadArray(DWORD address, BYTE* pData, nCount)
*                                                                       
* Overview: this function reads data array from the address specified
*                                                                       
* Input: flash memory address, pointer to the buffer receiving data, data number
*                                                                       
* Output: none
*                                                                       
************************************************************************/
void SST39ReadArray(DWORD address, BYTE *pData, WORD nCount)
{
    WORD    counter;
    BYTE    temp;

    SST39SetAddress(address);

    // enable
    SST39_CS_LAT = 0;

    // run dummy cycle to get data
    temp = PMDIN1;

    for(counter = 0; counter < nCount; counter++)
    {
        SST39PMPWaitBusy();

        if(PMADDR == 0)
        {

            // set upper address bits
            address += 0x010000;

            if(((DWORD_VAL) address).v[2] & 0x01)
                SST39_A16_LAT = 1;
            else
                SST39_A16_LAT = 0;

            if(((DWORD_VAL) address).v[2] & 0x02)
                SST39_A17_LAT = 1;
            else
                SST39_A17_LAT = 0;

            if(((DWORD_VAL) address).v[2] & 0x04)
                SST39_A18_LAT = 1;
            else
                SST39_A18_LAT = 0;
        }

        *pData++ = PMDIN1;
    }

    SST39PMPWaitBusy();

    // disable
    SST39_CS_LAT = 1;
}
Exemplo n.º 5
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)
{
	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
}
Exemplo n.º 6
0
/************************************************************************
* Function: void SST39SectorErase(DWORD address)                                 
*
* Overview: erase whole chip
*
* Input: none
*            
* Output: none
*
************************************************************************/
void SST39SectorErase(DWORD address)
{
    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=0x80;
    SST39PMPWaitBusy();
    SST39_CS_LAT = 1;

    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;
    
    // set the sector address
    SST39SetAddress(address);
    SST39_CS_LAT = 0;
    PMDIN1=0x30;
    SST39PMPWaitBusy();
    SST39_CS_LAT = 1;

    SST39WaitProgram();
}
Exemplo n.º 7
0
/************************************************************************
* Function: void SST39ChipErase(void)                                 
*
* Overview: erase whole chip
*
* Input: none
*            
* Output: none
*
************************************************************************/
void SST39ChipErase(void)
{
    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=0x80;
    SST39PMPWaitBusy();
    SST39_CS_LAT = 1;

    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=0x10;
    SST39PMPWaitBusy();
    SST39_CS_LAT = 1;

    SST39WaitProgram();
}