📄 lld.c
字号:
/* lld.c - Source Code for Spansion's Low Level Driver */
/* v7.2.0 */
/**************************************************************************
* Copyright (C)2007 Spansion LLC. All Rights Reserved .
*
* This software is owned and published by:
* Spansion LLC, 915 DeGuigne Dr. Sunnyvale, CA 94088-3453 ("Spansion").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software constitutes driver source code for use in programming Spansion's
* Flash memory components. This software is licensed by Spansion to be adapted only
* for use in systems utilizing Spansion's Flash memories. Spansion is not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. Spansion is providing this source code "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the source code herein.
*
* SPANSION MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE, ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED
* USE, INCLUDING, WITHOUT LIMITATION, NO IMPLIED WARRANTY OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE OR USE, OR NONINFRINGEMENT. SPANSION WILL
* HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT, NEGLIGENCE OR
* OTHERWISE) FOR ANY DAMAGES ARISING FROM USE OR INABILITY TO USE THE SOFTWARE,
* INCLUDING, WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA, SAVINGS OR PROFITS,
* EVEN IF SPANSION HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Copyright notice must be included with
* this software, whether used in part or whole, at all times.
*/
#include "lld.h"
unsigned int WriteBufferProgramming = 0;
/*
This global variable is set by command line 'EnableStatusCmd'
to switch to use status register read cmd to do polling for GL-R
device in run time.
*/
unsigned int enable_status_cmd_g = 0;
/* private functions */
/* Public Functions */
/******************************************************************************
*
* lld_ResetCmd - Writes a Software Reset command to the flash device
*
*
* RETURNS: void
*
* ERRNO:
*/
void lld_ResetCmd
(
FLASHDATA * base_addr /* device base address in system */
)
{
/* Write Software RESET command */
FLASH_WR(base_addr, 0, NOR_RESET_CMD);
}
#ifndef WS_P_CR1
/******************************************************************************
*
* lld_SetConfigRegCmd - Set configuration register command
*
* RETURNS: n/a
*/
void lld_SetConfigRegCmd
(
FLASHDATA * base_addr, /* device base address in system */
FLASHDATA value
)
{
FLASH_WR(base_addr, LLD_UNLOCK_ADDR1, NOR_UNLOCK_DATA1);
FLASH_WR(base_addr, LLD_UNLOCK_ADDR2, NOR_UNLOCK_DATA2);
FLASH_WR(base_addr, LLD_UNLOCK_ADDR1, NOR_SET_CONFIG_CMD);
FLASH_WR(base_addr, 0, value);
}
/******************************************************************************
*
* lld_ReadConfigRegCmd - Read configuration register command.
*
* RETURNS: config register
*
*/
FLASHDATA lld_ReadConfigRegCmd
(
FLASHDATA * base_addr /* device base address in system */
)
{
UINT16 u16Val;
FLASH_WR(base_addr, LLD_UNLOCK_ADDR1, NOR_UNLOCK_DATA1);
FLASH_WR(base_addr, LLD_UNLOCK_ADDR2, NOR_UNLOCK_DATA2);
FLASH_WR(base_addr, LLD_UNLOCK_ADDR1, NOR_READ_CONFIG_CMD);
return(FLASH_RD(base_addr, 0));
}
#else /* For WS-P device Configuration Reg. 1 is used to set wait states */
/******************************************************************************
*
* lld_SetConfigRegCmd - Set configuration register command for WS-P device.
* WS-P type device uses config. reg. 1 to set wait state.
* RETURNS: n/a
*/
void lld_SetConfigRegCmd
(
FLASHDATA * base_addr, /* device base address in system */
FLASHDATA value, /* Configuration Register 0 value */
FLASHDATA value1 /* Configuration Register 1 value */
)
{
FLASH_WR(base_addr, LLD_UNLOCK_ADDR1, NOR_UNLOCK_DATA1);
FLASH_WR(base_addr, LLD_UNLOCK_ADDR2, NOR_UNLOCK_DATA2);
FLASH_WR(base_addr, LLD_UNLOCK_ADDR1, NOR_SET_CONFIG_CMD);
FLASH_WR(base_addr, 0, value); /* configuration register 0 */
FLASH_WR(base_addr, 1, value1); /* configuration register 1 */
}
/******************************************************************************
*
* lld_ReadConfigRegCmd - Read configuration register command.
*
* RETURNS: config register
*
*/
FLASHDATA lld_ReadConfigRegCmd
(
FLASHDATA * base_addr, /* device base address in system */
FLASHDATA offset /* configuration reg. offset 0/1 */
)
{
FLASH_WR(base_addr, LLD_UNLOCK_ADDR1, NOR_UNLOCK_DATA1);
FLASH_WR(base_addr, LLD_UNLOCK_ADDR2, NOR_UNLOCK_DATA2);
FLASH_WR(base_addr, LLD_UNLOCK_ADDR1, NOR_READ_CONFIG_CMD);
return(FLASH_RD(base_addr, offset));
}
#endif
/******************************************************************************
*
* lld_SectorEraseCmd - Writes a Sector Erase Command to Flash Device
*
* This function only issues the Sector Erase Command sequence.
* Erase status polling is not implemented in this function.
*
*
* RETURNS: void
*
* ERRNO:
*/
#ifndef REMOVE_LLD_SECTOR_ERASE_CMD
void lld_SectorEraseCmd
(
FLASHDATA * base_addr, /* device base address in system */
ADDRESS offset /* address offset from base address */
)
{
/* Issue Sector Erase Command Sequence */
FLASH_WR(base_addr, LLD_UNLOCK_ADDR1, NOR_UNLOCK_DATA1);
FLASH_WR(base_addr, LLD_UNLOCK_ADDR2, NOR_UNLOCK_DATA2);
FLASH_WR(base_addr, LLD_UNLOCK_ADDR1, NOR_ERASE_SETUP_CMD);
FLASH_WR(base_addr, LLD_UNLOCK_ADDR1, NOR_UNLOCK_DATA1);
FLASH_WR(base_addr, LLD_UNLOCK_ADDR2, NOR_UNLOCK_DATA2);
/* Write Sector Erase Command to Offset */
FLASH_WR(base_addr, offset, NOR_SECTOR_ERASE_CMD);
}
#endif
/******************************************************************************
*
* lld_ChipEraseCmd - Writes a Chip Erase Command to Flash Device
*
* This function only issues the Chip Erase Command sequence.
* Erase status polling is not implemented in this function.
*
*
* RETURNS: void
*
* ERRNO:
*/
#ifndef REMOVE_LLD_CHIP_ERASE_CMD
void lld_ChipEraseCmd
(
FLASHDATA * base_addr /* device base address in system */
)
{
/* Issue Chip Erase Command Sequence */
FLASH_WR(base_addr, LLD_UNLOCK_ADDR1, NOR_UNLOCK_DATA1);
FLASH_WR(base_addr, LLD_UNLOCK_ADDR2, NOR_UNLOCK_DATA2);
FLASH_WR(base_addr, LLD_UNLOCK_ADDR1, NOR_ERASE_SETUP_CMD);
FLASH_WR(base_addr, LLD_UNLOCK_ADDR1, NOR_UNLOCK_DATA1);
FLASH_WR(base_addr, LLD_UNLOCK_ADDR2, NOR_UNLOCK_DATA2);
/* Write Chip Erase Command to Base Address */
FLASH_WR(base_addr, LLD_UNLOCK_ADDR1, NOR_CHIP_ERASE_CMD);
}
#endif
/******************************************************************************
*
* lld_ProgramCmd - Writes a Program Command to Flash Device
*
* This function only issues the Program Command sequence.
* Progran status polling is not implemented in this function.
*
*
* RETURNS: void
*
* ERRNO:
*/
#ifndef REMOVE_LLD_PROGRAM_CMD
void lld_ProgramCmd
(
FLASHDATA * base_addr, /* device base address in system */
ADDRESS offset, /* address offset from base address */
FLASHDATA *pgm_data_ptr /* variable containing data to program */
)
{
FLASH_WR(base_addr, LLD_UNLOCK_ADDR1, NOR_UNLOCK_DATA1);
FLASH_WR(base_addr, LLD_UNLOCK_ADDR2, NOR_UNLOCK_DATA2);
/* Write Program Command */
FLASH_WR(base_addr, LLD_UNLOCK_ADDR1, NOR_PROGRAM_CMD);
/* Write Data */
FLASH_WR(base_addr, offset, *pgm_data_ptr);
}
#endif
/******************************************************************************
*
* lld_UnlockBypassEntryCmd - Writes Unlock Bypass Enter command to flash
*
*
* RETURNS: void
*
* ERRNO:
*/
#ifndef REMOVE_LLD_UNLOCK_BYPASS_ENTRY_CMD
void lld_UnlockBypassEntryCmd
(
FLASHDATA * base_addr /* device base address in system */
)
{
/* Issue Unlock Bypass Enter Command Sequence */
FLASH_WR(base_addr, LLD_UNLOCK_ADDR1, NOR_UNLOCK_DATA1);
FLASH_WR(base_addr, LLD_UNLOCK_ADDR2, NOR_UNLOCK_DATA2);
FLASH_WR(base_addr, LLD_UNLOCK_ADDR1, NOR_UNLOCK_BYPASS_ENTRY_CMD);
}
#endif
/******************************************************************************
*
* lld_UnlockBypassProgramCmd - Writes Unlock Bypass Pgm Sequence to Flash
*
* This function issues the Unlock Bypass Programming Sequence to device.
* Device must be in Unlock Bypass mode before using this function.
* Status polling is not implemented in this function.
*
*
* RETURNS: void
*
* ERRNO:
*/
#ifndef REMOVE_LLD_UNLOCK_BYPASS_PROGRAM_CMD
void lld_UnlockBypassProgramCmd
(
FLASHDATA * base_addr, /* device base address in system */
ADDRESS offset, /* address offset from base address */
FLASHDATA *pgm_data_ptr /* variable containing data to program */
)
{
/* Issue Unlock Bypass Program Command Sequence */
/* Write Program Command */
FLASH_WR(base_addr, LLD_UNLOCK_ADDR1, NOR_PROGRAM_CMD);
/* Write Data */
FLASH_WR(base_addr, offset, *pgm_data_ptr);
}
#endif
/******************************************************************************
*
* lld_UnlockBypassResetCmd - Writes Unlock Bypass Exit command to flash
*
* Issues Unlock Bypass Exit command sequence to Flash Device.
*
*
* RETURNS: void
*
* ERRNO:
*/
#ifndef REMOVE_LLD_UNLOCK_BYPASS_RESET_CMD
void lld_UnlockBypassResetCmd
(
FLASHDATA * base_addr /* device base address in system */
)
{
/* Issue Unlock Bypass Exit Command Sequence */
/* First Unlock Bypass Reset Command */
FLASH_WR(base_addr, 0, NOR_UNLOCK_BYPASS_RESET_CMD1);
/* Second Unlock Bypass Reset Command */
FLASH_WR(base_addr, 0, NOR_UNLOCK_BYPASS_RESET_CMD2);
}
#endif
/******************************************************************************
*
* lld_AutoselectEntryCmd - Writes Autoselect Command Sequence to Flash
*
* This function issues the Autoselect Command Sequence to device.
*
*
* RETURNS: void
*
* ERRNO:
*/
#ifndef REMOVE_LLD_AUTOSELECT_ENTRY_CMD
void lld_AutoselectEntryCmd
(
FLASHDATA * base_addr /* device base address in system */
)
{
/* Issue Autoselect Command Sequence */
FLASH_WR(base_addr, LLD_UNLOCK_ADDR1, NOR_UNLOCK_DATA1);
FLASH_WR(base_addr, LLD_UNLOCK_ADDR2, NOR_UNLOCK_DATA2);
FLASH_WR(base_addr, LLD_UNLOCK_ADDR1, NOR_AUTOSELECT_CMD);
}
#endif
/******************************************************************************
*
* lld_AutoselectExitCmd - Writes Autoselect Exit Command Sequence to Flash
*
* This function resets the device out of Autoselect mode.
* This is a "wrapper function" to provide "Enter/Exit" symmetry in
* higher software layers.
*
*
* RETURNS: void
*
* ERRNO:
*/
#ifndef REMOVE_LLD_AUTOSELECT_EXIT_CMD
void lld_AutoselectExitCmd
(
FLASHDATA * base_addr /* device base address in system */
)
{
lld_ResetCmd(base_addr);
}
#endif
/******************************************************************************
*
* lld_SecSiSectorEntryCmd - Writes SecSi Sector Entry Command Sequence to Flash
*
* This function issues the Secsi Sector Entry Command Sequence to device.
* Use this function to Enable the SecSi Sector.
*
*
* RETURNS: void
*
* ERRNO:
*/
#ifndef REMOVE_LLD_SECSI_SECTOR_ENTRY_CMD
void lld_SecSiSectorEntryCmd
(
FLASHDATA * base_addr /* device base address in system */
)
{
/* Issue SecSi Sector Entry Command Sequence */
FLASH_WR(base_addr, LLD_UNLOCK_ADDR1, NOR_UNLOCK_DATA1);
FLASH_WR(base_addr, LLD_UNLOCK_ADDR2, NOR_UNLOCK_DATA2);
FLASH_WR(base_addr, LLD_UNLOCK_ADDR1, NOR_SECSI_SECTOR_ENTRY_CMD);
}
#endif
/******************************************************************************
*
* lld_SecSiSectorExitCmd - Writes SecSi Sector Exit Command Sequence to Flash
*
* This function issues the Secsi Sector Exit Command Sequence to device.
* Use this function to Exit the SecSi Sector.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -