-
Notifications
You must be signed in to change notification settings - Fork 1
/
nvm.h
63 lines (53 loc) · 1.92 KB
/
nvm.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef __NVM_H__
#define __NVM_H__
#include <stdint.h>
#include <stdbool.h>
enum {
nvm_ROWERASE = 1u<<15, //unused bits in wdata, to signify row erase
nvm_ROWUPDATE = 1u<<14, //unused bits in wdata, to signify row write
nvm_ID0 = 0x8000, //these are the only words in config space
nvm_ID1 = 0x8001, // that can be written (in a 16F15325)
nvm_ID2 = 0x8002,
nvm_ID3 = 0x8003
};
// all functions will take care of module power, and will leave the
// module powered off when done
// nvm_writeW is a basic way to write a word to any writable flash word
// it will take care of preserving all other bytes in the flash row
// nvm_writeNW is used to write N words to any writable flash address
// it will take care of preserving all other bytes in the flash row
// nvm_pgm can be used when anything else is needed- you are responsible
// for erasing the row, preserving any data, etc.
//=============================================================================
//read single word
uint16_t
nvm_read (uint16_t);
//write single word
bool
nvm_writeW (uint16_t, uint16_t);
//write n words
bool
nvm_writeNW (uint16_t, uint16_t*, uint8_t);
bool
//write latch, erase, row pgm
nvm_pgm (uint16_t, uint16_t);
//unique id from MUID bytes to uint32_t
uint32_t
nvm_mui (void);
//=============================================================================
/*
examples-
read User ID0-
uint16_t w = nvm_read( nvm_ID0 );
read Dev ID-
uint16_t w = nvm_read( 0x8006 );
read word at irq vector address
uint16_t w = nvm_read( 4 );
write 0x25 to User ID0-
nvm_writeW( nvm_ID0, 0x25 );
write 4 words to address 0 :)
uint16_t x[4] = { 1,2,3,4 };
nvm_writeNW( 0, x, 4 );
writes will return true if no errors
*/
#endif //__NVM_H__