-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlpc_aci_eeprom.c
124 lines (107 loc) · 2.85 KB
/
lpc_aci_eeprom.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include "lpc_aci_eeprom.h"
int anz_param_saved = 0;
struct ee_data content[COUNT_PAGES];
void lpc_aci_init(void)
{
int j=0;
int i=0;
for( j=0;j<COUNT_PAGES; j++)
for(i=0; i<254 ; i++) content[j].data[i]=0xFF;
aciSetSaveParaCallback(lpc_aci_SavePara);
aciSetReadParafromFlashCallback(lpc_aci_ReadParafromFlash);
aciSetWriteParatoFlashCallback(lpc_aci_WriteParatoFlash);
}
short lpc_aci_ReadParafromFlash(void)
{
unsigned int command_ee,response_ee[2];
int cnt=0;
short temp_id;
unsigned char temp_vartype;
struct ee_data *ee_data_ptr;
int para_load = 0;
int k = 0;
command_ee=0;
ee_readn(command_ee,response_ee);
short counting = 0;
ee_data_ptr= (struct ee_data *) response_ee[1];
memcpy(&content[0],ee_data_ptr,sizeof(struct ee_data));
para_load++;
while((!content[0].next_side) && (para_load<COUNT_PAGES) )
{
ee_readn(para_load,response_ee);
if(response_ee[0]!=0) break;
ee_data_ptr= (struct ee_data *) response_ee[1];
memcpy(&(content[para_load]),ee_data_ptr,sizeof(struct ee_data));
para_load++;
}
if((content[0].next_side!=1) && (content[0].next_side!=0) ) return (short) content[0].next_side ;
para_load=0;
unsigned char next_side_byte = 0;
while((!next_side_byte)){
cnt=0;
while(cnt<content[para_load].data_count)
{
memcpy(&temp_id,&content[para_load].data[cnt],2);
cnt+=2;
memcpy(&temp_vartype,&content[para_load].data[cnt],1);
cnt+=1;
for(k=0;k<aciListParCount;k++){
if(aciListPar[k].id==temp_id)
{
if(aciListPar[k].varType==temp_vartype)
{
memcpy(aciListPar[k].ptrToVar,&content[para_load].data[cnt],temp_vartype >> 2);
counting++;
}
break;
}
}
cnt+=temp_vartype >> 2;
}
next_side_byte=content[para_load].next_side;
para_load++;
}
return counting;
}
void lpc_aci_SavePara(void)
{
int cnt = 0;
anz_param_saved=0;
int para_load=0;
int k=0;
for(k=0;k<aciListParCount;k++) {
if((cnt+4+(aciListPar[k].varType >> 2))>253)
{
content[para_load].data_count=cnt;
content[para_load].next_side=0;
para_load++;
if(para_load==COUNT_PAGES) break;
cnt=0;
}
memcpy(&content[para_load].data[cnt], &aciListPar[k].id, 2);
cnt += 2;
memcpy(&content[para_load].data[cnt], &aciListPar[k].varType, 1);
cnt += 1;
memcpy(&content[para_load].data[cnt], aciListPar[k].ptrToVar, aciListPar[k].varType >> 2);
cnt += aciListPar[k].varType >> 2;
anz_param_saved++;
}
content[para_load].data_count=cnt;
content[para_load].next_side=1;
}
short lpc_aci_WriteParatoFlash(void)
{
unsigned int command_ee,response_ee[2];
//erase eeprom
ee_erase(command_ee,response_ee);
int para_load = 0;
unsigned char next_side_byte = 0;
while((!next_side_byte)){
command_ee=(unsigned int) (&content[0]);
ee_write(command_ee,response_ee);
if(response_ee[0]==501) return 501;
next_side_byte = content[para_load].next_side;
para_load++;
}
return anz_param_saved;
}