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

📄 lh28f320bf.c

📁 在sharp 404开发板的串口测试代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/***********************************************************************
 * $Workfile:   LH28F320BF.c  $
 * $Revision:   1.0  $
 * $Author:   WellsK  $
 * $Date:   Apr 22 2002 13:49:32  $
 *
 * Project:  LH28F320BFE-PBTL80 Driver
 *
 * Description:
 *   This module contains a driver for accessing the Sharp 
 *   LH28F320BFE-PBTL80 2Mbit X 16 flash device.
 *
 * Notes: 
 *   This source code contains functions copied from older modules.
 *   Original revision information for the functions are noted in the
 *   Function headers, but any changes to these functions should be
 *   noted from the revision history log, below:
 *
 * $Log:   //smaicnt2/pvcs/VM/CHIPS/archives/Tools/Flash/LH28F320BF.c-arc  $
 * 
 *    Rev 1.0   Apr 22 2002 13:49:32   WellsK
 * Initial revision.
 * 
 *
 *  COPYRIGHT (C) 2001  SHARP MICROELECTRONICS OF THE AMERICAS INC.
 *                         CAMAS, WA
 *********************************************************************/
#include "LH28F320BF.h"
/***************************************************************************
*
*   Function : read_array
*
*   Input    : address      flash address
*
*   Revision : 1.0, 1998/08/26
*                   release
*
*   Content  : Change read array mode
*
***************************************************************************/
void read_array(UNS_16 *address)
{
   *address = CMD_READ_ARRAY;
}

/********************************************************************
*
*   Function : word_write
*
*   Input    : address      write address
*              data         write data
*
*   Output   : csr to be checked for status of operation
*
*   Revision : 1.0, 1998/08/26
*                   release
*
*   Content  : Word write function
*
*	       In this function, after Word/Byte write command 
*              executes, operation idles until WSM is ready.
*	       Then function returns csr value.
*
********************************************************************/
UNS_16 word_write(volatile UNS_16 *address, UNS_16 data)
{
    UNS_16 csr;

    /* Actual data write to flash address */
    *address = CMD_DATA_WRITE;
    *address = data;

    /* Read Status Registers command */
    *address = CMD_READ_STATUS;
    /* Poll csr until csr.7 = 1 (WSM ready) */
    while(!(*address & CSR_WSM_STATUS_READY))    
    {
        /* System may issue an write suspend command (B0[B0])
           here to read data from a different address. */
    }

    /* Save csr before clearing it */
    csr = *address;
    /* Clear Status Registers command */
    *address = CMD_CLEAR_STATUS;

    /* Return csr to be checked for status of operation. */
    return csr;
}

/***************************************************************************
*
*   Function : block_erase
*
*   Input    : address       address of Erase Block
*
*   Output   : csr to be checked for status of operation
*
*   Revision : 1.0, 1998/08/26
*                   release
*
*   Content  : Block erase function 
*
***************************************************************************/
UNS_16 block_erase(volatile UNS_16 *address)
{
    UNS_16 csr;

    /* Single Block Erase command */
    *address = CMD_BLOCK_ERASE;
    /* Confirm command */
    *address = CMD_CONFIRM;

    /* Read csr comamnd */
    *address = CMD_READ_STATUS;
    /* Poll csr until csr.7 = 1 (WSM ready) */
    while(!(*address & CSR_WSM_STATUS_READY))
    {
        /* System may issue an erase suspend command (B0[B0])
           here to read data from a different block. */
    }

    /* Save csr before clearing it */
    csr = *address;
    /* Clear csr command */
    *address = CMD_CLEAR_STATUS;

    /* Return csr to be checked for status of operation. */
    return csr;
}

/***************************************************************************
*
*   Function : all_block_erase
*
*   Input    : address      flash address
*
*   Output   : csr to be checked for status of operation
*
*   Revision : 1.0, 1998/08/26
*                   release
*
*   Content  : Full chip erase function
*
*              All unlocked blocks are erased.
*
***************************************************************************/
UNS_16 all_block_erase(volatile UNS_16 *address)
{
    UNS_16 csr;

    /* All block erase command */
    *address = CMD_FULL_CHIP_ERASE;
    /* Confirm command */
    *address = CMD_CONFIRM;

    /* Read csr comamnd */
    *address = CMD_READ_STATUS;
    /* Poll csr until csr.7 = 1 (WSM ready) */
    while(!(*address & CSR_WSM_STATUS_READY))
    {
        /* System may issue an erase suspend command (B0[B0])
           here to read data from a different block. */
    }

    /* Save csr before clearing it */
    csr = *address;
    /* Clear csr command */
    *address = CMD_CLEAR_STATUS;

    /* Return csr to be checked for status of operation. */
    return csr;
}

/***************************************************************************
*
*   Function : set_block_lock
*
*   Input    : address      lock address
*
*   Output   : csr to be checked for status of operation
*
*   Revision : 1.0, 2001/03/29
*                   release
*
*   Content  : Set block lock bit function
*
***************************************************************************/
UNS_16 set_block_lock(volatile UNS_16 *address)
{
    UNS_16 csr;

    /* Set block lock-bit setup command */
    *address = CMD_BLOCK_LOCK;
    /* Set block lock-bit confirm command */
    *address = CMD_SET_LOCKBIT;

    /* Read csr comamnd */
    *address = CMD_READ_STATUS;
    /* Save csr before clearing it */
    csr = *address;

    /* Clear csr command */
    *address = CMD_CLEAR_STATUS;

    /* Return csr to be checked for status of operation. */
    return csr;
}

/***************************************************************************
*
*   Function : clear_block_lock
*
*   Input    : address      flash address
*
*   Output   : csr to be checked for status of operation
*
*   Revision : 1.0, 2001/03/29
*                   release
*
*   Content  : Clear block lock bit function
*
***************************************************************************/
UNS_16 clear_block_lock(volatile UNS_16 *address)
{
    UNS_16 csr;

    /* Set block lock-bit setup command */
    *address = CMD_BLOCK_LOCK;
    /* Clr block lock-bit confirm command */
    *address = CMD_RESET_LOCKBIT;

    /* Read csr comamnd */
    *address = CMD_READ_STATUS;
    /* Save csr before clearing it */
    csr = *address;

    /* Clear csr command */
    *address = CMD_CLEAR_STATUS;

    /* Return csr to be checked for status of operation. */
    return csr;
}

/***************************************************************************
*
*   Function : set_block_lockdown
*
*   Input    : address      lockdown address
*
*   Output   : csr to  be checked for status of operation
*
*   Revision : 1.0, 2001/03/29
*                   release
*
*   Content  : Set block lockdown bit
*
***************************************************************************/
UNS_16 set_block_lockdown(volatile UNS_16 *address)
{
    UNS_16 csr;

    /* Set block lock-bit setup command */
    *address = CMD_BLOCK_LOCK;
    /* Set block lock-bit confirm command */
    *address = CMD_SET_LOCKDOWNBIT;

    /* Read csr comamnd */
    *address = CMD_READ_STATUS;
    /* Save csr before clearing it */
    csr = *address;

    /* Clear csr command */
    *address = CMD_CLEAR_STATUS;

    /* Return csr to be checked for status of operation. */
    return csr;
}

/***********************************************************************
*
*   Function : multi_word_write
*
*   Input    : address       write address
*              data          write data pointer
*              num_of_data   write data count
*
*   Output   : csr to be checked for status of operation
*
*   Revision : 1.0, 1999/12/29
*                   release
*
*   Content  : Write multi word data into the flash memory
*
************************************************************************/
UNS_16 multi_word_write(volatile UNS_16 *address, UNS_16 *data,
    int num_of_data)
{
    UNS_16 csr;              /* csr data */
    volatile UNS_16 *tmp_add;         /* work address */
    int cnt_data;           /* data counter*/

    tmp_add = address;
    cnt_data = (MAX_MULTI_WRITE_NUM - ((int)tmp_add & MASK_MULTI_WRITE) / sizeof(UNS_16));

    if( 0 != cnt_data ){
        //multi_word_byte_write_sub(tmp_add, data, cnt_data);
        multi_word_write_sub(tmp_add, data, cnt_data);
        tmp_add += cnt_data;
        data += cnt_data;
    }

    while(cnt_data + MAX_MULTI_WRITE_NUM <= num_of_data){
        //multi_word_byte_write_sub(tmp_add, data, MAX_MULTI_WRITE_NUM);
        multi_word_write_sub(tmp_add, data, MAX_MULTI_WRITE_NUM);
        tmp_add += MAX_MULTI_WRITE_NUM;
        data += MAX_MULTI_WRITE_NUM;
        cnt_data += MAX_MULTI_WRITE_NUM;
    }

    cnt_data = num_of_data - cnt_data;
    if(0 < cnt_data)
        //multi_word_byte_write_sub(tmp_add, data, cnt_data);
        multi_word_write_sub(tmp_add, data, cnt_data);


    /* Read csr comamnd */
    *address = CMD_READ_STATUS;
    /* Poll csr until csr.7 = 1 (WSM ready) */
    while(!(*address & CSR_WSM_STATUS_READY))
    ;

    /* Store csr data */
    csr = *address;
    /* Clear csr command */
    *address = CMD_CLEAR_STATUS;

    /* Return csr to  be checked for status of operation. */
    return csr;
}

⌨️ 快捷键说明

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