Storage.cpp 854 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. simple test of Storage API
  3. */
  4. #include <AP_HAL/AP_HAL.h>
  5. void setup();
  6. void loop();
  7. const AP_HAL::HAL& hal = AP_HAL::get_HAL();
  8. void setup(void)
  9. {
  10. /*
  11. init Storage API
  12. */
  13. AP_HAL::Storage *st = hal.storage;
  14. hal.console->printf("Starting AP_HAL::Storage test\r\n");
  15. st->init();
  16. /*
  17. Calculate XOR of the full conent of memory
  18. Do it by block of 8 bytes
  19. */
  20. unsigned char buff[8], XOR_res = 0;
  21. for (uint32_t i = 0; i < HAL_STORAGE_SIZE; i += 8) {
  22. st->read_block((void *) buff, i, 8);
  23. for(uint32_t j = 0; j < 8; j++) {
  24. XOR_res ^= buff[j];
  25. }
  26. }
  27. /*
  28. print XORed result
  29. */
  30. hal.console->printf("XORed ememory: %u\r\n", (unsigned) XOR_res);
  31. }
  32. // In main loop do nothing
  33. void loop(void)
  34. {
  35. hal.scheduler->delay(1000);
  36. }
  37. AP_HAL_MAIN();