65 unsigned short eraseSector(
unsigned char PPage,
unsigned short *flashAddr){
70 unsigned char currentPage =
PPAGE;
73 (*flashAddr) = 0xFFFF;
109 unsigned char sectors;
110 unsigned char RAMPage;
112 unsigned short* RAMAddress;
113 unsigned short* FlashAddress;
116 if(details->
size == 0){
118 }
else if(details->
size < 1024){
119 unsigned short chunkFlashAddress = (
unsigned short)details->
FlashAddress;
124 if((offset + details->
size) > 1024){
132 FlashAddress = (
unsigned short*)(chunkFlashAddress - offset);
137 unsigned char oldFlashPage =
PPAGE;
142 memcpy(buffer, FlashAddress, offset);
147 unsigned char oldRAMPage =
RPAGE;
150 buffer += details->
size;
154 if((offset + details->
size) < 1024){
156 memcpy(buffer, chunkFlashEndAddress, (1024 - (offset + details->
size)));
160 PPAGE = oldFlashPage;
170 RAMAddress = (
unsigned short*)details->
RAMAddress;
175 for(i=0;i<sectors;i++){
207 unsigned short writeSector(
unsigned char RPage,
unsigned short* RAMSourceAddress,
unsigned char PPage ,
unsigned short* flashDestinationAddress){
213 if(((
unsigned short)flashDestinationAddress) < 0x4000){
218 eraseSector((
unsigned char)PPage, (
unsigned short*)flashDestinationAddress);
223 unsigned char currentRPage =
RPAGE;
224 unsigned char currentPPage =
PPAGE;
230 while (wordCount > 0)
232 unsigned short sourceData = *RAMSourceAddress;
233 unsigned short errorID =
writeWord(flashDestinationAddress, sourceData);
238 flashDestinationAddress++;
243 RPAGE = currentRPage;
244 PPAGE = currentPPage;
267 unsigned short writeWord(
unsigned short* flashDestination,
unsigned short data){
268 if((
unsigned short)flashDestination & 0x0001){
273 *flashDestination = data;