FreeEMS
0.2.0-SNAPSHOT-285-g028e24c
|
Flash manipulation functions. More...
#include "inc/freeEMS.h"
#include "inc/utils.h"
#include "inc/flashWrite.h"
#include "inc/flashBurn.h"
#include "inc/commsISRs.h"
#include "inc/commsCore.h"
#include <string.h>
Go to the source code of this file.
Macros | |
#define | FLASHWRITE_C |
Functions | |
unsigned short | eraseSector (unsigned char PPage, unsigned short *flashAddr) |
Erases a sector of flash memory. | |
unsigned short | writeBlock (blockDetails *details, void *buffer) |
Writes a block of memory to flash. | |
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. | |
unsigned short | writeWord (unsigned short *flashDestination, unsigned short data) |
Program Command. |
Flash manipulation functions.
This file contains all functions that operate directly or indirectly and only on flash memory. They are used for erasing data from and reprogramming data to the embedded flash non-volatile storage area.
Definition in file flashWrite.c.
#define FLASHWRITE_C |
Definition at line 39 of file flashWrite.c.
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 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().
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 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().