#include "inc/freeEMS.h"
#include "inc/flashWrite.h"
#include "inc/flashBurn.h"
#include "inc/commsISRs.h"
Include dependency graph for flashWrite.c:
Go to the source code of this file.
Defines | |
#define | FLASHWRITE_C |
Functions | |
unsigned char | eraseSector (unsigned short *flashAddr) |
unsigned char | writeAlignedBlock (unsigned short *flashAddr, unsigned short *RAMAddr) |
void | ping (unsigned short pong) |
unsigned char | writeWord (unsigned short *flashDestination, unsigned short data) |
#define FLASHWRITE_C |
Definition at line 24 of file flashWrite.c.
unsigned char eraseSector | ( | unsigned short * | flashAddr | ) |
Definition at line 54 of file flashWrite.c.
References ACCERR, Address_Not_Start_Of_Flash_Sector, Command_Successful, FCMD, Flash_Address_Not_Aligned, FlashSectorSize, FSTAT, PVIOL, SECTOR_ERASE, and StackBurner().
Referenced by writeAlignedBlock().
00054 { 00055 unsigned short FlashSectorSize = 1024; 00056 00057 if ((unsigned short)flashAddr & 0x001){ 00058 return Flash_Address_Not_Aligned; 00059 } 00060 00061 if ((unsigned short)flashAddr % FlashSectorSize != 0){ 00062 return Address_Not_Start_Of_Flash_Sector; 00063 } 00064 00065 FSTAT = (PVIOL|ACCERR); /* clear any errors */ 00066 (*flashAddr) = 0xFFFF; /* Dummy data to first word of page to be erased it will write FFFF regardless with the erase command*/ 00067 FCMD = SECTOR_ERASE; /* set the flash command register mode to ERASE */ 00068 StackBurner(55); //PPAGE loaded into Register B, PPAGE to be implemented 55 is a dummy value 00069 00070 //TODO add return for accerr and pviol error bits 00071 00072 return Command_Successful; 00073 }
Here is the call graph for this function:
void ping | ( | unsigned short | pong | ) |
unsigned char writeAlignedBlock | ( | unsigned short * | flashAddr, | |
unsigned short * | RAMAddr | |||
) |
Definition at line 82 of file flashWrite.c.
References Address_Not_Start_Of_Flash_Sector, eraseSector(), FlashSectorSize, ping(), and writeWord().
Referenced by decodePacketAndBuildResponse().
00082 { 00083 00084 unsigned short offSet = 0x2000; //TODO Figure out why this offset is needed, without it it will always write 0x4000 below your target 00085 flashAddr = flashAddr + offSet; 00086 00087 if ((unsigned short)flashAddr % FlashSectorSize != 0){ 00088 return Address_Not_Start_Of_Flash_Sector; 00089 } 00090 00091 eraseSector((unsigned short*)flashAddr); /* First Erase our destination block */ 00092 unsigned short wordCount = 512; /* 512 words to a 1024k sector */ 00093 00094 while (wordCount > 0) 00095 { 00096 00097 unsigned short sourceData = *RAMAddr; /*Convert the RAMAddr to data(dereference) */ 00098 writeWord(flashAddr, sourceData); 00099 RAMAddr++; 00100 flashAddr++; 00101 ping(sourceData); // TODO figure out why this is needed ,without it it will not write 00102 wordCount--; /* Decrement our word counter */ 00103 } 00104 00105 return 1; 00106 }
Here is the call graph for this function:
unsigned char writeWord | ( | unsigned short * | flashDestination, | |
unsigned short | data | |||
) |
Definition at line 136 of file flashWrite.c.
References ACCERR, Command_Successful, FCMD, Flash_Address_Not_Aligned, FSTAT, PVIOL, StackBurner(), and WORD_PROGRAM.
Referenced by writeAlignedBlock().
00136 { 00137 // TODO Create error check methods to get rid of redundant code 00138 if ((unsigned short)flashDestination & 0x0001){ 00139 return Flash_Address_Not_Aligned; 00140 } 00141 00142 FSTAT=(ACCERR | PVIOL); 00143 (*flashDestination)= data; 00144 FCMD = WORD_PROGRAM; //Load Flash Command Register With Word_Program mask 00145 StackBurner(55); //PPAGE loaded into Register B, PPAGE to be implemented 55 is a dummy value 00146 00147 return Command_Successful; 00148 }
Here is the call graph for this function: