合众达FLASH测试程序 erase,Writes/Writem,Read/Readm
发布时间:2020-12-15 06:42:00 所属栏目:百科 来源:网络整理
导读:?#include stdio.h #include csl.h #include csl_irq.h #include csl_chip.h #include csl_emif.h #include csl_irq.h #include "DEC6713_FLASH.h" /********************************************************************************/ Uint16 Data_Buffer
?#include <stdio.h>
#include <csl.h> #include <csl_irq.h> #include <csl_chip.h> #include <csl_emif.h> #include <csl_irq.h> #include "DEC6713_FLASH.h" /********************************************************************************/ Uint16 Data_Buffer[0x1000]; Uint16 Temp_Buffer[0x1000]; Uint32 i; extern far void vectors(); /********************************************************************************/ /********************************************************************************/ void main() { ????????CSL_init();????? /* Initialize CSL,must when using. */ ???????? ??????? DEC6713_init();??????? /* Initialize DEC6713 board. */ ???????? ??????? IRQ_setVecs(vectors);??????????? /* Configure interrupt. */ ??? ??? IRQ_nmiEnable(); ????? ? IRQ_globalEnable(); ???? ?? /* Erase flash memory. */ ????? ? Flash_Erase(0x90000000,0x10); ? ? ? ? printf("nErase flash ok."); ???????? ???/* Initialize data. */ ???? ? ? for(i = 0; i < 0x1000; i++) ????? ? { ? ? ? ? ? ????? Data_Buffer[i] = i; ? ??? ??} ???? ???/* Write flash memory. */ ? ?? ?? Flash_Writem(0x90000000,&Data_Buffer[0],0x1000); ? ????? printf("nWrite flash ok."); ???????????? ???/* Read flash memory. */ ? ? ? ? Flash_Readm(0x90000000,&Temp_Buffer[0],0x1000); ? ????? printf("nRead flash ok."); ???? ???/* Compare data. */ ? ? ? ? for(i=0;i<0x100;i++) ? ? ? ? { ? ? ? ? ? ? ? ? if(Temp_Buffer[i] != Data_Buffer[i]) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? printf("nOpereation is failure."); ? ? ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? printf("nOpereation is success."); } /******************************************************************************** *? ? ? ? Flash function difine. * ********************************************************************************/ /******************************************************************************** * Flash erase function. * ********************************************************************************/ Uint32 Flash_Erase(Uint32 addr,Uint16 type) { ? ? ? ? Uint32 i,j; ? ? ? ? *FLASH_5555 = FLASH_UL1;? ? ? ? //first ? ? ? ? *FLASH_2AAA = FLASH_UL2;? ? ? ? //second ? ? ? ? *FLASH_5555 = FLASH_UL3;? ? ? ? //third ? ? ? ? *FLASH_5555 = FLASH_UL4; ? ? ? ? *FLASH_2AAA = FLASH_UL5; ? ? ? ? switch(type) ? ? ? ? { ? ? ? ? ? ? ? ? case 0x50:? ? ? ? ? ? ? ? //block erase ? ? ? ? ? ? ? ? ? ? ? ? *(Uint16 *)addr = type; ? ? ? ? ? ? ? ? ? ? ? ? while((*(Uint16 *)addr & 0x80) != 0x80); ? ? ? ? ? ? ? ? ? ? ? ? for(i = 0; i < BLOCK_SIZE; i++) ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if(*(Uint16 *)(addr + i) != 0xffff) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? j = 0; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? j = 1; ? ? ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? case 0x30:? ? ? ? ? ? ? ? //sector erase ? ? ? ? ? ? ? ? ? ? ? ? *(Uint16 *)addr = type; ? ? ? ? ? ? ? ? ? ? ? ? while((*(Uint16 *)addr & 0x80) != 0x80); ? ? ? ? ? ? ? ? ? ? ? ? for(i = 0; i < SECTOR_SIZE; i++) ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if(*(Uint16 *)(addr + i) != 0xffff) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? j = 0; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? j = 1; ? ? ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? case 0x10:? ? ? ? ? ? ? ? //chip erase ? ? ? ? //? ? ? ? for(;;) ? ? ? ? //? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? *FLASH_5555 = type; ? ? ? ? //? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? while((*FLASH_5555 & 0x80) != 0x80); ? ? ? ? ? ? ? ? ? ? ? ? for(i = 0; i < CHIP_SIZE; i++) ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if(*(Uint16 *)(addr + i) != 0xffff) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? j = 0; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? j = 1; ? ? ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? default: ? ? ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? } ? ? ? ? return (j); } while((*FLASH_5555 & 0x80) != 0x80); 为什么要写成无限循环的形式呢? 那是因为系统会为每一个任务保留一个堆栈空间,由系统在任务切换的时候恢复上下文,并执行一条reti 指令返回。如果允许任务执行到最后一个花括号(那一般都意味着一条ret指令)的话,很可能会破坏系统堆栈空间从而使应用程序的执行不确定。换句话说,就是“跑飞”了。所以,每一个任务必须被写成无限循环的形式。 程序员一定要相信,自己的任务是会放弃CPU使用权的,而不管是系统强制(通过ISR)还是主动放弃(通过调用OS API)。 标准C运行在操作系统下,退出你的函数后,控制权会交给操作系统。而在DSP的CCS中没有操作系统,退出函数意味着程序跑飞!!!这就是标准C和DSP的C的区别。所以while((*FLASH_5555 & 0x80) != 0x80);这里时,不是死循环!是程序的必要条件。 /******************************************************************************** *??Write a single data. * ********************************************************************************/ void Flash_Writes(Uint32 addr,Uint16 data) { //? ? ? ? Uint16 TempData=0; ? ? ? ? *FLASH_5555 = FLASH_UL1; ? ? ? ? *FLASH_2AAA = FLASH_UL2; ? ? ? ? *FLASH_5555 = FLASH_PROGRAM; ? ? ? ? *(Uint16 *)addr = data; ? ? ? ? //TempData = *(Uint16 *)(addr+28); ? ? ? ? while(*(Uint16 *)addr != data); } /******************************************************************************** * Write the certain length data. * ********************************************************************************/ void Flash_Writem(Uint32 addr,Uint16 *ptr,Uint32 length) { ? ? ? ? Uint32 i; ? ? ? ? for(i??= 0; i < length; i++) ? ? ? ? { ? ? ? ? //? ? ? ? for(;;) ? ? ? ? //? ? ? ? { ? ? ? ? ? ? ? ? Flash_Writes(addr+2*i,*(ptr+i)); ? ? ? ? //? ? ? ? } ? ? ? ? } } /******************************************************************************** * Read a single data. * ********************************************************************************/ Uint32 Flash_Reads(Uint32 addr) { ? ? ? ? return (*(Uint16 *)addr); } /******************************************************************************** * Read the certain length data. * ********************************************************************************/ void Flash_Readm(Uint32 addr,Uint32 length) { ? ? ? ? Uint32 i; ? ? ? ? for(i = 0; i < length; i++) ? ? ? ? { ? ? ? ? ? ? ? ? *(ptr + i) = Flash_Reads(addr+2*i); ? ? ? ? } } /******************************************************************************** * End of DEC6713_FLASH.C * ********************************************************************************/(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |