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

📄 seeddm642_flash.c

📁 TMS320DM642对FLASH AM29LV033C编程
💻 C
字号:
/********************************************************************/
/*  Copyright 2004 by SEED Incorporated.							*/
/*  All rights reserved. Property of SEED Incorporated.				*/
/*  Restricted rights to use, duplicate or disclose this code are	*/
/*  granted through contract.									    */
/*  															    */
/********************************************************************/
#include <std.h>
#include <csl.h>

#include <seeddm642.h>
#include <seeddm642_flash.h>

/************************************************************/
/*  ======== seeddm642_flash.c ========						*/
/*  SEEDDM642_FLASH_erase() implementation					*/
/************************************************************/

/* Constant table containing end address of each sector */
static Uint32 sector_end[SEEDDM642_FLASH_SECTORS] = {
    SEEDDM642_FLASH_BASE + 0x00ffff, /* Sector  0 */
    SEEDDM642_FLASH_BASE + 0x01ffff, /* Sector  1 */
    SEEDDM642_FLASH_BASE + 0x02ffff, /* Sector  2 */
    SEEDDM642_FLASH_BASE + 0x03ffff, /* Sector  3 */
    SEEDDM642_FLASH_BASE + 0x04ffff, /* Sector  4 */
    SEEDDM642_FLASH_BASE + 0x05ffff, /* Sector  5 */
    SEEDDM642_FLASH_BASE + 0x06ffff, /* Sector  6 */
    SEEDDM642_FLASH_BASE + 0x07ffff  /* Sector  7 */
};


/* Erase a segment of Flash memory */
void SEEDDM642_FLASH_erase(Uint32 start, Uint32 length)
{
    Int16 i;
    Uint8 *pdata;
    Uint32 sector_base, end;
    
    /* Calculate extents of range to erase */
    end = start + length - 1;
    
    /* Walk through each sector, erase any sectors within range */
    sector_base = SEEDDM642_FLASH_BASE;
    for (i = 0; i < SEEDDM642_FLASH_SECTORS; i++)
    {
        if ((start <= sector_base) && (sector_end[i] <= end))
        {
            /* Start sector erase sequence */
            *((Uint8 *)SEEDDM642_FLASH_BASE) = 0xaa;
            *((Uint8 *)SEEDDM642_FLASH_BASE) = 0x55;
            *((Uint8 *)SEEDDM642_FLASH_BASE) = 0x80;
            *((Uint8 *)SEEDDM642_FLASH_BASE) = 0xaa;
            *((Uint8 *)SEEDDM642_FLASH_BASE) = 0x55;
            
            /* Start erase at sector address */
            pdata = (Uint8 *)sector_base;
            *pdata = 0x30;
            
            /* Wait for erase to complete */
            while (1)
            {
                if (*pdata & 0x80)
                {
                    break;
                }
             }       
            /* Put back in read mode */
            *((Uint8 *)SEEDDM642_FLASH_BASE) = 0xf0;                    
        }
        
        /* Advance to next sector */
        sector_base = sector_end[i] + 1;
    }
}
/**************************************************************/
/*  ======== seeddm642_flash.c ========						  */
/*  EVMDM642_FLASH_read() implementation					  */
/**************************************************************/
/* Read data from a data range in Flash */
void SEEDDM642_FLASH_read(Uint32 src, Uint32 dst, Uint32 length)
{
    Uint8 *psrc, *pdst;
    Uint32 i;
    
    /* Establish source and destination */
    psrc = (Uint8 *)src;
    pdst = (Uint8 *)dst;
    for (i = 0; i < length; i++)
    {
        *pdst++ = *psrc++;
    }
}
/**************************************************************/
/*  ======== seeddm642_flash.c ========						  */
/*  EVMDM642_FLASH_write() implementation					  */
/**************************************************************/
/* Write data to a data range in Flash */
void SEEDDM642_FLASH_write(Uint32 src, Uint32 dst, Uint32 length)
{
    Uint8 *psrc, *pdst;
    Uint32 i;

    /* Establish source and destination */
    psrc = (Uint8 *)src;
    pdst = (Uint8 *)dst; 
    for (i = 0; i < length; i++)
    {
        // Program one 8-bit word
        *((Uint8 *)SEEDDM642_FLASH_BASE) = 0xaa;
        *((Uint8 *)SEEDDM642_FLASH_BASE) = 0x55;
        *((Uint8 *)SEEDDM642_FLASH_BASE) = 0xa0;
        *pdst = *psrc;
        
        // Wait for operation to complete
        while(1)
        {
            if (*pdst == *psrc)
            {
                break;
            }
        }       
        pdst++;
        psrc++;
    }
    
    /* Put back in read mode */
    *((Uint16 *)SEEDDM642_FLASH_BASE) = 0xf0;    
}

⌨️ 快捷键说明

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