Last active
December 22, 2015 00:09
-
-
Save Embedded-linux/6387743 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include ”../FlashOs.H” | |
| // Memory Mapping Control | |
| #define MEMMAP (*((volatile unsigned char *) 0x E01FC040)) | |
| // Phase Locked Loop (PLL) | |
| #define PLLCON (*((volatile unsigned char*) 0xE01FC080)) | |
| #define PLLCFG (*((volatile unsigned char *) 0xE01FC084)) | |
| #define PLLSTAT (*((volatile unsigned short*) 0xE01FC088)) | |
| #define PLLFEED (*((volatile unsigned char *) 0xE01FC08C)) | |
| #define STACK_SIZE 64 | |
| #define SET_VALID_CODE 1 | |
| unsigned long CCLK; | |
| struct sIAP { | |
| unsigned long command; | |
| unsigned long param[4]; | |
| unsigned long stat; | |
| } IAP; | |
| void IAP_Execuate (struct sIAP *pIAP); | |
| unsigned long GetSecNum (unsigned long adr) { | |
| unsigned long n; | |
| n = (adr >> 12) & 0×01; | |
| return(n); | |
| } //Get sector Number | |
| /*Initilize Flash Program Function */ | |
| int Init (unsigned long adr, unsigned long clk, unsigned long func) { | |
| CCLK = (1049*(clk >> 10)) >> 10; | |
| PLLCON = 0×00; | |
| PLLFEED = 0×55; | |
| PLLFEDD = 0xAA; | |
| MEMMAP = 0×01; | |
| return (0); | |
| } | |
| /*Deinitilize Flash Programming Function*/ | |
| int Uninit (unsigned long fnc) { | |
| return(0); | |
| } | |
| /* Erase Complete Flash Memory */ | |
| int Erasechip (void) { | |
| IAP.cmd = 50; | |
| IAP.par[0] = 0; //start sector | |
| IAP.par[1] = 1; //End Sector | |
| IAP_Execuate (&IAP); | |
| if (IAP.stat) return (1); | |
| IAP.cmd = 52; | |
| IAP.par[0] = 0; | |
| IAP.par[1] = 1; | |
| IAP.par[2] = CCLK; | |
| IAP.Execuate(&IAP); | |
| if (IAP.stat) return (1); | |
| return (0); | |
| } | |
| /* Erase Sector in Flash Memory */ | |
| int EraseSector (unsigned long adr) { | |
| unsigned long n; | |
| n = GetSectNum (adr); | |
| IAP.cmd = 50; | |
| IAP.par[0] = n; | |
| IAP.par[1] = n; | |
| IAP.Execaute(&IAP); | |
| if(IAP.stat) return(1) ; | |
| IAP.cmd = 52; | |
| IAP.par[0] = n; | |
| IAP.par[1] = n; | |
| IAP.par[2] = CCLK; | |
| IAP.Execaute(&IAP); | |
| if(IAP.stat) return(1) ; | |
| return(0); | |
| } | |
| /* Program Page in Flash Memory */ | |
| int ProgramPage(unsigned long adr, unsigned long sz, unsigned char *buf) { | |
| unsigned long n; | |
| #if SET_VALID_CODE !=0 | |
| if (adr == 0) { | |
| n = *( ( unsigned long * ) ( buf + 0×00) ) + | |
| *( (unsigned long * ) ( buf + 0×04)) + | |
| *( (unsigned long * ) ( buf + 0×08)) + | |
| *( (unsigned long * ) ( buf + 0x0c)) + | |
| *( (unsigned long * ) ( buf + 0×10)) + | |
| *( (unsigned long * ) ( buf + 0×18)) + | |
| *( (unsigned long * ) ( buf + 0x1C)) + | |
| *( (unsigned long * ) ( buf + 0×14)) = 0 – n; | |
| #endif | |
| } | |
| n = GetSetNum (adr); | |
| IAP.cmd = 50; // Prepare Sector for Write | |
| IAP.par[0] = n; // Start Sector | |
| IAP.par[1] = n; // End Sector | |
| IAP_Execute (&IAP); // Execute IAP Command | |
| if (IAP.stat) return (1); // Command Failed | |
| IAP.cmd = 51; // Copy RAM to Flash | |
| IAP.par[0] = adr; // Destination Flash Address | |
| IAP.par[1] = (unsigned long)buf; // Source RAM Address | |
| IAP.par[2] = 1024; // Fixed Page Size | |
| IAP.par[3] = CCLK; // CCLK in kHz | |
| IAP_Execute (&IAP); // Execute IAP Command | |
| if (IAP.stat) return (1); // Command Failed | |
| return (0); // Finished without Errors | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ARM Controller Interfacing for IAP Programming