-
Notifications
You must be signed in to change notification settings - Fork 7
/
nvs.c
45 lines (34 loc) · 1.14 KB
/
nvs.c
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
// golden
#include "nvs.h"
int nvs_read(unsigned char *flashdata, unsigned int bank, unsigned int block, unsigned int offset, int size, unsigned char *buffer) {
if(bank != 0) {
printf("error: invalid NVS bank number %i\n", bank);
return 1;
}
if(block > 4) {
printf("error: invalid NVS block number %i\n", block);
return 1;
}
if(offset >= g_nvs_block_sizes[block]) {
printf("error: invalid NVS offset 0x%X\n", offset);
return 1;
}
memcpy(buffer, flashdata + g_nvs_block_offsets[block] + offset, size);
return 0;
}
int nvs_write(unsigned char *flashdata, unsigned int bank, unsigned int block, unsigned int offset, int size, unsigned char *buffer) {
if(bank != 0) {
printf("error: invalid NVS bank number %i\n", bank);
return 1;
}
if(block > 4) {
printf("error: invalid NVS block number %i\n", block);
return 1;
}
if(offset >= g_nvs_block_sizes[block]) {
printf("error: invalid NVS offset 0x%X\n", offset);
return 1;
}
memcpy(flashdata + g_nvs_block_offsets[block] + offset, buffer, size);
return 0;
}