flashWrite.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define EXTERN   extern
#define ERASE_CMD   0x40
#define WORD_PROGRAM   0x20
#define SECTOR_ERASE   0x40
#define Flash_Address_Not_Aligned   -1;
#define Flash_Not_Erased   -2;
#define Access_Error   -3;
#define Protection_Error   -4;
#define Address_Not_Start_Of_Flash_Sector   -5;
#define Command_Successful   1;

Functions

EXTERN unsigned char eraseSector (unsigned short *)
EXTERN unsigned char writeWord (unsigned short *, unsigned short)
EXTERN unsigned char writeAlignedBlock (unsigned short *, unsigned short *)
EXTERN void ping (unsigned short)


Define Documentation

#define Access_Error   -3;

Definition at line 51 of file flashWrite.h.

#define Address_Not_Start_Of_Flash_Sector   -5;

Definition at line 53 of file flashWrite.h.

Referenced by eraseSector(), and writeAlignedBlock().

#define Command_Successful   1;

Definition at line 54 of file flashWrite.h.

Referenced by eraseSector(), and writeWord().

#define ERASE_CMD   0x40

Definition at line 37 of file flashWrite.h.

#define EXTERN   extern

Definition at line 32 of file flashWrite.h.

#define Flash_Address_Not_Aligned   -1;

Definition at line 49 of file flashWrite.h.

Referenced by eraseSector(), and writeWord().

#define Flash_Not_Erased   -2;

Definition at line 50 of file flashWrite.h.

#define Protection_Error   -4;

Definition at line 52 of file flashWrite.h.

#define SECTOR_ERASE   0x40

Definition at line 39 of file flashWrite.h.

Referenced by eraseSector().

#define WORD_PROGRAM   0x20

Definition at line 38 of file flashWrite.h.

Referenced by writeWord().


Function Documentation

EXTERN unsigned char eraseSector ( unsigned short *   ) 

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:

EXTERN void ping ( unsigned  short  ) 

Definition at line 108 of file flashWrite.c.

Referenced by writeAlignedBlock().

00109 {
00110         pong++;
00111 }

EXTERN unsigned char writeAlignedBlock ( unsigned short *  ,
unsigned short *   
)

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:

EXTERN unsigned char writeWord ( unsigned short *  ,
unsigned  short 
)

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:


Generated on Mon Nov 10 21:19:01 2008 for freeems by  doxygen 1.5.2