From 673482249a4c30e8f302920e104d1705e2edaedf Mon Sep 17 00:00:00 2001 From: gferraro Date: Mon, 19 Aug 2024 13:46:47 +1200 Subject: [PATCH 1/8] check for ffc --- src/attiny_rtc_i2c.rs | 8 ++++++++ src/core0_task.rs | 23 ++++++++++++++++++++--- src/core1_task.rs | 32 +++++++++++++++++++++++++++++--- src/main.rs | 2 +- 4 files changed, 58 insertions(+), 7 deletions(-) diff --git a/src/attiny_rtc_i2c.rs b/src/attiny_rtc_i2c.rs index a77bc05..11eb3c2 100644 --- a/src/attiny_rtc_i2c.rs +++ b/src/attiny_rtc_i2c.rs @@ -376,6 +376,14 @@ impl SharedI2C { Err(x) => Err(x), } } + + pub fn tc2_agent_is_recording(&mut self, delay: &mut Delay) -> Result { + match self.try_attiny_read_command(REG_TC2_AGENT_STATE, delay, None) { + Ok(state) => Ok((state & 0x04) == 0x04), + Err(e) => Err(e), + } + } + pub fn pi_is_waking_or_awake(&mut self, delay: &mut Delay) -> Result { match self.try_attiny_read_command(REG_CAMERA_STATE, delay, None) { Ok(state) => { diff --git a/src/core0_task.rs b/src/core0_task.rs index a80ad96..c4a0c9c 100644 --- a/src/core0_task.rs +++ b/src/core0_task.rs @@ -102,7 +102,8 @@ pub fn frame_acquisition_loop( // Do FFC every 20 mins? let mut needs_ffc = false; let mut ffc_requested = false; - + let mut can_do_ffc = true; + let mut high_power_mode = false; let mut seen_telemetry_revision = [0u8, 0u8]; let mut times_telemetry_revision_stable = -1; let mut frames_seen = 0; @@ -137,6 +138,7 @@ pub fn frame_acquisition_loop( // Initiate the transfer of the previous frame sio_fifo.write(Core1Task::ReceiveFrame.into()); sio_fifo.write(selected_frame_buffer); + sio_fifo.write(needs_ffc as u32); if selected_frame_buffer == 0 { selected_frame_buffer = 1; } else { @@ -175,7 +177,8 @@ pub fn frame_acquisition_loop( if got_sync && valid_frame_current_segment_num == 1 { // Check if we need an FFC if unverified_frame_counter == prev_frame_counter + 2 { - if !is_recording + if !needs_ffc + && !is_recording && telemetry.msec_on != 0 && (telemetry.time_at_last_ffc != 0 || !has_done_initial_ffc) { @@ -190,9 +193,18 @@ pub fn frame_acquisition_loop( && telemetry.ffc_status != FFCStatus::Imminent && telemetry.ffc_status != FFCStatus::InProgress { + info!("Requesting ffc"); needs_ffc = true; ffc_requested = false; + if high_power_mode { + can_do_ffc = false; + } } + info!( + "Requesting ffc in {}", + FFC_INTERVAL_MS / 1000 + - (telemetry.msec_on - telemetry.time_at_last_ffc) / 1000 + ); // Sometimes the header is invalid, but the frame becomes valid and gets sync. // Because the telemetry revision is static across frame headers we can detect this // case and not send the frame, as it may cause false triggers. @@ -339,7 +351,7 @@ pub fn frame_acquisition_loop( prev_segment_was_4 = is_last_segment; if packet_id == last_packet_id_for_segment { if is_last_segment { - if needs_ffc && !ffc_requested { + if can_do_ffc && needs_ffc && !ffc_requested { ffc_requested = true; info!("Requesting needed FFC"); let success = lepton.do_ffc(); @@ -468,6 +480,8 @@ pub fn frame_acquisition_loop( } } else if message == Core1Task::EndRecording.into() { recording_ended = true; + can_do_ffc = true; + info!("Can do ffc is {}", can_do_ffc); if let Some(message) = sio_fifo.read() { if message == Core1Task::FrameProcessingComplete.into() { transferring_prev_frame = false; @@ -493,6 +507,9 @@ pub fn frame_acquisition_loop( // Wait until the watchdog timer kills us. nop(); } + } else if message == Core1Task::HighPowerMode.into() { + high_power_mode = true; + info!("in high power mode"); } } // if !transferring_prev_frame || recording_started { diff --git a/src/core1_task.rs b/src/core1_task.rs index d664771..407b366 100644 --- a/src/core1_task.rs +++ b/src/core1_task.rs @@ -49,6 +49,7 @@ pub enum Core1Task { EndFileOffload = 0xfb, ReadyToSleep = 0xef, RequestReset = 0xea, + HighPowerMode = 0xeb, } impl Into for Core1Task { @@ -326,6 +327,7 @@ pub fn core_1_task( huffman_table.copy_from_slice(&HUFFMAN_TABLE[..]); sio.fifo.write_blocking(Core1Task::Ready.into()); + let radiometry_enabled = sio.fifo.read_blocking(); info!("Core 1 got radiometry enabled: {}", radiometry_enabled == 2); let lepton_version = if radiometry_enabled == 2 { 35 } else { 3 }; @@ -392,7 +394,6 @@ pub fn core_1_task( None, ); } - // NOTE: We'll only wake the pi if we have files to offload, and it is *outside* the recording // window, or the previous offload happened more than 24 hours ago, or the flash is nearly full. // Otherwise, if the rp2040 happens to restart, we'll pretty much @@ -444,7 +445,9 @@ pub fn core_1_task( .map_err(|e| error!("Error setting recording flag on attiny: {}", e)); warn!("Core 1 is ready to receive frames"); sio.fifo.write_blocking(Core1Task::Ready.into()); - + if !device_config.config().use_low_power_mode { + sio.fifo.write_blocking(Core1Task::HighPowerMode.into()); + } let mut cptv_stream: Option = None; let mut prev_frame: [u16; (FRAME_WIDTH * FRAME_HEIGHT) + 1] = [0u16; (FRAME_WIDTH * FRAME_HEIGHT) + 1]; @@ -488,6 +491,8 @@ pub fn core_1_task( let mut made_startup_status_recording = !has_files_to_offload || did_offload_files; let mut made_shutdown_status_recording = false; let mut making_status_recording = false; + let mut high_power_recording = false; + let mut last_rec_check = 0; // Enable raw frame transfers to pi – if not already enabled. pi_spi.enable_pio_spi(); info!("Entering frame loop"); @@ -503,6 +508,7 @@ pub fn core_1_task( let start = timer.get_counter(); // Get the currently selected buffer to transfer/write to disk. let selected_frame_buffer = sio.fifo.read_blocking(); + let needs_ffc = sio.fifo.read_blocking() > 0; critical_section::with(|cs| { // Now we just swap the buffers? let buffer = if selected_frame_buffer == 0 { @@ -526,7 +532,27 @@ pub fn core_1_task( is_frame_telemetry_is_valid(&frame_telemetry, &mut stable_telemetry_tracker); (frame_telemetry, frame_header_is_valid) }; - + if needs_ffc && !device_config.use_low_power_mode() { + if frame_telemetry.frame_num - last_rec_check > 9 * 20 { + if let Ok(is_recording) = shared_i2c.tc2_agent_is_recording(&mut delay) { + last_rec_check = frame_telemetry.frame_num; + info!( + "Checking if recording {} am recording ?? {}", + is_recording, high_power_recording + ); + if is_recording { + sio.fifo.write(Core1Task::StartRecording.into()); + high_power_recording = true; + } else { + sio.fifo.write(Core1Task::EndRecording.into()); + high_power_recording = false; + } + } + } + } else if high_power_recording { + high_power_recording = false; + last_rec_check = 0; + } let frame_transfer_start = timer.get_counter(); // Transfer RAW frame to pi if it is available. let transfer = if frame_header_is_valid { diff --git a/src/main.rs b/src/main.rs index 797d3d7..863a13b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -69,7 +69,7 @@ const ROSC_TARGET_CLOCK_FREQ_HZ_THERMAL: u32 = 150_000_000; // got funny results at 150 for aduio seems to work better at 125 const ROSC_TARGET_CLOCK_FREQ_HZ_AUDIO: u32 = 125_000_000; -const FFC_INTERVAL_MS: u32 = 60 * 1000 * 20; // 20 mins between FFCs +const FFC_INTERVAL_MS: u32 = 1000 * 40; // 20 mins between FFCs pub type FramePacketData = [u8; FRAME_WIDTH]; pub type FrameSegments = [[FramePacketData; 61]; 4]; const TRANSFER_HEADER_LENGTH: usize = 18; From 43abbb2179610c221e22930ea462f27b50d85a2f Mon Sep 17 00:00:00 2001 From: gferraro Date: Mon, 19 Aug 2024 17:15:46 +1200 Subject: [PATCH 2/8] remove logging --- src/core0_task.rs | 7 ------- src/main.rs | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/core0_task.rs b/src/core0_task.rs index c4a0c9c..30172c8 100644 --- a/src/core0_task.rs +++ b/src/core0_task.rs @@ -193,18 +193,12 @@ pub fn frame_acquisition_loop( && telemetry.ffc_status != FFCStatus::Imminent && telemetry.ffc_status != FFCStatus::InProgress { - info!("Requesting ffc"); needs_ffc = true; ffc_requested = false; if high_power_mode { can_do_ffc = false; } } - info!( - "Requesting ffc in {}", - FFC_INTERVAL_MS / 1000 - - (telemetry.msec_on - telemetry.time_at_last_ffc) / 1000 - ); // Sometimes the header is invalid, but the frame becomes valid and gets sync. // Because the telemetry revision is static across frame headers we can detect this // case and not send the frame, as it may cause false triggers. @@ -481,7 +475,6 @@ pub fn frame_acquisition_loop( } else if message == Core1Task::EndRecording.into() { recording_ended = true; can_do_ffc = true; - info!("Can do ffc is {}", can_do_ffc); if let Some(message) = sio_fifo.read() { if message == Core1Task::FrameProcessingComplete.into() { transferring_prev_frame = false; diff --git a/src/main.rs b/src/main.rs index 863a13b..797d3d7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -69,7 +69,7 @@ const ROSC_TARGET_CLOCK_FREQ_HZ_THERMAL: u32 = 150_000_000; // got funny results at 150 for aduio seems to work better at 125 const ROSC_TARGET_CLOCK_FREQ_HZ_AUDIO: u32 = 125_000_000; -const FFC_INTERVAL_MS: u32 = 1000 * 40; // 20 mins between FFCs +const FFC_INTERVAL_MS: u32 = 60 * 1000 * 20; // 20 mins between FFCs pub type FramePacketData = [u8; FRAME_WIDTH]; pub type FrameSegments = [[FramePacketData; 61]; 4]; const TRANSFER_HEADER_LENGTH: usize = 18; From 02a7cc9c2c1231b9cf75147663a3b70090f3f2c5 Mon Sep 17 00:00:00 2001 From: gferraro Date: Mon, 19 Aug 2024 21:42:59 +1200 Subject: [PATCH 3/8] remove log --- src/onboard_flash.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/onboard_flash.rs b/src/onboard_flash.rs index 3b5a3cf..e52baa6 100644 --- a/src/onboard_flash.rs +++ b/src/onboard_flash.rs @@ -1174,10 +1174,6 @@ impl OnboardFlash { let space = &mut bytes[4..][0x820..=0x83f][14..=15]; LittleEndian::write_u16(space, previous_start as u16); } - info!( - "Written start {} previous start {}", - self.file_start_block_index, self.previous_file_start_block_index - ); //info!("Wrote user meta {:?}", bytes[4..][0x820..=0x83f][0..10]); } // info!( From 9a8d5c2b2c2f86c36d19559096efcf6ea7adf6dd Mon Sep 17 00:00:00 2001 From: gferraro Date: Tue, 20 Aug 2024 14:36:39 +1200 Subject: [PATCH 4/8] ffc pending --- src/core0_task.rs | 31 ++++++++++++++++++++++--------- src/core1_task.rs | 15 +++++++++++++++ src/main.rs | 7 ++++++- 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/src/core0_task.rs b/src/core0_task.rs index 30172c8..058bc40 100644 --- a/src/core0_task.rs +++ b/src/core0_task.rs @@ -75,7 +75,6 @@ pub fn frame_acquisition_loop( let crc_check = Crc::::new(&CRC_16_XMODEM); let do_crc_check = true; let mut crc_buffer = [0u8; 164]; - let mut prev_segment_was_4 = false; let mut scanline_buffer = [0u16; 82]; @@ -199,6 +198,12 @@ pub fn frame_acquisition_loop( can_do_ffc = false; } } + info!( + "Doing ffc in {}", + (FFC_INTERVAL_MS - telemetry.msec_on + + telemetry.time_at_last_ffc) + / 1000 + ); // Sometimes the header is invalid, but the frame becomes valid and gets sync. // Because the telemetry revision is static across frame headers we can detect this // case and not send the frame, as it may cause false triggers. @@ -313,24 +318,27 @@ pub fn frame_acquisition_loop( && packet_id != 0 && valid_frame_current_segment_num != 1 { - warn!( - "Checksum fail on packet {}, segment {}", - packet_id, current_segment_num - ); + // warn!( + // "Checksum fail on packet {}, segment {} buffer {}", + // packet_id, current_segment_num, selected_frame_buffer + // ); } } + let is_last_packet = packet_id == last_packet_id_for_segment; + let is_last_segment = valid_frame_current_segment_num == 4; // Copy the line out to the appropriate place in the current segment buffer. critical_section::with(|cs| { let segment_index = ((valid_frame_current_segment_num as u8).max(1).min(4) - 1) as usize; // NOTE: We may be writing the incorrect seg number here initially, but it will always be - // set correctly when we reach packet 20, assuming we do manage to write out a full segment. + // set correctly when we reach qpacket 20, assuming we do manage to write out a full segment. let buffer = if selected_frame_buffer == 0 { frame_buffer_local } else { frame_buffer_local_2 }; + LittleEndian::write_u16_into( &scanline_buffer[2..], buffer @@ -339,11 +347,16 @@ pub fn frame_acquisition_loop( .unwrap() .packet(segment_index, packet_id as usize), ); + if is_last_segment && is_last_packet { + buffer + .borrow_ref_mut(cs) + .as_mut() + .unwrap() + .ffc_pending(needs_ffc); + } }); - - let is_last_segment = valid_frame_current_segment_num == 4; prev_segment_was_4 = is_last_segment; - if packet_id == last_packet_id_for_segment { + if is_last_packet { if is_last_segment { if can_do_ffc && needs_ffc && !ffc_requested { ffc_requested = true; diff --git a/src/core1_task.rs b/src/core1_task.rs index 9414fd5..5a6580c 100644 --- a/src/core1_task.rs +++ b/src/core1_task.rs @@ -532,6 +532,17 @@ pub fn core_1_task( is_frame_telemetry_is_valid(&frame_telemetry, &mut stable_telemetry_tracker); (frame_telemetry, frame_header_is_valid) }; + let telemetry_ffc = thread_local_frame_buffer + .as_mut() + .unwrap() + .frame_data_as_u8_slice_mut()[637]; + + // crate::assert_eq!( + // needs_ffc, + // telemetry_ffc > 0, + // "Needs ffc doesn't match telemtry {}", + // needs_ffc + // ); if needs_ffc && !device_config.use_low_power_mode() { if frame_telemetry.frame_num - last_rec_check > 9 * 20 { if let Ok(is_recording) = shared_i2c.tc2_agent_is_recording(&mut delay) { @@ -543,6 +554,10 @@ pub fn core_1_task( if is_recording { sio.fifo.write(Core1Task::StartRecording.into()); high_power_recording = true; + thread_local_frame_buffer + .as_mut() + .unwrap() + .ffc_pending(false); } else { sio.fifo.write(Core1Task::EndRecording.into()); high_power_recording = false; diff --git a/src/main.rs b/src/main.rs index 797d3d7..2bd9e95 100644 --- a/src/main.rs +++ b/src/main.rs @@ -69,7 +69,7 @@ const ROSC_TARGET_CLOCK_FREQ_HZ_THERMAL: u32 = 150_000_000; // got funny results at 150 for aduio seems to work better at 125 const ROSC_TARGET_CLOCK_FREQ_HZ_AUDIO: u32 = 125_000_000; -const FFC_INTERVAL_MS: u32 = 60 * 1000 * 20; // 20 mins between FFCs +const FFC_INTERVAL_MS: u32 = 1000 * 20; // 20 mins between FFCs pub type FramePacketData = [u8; FRAME_WIDTH]; pub type FrameSegments = [[FramePacketData; 61]; 4]; const TRANSFER_HEADER_LENGTH: usize = 18; @@ -91,6 +91,11 @@ impl FrameBuffer { &mut self.0 } + pub fn ffc_pending(&mut self, is_pending: bool) { + self.0[TRANSFER_HEADER_LENGTH + 637] = if is_pending { 1 } else { 0 }; + self.0[TRANSFER_HEADER_LENGTH + 636] = if is_pending { 1 } else { 0 }; + } + pub fn frame_data_as_u8_slice_mut(&mut self) -> &mut [u8] { &mut self.0[TRANSFER_HEADER_LENGTH..TRANSFER_HEADER_LENGTH + 39040] } From f02ba56d6b0eea6c8c9b9182614fd23dbf329576 Mon Sep 17 00:00:00 2001 From: gferraro Date: Tue, 20 Aug 2024 19:12:16 +1200 Subject: [PATCH 5/8] just use frame message --- src/core0_task.rs | 28 ++++++++++++---------------- src/core1_task.rs | 30 +++++++++++++++++------------- src/main.rs | 1 - 3 files changed, 29 insertions(+), 30 deletions(-) diff --git a/src/core0_task.rs b/src/core0_task.rs index 058bc40..31b5869 100644 --- a/src/core0_task.rs +++ b/src/core0_task.rs @@ -135,9 +135,12 @@ pub fn frame_acquisition_loop( } if !transferring_prev_frame && prev_frame_needs_transfer { // Initiate the transfer of the previous frame - sio_fifo.write(Core1Task::ReceiveFrame.into()); + if needs_ffc { + sio_fifo.write(Core1Task::ReceiveFrameWithPendingFFC.into()); + } else { + sio_fifo.write(Core1Task::ReceiveFrame.into()); + } sio_fifo.write(selected_frame_buffer); - sio_fifo.write(needs_ffc as u32); if selected_frame_buffer == 0 { selected_frame_buffer = 1; } else { @@ -318,15 +321,13 @@ pub fn frame_acquisition_loop( && packet_id != 0 && valid_frame_current_segment_num != 1 { - // warn!( - // "Checksum fail on packet {}, segment {} buffer {}", - // packet_id, current_segment_num, selected_frame_buffer - // ); + warn!( + "Checksum fail on packet {}, segment {} buffer {}", + packet_id, current_segment_num, selected_frame_buffer + ); } } - let is_last_packet = packet_id == last_packet_id_for_segment; - let is_last_segment = valid_frame_current_segment_num == 4; // Copy the line out to the appropriate place in the current segment buffer. critical_section::with(|cs| { let segment_index = @@ -347,16 +348,11 @@ pub fn frame_acquisition_loop( .unwrap() .packet(segment_index, packet_id as usize), ); - if is_last_segment && is_last_packet { - buffer - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .ffc_pending(needs_ffc); - } }); + + let is_last_segment = valid_frame_current_segment_num == 4; prev_segment_was_4 = is_last_segment; - if is_last_packet { + if packet_id == last_packet_id_for_segment { if is_last_segment { if can_do_ffc && needs_ffc && !ffc_requested { ffc_requested = true; diff --git a/src/core1_task.rs b/src/core1_task.rs index 5a6580c..f700f9e 100644 --- a/src/core1_task.rs +++ b/src/core1_task.rs @@ -50,6 +50,7 @@ pub enum Core1Task { ReadyToSleep = 0xef, RequestReset = 0xea, HighPowerMode = 0xeb, + ReceiveFrameWithPendingFFC = 0xac, } impl Into for Core1Task { @@ -498,17 +499,22 @@ pub fn core_1_task( info!("Entering frame loop"); loop { let input = sio.fifo.read_blocking(); - crate::assert_eq!( - input, - Core1Task::ReceiveFrame.into(), - "Got unknown fifo input to core1 task loop {}", - input - ); + let needs_ffc: bool; + if input == Core1Task::ReceiveFrameWithPendingFFC.into() { + needs_ffc = true; + } else { + crate::assert_eq!( + input, + Core1Task::ReceiveFrame.into(), + "Got unknown fifo input to core1 task loop {}", + input + ); + needs_ffc = false; + } let start = timer.get_counter(); // Get the currently selected buffer to transfer/write to disk. let selected_frame_buffer = sio.fifo.read_blocking(); - let needs_ffc = sio.fifo.read_blocking() > 0; critical_section::with(|cs| { // Now we just swap the buffers? let buffer = if selected_frame_buffer == 0 { @@ -537,12 +543,6 @@ pub fn core_1_task( .unwrap() .frame_data_as_u8_slice_mut()[637]; - // crate::assert_eq!( - // needs_ffc, - // telemetry_ffc > 0, - // "Needs ffc doesn't match telemtry {}", - // needs_ffc - // ); if needs_ffc && !device_config.use_low_power_mode() { if frame_telemetry.frame_num - last_rec_check > 9 * 20 { if let Ok(is_recording) = shared_i2c.tc2_agent_is_recording(&mut delay) { @@ -561,6 +561,10 @@ pub fn core_1_task( } else { sio.fifo.write(Core1Task::EndRecording.into()); high_power_recording = false; + thread_local_frame_buffer + .as_mut() + .unwrap() + .ffc_pending(true); } } } diff --git a/src/main.rs b/src/main.rs index 2bd9e95..9669375 100644 --- a/src/main.rs +++ b/src/main.rs @@ -93,7 +93,6 @@ impl FrameBuffer { pub fn ffc_pending(&mut self, is_pending: bool) { self.0[TRANSFER_HEADER_LENGTH + 637] = if is_pending { 1 } else { 0 }; - self.0[TRANSFER_HEADER_LENGTH + 636] = if is_pending { 1 } else { 0 }; } pub fn frame_data_as_u8_slice_mut(&mut self) -> &mut [u8] { From c5c312b77bf645290b55534bec824e42d427d30e Mon Sep 17 00:00:00 2001 From: gferraro Date: Wed, 21 Aug 2024 14:48:01 +1200 Subject: [PATCH 6/8] ffc imminent --- src/core1_task.rs | 13 ++++++++++--- src/main.rs | 5 +++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/core1_task.rs b/src/core1_task.rs index f700f9e..0adbac4 100644 --- a/src/core1_task.rs +++ b/src/core1_task.rs @@ -546,32 +546,39 @@ pub fn core_1_task( if needs_ffc && !device_config.use_low_power_mode() { if frame_telemetry.frame_num - last_rec_check > 9 * 20 { if let Ok(is_recording) = shared_i2c.tc2_agent_is_recording(&mut delay) { + high_power_recording = is_recording; last_rec_check = frame_telemetry.frame_num; info!( "Checking if recording {} am recording ?? {}", is_recording, high_power_recording ); - if is_recording { + if high_power_recording { sio.fifo.write(Core1Task::StartRecording.into()); high_power_recording = true; thread_local_frame_buffer .as_mut() .unwrap() - .ffc_pending(false); + .ffc_imminent(false); } else { sio.fifo.write(Core1Task::EndRecording.into()); high_power_recording = false; thread_local_frame_buffer .as_mut() .unwrap() - .ffc_pending(true); + .ffc_imminent(true); } } + } else if !high_power_recording { + thread_local_frame_buffer + .as_mut() + .unwrap() + .ffc_imminent(true); } } else if high_power_recording { high_power_recording = false; last_rec_check = 0; } + let frame_transfer_start = timer.get_counter(); // Transfer RAW frame to pi if it is available. let transfer = if frame_header_is_valid { diff --git a/src/main.rs b/src/main.rs index 9669375..37e46d2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -91,8 +91,9 @@ impl FrameBuffer { &mut self.0 } - pub fn ffc_pending(&mut self, is_pending: bool) { - self.0[TRANSFER_HEADER_LENGTH + 637] = if is_pending { 1 } else { 0 }; + pub fn ffc_imminent(&mut self, is_imminent: bool) { + self.0[TRANSFER_HEADER_LENGTH + 636] = if is_imminent { 1 } else { 0 }; + self.0[TRANSFER_HEADER_LENGTH + 637] = if is_imminent { 1 } else { 0 }; } pub fn frame_data_as_u8_slice_mut(&mut self) -> &mut [u8] { From 1a0d94174e0478d9c893369729761d5d5095d968 Mon Sep 17 00:00:00 2001 From: gferraro Date: Wed, 21 Aug 2024 14:51:54 +1200 Subject: [PATCH 7/8] add some comments --- src/core0_task.rs | 7 +++---- src/core1_task.rs | 11 +++-------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/core0_task.rs b/src/core0_task.rs index 31b5869..cd9e5cd 100644 --- a/src/core0_task.rs +++ b/src/core0_task.rs @@ -322,8 +322,8 @@ pub fn frame_acquisition_loop( && valid_frame_current_segment_num != 1 { warn!( - "Checksum fail on packet {}, segment {} buffer {}", - packet_id, current_segment_num, selected_frame_buffer + "Checksum fail on packet {}, segment {}", + packet_id, current_segment_num ); } } @@ -333,7 +333,7 @@ pub fn frame_acquisition_loop( let segment_index = ((valid_frame_current_segment_num as u8).max(1).min(4) - 1) as usize; // NOTE: We may be writing the incorrect seg number here initially, but it will always be - // set correctly when we reach qpacket 20, assuming we do manage to write out a full segment. + // set correctly when we reach packet 20, assuming we do manage to write out a full segment. let buffer = if selected_frame_buffer == 0 { frame_buffer_local } else { @@ -511,7 +511,6 @@ pub fn frame_acquisition_loop( } } else if message == Core1Task::HighPowerMode.into() { high_power_mode = true; - info!("in high power mode"); } } // if !transferring_prev_frame || recording_started { diff --git a/src/core1_task.rs b/src/core1_task.rs index 0adbac4..a3a6f82 100644 --- a/src/core1_task.rs +++ b/src/core1_task.rs @@ -538,12 +538,10 @@ pub fn core_1_task( is_frame_telemetry_is_valid(&frame_telemetry, &mut stable_telemetry_tracker); (frame_telemetry, frame_header_is_valid) }; - let telemetry_ffc = thread_local_frame_buffer - .as_mut() - .unwrap() - .frame_data_as_u8_slice_mut()[637]; + //if in high power mode need to check thermal-recorder hasn't made a recording if needs_ffc && !device_config.use_low_power_mode() { + //only check status every 20 seconds if frame_telemetry.frame_num - last_rec_check > 9 * 20 { if let Ok(is_recording) = shared_i2c.tc2_agent_is_recording(&mut delay) { high_power_recording = is_recording; @@ -555,10 +553,6 @@ pub fn core_1_task( if high_power_recording { sio.fifo.write(Core1Task::StartRecording.into()); high_power_recording = true; - thread_local_frame_buffer - .as_mut() - .unwrap() - .ffc_imminent(false); } else { sio.fifo.write(Core1Task::EndRecording.into()); high_power_recording = false; @@ -569,6 +563,7 @@ pub fn core_1_task( } } } else if !high_power_recording { + //depending on timing might get 2 frames with needs_ffc event after said ok thread_local_frame_buffer .as_mut() .unwrap() From db83bc3cc796295566723ed502a653e4246b52e9 Mon Sep 17 00:00:00 2001 From: gferraro Date: Fri, 23 Aug 2024 17:06:16 +1200 Subject: [PATCH 8/8] remove debugging --- src/core0_task.rs | 7 +------ src/main.rs | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/core0_task.rs b/src/core0_task.rs index cd9e5cd..2977c8a 100644 --- a/src/core0_task.rs +++ b/src/core0_task.rs @@ -201,12 +201,7 @@ pub fn frame_acquisition_loop( can_do_ffc = false; } } - info!( - "Doing ffc in {}", - (FFC_INTERVAL_MS - telemetry.msec_on - + telemetry.time_at_last_ffc) - / 1000 - ); + // Sometimes the header is invalid, but the frame becomes valid and gets sync. // Because the telemetry revision is static across frame headers we can detect this // case and not send the frame, as it may cause false triggers. diff --git a/src/main.rs b/src/main.rs index 37e46d2..415e318 100644 --- a/src/main.rs +++ b/src/main.rs @@ -69,7 +69,7 @@ const ROSC_TARGET_CLOCK_FREQ_HZ_THERMAL: u32 = 150_000_000; // got funny results at 150 for aduio seems to work better at 125 const ROSC_TARGET_CLOCK_FREQ_HZ_AUDIO: u32 = 125_000_000; -const FFC_INTERVAL_MS: u32 = 1000 * 20; // 20 mins between FFCs +const FFC_INTERVAL_MS: u32 = 60 * 1000 * 20; // 20 mins between FFCs pub type FramePacketData = [u8; FRAME_WIDTH]; pub type FrameSegments = [[FramePacketData; 61]; 4]; const TRANSFER_HEADER_LENGTH: usize = 18;