⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lld.c

📁 Spansion 公司(原AMD flash 部门 / 富士通 闪存部门) FLASH 访问的参考函数
💻 C
📖 第 1 页 / 共 3 页
字号:
*
*
* RETURNS: void
*
* ERRNO: 
*/
#ifndef REMOVE_LLD_SECTI_SECTOR_EXIT_CMD
void lld_SecSiSectorExitCmd
(
FLASHDATA * base_addr               /* device base address in system */
)
{       
  
  /* Issue SecSi Sector Exit Command Sequence */
  FLASH_WR(base_addr, LLD_UNLOCK_ADDR1, NOR_UNLOCK_DATA1);
  FLASH_WR(base_addr, LLD_UNLOCK_ADDR2, NOR_UNLOCK_DATA2);

  /* First Secsi Sector Reset Command */
  FLASH_WR(base_addr, LLD_UNLOCK_ADDR1, NOR_SECSI_SECTOR_EXIT_SETUP_CMD);
  /* Second Secsi Sector Reset Command */
  FLASH_WR(base_addr, 0, NOR_SECSI_SECTOR_EXIT_CMD);

}
#endif
/******************************************************************************
* 
* lld_WriteToBufferCmd - Writes "Write to Buffer Pgm" Command sequence to Flash
*
*
* RETURNS: void
*
* ERRNO: 
*/
#ifndef REMOVE_WRITE_BUFFER_PROGRAMMING
void lld_WriteToBufferCmd
(
FLASHDATA * base_addr,               /* device base address in system */
ADDRESS offset                       /* address offset from base address */
)
{       
  /* Issue unlock command sequence */
  FLASH_WR(base_addr, LLD_UNLOCK_ADDR1, NOR_UNLOCK_DATA1);
  FLASH_WR(base_addr, LLD_UNLOCK_ADDR2, NOR_UNLOCK_DATA2);

  /* Write Write Buffer Load Command */
  FLASH_WR(base_addr, offset, NOR_WRITE_BUFFER_LOAD_CMD);
  
}
#endif
/******************************************************************************
* 
* lld_ProgramBufferToFlashCmd - Writes "Pgm Buffer To Flash" Cmd sequence to Flash
*
*
* RETURNS: void
*
* ERRNO: 
*/
#ifndef REMOVE_WRITE_BUFFER_PROGRAMMING
void lld_ProgramBufferToFlashCmd
(
FLASHDATA * base_addr,               /* device base address in system */
ADDRESS offset                       /* address offset from base address */
)
{       
  
  /* Transfer Buffer to Flash Command */
  FLASH_WR(base_addr, offset, NOR_WRITE_BUFFER_PGM_CONFIRM_CMD);
 
}
#endif
/******************************************************************************
* 
* lld_WriteBufferAbortResetCmd - Writes "Write To Buffer Abort" Reset to Flash
*
*
* RETURNS: void
*
* ERRNO: 
*/
#ifndef REMOVE_WRITE_BUFFER_PROGRAMMING
void lld_WriteBufferAbortResetCmd
(
FLASHDATA * base_addr        /* device base address in system */
)
{       
  
  /* Issue Write Buffer Abort Reset Command Sequence */
  FLASH_WR(base_addr, LLD_UNLOCK_ADDR1, NOR_UNLOCK_DATA1);
  FLASH_WR(base_addr, LLD_UNLOCK_ADDR2, NOR_UNLOCK_DATA2);

  /* Write to Buffer Abort Reset Command */
  FLASH_WR(base_addr, LLD_UNLOCK_ADDR1, NOR_WRITE_BUFFER_ABORT_RESET_CMD);  
  
}
#endif
/******************************************************************************
* 
* lld_ProgramSuspendCmd - Writes Suspend Command to Flash
*
*
* RETURNS: void
*
* ERRNO: 
*/
#ifndef REMOVE_LLD_PROGRAM_SUSPEND_CMD
void lld_ProgramSuspendCmd
(
FLASHDATA * base_addr,         /* device base address in system    */
ADDRESS offset                 /* address offset from base address */
)
{       
  
  /* Write Suspend Command */
  FLASH_WR(base_addr, offset, NOR_SUSPEND_CMD);

}
#endif
/******************************************************************************
* 
* lld_EraseSuspendCmd - Writes Suspend Command to Flash
*
*
* RETURNS: void
*
* ERRNO: 
*/
#ifndef REMOVE_LLD_ERASE_SUSPEND_CMD
void lld_EraseSuspendCmd
(
FLASHDATA * base_addr,       /* device base address in system    */
ADDRESS offset               /* address offset from base address */
)
{       
  
#ifdef PAUSE_BETWEEN_ERASE_SUSPENDS
  DELAY_MS(10);
#endif

  /* Write Suspend Command */
  FLASH_WR(base_addr, offset, NOR_SUSPEND_CMD);

}
#endif
/******************************************************************************
* 
* lld_EraseResumeCmd - Writes Resume Command to Flash
*
*
* RETURNS: void
*
* ERRNO: 
*/
#ifndef REMOVE_LLD_ERASE_RESUME_CMD
void lld_EraseResumeCmd
(
FLASHDATA * base_addr,       /* device base address in system    */
ADDRESS offset               /* address offset from base address */
)
{       

  /* Write Resume Command */
  FLASH_WR(base_addr, offset, NOR_RESUME_CMD);

}
#endif
/******************************************************************************
* 
* lld_ProgramResumeCmd - Writes Resume Command to Flash
*
*
* RETURNS: void
*
* ERRNO: 
*/
#ifndef REMOVE_LLD_PROGRAM_RESUME_CMD
void lld_ProgramResumeCmd
(
FLASHDATA * base_addr,       /* device base address in system    */
ADDRESS offset               /* address offset from base address */
)
{       

  /* Write Resume Command */
  FLASH_WR(base_addr, offset, NOR_RESUME_CMD);

}
#endif
/******************************************************************************
* 
* lld_CfiEntryCmd - Writes CFI Entry Command Sequence to Flash
*
*
* RETURNS: void
*
* ERRNO: 
*/
#ifndef REMOVE_LLD_CFI_ENTRY_CMD
void lld_CfiEntryCmd
(
FLASHDATA * base_addr /* device base address in system */
)
{       
 
  FLASH_WR(base_addr, LLD_UNLOCK_ADDR1, NOR_CFI_QUERY_CMD);

}
#endif
/******************************************************************************
* 
* lld_CfiExitCmd - Writes Cfi Exit Command Sequence to Flash
*
* This function resets the device out of CFI Query mode.
* This is a "wrapper function" to provide "Enter/Exit" symmetry in
* higher software layers.
*
*
* RETURNS: void
*
* ERRNO: 
*/
#ifndef REMOVE_LLD_CFI_EXIT_CMD
void lld_CfiExitCmd
(
FLASHDATA * base_addr   /* device base address in system */
)
{       

  lld_ResetCmd(base_addr);

}
#endif

#ifdef STATUS_REG
/******************************************************************************
* 
* wlld_StatusRegReadCmd - Status register read command
*
* This function sends the status register read command before actualy read it.
*
* RETURNS: void
*
* ERRNO: 
*/
#ifndef REMOVE_LLD_STATUS_REG_READ_CMD
void wlld_StatusRegReadCmd
(
FLASHDATA * base_addr,    /* device base address in system */
ADDRESS offset           /* address offset from base address */
)
{         
  FLASH_WR(base_addr, (offset & SA_OFFSET_MASK) + LLD_UNLOCK_ADDR1, NOR_STATUS_REG_READ_CMD); 
}
#endif

/******************************************************************************
* 
* wlld_StatusRegClearCmd - Status register clear command
*
* This function clear the status register. It will not clear the device operation 
* bits such as program suspend and erase suspend bits.
*
* RETURNS: void
*
* ERRNO: 
*/
#ifndef REMOVE_LLD_STATUS_REG_CLEAR_CMD
void wlld_StatusRegClearCmd
(
FLASHDATA * base_addr,   /* device base address in system */
ADDRESS offset           /* sector address offset from base address */
)
{         
  FLASH_WR(base_addr, (offset & SA_OFFSET_MASK) + LLD_UNLOCK_ADDR1, NOR_STATUS_REG_CLEAR_CMD); 
 }
#endif
#endif		/* STATUS_RESD */



/*====================================================================
| Section below are example operations that utilize the LLD drivers  |
| to interface to the flash device.                                  |
=====================================================================*/

/*************************************************************************
* 
* lld_Poll - Polls flash device for embedded operation completion
*
* Function polls the Flash device to determine when an embedded
*  operation has finished.  
*  Function performs a verify on the polling address if the device
*  returns from status routine in a non-busy/non-error state.
*
* <polling_type> variable is used to determine type of polling to perform.
*  This variable tells the status routine what mode the device is in.
*  Future versions of this function will also use the <polling_type>
*  variable to properly initialize and implement watchdog timers.
*  Acceptable values for <polling_type> are:
*   LLD_P_POLL_PGM 
*   LLD_P_POLL_WRT_BUF_PGM
*   LLD_P_POLL_SEC_ERS   
*   LLD_P_POLL_CHIP_ERS 
*
*
* RETURNS: DEVSTATUS
*
* ERRNO: 
*
*/
#ifndef REMOVE_LLD_POLL
DEVSTATUS lld_Poll
(
FLASHDATA * base_addr,          /* device base address in system */
ADDRESS offset,                 /* address offset from base address */
FLASHDATA *exp_data_ptr,        /* expect data */
FLASHDATA *act_data_ptr,        /* actual data */
POLLING_TYPE polling_type       /* type of polling to perform */
)
{       
  DEVSTATUS       dev_status;
  unsigned int    polling_counter = 0xFFFFFFFF;

#ifdef WAIT_4us_FOR_DATA_POLLING_BITS_TO_BECOME_ACTIVE
  DELAY_US(4);
#endif
  /* set the WriteBuffer flag if writebuffer operation */
  if (polling_type == LLD_P_POLL_WRT_BUF_PGM)
     WriteBufferProgramming = 1;
  else
     WriteBufferProgramming = 0;

  do
  {
    polling_counter--;
    dev_status = lld_StatusGet(base_addr, offset);
  }
  while((dev_status == DEV_BUSY) && polling_counter);
  
  /* reset the WriteBuffer flag */
  WriteBufferProgramming = 0;

  /* if device returns status other than "not busy" then we
     have a polling error state. */                
  if(dev_status != DEV_NOT_BUSY)
  {
    if(dev_status == DEV_WRITE_BUFFER_ABORT)
    {
#ifndef REMOVE_WRITE_BUFFER_PROGRAMMING
      lld_WriteBufferAbortResetCmd(base_addr);
#endif
    }
    else 
    {
      /* Issue software reset. */
      lld_ResetCmd(base_addr);
    }
    /* indicate to caller that there was an error */
    return(dev_status);
  }
  else 
  {
	 /* read the actual data */
	 *act_data_ptr = FLASH_RD(base_addr, offset);
 
	 /* Check that polling location verifies correctly */
	 if((*exp_data_ptr & LLD_DB_READ_MASK) == (*act_data_ptr & LLD_DB_READ_MASK))
	 {
	   dev_status = DEV_NOT_BUSY;
	   return(dev_status);
	 }
	 else 
	 {
	   dev_status = DEV_VERIFY_ERROR;
	   return(dev_status);
	 }
  }
}
#endif


#ifndef REMOVE_LLD_STATUS_GET
/******************************************************************************
*    
* lld_StatusGet - Determines Flash Status for GL-R device
*
* Note: This routine implements both (1) read status and check toggles (2)
*       use read status command(GL-R device). The enable_status_cmd_g 
*       flag switch between these two status get methods.
*       When calling this function, the WriteBufferProgramming flag needs
*       to be set to 1 if the caller wants to check DQ1 for WriteBuffer abort.
*       Then the flag needs to be set back to 0. See lld_poll for example of 
*       how to use the WriteBufferProgramming flag.
*
* RETURNS: DEVSTATUS
*
*/
#define DQ1_MASK   (0x02 * LLD_DEV_MULTIPLIER)  /* DQ1 mask for all interleave devices */
#define DQ2_MASK   (0x04 * LLD_DEV_MULTIPLIER)  /* DQ2 mask for all interleave devices */
#define DQ5_MASK   (0x20 * LLD_DEV_MULTIPLIER)  /* DQ5 mask for all interleave devices */
#define DQ6_MASK   (0x40 * LLD_DEV_MULTIPLIER)  /* DQ6 mask for all interleave devices */

#define DQ6_TGL_DQ1_MASK (dq6_toggles >> 5) /* Mask for DQ1 when device DQ6 toggling */
#define DQ6_TGL_DQ5_MASK (dq6_toggles >> 1) /* Mask for DQ5 when device DQ6 toggling */

DEVSTATUS lld_StatusGet
(
FLASHDATA *  base_addr,      /* device base address in system */
ADDRESS      offset          /* address offset from base address */
)
{

	FLASHDATA dq6_toggles;
	FLASHDATA status_read_1;
	FLASHDATA status_read_2;
	FLASHDATA status_read_3;


    if( enable_status_cmd_g == 0 )       /* Do not use Read Status Command */
	{
		status_read_1 = FLASH_RD(base_addr, offset);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -