log_api.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include "log_api.h"
  2. #include "log.h"
  3. #include "rtc.h"
  4. #include "ringfs.h"
  5. #include "spi_flash.h"
  6. #include "FreeRTOS.h"
  7. #include "task.h"
  8. #include "semphr.h"
  9. #include "rtc.h"
  10. #include <string.h>
  11. #include <stdio.h>
  12. #include <inttypes.h>
  13. #undef DBG
  14. #define DBG if(1)
  15. extern struct ringfs fs_archive;
  16. extern SemaphoreHandle_t log_mutex;
  17. //
  18. void log_get_entry_count(void)
  19. {
  20. int count_flash = 0;
  21. count_flash = ringfs_count_exact(&fs_archive);
  22. printf("Count archive entry: %u\r\n", count_flash);
  23. }
  24. //
  25. int log_get_entry(uint32_t index, struct ringfs *fs)
  26. {
  27. archive_entry_t entry;
  28. int start = ringfs_count_estimate(fs);
  29. fs->cursor_position = start - (index - 1) - 1;
  30. if (fs->cursor_position < 0)
  31. return -1;
  32. else
  33. {
  34. fs->cursor.sector = (fs->read.sector + fs->cursor_position/fs->slots_per_sector)%fs->flash->sector_count;
  35. fs->cursor.slot = fs->cursor_position%fs->slots_per_sector;
  36. }
  37. log_fetch(&entry, ARCHIVE_ENTRY, portMAX_DELAY);
  38. printf("[entry] timestamp = % " PRId64 ", value = %u, crc = %u\r\n", entry.timestamp, entry.input_value, entry.crc);
  39. return 0;
  40. }