-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsettings.c
61 lines (50 loc) · 1.33 KB
/
settings.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "sys.h"
#include "eeprom.h"
#include "settings.h"
EEP_Param eep;
static code EEP_Param eepDef = {0xFF, 0, 2, 0, 0, 1, 5, 0, 7, 30, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0};
code EEP_Param eepMin = {0xFF, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -9, -128, 0};
code EEP_Param eepMax = {0xFF, 1, 5, 4, 4, 1, 6, 1, 23, 59, 1, 1, 1, 1, 1, 1, 1, 9, 127, 2};
static uint8_t workSector = 0;
static void settingsFirstEnable(void)
{
bit needDef = 1;
uint8_t i;
for(i=0; i<9; i++){
if( *((uint8_t*)(&eep.on + i)) != 0xFF ) {
needDef = 0;
break;
}
}
if(needDef) {
for( i=0; i<sizeof(EEP_Param); i++ ){
*((uint8_t*)(&eep.pageBlock + i)) = *((uint8_t*)(&eepDef.pageBlock + i));
}
settingsSave();
}
return;
}
void settingsInit(void)
{
uint8_t i;
for( i=0; i < sizeof(EEP_Param); i++) {
*((uint8_t*)&eep + i) = IapReadByte((workSector <<9) + i);
}
settingsFirstEnable();
return;
}
void settingsSave(void)
{
uint8_t i;
IapEraseSector(workSector);
/*
ó STC15W1K24S 10 áëîêîâ(ñåêòîðîâ) ïî 512 áàéò, âðîäå êàê ðàññ÷èòàíûõ íà 100ê ñòåðàíèé.
ïîñëå ñòåðàíèÿ íóæíî óäîñòîâåðèòüñÿ ÷òî áëîê ñòåðñÿ è ñîäåðæèò 0xFF,
åñëè íåò òî â ïåðâûé áàéò áëîêà çàïèñàòü 0,
è íà÷àòü èñïîëüçîâàòü ñëåäóþùèé áëîê (workSector++).
*/
for( i=0; i < sizeof(EEP_Param); i++) {
IapProgramByte((workSector <<9) + i, *((uint8_t*)&eep + i));
}
return;
}