|
上一篇写完了Flash的初始化子函数,那么接下来就要编写写入Flash的子函数和从闪存中读取的子函数。写入闪存的子函数代码如下。
void WriteToFlash(unsigned long *pArray, unsigned long ulStartAddress, unsigned int uiSize){ unsigned int uiPollFEESTA = 0; volatile unsigned long *flashAddress; unsigned int i = 0; flashAddress = ( unsigned long *)ulStartAddress; FeeWrEn(1); uiPollFEESTA = FeeSta(); for (i = 0; i < uiSize; i = i+4) { uiPollFEESTA = 0; *flashAddress++ = *pArray++; do uiPollFEESTA = FeeSta(); while((uiPollFEESTA & FEESTA_CMDBUSY) == FEESTA_CMDBUSY); } FeeWrEn(0); }这段代码的大致意思就是首先开允许写入,然后要确保阅读状态是被清除的,然后将数据写入指定的页面中,然后在失能写入到闪存的权限,这样写入闪存子函数就编写完成了。然后从闪存函数中读取数据,这个子函数相对来讲就比较简单了,代码先给出来。void ReadFromFlash(unsigned long *pArray, unsigned long ulStartAddress, unsigned int uiSize){ volatile unsigned long *flashAddress; unsigned int i = 0; flashAddress = ( unsigned long*)ulStartAddress; for (i = 0; i < uiSize; i = i+4) { *pArray++ = *flashAddress++; }}可以看出只是将写入闪存子函数中的一部分拿出来就完成了读取子函数的编写,代码也是很容易理解的,这里就不在啰嗦了。接下来还有一个中断子函数,在初始化子函数中已经将其使能。中断子函数就是等待闪存控制寄存器完成,然后在判忙一下就可以了,代码贴出来。void Ext_Int1_Handler (){ uiFEESTA = FeeSta(); while ((uiFEESTA & FEESTA_CMDBUSY) == FEESTA_CMDBUSY){ uiFEESTA = FeeSta(); } FeeMErs();} |
|