5.2 RTSP Operation
RTSP allows the user application to program one double instruction word or one row at a time. The double instruction word write blocks and single row write blocks are edge-aligned, from the beginning of program memory, on boundaries of one double instruction word and 64 double instruction words, respectively.
The basic sequence for RTSP programming is to first load two 24-bit instructions into the NVM write latches found in configuration memory space. Then, the WR bit in the NVMCON register is set to initiate the write process. The processor stalls (waits) until the programming operation is finished. The WR bit is automatically cleared when the operation is finished.
Double instruction word writes are performed by manually loading both
write latches, using TBLWTL
and TBLWTH
instructions, and
then initiating the NVM write while the NVMOPx bits are set to ‘0x1
’. The
program space destination address is defined by the NVMADR/U registers.
Row programming is performed by first loading 128 instructions into data RAM and then loading the address of the first instruction in that row into the NVMSRCADRL/H registers. Once the write has been initiated, the device will automatically load two instructions into the write latches and write them to the program space destination address defined by the NVMADR/U registers.
The operation will increment the NVMSRCADRL/H and the NVMADR/U registers until all double instruction words have been programmed.
The RPDF bit (NVMCON[9]) selects the format of the stored data in RAM to be either compressed or uncompressed. See Figure 5-2 for data formatting.
Compressed data help to reduce the amount of required RAM by using the upper byte of the second word for the MSB of the second instruction.
All erase and program operations may optionally use the NVM interrupt to signal the successful completion of the operation.
Flash Write/Read
/////////Flash write ////////////////////////
//Sample code for writing 0x123456 to address locations 0x10000 / 10002
NVMCON = 0x4001;
TBLPAG = 0xFA; // write latch upper address
NVMADR = 0x0000; // set target write address of general segment
NVMADRU = 0x0001;
__builtin_tblwtl(0, 0x3456); // load write latches
__builtin_tblwth (0,0x12);
__builtin_tblwtl(2, 0x3456); // load write latches
__builtin_tblwth (2,0x12);
asm volatile (“disi #5”);
__builtin_write_NVM();
while(_WR == 1 ) ;
////////////Flash Read///////////////
//Sample code to read the Flash content of address 0x10000
// readDataL/ readDataH variables need to defined
TBLPAG = 0x0001;
readDataL = __builtin_tblrdl(0x0000);
readDataH = __builtin_tblrdh(0x0000);