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

📄 flash.c

📁 dm642_video_stream
💻 C
字号:
/********************************************************************/
/*  Copyright 2006 by VisionMagic Ltd.								*/
/*  All rights reserved. Property of VisionMagic Ltd.				*/
/*  Restricted rights to use, duplicate or disclose this code are	*/
/*  granted through contract.									    */
/*  															    */
/********************************************************************/
#include <std.h>
#include <csl.h>

#include "bsl.h"


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


/* Erase a segment of Flash memory */
void VMD642_FLASH_erase(Uint32 start, Uint32 length)
{
#if 0
    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 = VMD642_FLASH_BASE;
    for (i = 0; i < VMD642_FLASH_SECTORS; i++)
    {
        if ((start <= sector_base) && (sector_end[i] <= end))
        {
            /* Start sector erase sequence */
            *((Uint8 *)VMD642_FLASH_BASE) = 0xaa;
            *((Uint8 *)VMD642_FLASH_BASE) = 0x55;
            *((Uint8 *)VMD642_FLASH_BASE) = 0x80;
            *((Uint8 *)VMD642_FLASH_BASE) = 0xaa;
            *((Uint8 *)VMD642_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 *)VMD642_FLASH_BASE) = 0xf0;                    
        }
        
        /* Advance to next sector */
        sector_base = sector_end[i] + 1;
    }
#endif
}

/* Read data from a data range in Flash */
void VMD642_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++;
    }
}

/* Write data to a data range in Flash */
void VMD642_FLASH_write(Uint32 src, Uint32 dst, Uint32 length)
{
#if 0
    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 *)VMD642_FLASH_BASE) = 0xaa;
        *((Uint8 *)VMD642_FLASH_BASE) = 0x55;
        *((Uint8 *)VMD642_FLASH_BASE) = 0xa0;
        *pdst = *psrc;
        
        // Wait for operation to complete
        while(1)
        {
            if (*pdst == *psrc)
            {
                break;
            }
        }       
        pdst++;
        psrc++;
    }
    
    /* Put back in read mode */
    *((Uint16 *)VMD642_FLASH_BASE) = 0xf0;    
#endif
}


/*
 *get the page number and the appropriate address
 */
Uint32 GetPageAddr(Uint32 _addr, Uint8 *_page)
{

	Uint32 a1 = _addr - VMD642_FLASH_BASE, a2;

	*_page = a1 / VMD642_FLASH_PAGESIZE;

	a2 = a1 - (*_page) * VMD642_FLASH_PAGESIZE;

	return VMD642_FLASH_BASE + a2;
}

⌨️ 快捷键说明

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