📄 flash.c
字号:
/*********************************************************************
* (C) COPYRIGHT TEXAS INSTRUMENTS, INC. 2000, 2001
* flash.c -- Flash Memory handlers for evm 5510
*/
/* Change Log:
*/
/*
* $Log: flash.c,v $
* Revision 1.3 2001/06/27 17:55:14 heeschen
* v00.32 Beta Prep
* Capturing all files to prepare for Beta Release
*
* Revision 1.2 2001/04/19 18:56:50 heeschen
* v00.30 Alpha - Updated comments
*
*
*/
#include "flash.h"
#define FCP5 (FLASH_BASE_ADDR+(0x5555ul<<1)) //flash command port 5
#define FCPA (FLASH_BASE_ADDR+(0x2aaaul<<1)) //flash command port A
#define FCW5 0x55555555ul
#define FCWA 0xaaaaaaaaul
#define FWORDWRITE 0xA0A0A0A0ul
#define FRESET 0xF0F0F0F0ul
#define FCHIPERASE0 0x80808080ul
#define FCHIPERASE1 0x10101010ul
#define FSECTORERASE0 0x80808080ul
#define FSECTORERASE1 0x30303030ul
#define FCHIPID 0x90909090ul
#define DQ7 (1ul<<7)
#define DQ6 (1ul<<6)
#define DQ5 (1ul<<5)
#define DQ3 (1ul<<3)
#define DQ2 (1ul<<2)
static u32 fcwa[2] = {(FCWA & 0xffff0000), (FCWA & 0xffff)};
static u32 fcw5[2] = {(FCW5 & 0xffff0000), (FCW5 & 0xffff)};
static u32 fwordwrite[2] = {(FWORDWRITE & 0xffff0000), (FWORDWRITE & 0xffff)};
static int waitFor16bitCompletion(volatile u16 *s, u16 value);
/* Reset the Flash Memory. Places chip in read mode
*/
void flash_reset()
{
/* 2 chips 16 bits wide: 32 bits.
*/
*(volatile u32 *)FLASH_BASE_ADDR = FRESET;
}
/* Writes length words from source to dest in flash.
*/
int flash_write(u16 *source, u16 *dest, u16 length)
{
u16 *pdst = dest;
u16 *psrc = source;
u16 i,len = length;
for(i = 0; i < len; i++)
{
*(volatile u32 *)FCP5 = fcwa[((u32)pdst) & 1];
*(volatile u32 *)FCPA = fcw5[((u32)pdst) & 1];
*(volatile u32 *)FCP5 = fwordwrite[((u32)pdst) & 1];
*pdst = *psrc;
if (waitFor16bitCompletion((volatile u16 *)pdst++, *psrc++) == ERROR)
return ERROR;
}
return OK;
}
/*****************************************************
* int chip_erase()
*
* This function commands an entire flash erasure
* returns immediately. Use checkFor32bitCompletion()
* to see when erasing is complete.
*
* Parameters:
* none
*
* Return:
* - OK success
* - ERROR failure
*
* Notes:
*
*/
void chip_erase(void)
{
*(volatile u32 *)FCP5 = FCWA;
*(volatile u32 *)FCPA = FCW5;
*(volatile u32 *)FCP5 = FCHIPERASE0;
*(volatile u32 *)FCP5 = FCWA;
*(volatile u32 *)FCPA = FCW5;
*(volatile u32 *)FCP5 = FCHIPERASE1;
return;
}
/*************
* Local Funcs
*************
*/
/* Waits for the flash operation to complete.
*
* s - pointer to location to compare to value
* value - value to compare to data stored in location pointedt to by s
*
* Returns OK if success, else ERROR
*/
int waitFor16bitCompletion(volatile u16 *s, u16 value)
{
while(1)
{
if ((*s & DQ7) == (value & DQ7))
return OK;
if (*s & DQ5)
{
return ((*s & DQ7) == (value & DQ7)) ? OK : ERROR;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -