예제 #1
0
void DataFlash_APM1::WriteByte(byte data)
{
  if (!df_Stop_Write)
    {
    BufferWrite(df_BufferNum,df_BufferIdx,data);
    df_BufferIdx++;
    if (df_BufferIdx >= df_PageSize)  // End of buffer?
      {
      df_BufferIdx=4;		//(4 bytes for FileNumber, FilePage)
	  BufferToPage(df_BufferNum,df_PageAdr,0);  // Write Buffer to memory, NO WAIT
      df_PageAdr++;
	  if (OVERWRITE_DATA==1)
	    {
        if (df_PageAdr>DF_LAST_PAGE)  // If we reach the end of the memory, start from the begining
		  df_PageAdr = 1;
	    }
      else
	    {
        if (df_PageAdr>DF_LAST_PAGE)  // If we reach the end of the memory, stop here
		  df_Stop_Write=1;
	    }

      if (df_BufferNum==1)  // Change buffer to continue writing...
        df_BufferNum=2;
      else
        df_BufferNum=1;
      // We are starting a new page - write FileNumber and FilePage
		BufferWrite(df_BufferNum,0,df_FileNumber>>8);   // High byte
		BufferWrite(df_BufferNum,1,df_FileNumber&0xFF); // Low byte
		df_FilePage++;
		BufferWrite(df_BufferNum,2,df_FilePage>>8);   // High byte
		BufferWrite(df_BufferNum,3,df_FilePage&0xFF); // Low byte
      }
예제 #2
0
void DataFlash_Block::FinishWrite(void)
{
    // Write Buffer to flash, NO WAIT
    BufferToPage(df_BufferNum, df_PageAdr, 0);      
    df_PageAdr++;
    // If we reach the end of the memory, start from the begining    
    if (df_PageAdr > df_NumPages)
        df_PageAdr = 1;

    // switch buffer
    df_BufferNum ^= 1;
    df_BufferIdx = 0;
}
예제 #3
0
void DataFlash_Class::FinishWrite(void)
{
    df_BufferIdx=0;
    BufferToPage(df_BufferNum,df_PageAdr,0);      // Write Buffer to memory, NO WAIT
    df_PageAdr++;
    if (DF_OVERWRITE_DATA==1) {
        if (df_PageAdr>df_NumPages)  // If we reach the end of the memory, start from the begining
            df_PageAdr = 1;
    } else {
        if (df_PageAdr>df_NumPages)  // If we reach the end of the memory, stop here
            df_Stop_Write=1;
    }

    if (df_BufferNum==1)      // Change buffer to continue writing...
        df_BufferNum=2;
    else
        df_BufferNum=1;
}
예제 #4
0
void DataFlash_Block::FinishWrite(void)
{
    WaitReady();

    BufferToPage (df_PageAdr << 8); // Save 256 bytes from buffer to Page

    df_PageAdr++;

    if (df_PageAdr > df_NumPages){
	Flash_Jedec_EraseSector(0); // Erase Sector 0
    	df_PageAdr = 1;
    }
    // check if new sector is erased
    if (df_PageAdr % 256 == 0){
	uint16_t data = 0;
	BlockRead((df_PageAdr << 8), &data, sizeof(data));
    	if (data != 0xFFFF){
    	   Flash_Jedec_EraseSector(df_PageAdr << 8); // Erase Sector
        }
    }

    df_BufferIdx = 0;
}
예제 #5
0
파일: AT45D.c 프로젝트: Inspirati/freeMixer
void WriteSector(uint16_t sector, uint8_t* buffer)
{
	BufferWriteStr(2, 0, 512, buffer);
	BufferToPage(2, sector);
}
예제 #6
0
void WriteSector(uint16_t sector, uint8_t* buffer)
{
	BufferWriteStr(2, 0, 512, buffer);  // write 512 bytes to beginning (offset 0) of AT45D internal buffer 2
	BufferToPage(2, sector);            // transfer AT45D internal buffer 2 into AT45D internal page 'sector'  
}