1 /* Copyright (C) 2008 Sean D'Epagnier <sean@depagnier.com>
3 * This Program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public
5 * License as published by the Free Software Foundation; either
6 * version 3 of the License, or (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 * For more information on the GPL, please go to:
18 * http://www.gnu.org/copyleft/gpl.html
21 /* the routines in avrlibc for reading and writing to eeprom are not
24 I disable interrupt 2 (if it was enabled)
27 #include <avr/interrupt.h>
29 #define AVRDATA_SKIP_EEPROM_DEFINE
33 eeprom_read_byte_safe(const uint8_t *addr
)
37 val
= eeprom_read_byte(addr
);
43 eeprom_read_word_safe(const uint16_t *addr
)
46 uint16_t val
= eeprom_read_word(addr
);
52 eeprom_read_block_safe(void *pointer_ram
, const void *pointer_eeprom
,
57 ((uint8_t*)pointer_ram
)[i
] =
58 eeprom_read_byte_safe((uint8_t*)pointer_eeprom
+ i
);
62 eeprom_read_float_safe(float *var
)
65 eeprom_read_block_safe(&val
, var
, sizeof val
);
70 eeprom_write_byte_safe(uint8_t *addr
, uint8_t val
)
73 eeprom_write_byte(addr
, val
);
78 eeprom_write_word_safe(uint16_t *addr
, uint16_t val
)
81 eeprom_write_word(addr
, val
);
86 eeprom_write_block_safe(const void *pointer_ram
, void *pointer_eeprom
,
91 eeprom_write_byte_safe((uint8_t*)pointer_eeprom
+ i
,
92 ((uint8_t*)pointer_ram
)[i
]);
96 eeprom_write_float_safe(float *var
, float val
)
98 eeprom_write_block_safe(&val
, var
, sizeof val
);