基于ARM7软中断程序的设计
4 实现方案
本文引用地址:https://www.eepw.com.cn/article/262221.htm4.1 SWI实现接口程序
如图1所示,LPC2458内部的FLASH存放boot程序,外部的FLASH存放应用程序。在需要擦写外部FLASH时,由应用程序产生一个软中断,使程序跳到内部FLASH中运行。CPU不再从片外FLASH中取指令,因此可擦写片外FLASH。当软中断程序运行完毕后,程序又跳回片外FLASH中。
由于SWI软中断中传送参数比较麻烦,我们的SWI软中断程序仅返回处理函数的地址,获得地址后,重定义为函数地址指针的方法简化处理,使程序的可读性和维护性增强。
我们以FLASH的写函数举例说明采用SWI方式的流程。
//定义函数指针类型
typedef unsigned long (*FuncWR_t)(unsigned long, void *, unsigned long);
//定义写FLASH函数,调用软中断
unsigned long Write_Flash(unsigned long StartAddr, unsigned short* DataPtr, unsigned long Count)
{
Extern unsigned long __swi(3) Get_Write_Addr(void);
FuncWR_t Func; //定义一个函数指针
Func = (FuncWR_t)Get_Write_Addr();
return Func(StartAddr, DataPtr, Count);
}
unsigned long __swi(3)Get_Write_Addr(void);
unsigned long __swi_3(void) //Get Write Flash Function Address
{
return (unsigned long)NorFlash_Write;
}
NorFlash_Write函数接口定义如下:
unsigned long NorFlash_Write(unsigned long StartAddr, unsigned short * DataPtr, unsigned long Count);
4.2 CFI接口实现
对于FLASH中采用CFI接口的编程实现,在网上有很多的源码可以参考,本文不再对此详述。以写FLASH为例,函数如下:
unsigned long NorFlash_Write(unsigned long StartAddr, unsigned short * DataPtr, unsigned long Count)
{
……..
……..
WRITE_CMD(0X5555,0XAAAA);
WRITE_CMD(0X2AAA,0X5555);
WRITE_CMD(0X5555,0XA0A0);
……..
……..
}
5 总结
本文以ARM7内核的LPC2458 MCU,采用软中断的方法实现片外FLASH在运行程序时,同时实现对此FLASH的写操作例程。详细描述了ARM7内核的MCU软中断程序的设计方法。希望能对使用ARM7内核、Cortex-M3/M4内核的MCU,实现软中断程序起到一个参考的作用。
参考文献:
[1]S29GL-N_00.pdf[R/OL].百度文库[2013-1-17].http://wenku.baidu.com/link?url=uIBbmLbL0OkLtOKPZScgd1Pdc0BfBgwwklmKxNfW5ai8YWEl00BOGuZM3ZZMp6stRW4DWEWJZsvIBRDMU1W2kVLpaVul8loAlKsKQFq7CZ3
[2]杜春雷.ARM体系架构与编程.清华大学出版社
[3]LPC2458 datasheet.pdf[R/OL]. (2008-8-24).http://www.elecfans.com/soft/39/2008/200808247525.html
[4]SWI软中断[R/OL].百度文库[2012-5-5]. http://wenku.baidu.com/link?url=bzr8t4KV2YQPXVCQC41uZzaEEZLke4yYmBhnToZGGoEqbk_eAmTI-qi4DCs8wgr7RBntegBxj_lP3u3cBmfwmdAhe8B31BxHcDfHba42bp_
[5]SWI的具体分析[R/OL]. 百度文库[2011-3-28]. http://wenku.baidu.com/view/f002e5ffc8d376eeaeaa313c.html
评论