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

📄 davincievm_flash_erase.c

📁 TI的DM6446的硬件平台搭建的相关例子
💻 C
字号:
/*
 *  Copyright 2005 by Spectrum Digital Incorporated.
 *  All rights reserved. Property of Spectrum Digital Incorporated.
 *
 *  Not for distribution.
 */

/*
 *  Flash implementation - Erase AMD Flash
 *
 */

#include "davincievm_flash.h"

/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  DAVINCIEVM_FLASH_erase( start, length )                                 *
 *      Erase Flash containing address ( start ) to ( start + length ).     *
 *      Flash can only erase entire blocks containing the range.            *
 *                                                                          *
 *      start  <- starting address                                          *
 *      length <- length in bytes                                           *
 *                                                                          *
 * ------------------------------------------------------------------------ */
Int16 DAVINCIEVM_FLASH_erase( Uint32 start, Uint32 length )
{
    Uint32 end;

    Uint32 flash_base;
    Uint8 *pflash_base;

    Int32 timecount;
    Int32 timeout = 0xFFFFFF;

    /* Calculate extents of range to erase */
    end = start + length - 1;

    /* Erase the pages of flash contained within the address range */
    /* Alignment must be 16-bit words */
    start &= 0xFFFFFFFE;

    /* Loop until the the flash_base is passed end */
    for ( flash_base = start ; flash_base <= end ; flash_base += FLASH_PAGESIZE )
    {
        pflash_base = ( Uint8* )( flash_base );
        FLASH_CTL555 = FLASH_CMD_AA;
        FLASH_CTL2AA = FLASH_CMD_55;
        FLASH_CTL555 = FLASH_ERASE;             // Erase Sector
        FLASH_CTL555 = FLASH_CMD_AA;
        FLASH_CTL2AA = FLASH_CMD_55;
        *pflash_base = FLASH_ERASE_SECTOR;      // Confirm Erase

        /* Wait for erase to complete */
        timecount = 0;
        while ( ( *pflash_base != 0xFF ) && ( ++timecount < timeout ) );

        *pflash_base = FLASH_RESET;             // Reset Flash

        if ( timecount == timeout )             // On Timeout, return an error
            return -1;
    }

    return 0;
}

⌨️ 快捷键说明

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