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

📄 lh28f320bf.c

📁 在sharp 404开发板的串口测试代码
💻 C
📖 第 1 页 / 共 2 页
字号:

/***********************************************************************
*
*   Function : multi_word_write_sub
*
*   Input    : address      write address
*              data         write data pointer
*              word_count   write data count
*
*   Output   :
*
*   Revision : 1.0, 1999/11/29
*                   release
*
*   Content  : Write multi word data into the flash memory
*
************************************************************************/
void multi_word_write_sub(volatile UNS_16 *address, UNS_16 *data,
    int num_of_data)
{
    volatile UNS_16 *end_max_add;

    /* Multi write command setup */
    *address = CMD_MULTI_DATA_WRITE;

    /* Poll XSR until csr.7 = 1 (PageBuffer is not full) */
    while(!(*address & XSR_MULTI_WRITE_READY)) {
        *address = CMD_MULTI_DATA_WRITE;
    }

    /* Data size setup */
    *address = num_of_data - 1;

    /* Data setup */
    end_max_add = address + num_of_data;
    while(address < end_max_add) {
        *(address++) = *(data++);
    }

    /* Confirm command */
    *address = CMD_CONFIRM;
}

/********************************************************************
*
*   Function : write_suspend_to_read
*
*   Input    : address      read address
*              result       read data pointer
*
*   Output   : None
*
*   Revision : 1.0, 1998/08/26
*                   release
*
*   Content  : Word read while write suspend mode
*
*              In case of executing write suspend or resume command,
*	           that will be ignored when the write operation is completed.
*     	       Status register keeps status since write operation is executed.
*              Word write function of this driver does not 
*	           execute another task until function completes.
*              Therefore, when using this function, function call operation 
*	           must be described separately at WSM poling of erase function
*              part in word write function.
*
********************************************************************/
void write_suspend_to_read(volatile UNS_16 *address, UNS_16 *result)
{
    /* Word Write suspend command */
    *address = CMD_SUSPEND;

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

    /* if csr.2 = 1 (Word Write incomplete) */
    if(*address & CSR_WRITE_SUSPEND)
    {
        /* SUSPEND MODE */
        /* Read Flash Array command */
        *address = CMD_READ_ARRAY;
        /* Do the actual read */
        *result = *address;
        /* Word Write resume command */
        *address = CMD_RESUME;
    } else {
        /* WORD WRITE COMPLETED */
        /* Read Flash Array command */
        *address = CMD_READ_ARRAY;
        /* Do the actual read */
        *result = *address;
    }
}

/***********************************************************
*
*   Function : erase_suspend_to_read
*
*   Input    : address          read address
*              result           read data pointer
*
*   Output   : csr to be checked for status of operation
*
*   Revision : 1.0, 1998/08/26
*                   release
*
*   Content  : Word read while Erase suspend mode
*
*              In case of executing erase suspend or resume command,
*	           that will be ignored when the erase operation is completed.
*     	       Status register keeps status since erase operation is executed.
*              Word write function of this driver does not 
*	           execute another task until function completes.
*              Therefore, when using this function, function call operation 
*	           must be described separately at WSM poling of erase function
*              part in word write function.
*
**********************************************************/
void erase_suspend_to_read(volatile UNS_16 *address, UNS_16 *result)
{
    /* Erase Suspend cmmand */
    *address = CMD_SUSPEND;

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

    /* if csr.6 = 1 (erase incomplete) */
    if(*address & CSR_ERASE_SUSPEND)
    {
        /* SUSPEND MODE */
        /* Read Flash Array command */
        *address = CMD_READ_ARRAY;
        /* Do the actual read */
        *result = *address;
        /* Erase Resume command */
        *address = CMD_RESUME;
        /* Read csr comamnd */
        *address = CMD_READ_STATUS;
    } else {
        /* ERASE COMPLETED */
        /* Read Flash Array command */
        *address = CMD_READ_ARRAY;
        /* Do the actual read */
        *result = *address;
        /* Read csr comamnd */
        *address = CMD_READ_STATUS;
    }
}

/***************************************************************************
*
*   Function : csr_full_status_check
*
*   Input    : csr           value of status register
*
*   Output   : Error code
*               0 ERR_NO_ERROR
*               1 ERR_LOW_VPP
*               2 ERR_BLOCK_LOCKED
*               3 ERR_COMMAND_SEQ_ERROR
*               4 ERR_WP_LOW
*               5 ERR_WRITE
*               6 ERR_ERASE
*               7 ERR_WRITE_ERASING_BLOCK
*
*   Revision : 1.0, 1998/08/26
*                   release
*
*   Content  : Exchange csr value to Error Codes function
*
***************************************************************************/
int csr_full_status_check(UNS_16 csr)
{
    int errcode;

    if(csr & CSR_LOW_VPP)
    /* Vpp Low detect */
        errcode = ERR_LOW_VPP;
    else if(csr & CSR_DEVICE_PROTECT)
    /* Master Lock-bit, Block Lock-bit and/or RP# Lock Detected */
        errcode = ERR_BLOCK_LOCKED;
    else if((csr & CSR_WRITE_ERROR) && (csr & CSR_ERASE_ERROR))
    /* Mistake Command Sequence */ /* Program error check */
        errcode = ERR_COMMAND_SEQ_ERROR;
    else if((csr & CSR_WRITE_ERROR) && (csr & CSR_ERASE_SUSPEND))
    /* write error or Write data on Erasing Block */
        errcode = ERR_WRITE_ERASING_BLOCK;
    else if(csr & CSR_WRITE_ERROR)
    /* Write error */
        errcode = ERR_WRITE;
    else if(csr & CSR_ERASE_ERROR)
    /* Block erase error */
        errcode = ERR_ERASE;
    else
        errcode = ERR_NO_ERROR;

    return errcode;
}

/***************************************************************************
*
*   Function : read_id_codes
*
*   Input    : base_add         flash base address
*            : Maker_code       pointer of maker code
*            : Device_code      pointer of device code
*
*   Revision : 1.0, 1998/08/26
*                   release
*
*   Content  : Read device code and manufacturer code function
*
***************************************************************************/
void read_id_codes(volatile UNS_16 *base_add, UNS_16 *Maker_code, UNS_16 *Device_code)
{
    /* Read identifier codes command */
    *base_add = CMD_READ_ID_CODE;

    /* Store Maker code */
    *Maker_code = *base_add;

    /* Store Device code */
    *Device_code = *(base_add + ID_DEVICE_OFFSET);
}

/***************************************************************************
*
*   Function : check_id_codes
*
*   Input    : base_add         flash base address
*
*   Output   : OK(0),fail(-1)
*
*   Revision : 1.0, 1998/08/26
*                   release
*
*   Content  : Check device code and manufacturer code function
*
*              If Both values confirm defines, then return "0",
*	           else return "-1".
*
***************************************************************************/
int check_id_codes(volatile UNS_16 *base_add)
{

    /* Read identifier codes command */
    *base_add = CMD_READ_ID_CODE;

    /* check identifier codes */
    if( (ID_MAKER_CODE  == *base_add)
      &&(ID_DEVICE_CODE == *(base_add + ID_DEVICE_OFFSET)) )
    {
        return 0;
    } else {
        return -1;
    }
}

/***************************************************************************
*
*   Function : read_block_info
*
*   Input    : block_add         flash block base address
*
*   Output   : status bit
*
*   Revision : 1.0, 2001/03/29
*                   release
*
*   Content  : Read block lock bit and block lockdown bit
*
***************************************************************************/
UNS_16 read_block_info(volatile UNS_16 *block_add)
{

    /* Read identifier codes command */
    *block_add = CMD_READ_ID_CODE;

    /* check block lock bit & block lockdown bit */
    return *(block_add + ID_BLOCK_OFFSET);
}

/***************************************************************************
*
*   Function : set_pcr
*
*   Input    : base_add      flash base address
*              pcv           partition configuration value [0-7]
*
*   Output   :
*
*   Revision : 1.0, 2001/03/29
*                   release
*
*   Content  : Set partition configuration register
*
***************************************************************************/
void set_pcr(UNS_16 *base_add, int pcv)
{
    volatile UNS_16 *pcrc;

    pcrc = base_add + (pcv<<8);//(pcrc<<8);

    /* Set partition configuration register setup command */
    *pcrc = CMD_SET_PCR;
    /* Set confirm command */
    *pcrc = CMD_PCR_CONFIRM;
}

/***************************************************************************
*
*   Function : read_pcr_info
*
*   Input    : base_add      flash base address
*
*   Output   : partition configuration value [0-7]
*
*   Revision : 1.0, 2001/03/29
*                   release
*
*   Content  : Read partition configuration register
*
***************************************************************************/
int read_pcr_info(UNS_16 *base_add, UNS_16 *block_add)
{
    int pcv;

    /* Read identifier codes command */
    *base_add = CMD_READ_ID_CODE;

    pcv = ((*(block_add + ID_PCR_OFFSET))>>8) & 0x07;

    /* check partition configuration register */
    return pcv;
}

⌨️ 快捷键说明

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