forked from ethersex/ethersex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheeprom.c
187 lines (152 loc) · 4.72 KB
/
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
*
* (c) by Alexander Neumann <[email protected]>
* Copyright(c) 2008 Christian Dietrich <[email protected]>
* Copyright(c) 2008 Stefan Siegl <[email protected]>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License (either version 2 or
* version 3) as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
*/
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <util/crc16.h>
#include <avr/pgmspace.h>
#include "config.h"
#include "core/eeprom.h"
#ifdef CRC_SUPPORT
uint8_t
crc_checksum (void *data, uint8_t length)
{
uint8_t crc = 0;
uint8_t *p = (uint8_t *) data;
for (uint8_t i = 0; i < length; i++)
{
crc = _crc_ibutton_update (crc, *p);
p++;
}
return crc;
}
#endif /* CRC_SUPPORT */
#ifdef EEPROM_SUPPORT
void
eeprom_write_block_hack (void *dst, const void *src, size_t n)
{
while (n--)
{
eeprom_write_byte (&((uint8_t *) dst)[n], ((uint8_t *) src)[n]);
}
}
uint8_t
eeprom_get_chksum (void)
{
uint8_t eeprom_crc = 0;
uint8_t *p = (uint8_t *) EEPROM_CONFIG_BASE;
for (uint16_t i = 0; i < (sizeof (struct eeprom_config_t) - 1); i++)
{
eeprom_crc = _crc_ibutton_update (eeprom_crc, eeprom_read_byte (p));
p++;
}
return eeprom_crc;
}
void
eeprom_init (void)
{
uip_ipaddr_t ip;
(void) ip; /* Keep GCC quiet. */
#ifdef ETHERNET_SUPPORT
eeprom_save_P (mac, PSTR (CONF_ETHERSEX_MAC), 6);
#endif
#if (defined(IPV4_SUPPORT) && !defined(BOOTP_SUPPORT) && !defined(DHCP_SUPPORT)) || defined(IPV6_STATIC_SUPPORT)
set_CONF_ETHERSEX_IP (&ip);
eeprom_save (ip, &ip, IPADDR_LEN);
#ifdef ETHERNET_SUPPORT
set_CONF_ETHERSEX_GATEWAY (&ip);
eeprom_save (gateway, &ip, IPADDR_LEN);
#endif
#ifdef IPV4_SUPPORT
set_CONF_ETHERSEX_IP4_NETMASK (&ip);
eeprom_save (netmask, &ip, IPADDR_LEN);
#endif
#endif
#ifdef DNS_SUPPORT
set_CONF_DNS_SERVER (&ip);
eeprom_save (dns_server, &ip, IPADDR_LEN);
#endif
#ifdef PAM_SINGLE_USER_EEPROM_SUPPORT
/* Copy the httpd's password. */
eeprom_save_P (pam_username, PSTR (PAM_SINGLE_USERNAME), 16);
eeprom_save_P (pam_password, PSTR (PAM_SINGLE_PASSWORD), 16);
#endif
#ifdef ADC_VOLTAGE_SUPPORT
eeprom_save_int (adc_vref, ADC_REF_VOLTAGE);
#endif
#ifdef KTY_SUPPORT
eeprom_save_char (kty_calibration, 0);
#endif
#ifdef STELLA_EEPROM
uint8_t stella_temp[10] = { 0 };
eeprom_save (stella_channel_values, stella_temp, 10);
#endif
#ifdef DMX_FXSLOT_SUPPORT
struct fxslot_struct_stripped fxslots_temp[DMX_FXSLOT_AMOUNT] = { {0,0,0,0,0,0,0} };
eeprom_save (dmx_fxslots, fxslots_temp, DMX_FXSLOT_AMOUNT*sizeof(struct fxslot_struct_stripped));
#endif
#ifdef ONEWIRE_NAMING_SUPPORT
ow_name_t temp_name;
memset(&temp_name, 0, sizeof(ow_name_t));
for (int8_t i = 0; i < OW_SENSORS_COUNT; i++)
{
eeprom_save(ow_names[i], &temp_name, sizeof(ow_name_t));
}
#endif
#ifdef SMS77_EEPROM_SUPPORT
eeprom_save_P (sms77_username, PSTR (CONF_SMS77_USER), SMS77_VALUESIZE);
eeprom_save_P (sms77_password, PSTR (CONF_SMS77_PASS), SMS77_VALUESIZE);
eeprom_save_P (sms77_receiver, PSTR (CONF_SMS77_TO), SMS77_VALUESIZE);
eeprom_save_P (sms77_type, PSTR (CONF_SMS77_TYPE), SMS77_VALUESIZE);
#endif
#ifdef JABBER_EEPROM_SUPPORT
eeprom_save_P (jabber_username, PSTR (CONF_JABBER_USERNAME),
JABBER_VALUESIZE);
eeprom_save_P (jabber_password, PSTR (CONF_JABBER_PASSWORD),
JABBER_VALUESIZE);
eeprom_save_P (jabber_resource, PSTR (CONF_JABBER_RESOURCE),
JABBER_VALUESIZE);
eeprom_save_P (jabber_hostname, PSTR (CONF_JABBER_HOSTNAME),
JABBER_VALUESIZE);
#endif
#ifdef MOTD_SUPPORT
eeprom_save_P (motd_text, PSTR (CONF_MOTD_DEFAULT), MOTD_VALUESIZE);
#endif
#ifdef CRON_EEPROM_SUPPORT
uint8_t count = 0;
eeprom_save_offset(crontab, 0, &count, sizeof(count));
#endif
#ifdef TANKLEVEL_SUPPORT
tanklevel_params_t tanklevel_temp = {
.sensor_offset = TANKLEVEL_SENSOR_OFFSET,
.med_density = TANKLEVEL_MED_DENSITY,
.ltr_per_m = TANKLEVEL_LTR_PER_M,
.ltr_full = TANKLEVEL_LTR_FULL,
.raise_time = TANKLEVEL_RAISE_TIME,
.hold_time = TANKLEVEL_HOLD_TIME
};
eeprom_save (tanklevel_params, &tanklevel_temp, sizeof(tanklevel_params_t));
#endif
eeprom_update_chksum ();
}
#endif /* EEPROM_SUPPORT */