mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-22 00:28:30 -04:00
AP_HAL_AVR Storage: commit test
This commit is contained in:
parent
187571cca9
commit
229f58412b
0
libraries/AP_HAL_AVR/examples/Storage/Arduino.h
Normal file
0
libraries/AP_HAL_AVR/examples/Storage/Arduino.h
Normal file
1
libraries/AP_HAL_AVR/examples/Storage/Makefile
Normal file
1
libraries/AP_HAL_AVR/examples/Storage/Makefile
Normal file
@ -0,0 +1 @@
|
||||
include ../../../AP_Common/Arduino.mk
|
58
libraries/AP_HAL_AVR/examples/Storage/Storage.pde
Normal file
58
libraries/AP_HAL_AVR/examples/Storage/Storage.pde
Normal file
@ -0,0 +1,58 @@
|
||||
|
||||
#include <AP_Common.h>
|
||||
#include <AP_HAL.h>
|
||||
#include <AP_HAL_AVR.h>
|
||||
|
||||
const AP_HAL::HAL& hal = AP_HAL_AVR_APM1;
|
||||
|
||||
uint8_t fibs[12] = { 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144 };
|
||||
|
||||
void test_erase() {
|
||||
hal.uart0->printf_P(PSTR("erasing... "));
|
||||
for(int i = 0; i < 100; i++) {
|
||||
hal.storage->write_byte((uint8_t*)i, 0);
|
||||
}
|
||||
hal.uart0->printf_P(PSTR(" done.\r\n"));
|
||||
}
|
||||
|
||||
void test_write() {
|
||||
hal.uart0->printf_P(PSTR("writing... "));
|
||||
hal.storage->write_block(fibs, (uint8_t*)0, 12);
|
||||
hal.uart0->printf_P(PSTR(" done.\r\n"));
|
||||
}
|
||||
|
||||
void test_readback() {
|
||||
hal.uart0->printf_P(PSTR("reading back...\r\n"));
|
||||
uint8_t readback[12];
|
||||
bool success = true;
|
||||
hal.storage->read_block(readback, (uint8_t*)0, 12);
|
||||
for (int i = 0; i < 12; i++) {
|
||||
if (readback[i] != fibs[i]) {
|
||||
success = false;
|
||||
hal.uart0->printf_P(PSTR("At index %d expected %d got %d\r\n"),
|
||||
i, (int) fibs[i], (int) readback[i]);
|
||||
}
|
||||
}
|
||||
if (success) {
|
||||
hal.uart0->printf_P(PSTR("all bytes read successfully\r\n"));
|
||||
}
|
||||
hal.uart0->printf_P(PSTR("done reading back.\r\n"));
|
||||
}
|
||||
|
||||
void setup (void) {
|
||||
hal.uart0->printf_P(PSTR("Starting AP_HAL_AVR::Storage test\r\n"));
|
||||
test_erase();
|
||||
test_write();
|
||||
test_readback();
|
||||
}
|
||||
|
||||
void loop (void) { }
|
||||
|
||||
extern "C" {
|
||||
int main (void) {
|
||||
hal.init(NULL);
|
||||
setup();
|
||||
for(;;) loop();
|
||||
return 0;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user