2012-12-12 18:04:27 -04:00
|
|
|
#include <AP_HAL.h>
|
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_AVR_SITL
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "Storage.h"
|
|
|
|
using namespace AVR_SITL;
|
|
|
|
|
|
|
|
void SITLEEPROMStorage::_eeprom_open(void)
|
|
|
|
{
|
|
|
|
if (_eeprom_fd == -1) {
|
|
|
|
_eeprom_fd = open("eeprom.bin", O_RDWR|O_CREAT, 0777);
|
2014-08-13 01:42:35 -03:00
|
|
|
assert(ftruncate(_eeprom_fd, HAL_STORAGE_SIZE) == 0);
|
2012-12-12 18:04:27 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SITLEEPROMStorage::read_block(void *dst, uint16_t src, size_t n)
|
|
|
|
{
|
2014-08-13 04:29:50 -03:00
|
|
|
assert(src < HAL_STORAGE_SIZE && src + n <= HAL_STORAGE_SIZE);
|
2012-12-12 18:04:27 -04:00
|
|
|
_eeprom_open();
|
|
|
|
assert(pread(_eeprom_fd, dst, n, src) == (ssize_t)n);
|
|
|
|
}
|
|
|
|
|
2013-06-04 01:02:13 -03:00
|
|
|
void SITLEEPROMStorage::write_block(uint16_t dst, const void *src, size_t n)
|
2012-12-12 18:04:27 -04:00
|
|
|
{
|
2014-08-13 01:42:35 -03:00
|
|
|
assert(dst < HAL_STORAGE_SIZE);
|
2012-12-12 18:04:27 -04:00
|
|
|
_eeprom_open();
|
|
|
|
assert(pwrite(_eeprom_fd, src, n, dst) == (ssize_t)n);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|