X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=pkernel%2Fflash.c;h=e7049f3d133c9fa1297d798c1716119170f32376;hb=c380c7da56e97c4430481fe7ccecb98330268726;hp=c72b4633eb3dfd991932f455f644158d3bb1ae69;hpb=96324b051bfefe94b0887d30f1897ed21b25efff;p=pyfrprog.git diff --git a/pkernel/flash.c b/pkernel/flash.c index c72b463..e7049f3 100644 --- a/pkernel/flash.c +++ b/pkernel/flash.c @@ -10,9 +10,6 @@ static unsigned int IFlag; -#pragma section CODE=IRAM,attr=CODE - - void FLASH_PrepareWriteHalfWordMode() { /* Set FLASH Access Mode via BootROM Routine */ @@ -63,6 +60,53 @@ void FLASH_PrepareReadMode() FMWT_WTC = 4; } +unsigned char FLASH_ChipErase(void) +{ + unsigned char flag = 0; + + /*Disable Interrupts if necessary*/ + IFlag = FLASH_SaveDisableInterruptFlag(); + + /*Set FLASH access mode to 16Bit Write Mode*/ + FLASH_PrepareWriteHalfWordMode(); + + /*Start FLASH Sector Erase Sequence*/ + *hseq_1 = 0x00AA; + *hseq_2 = 0x0055; + *hseq_1 = 0x0080; + *hseq_1 = 0x00AA; + *hseq_2 = 0x0055; + *hseq_1 = 0x0010; + + /*Wait for the Auto Algorithm to finish*/ + while( flag == 0 ) { + /* Feed Hardware Watchdog */ + HWWD_CL = 0; + + if(*hseq_1 & DPOLL) { + flag = 1; + } + if(*hseq_1 & TLOVER) { + if(*hseq_1 & DPOLL) { + flag = 1; + } + else { + /*Reset FLASH (keep in mind 16Bit access to FLASH)*/ + *hseq_1 = 0x00F0; // Keep in Mind (16Bit access) + + flag = 2; + } + } + } + + /*Set FLASH access mode to 32Bit Read Mode*/ + FLASH_PrepareReadMode(); + + /*Restore the original Interrupt Flag*/ + FLASH_RestoreInterruptFlag(IFlag); + + return flag; +} unsigned char FLASH_SectorErase(unsigned int secadr) {