11.07.2015 Views

PicC 9.50 dsPIC Manual.pdf

PicC 9.50 dsPIC Manual.pdf

PicC 9.50 dsPIC Manual.pdf

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Library FunctionsPERSIST_CHECK, PERSIST_VALIDATESynopsis#include int persist_check (int flag)void persist_validate (void)DescriptionThe persist_check() function is used with non-volatile RAM variables, declared with the persistentqualifier. It tests the nvram area, using a magic number stored in a hidden variable by a previous callto persist_validate() and a checksum also calculated by persist_validate(). If the magic number andchecksum are correct, it returns true (non-zero). If either are incorrect, it returns zero. In this case itwill optionally zero out and re-validate the non-volatile RAM area (by calling persist_validate()).This is done if the flag argument is true.The persist_validate() routine should be called after each change to a persistent variable. It willset up the magic number and recalculate the checksum.Example#include #include persistent long reset_count;voidmain (void){if(!persist_check(1))printf("Reset count invalid - zeroed\n");elseprintf("Reset number %ld\n", reset_count);reset_count++; /* update count */persist_validate(); /* and checksum */for(;;)continue; /* sleep until next reset */173

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!