MCPcopy Create free account
hub / github.com/ArduPilot/ardupilot / io_timer

Method io_timer

libraries/AP_Logger/AP_Logger_File.cpp:907–1028  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

905#endif
906
907void AP_Logger_File::io_timer(void)
908{
909 uint32_t tnow = AP_HAL::millis();
910 _io_timer_heartbeat = tnow;
911
912 if (start_new_log_pending) {
913 start_new_log();
914 start_new_log_pending = false;
915 }
916
917 if (erase.log_num != 0) {
918 // continue erase
919 erase_next();
920 return;
921 }
922
923 if (_write_fd == -1 || !_initialised || recent_open_error()) {
924 return;
925 }
926
927 if (last_log_is_marked_discard && hal.util->get_soft_armed()) {
928 // time to make the log permanent
929 const auto log_num = find_last_log();
930 last_log_is_marked_discard = false;
931 write_lastlog_file(log_num);
932 }
933
934 uint32_t nbytes = _writebuf.available();
935 if (nbytes == 0) {
936 return;
937 }
938 if (nbytes < _writebuf_chunk &&
939 tnow - _last_write_time < 2000UL) {
940 // write in _writebuf_chunk-sized chunks, but always write at
941 // least once per 2 seconds if data is available
942 return;
943 }
944 if (tnow - _free_space_last_check_time > _free_space_check_interval) {
945 _free_space_last_check_time = tnow;
946 last_io_operation = "disk_space_avail";
947 if (disk_space_avail() < _free_space_min_avail && disk_space() > 0) {
948 DEV_PRINTF("Out of space for logging\n");
949 stop_logging();
950 _open_error_ms = AP_HAL::millis(); // prevent logging starting again for 5s
951 last_io_operation = "";
952 return;
953 }
954 last_io_operation = "";
955 }
956
957 _last_write_time = tnow;
958 if (nbytes > _writebuf_chunk) {
959 // be kind to the filesystem layer
960 nbytes = _writebuf_chunk;
961 }
962
963 uint32_t size;
964 const uint8_t *head = _writebuf.readptr(size);

Callers

nothing calls this directly

Calls 14

MINFunction · 0.85
strerrorFunction · 0.85
get_soft_armedMethod · 0.80
get_utc_usecMethod · 0.80
millisFunction · 0.50
availableMethod · 0.45
readptrMethod · 0.45
takeMethod · 0.45
giveMethod · 0.45
writeMethod · 0.45
closeMethod · 0.45
advanceMethod · 0.45

Tested by

no test coverage detected