-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patheeprom.c
122 lines (89 loc) · 2.54 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
#include "eeprom.h"
#include <avr/eeprom.h>
#include "ethernet_macaddr.h"
#include <stdint.h>
typedef struct
{
mac_addr_t my_mac_address;
float bandgap;
struct
{
float factor;
float offset;
} temp_cal[temp_cal_size];
struct
{
float factor;
float offset;
} light_cal[light_cal_size];
} eeprom_t;
void eeprom_read_mac_address(mac_addr_t *dst)
{
eeprom_read_block(dst, (const void *)offsetof(eeprom_t, my_mac_address), sizeof(mac_addr_t));
}
float eeprom_read_bandgap(void)
{
float value;
eeprom_read_block((void *)&value, (const void *)offsetof(eeprom_t, bandgap), sizeof(value));
return(value);
}
void eeprom_write_bandgap(float value)
{
eeprom_update_block((const void *)&value, (void *)offsetof(eeprom_t, bandgap), sizeof(value));
}
float eeprom_read_temp_cal_factor(uint8_t index)
{
float value;
if(index >= temp_cal_size)
return(0);
eeprom_read_block((void *)&value, (const void *)offsetof(eeprom_t, temp_cal[index].factor), sizeof(value));
return(value);
}
void eeprom_write_temp_cal_factor(uint8_t index, float value)
{
if(index >= temp_cal_size)
return;
eeprom_update_block((const void *)&value, (void *)offsetof(eeprom_t, temp_cal[index].factor), sizeof(value));
}
float eeprom_read_temp_cal_offset(uint8_t index)
{
float value;
if(index >= temp_cal_size)
return(0);
eeprom_read_block((void *)&value, (const void *)offsetof(eeprom_t, temp_cal[index].offset), sizeof(value));
return(value);
}
void eeprom_write_temp_cal_offset(uint8_t index, float value)
{
if(index >= temp_cal_size)
return;
eeprom_update_block((const void *)&value, (void *)offsetof(eeprom_t, temp_cal[index].offset), sizeof(value));
}
float eeprom_read_light_cal_factor(uint8_t index)
{
float value;
if(index >= light_cal_size)
return(0);
eeprom_read_block((void *)&value, (const void *)offsetof(eeprom_t, light_cal[index].factor), sizeof(value));
return(value);
}
void eeprom_write_light_cal_factor(uint8_t index, float value)
{
if(index >= light_cal_size)
return;
eeprom_update_block((const void *)&value, (void *)offsetof(eeprom_t, light_cal[index].factor), sizeof(value));
}
float eeprom_read_light_cal_offset(uint8_t index)
{
float value;
if(index >= light_cal_size)
return(0);
eeprom_read_block((void *)&value, (const void *)offsetof(eeprom_t, light_cal[index].offset), sizeof(value));
return(value);
}
void eeprom_write_light_cal_offset(uint8_t index, float value)
{
if(index >= light_cal_size)
return;
eeprom_update_block((const void *)&value, (void *)offsetof(eeprom_t, light_cal[index].offset), sizeof(value));
}