flashWrite.c File Reference

#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 short eraseSector (unsigned char PPage, unsigned short *flashAddr)
unsigned short writeBlock (unsigned char RPage, unsigned short *RAMSourceAddress, unsigned char PPage, unsigned short *flashDestinationAddr, unsigned short size)
unsigned short writeSector (unsigned char RPage, unsigned short *RAMSourceAddress, unsigned char PPage, unsigned short *flashDestinationAddress)
unsigned short writeWord (unsigned short *flashDestination, unsigned short data)


Define Documentation

#define FLASHWRITE_C

Definition at line 24 of file flashWrite.c.


Function Documentation

unsigned short eraseSector ( unsigned char  PPage,
unsigned short *  flashAddr 
)

Definition at line 56 of file flashWrite.c.

References ACCERR, addressNotSectorAligned, FCMD, flashSectorSize, FSTAT, PPAGE, PVIOL, SECTOR_ERASE, and StackBurner().

Referenced by decodePacketAndRespond(), and writeSector().

00056                                                                           {
00057 
00058         if (((unsigned short)flashAddr % flashSectorSize) != 0){
00059                 return addressNotSectorAligned;
00060         }
00061         unsigned char currentPage = PPAGE;
00062         PPAGE = PPage;
00063         FSTAT = (PVIOL|ACCERR); /* clear any errors */
00064         (*flashAddr) = 0xFFFF;     /* Dummy data to first word of page to be erased it will write FFFF regardless with the erase command*/
00065         PPAGE = currentPage;
00066         FCMD = SECTOR_ERASE;            /* set the flash command register mode to ERASE */
00067         StackBurner();   //PPAGE loaded into Register B, PPAGE is set with Reg B in StackBurn asm file
00068         //TODO add return for accerr and pviol error bits
00069 
00070         return 0;
00071 }

Here is the call graph for this function:

unsigned short writeBlock ( unsigned char  RPage,
unsigned short *  RAMSourceAddress,
unsigned char  PPage,
unsigned short *  flashDestinationAddr,
unsigned short  size 
)

Definition at line 94 of file flashWrite.c.

References flashSectorSize, flashSectorSizeInWords, sizeNotMultipleOfSectorSize, and writeSector().

Referenced by decodePacketAndRespond().

00094                                                                                                                                                                 {
00095 
00096         if(((size % flashSectorSize) != 0) || (size == 0)){
00097                 return sizeNotMultipleOfSectorSize;
00098         }
00099 
00100         unsigned char sectors = size / flashSectorSize;
00101         unsigned char i;
00102         for(i=0;i<sectors;i++){
00103                 unsigned short errorID = writeSector(RPage, RAMSourceAddress, PPage, flashDestinationAddr);
00104                 if(errorID != 0){
00105                         return errorID;
00106                 }
00107                 /* Incrementing a pointer is done by blocks the size of the type, hence 512 per sector here */
00108                 flashDestinationAddr += flashSectorSizeInWords;
00109                 RAMSourceAddress += flashSectorSizeInWords;
00110         }
00111         return 0;
00112 }

Here is the call graph for this function:

unsigned short writeSector ( unsigned char  RPage,
unsigned short *  RAMSourceAddress,
unsigned char  PPage,
unsigned short *  flashDestinationAddress 
)

Definition at line 120 of file flashWrite.c.

References addressNotFlashRegion, addressNotSectorAligned, eraseSector(), flashSectorSize, flashSectorSizeInWords, PPAGE, RPAGE, and writeWord().

Referenced by decodePacketAndRespond(), and writeBlock().

00120                                                                                                                                                 {
00121 
00122         if (((unsigned short)flashDestinationAddress % flashSectorSize) != 0){
00123                         return addressNotSectorAligned;
00124                 }
00125 
00126         if(((unsigned short)flashDestinationAddress) < 0x4000){
00127                 return addressNotFlashRegion;
00128         }
00129 
00130         //TODO Decide if we need to disable interrupts since we are manually setting Flash/RAM pages.
00131         eraseSector((unsigned char)PPage, (unsigned short*)flashDestinationAddress);  /* First Erase our destination block */
00132 
00133         unsigned short wordCount = flashSectorSizeInWords;
00134 
00135         /* Save pages */
00136         unsigned char currentRPage = RPAGE;
00137         unsigned char currentPPage = PPAGE;
00138 
00139         /* Switch pages */
00140         RPAGE = RPage;
00141         PPAGE = PPage;
00142 
00143         while (wordCount > 0)
00144         {
00145         unsigned short sourceData = *RAMSourceAddress; /*Convert the RAMAddr to data(dereference) */
00146         unsigned short errorID = writeWord(flashDestinationAddress, sourceData);
00147         if(errorID != 0){
00148                         return errorID;
00149                 }
00150                 RAMSourceAddress++;
00151                 flashDestinationAddress++;
00152                 wordCount--; /* Decrement our word counter */
00153         }
00154 
00155         /* Restore pages */
00156         RPAGE = currentRPage;
00157         PPAGE = currentPPage;
00158         return 0;
00159 }

Here is the call graph for this function:

unsigned short writeWord ( unsigned short *  flashDestination,
unsigned short  data 
)

Definition at line 184 of file flashWrite.c.

References ACCERR, addressNotWordAligned, FCMD, FSTAT, PVIOL, StackBurner(), and WORD_PROGRAM.

Referenced by writeSector().

00184                                                                                {
00185         if ((unsigned short)flashDestination & 0x0001){
00186                 return addressNotWordAligned;
00187         }
00188 
00189         FSTAT=(ACCERR | PVIOL);
00190         *flashDestination = data;
00191         FCMD = WORD_PROGRAM;        //Load Flash Command Register With Word_Program mask
00192     StackBurner();
00193 
00194     return 0;
00195 }

Here is the call graph for this function:


Generated on Mon Dec 22 21:29:50 2008 for freeems by  doxygen 1.5.2