?? qxddm642_flash.c
字號:
/******************************************************/
/* 深圳市奇想達科技有限公司QXD-DM642開發板源程序 */
/* 網址:http://www.szqxd.com */
/******************************************************/
#include <std.h>
#include <csl.h>
#include <QXDdm642.h>
#include <QXDdm642_flash.h>
/************************************************************/
/* ======== QXDdm642_flash.c ======== */
/* QXDDM642_FLASH_erase() implementation */
/************************************************************/
/* Constant table containing end address of each sector */
static Uint32 sector_end[QXDDM642_FLASH_SECTORS] = {
QXDDM642_FLASH_BASE + 0x00ffff, /* Sector 0 */
QXDDM642_FLASH_BASE + 0x01ffff, /* Sector 1 */
QXDDM642_FLASH_BASE + 0x02ffff, /* Sector 2 */
QXDDM642_FLASH_BASE + 0x03ffff, /* Sector 3 */
QXDDM642_FLASH_BASE + 0x04ffff, /* Sector 4 */
QXDDM642_FLASH_BASE + 0x05ffff, /* Sector 5 */
QXDDM642_FLASH_BASE + 0x06ffff, /* Sector 6 */
QXDDM642_FLASH_BASE + 0x07ffff /* Sector 7 */
};
/* Erase a segment of Flash memory */
void QXDDM642_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 = QXDDM642_FLASH_BASE;
for (i = 0; i < QXDDM642_FLASH_SECTORS; i++)
{
if ((start <= sector_base) && (sector_end[i] <= end))
{
/* Start sector erase sequence */
*((Uint8 *)QXDDM642_FLASH_BASE) = 0xaa;
*((Uint8 *)QXDDM642_FLASH_BASE) = 0x55;
*((Uint8 *)QXDDM642_FLASH_BASE) = 0x80;
*((Uint8 *)QXDDM642_FLASH_BASE) = 0xaa;
*((Uint8 *)QXDDM642_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 *)QXDDM642_FLASH_BASE) = 0xf0;
}
/* Advance to next sector */
sector_base = sector_end[i] + 1;
}
}
/**************************************************************/
/* ======== QXDdm642_flash.c ======== */
/* EVMDM642_FLASH_read() implementation */
/**************************************************************/
/* Read data from a data range in Flash */
void QXDDM642_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++;
}
}
/**************************************************************/
/* ======== QXDdm642_flash.c ======== */
/* EVMDM642_FLASH_write() implementation */
/**************************************************************/
/* Write data to a data range in Flash */
void QXDDM642_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 *)QXDDM642_FLASH_BASE) = 0xaa;
*((Uint8 *)QXDDM642_FLASH_BASE) = 0x55;
*((Uint8 *)QXDDM642_FLASH_BASE) = 0xa0;
*pdst = *psrc;
// Wait for operation to complete
while(1)
{
if (*pdst == *psrc)
{
break;
}
}
pdst++;
psrc++;
}
/* Put back in read mode */
*((Uint16 *)QXDDM642_FLASH_BASE) = 0xf0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -