FreeEMS
0.2.0-SNAPSHOT-282-g9efc524
|
Go to the source code of this file.
Macros | |
#define | EXTERN extern |
#define | MASS_ERASE 0x?? /* Used to erase 128k flash blocks */ |
#define | WORD_PROGRAM 0x20 /* Word = 2 bytes, this is the minimum write size, 64K of these per block, 512 per sector */ |
#define | SECTOR_ERASE 0x40 /* Sector = 1024 bytes, there are 128 sectors to a block, and 4 blocks to the chip */ |
Functions | |
unsigned short | writeWord (unsigned short *, unsigned short) TEXT |
Program Command. | |
unsigned short | eraseSector (unsigned char, unsigned short *) TEXT |
Erases a sector of flash memory. | |
unsigned short | writeSector (unsigned char, unsigned short *, unsigned char, unsigned short *) TEXT |
Writes a sector from memory to a sector in flash. | |
unsigned short | writeBlock (blockDetails *, void *) TEXT |
Writes a block of memory to flash. |
Definition in file flashWrite.h.
#define EXTERN extern |
Definition at line 50 of file flashWrite.h.
#define MASS_ERASE 0x?? /* Used to erase 128k flash blocks */ |
Definition at line 55 of file flashWrite.h.
#define WORD_PROGRAM 0x20 /* Word = 2 bytes, this is the minimum write size, 64K of these per block, 512 per sector */ |
Definition at line 56 of file flashWrite.h.
Referenced by writeWord().
#define SECTOR_ERASE 0x40 /* Sector = 1024 bytes, there are 128 sectors to a block, and 4 blocks to the chip */ |
Definition at line 57 of file flashWrite.h.
Referenced by eraseSector().
unsigned short writeWord | ( | unsigned short * | flashDestination, |
unsigned short | data | ||
) |
Program Command.
This will write 1 word to an empty(0xFFFF) flash address. If you try to write to an address containing data(not 0xFFFF),an error will register at FSTAT. The embedded algorithm works like this, just write to the desired flash address as you would any other writable address. Then register the program command(0x20) at FCDM, the rest is handled by StackBurner();
flashDestination | where you want to write your data |
data | the data you are going to write |
Definition at line 267 of file flashWrite.c.
References ACCERR, addressNotWordAligned, FCMD, FSTAT, PVIOL, StackBurner(), and WORD_PROGRAM.
Referenced by writeSector().
unsigned short eraseSector | ( | unsigned char | PPage, |
unsigned short * | flashAddr | ||
) |
Erases a sector of flash memory.
This will erase a 1k sector in flash. Write 0xFFFF to the starting sector to be erased, 0xFFFF will be written regardless. Register the flash sector erase command(0x40) and call StackBurner();. If you try to erase a protected sector you will get PVIOL in the FSTAT register.
PPage | the flash page the sector is in |
flashAddr | the start address of the sector |
Definition at line 65 of file flashWrite.c.
References ACCERR, addressNotSectorAligned, FCMD, flashSectorSize, FSTAT, PPAGE, PVIOL, SECTOR_ERASE, and StackBurner().
Referenced by writeSector().
unsigned short writeSector | ( | unsigned char | RPage, |
unsigned short * | RAMSourceAddress, | ||
unsigned char | PPage, | ||
unsigned short * | flashDestinationAddress | ||
) |
Writes a sector from memory to a sector in flash.
Uses writeWord to write a 1k block from sourceAddress(RAM) to flashDestinationAddress, one word at a time. Give it the starting memory address and the destination flash address. Both addresses will be incremented by 1 word after a successful writeWord, until the whole 1024 byte sector has been written. Before any writing occurs eraseSector is called to make sure the destination is blank.
RPage | the page of RAM the RAMSourceAddress is located |
RAMSourceAddress | the address of the source data |
PPage | the page of flash where your flashDestinationAddress is located |
flashDestinationAddress | where your data will be written to in flash |
Definition at line 207 of file flashWrite.c.
References addressNotFlashRegion, addressNotSectorAligned, eraseSector(), flashSectorSize, flashSectorSizeInWords, PPAGE, RPAGE, and writeWord().
Referenced by writeBlock().
unsigned short writeBlock | ( | blockDetails * | details, |
void * | buffer | ||
) |
Writes a block of memory to flash.
The block size must either be under 1024, or an exact multiple of 1024. Additionally, if under 1024 the destination should be within a single flash sector, and if a multiple of 1024, the destination should be sector aligned.
Because the RAM version will be in an arbitrary place we need to base our positioning from the flash location. Firstly we need to ensure that it doesn't cross any sector boundaries. Then we need to find the address of the sector to be burned to. We also need to determine if there are 2 or 3 chunks of memory to be copied to the buffer, three cases exist for that :
| From Flash | From RAM | From flash | | From Flash | From RAM | | From RAM | From Flash |
details | contains the RAM address and page to be read from, the flash address and page to be burned to and the size to be read. |
buffer | is a pointer to a block of RAM at least 1024 bytes long used to allow small chunks to be burned independently. |
Definition at line 108 of file flashWrite.c.
References blockDetails::FlashAddress, blockDetails::FlashPage, flashSectorSize, flashSectorSizeInWords, PPAGE, blockDetails::RAMAddress, blockDetails::RAMPage, RPAGE, blockDetails::size, sizeNotMultipleOfSectorSize, sizeOfBlockToBurnIsZero, smallBlockCrossesSectorBoundary, and writeSector().
Referenced by decodePacketAndRespond().