2015-08-11 03:28:43 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2012-12-12 18:01:40 -04:00
|
|
|
#if (CONFIG_HAL_BOARD == HAL_BOARD_APM1 || CONFIG_HAL_BOARD == HAL_BOARD_APM2)
|
2012-08-30 21:18:20 -03:00
|
|
|
|
|
|
|
#include <avr/io.h>
|
|
|
|
#include <avr/eeprom.h>
|
|
|
|
#include "Storage.h"
|
|
|
|
using namespace AP_HAL_AVR;
|
|
|
|
|
2014-08-13 01:59:28 -03:00
|
|
|
void AVREEPROMStorage::read_block(void *dst, uint16_t src, size_t n)
|
|
|
|
{
|
2012-11-12 15:05:20 -04:00
|
|
|
eeprom_read_block(dst,(const void*)src,n);
|
2012-08-30 21:18:20 -03:00
|
|
|
}
|
|
|
|
|
2014-08-13 01:59:28 -03:00
|
|
|
void AVREEPROMStorage::write_block(uint16_t dst, const void *src, size_t n)
|
|
|
|
{
|
2013-06-04 00:33:41 -03:00
|
|
|
uint8_t *p = (uint8_t *)src;
|
|
|
|
while (n--) {
|
2014-08-13 01:59:28 -03:00
|
|
|
/*
|
|
|
|
it is much faster to read than write, so it is worth
|
|
|
|
checking if the value is already correct
|
|
|
|
*/
|
|
|
|
uint8_t b = eeprom_read_byte((uint8_t*)dst);
|
|
|
|
if (b != *p) {
|
|
|
|
eeprom_write_byte((uint8_t*)dst, *p);
|
|
|
|
}
|
|
|
|
dst++;
|
2014-10-15 01:13:00 -03:00
|
|
|
p++;
|
2013-06-04 00:33:41 -03:00
|
|
|
}
|
2012-08-30 21:18:20 -03:00
|
|
|
}
|
|
|
|
|
2012-12-12 18:01:40 -04:00
|
|
|
#endif
|