📄 lld_wsxxx_asp.c
字号:
/* lld_wsxxx.asp.c - Source Code for Spansion's Advance Sector Protection 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"
#include "lld_wsxxx_asp.h"
#define WSXXX_LOCK_REG_ENTRY (0x40*LLD_DEV_MULTIPLIER)
#define WSXXX_PSWD_PROT_CMD_ENTRY (0x60*LLD_DEV_MULTIPLIER)
#define WSXXX_PSWD_UNLOCK_1 (0x25*LLD_DEV_MULTIPLIER)
#define WSXXX_PSWD_UNLOCK_2 (0x03*LLD_DEV_MULTIPLIER)
#define WSXXX_PSWD_UNLOCK_3 (0x29*LLD_DEV_MULTIPLIER)
#define WSXXX_PPB_ENTRY (0xC0*LLD_DEV_MULTIPLIER)
#define WSXXX_PPB_ERASE_CONFIRM (0x30*LLD_DEV_MULTIPLIER)
#define WSXXX_PPB_LOCK_ENTRY (0x50*LLD_DEV_MULTIPLIER)
#define WSXXX_DYB_ENTRY (0xE0*LLD_DEV_MULTIPLIER)
#define WSXXX_DYB_CLEAR (0x01*LLD_DEV_MULTIPLIER)
/* WSxxx Commands */
/******************************************************************************
*
* lld_LockRegEntryCmd - Lock register entry command.
*
* RETURNS: n/a
*
*/
void lld_LockRegEntryCmd
(
FLASHDATA * base_addr /* device base address in system */
)
{
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, WSXXX_LOCK_REG_ENTRY);
}
/******************************************************************************
*
* lld_LockRegBitsProgramCmd - Lock register program command.
*
* RETURNS: n/a
*
*/
void lld_LockRegBitsProgramCmd
(
FLASHDATA * base_addr, /* device base address in system */
FLASHDATA value /* value to program to lock reg. */
)
{
FLASH_WR(base_addr, 0, NOR_UNLOCK_BYPASS_PROGRAM_CMD);
FLASH_WR(base_addr, 0x77, value);
}
/******************************************************************************
*
* lld_LockRegBitsReadCmd - Lock register read command.
* Note: Need to issue lld_LockRegEntryCmd() before use this routine.
*
* RETURNS:
* DQ0 Customer SecSi Sector Protection Bit 0 = set
* DQ1 Persistent Protection Mode Lock Bit 0 = set
* DQ2 Password Protection Mode Lock Bit 0 = set
*
*/
FLASHDATA lld_LockRegBitsReadCmd
(
FLASHDATA * base_addr /* device base address in system */
)
{
return(FLASH_RD(base_addr, 0x77));
}
/******************************************************************************
*
* lld_LockRegExitCmd - Exit lock register read/write mode command.
*
* RETURNS: n/a
*
*/
void lld_LockRegExitCmd
(
FLASHDATA * base_addr /* device base address in system */
)
{
FLASH_WR(base_addr, 0, NOR_SECSI_SECTOR_EXIT_SETUP_CMD);
FLASH_WR(base_addr, 0, NOR_SECSI_SECTOR_EXIT_CMD);
}
#ifndef REMOVE_ASP_PASSWORD
/******************************************************************************
*
* lld_PasswordProtectionEntryCmd - Write Password Protection Entry command sequence
*
* RETURNS: n/a
*
*/
void lld_PasswordProtectionEntryCmd
(
FLASHDATA * base_addr /* device base address in system */
)
{
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, WSXXX_PSWD_PROT_CMD_ENTRY);
}
/******************************************************************************
*
* lld_PasswordProtectionProgramCmd - Write Password Protection Program command.
* Note: Need to issue lld_PasswordProtectionEntryCmd() before issue this routine.
* RETURNS: n/a
*
*/
void lld_PasswordProtectionProgramCmd
(
FLASHDATA * base_addr, /* device base address in system */
ADDRESS offset,
FLASHDATA pwd
)
{
FLASH_WR(base_addr, offset, NOR_UNLOCK_BYPASS_PROGRAM_CMD);
FLASH_WR(base_addr, offset, pwd);
}
/******************************************************************************
*
* lld_PasswordProtectionReadCmd - Issue read password command
* Note: Need to issue lld_PasswordProtectionEntryCmd() before issue this routine.
* RETURNS: n/a
*
*/
void lld_PasswordProtectionReadCmd
(
FLASHDATA * base_addr, /* device base address in system */
FLASHDATA *pwd0,
FLASHDATA *pwd1,
FLASHDATA *pwd2,
FLASHDATA *pwd3
)
{
*pwd0 = FLASH_RD(base_addr, 0);
*pwd1 = FLASH_RD(base_addr, 1);
*pwd2 = FLASH_RD(base_addr, 2);
*pwd3 = FLASH_RD(base_addr, 3);
}
/******************************************************************************
*
* lld_PasswordProtectionUnlockCmd - Issue unlock password command.
* Note: Need to issue lld_PasswordProtectionEntryCmd() before issue this routine.
* RETURNS: n/a
*
*/
void lld_PasswordProtectionUnlockCmd
(
FLASHDATA * base_addr, /* device base address in system */
FLASHDATA pwd0,
FLASHDATA pwd1,
FLASHDATA pwd2,
FLASHDATA pwd3
)
{
FLASH_WR(base_addr, 0, WSXXX_PSWD_UNLOCK_1);
FLASH_WR(base_addr, 0, WSXXX_PSWD_UNLOCK_2);
FLASH_WR(base_addr, 0, pwd0);
FLASH_WR(base_addr, 1, pwd1);
FLASH_WR(base_addr, 2, pwd2);
FLASH_WR(base_addr, 3, pwd3);
FLASH_WR(base_addr, 0, WSXXX_PSWD_UNLOCK_3);
}
/******************************************************************************
*
* lld_PasswordProtectionExitCmd - Issue exit password protection mode command.
*
* RETURNS: n/a
*
*/
void lld_PasswordProtectionExitCmd
(
FLASHDATA * base_addr /* device base address in system */
)
{
FLASH_WR(base_addr, 0, NOR_SECSI_SECTOR_EXIT_SETUP_CMD);
FLASH_WR(base_addr, 0, NOR_SECSI_SECTOR_EXIT_CMD);
}
#endif /* REMOVE_ASP_PASSWORD */
#ifndef REMOVE_ASP_PPB
/******************************************************************************
*
* lld_PpbEntryCmd - Non-Volatile Sector Protection Entry Command.
* Ppb entry command will disable the reads and writes for the bank selectd.
* RETURNS: n/a
*
*/
void lld_PpbEntryCmd
(
FLASHDATA * base_addr, /* device base address in system */
ADDRESS offset
)
{
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+(offset & SA_OFFSET_MASK), WSXXX_PPB_ENTRY);
}
/******************************************************************************
*
* lld_PpbProgramCmd - Program Non-Volatile Sector Protection Command.
* Note: Need to issue lld_PpbEntryCmd() before issue this routine.
* RETURNS: n/a
*
*/
void lld_PpbProgramCmd
(
FLASHDATA * base_addr, /* device base address in system */
ADDRESS offset /* Sector offset address */
)
{
FLASH_WR(base_addr, 0, NOR_UNLOCK_BYPASS_PROGRAM_CMD);
FLASH_WR(base_addr, offset, 0);
}
/******************************************************************************
*
* lld_PpbAllEraseCmd - Erase Non-Volatile Protection for All Sectors Command.
* Note: Need to issue lld_PpbEntryCmd() before issue this routine.
* RETURNS: n/a
*
*/
void lld_PpbAllEraseCmd
(
FLASHDATA * base_addr /* device base address in system */
)
{
FLASH_WR(base_addr, 0, NOR_ERASE_SETUP_CMD);
FLASH_WR(base_addr, 0, WSXXX_PPB_ERASE_CONFIRM);
}
/******************************************************************************
*
* lld_PpbStatusReadCmd - Read Non-Volatile Sector Status Command.
* Note: Need to issue lld_PpbEntryCmd() before issue this routine.
* Sector status 0 is locked and 1 is unlocked.
* RETURNS:
*
*/
FLASHDATA lld_PpbStatusReadCmd
(
FLASHDATA * base_addr, /* device base address in system */
ADDRESS offset /* sector offset address */
)
{
return(FLASH_RD(base_addr, offset));
}
/******************************************************************************
*
* lld_PpbExitCmd - Exit the Non-Volatile Sector Status mode.
* After the exit command the device goes back to memory array mode.
* RETURNS: n/a
*
*/
void lld_PpbExitCmd
(
FLASHDATA * base_addr /* device base address in system */
)
{
FLASH_WR(base_addr, 0, NOR_SECSI_SECTOR_EXIT_SETUP_CMD);
FLASH_WR(base_addr, 0, NOR_SECSI_SECTOR_EXIT_CMD);
}
#endif /* REMOVE_ASP_PPB */
#ifndef REMOVE_ASP_PPB_LOCK_BIT
/******************************************************************************
*
* lld_PpbLockBitEntryCmd - Issue Persistent Protection Bit Lock Bit Entry Command.
* The Ppb Lock Bit is a global bit for all sectors.
* RETURNS: n/a
*
*/
void lld_PpbLockBitEntryCmd
(
FLASHDATA * base_addr /* device base address in system */
)
{
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, WSXXX_PPB_LOCK_ENTRY);
}
/******************************************************************************
*
* lld_PpbLockBitSetCmd - Issue set Persistent Protection Bit Lock Bit command.
* Once bit is set there is no command to unset it only hardware reset and power up
* will clear the bit.
* RETURNS: n/a
*
*/
void lld_PpbLockBitSetCmd
(
FLASHDATA * base_addr /* device base address in system */
)
{
FLASH_WR(base_addr, 0, NOR_UNLOCK_BYPASS_PROGRAM_CMD);
FLASH_WR(base_addr, 0, 0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -