You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
809 B
36 lines
809 B
12 years ago
|
#include <AP_HAL.h>
|
||
10 years ago
|
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
|
||
12 years ago
|
|
||
|
#include <assert.h>
|
||
|
#include <sys/types.h>
|
||
|
#include <sys/stat.h>
|
||
|
#include <fcntl.h>
|
||
|
#include <unistd.h>
|
||
|
|
||
|
#include "Storage.h"
|
||
10 years ago
|
using namespace HALSITL;
|
||
12 years ago
|
|
||
|
void SITLEEPROMStorage::_eeprom_open(void)
|
||
|
{
|
||
|
if (_eeprom_fd == -1) {
|
||
|
_eeprom_fd = open("eeprom.bin", O_RDWR|O_CREAT, 0777);
|
||
11 years ago
|
assert(ftruncate(_eeprom_fd, HAL_STORAGE_SIZE) == 0);
|
||
12 years ago
|
}
|
||
|
}
|
||
|
|
||
|
void SITLEEPROMStorage::read_block(void *dst, uint16_t src, size_t n)
|
||
|
{
|
||
11 years ago
|
assert(src < HAL_STORAGE_SIZE && src + n <= HAL_STORAGE_SIZE);
|
||
12 years ago
|
_eeprom_open();
|
||
|
assert(pread(_eeprom_fd, dst, n, src) == (ssize_t)n);
|
||
|
}
|
||
|
|
||
12 years ago
|
void SITLEEPROMStorage::write_block(uint16_t dst, const void *src, size_t n)
|
||
12 years ago
|
{
|
||
11 years ago
|
assert(dst < HAL_STORAGE_SIZE);
|
||
12 years ago
|
_eeprom_open();
|
||
|
assert(pwrite(_eeprom_fd, src, n, dst) == (ssize_t)n);
|
||
|
}
|
||
|
|
||
|
#endif
|