diff --git a/tests/xcp_test_executor.rs b/tests/xcp_test_executor.rs index c7ef2be..765e8fa 100644 --- a/tests/xcp_test_executor.rs +++ b/tests/xcp_test_executor.rs @@ -19,12 +19,12 @@ pub use xcp_client::xcp_client::XCPTL_MAX_SEGMENT_SIZE; //----------------------------------------------------------------------------- // Logging -pub const OPTION_LOG_LEVEL: xcp::XcpLogLevel = xcp::XcpLogLevel::Info; -pub const OPTION_XCP_LOG_LEVEL: xcp::XcpLogLevel = xcp::XcpLogLevel::Info; +pub const OPTION_LOG_LEVEL: xcp::XcpLogLevel = xcp::XcpLogLevel::Debug; +pub const OPTION_XCP_LOG_LEVEL: xcp::XcpLogLevel = xcp::XcpLogLevel::Debug; // Test parameters -pub const MULTI_THREAD_TASK_COUNT: usize = 16; // Number of threads -pub const DAQ_TEST_TASK_SLEEP_TIME_US: u64 = 500; // Measurement thread task cycle time in us +pub const MULTI_THREAD_TASK_COUNT: usize = 8; // Number of threads +pub const DAQ_TEST_TASK_SLEEP_TIME_US: u64 = 1000; // Measurement thread task cycle time in us const DAQ_TEST_DURATION_MS: u64 = 6000; // DAQ test duration, 6s to get a nano second 32 bit overflow while checking timestamp monotony const CAL_TEST_MAX_ITER: u32 = 4000; // Number of calibrations const CAL_TEST_TASK_SLEEP_TIME_US: u64 = 100; // Checking task cycle time in us diff --git a/xcp_client/src/xcp_client.rs b/xcp_client/src/xcp_client.rs index 3259486..b6b4121 100644 --- a/xcp_client/src/xcp_client.rs +++ b/xcp_client/src/xcp_client.rs @@ -948,22 +948,23 @@ impl XcpClient { Ok(()) } - // START_STOP mode - const XCP_STOP: u8 = 0; - const XCP_START: u8 = 1; - const XCP_SELECT: u8 = 2; - async fn start_stop_daq_list(&mut self, mode: u8, daq: u16) -> Result<(), Box<dyn Error>> { - self.send_command(XcpCommandBuilder::new(CC_START_STOP_DAQ_LIST).add_u8(mode).add_u16(daq).build()).await?; + // Select DAQ list + async fn select_daq_list(&mut self, daq: u16) -> Result<(), Box<dyn Error>> { + self.send_command(XcpCommandBuilder::new(CC_START_STOP_DAQ_LIST).add_u8(2).add_u16(daq).build()).await?; Ok(()) } - // START_STOP_SYNC mode - const XCP_STOP_ALL: u8 = 0; - const XCP_START_SELECTED: u8 = 1; - const XCP_STOP_SELECTED: u8 = 2; - const XCP_PREPARE_START_SELECTED: u8 = 3; - async fn start_stop_sync(&mut self, mode: u8) -> Result<(), Box<dyn Error>> { - self.send_command(XcpCommandBuilder::new(CC_START_STOP_SYNCH).add_u8(mode).build()).await?; + // Prepare, start selected, stop all + async fn prepare_selected_daq_lists(&mut self) -> Result<(), Box<dyn Error>> { + self.send_command(XcpCommandBuilder::new(CC_START_STOP_SYNCH).add_u8(3 /* prepare selected */).build()).await?; + Ok(()) + } + async fn start_selected_daq_lists(&mut self) -> Result<(), Box<dyn Error>> { + self.send_command(XcpCommandBuilder::new(CC_START_STOP_SYNCH).add_u8(1 /* start selected */).build()).await?; + Ok(()) + } + async fn stop_all_daq_lists(&mut self) -> Result<(), Box<dyn Error>> { + self.send_command(XcpCommandBuilder::new(CC_START_STOP_SYNCH).add_u8(0).build()).await?; Ok(()) } @@ -1345,10 +1346,11 @@ impl XcpClient { debug!("Set event: daq={}, event={}", daq, event); } - // Select all DAQ lists + // Select and prepare all DAQ lists for daq in 0..daq_count { - self.start_stop_daq_list(XcpClient::XCP_SELECT, daq).await?; + self.select_daq_list(daq).await?; } + self.prepare_selected_daq_lists().await?; // Reset the DAQ decoder and set measurement start time let daq_clock = self.get_daq_clock_raw().await?; @@ -1359,7 +1361,7 @@ impl XcpClient { self.tx_task_control.as_ref().unwrap().send(self.task_control).await.unwrap(); // Start DAQ - self.start_stop_sync(XcpClient::XCP_START_SELECTED).await?; + self.start_selected_daq_lists().await?; Ok(()) } @@ -1367,7 +1369,7 @@ impl XcpClient { /// Stop DAQ pub async fn stop_measurement(&mut self) -> Result<(), Box<dyn Error>> { // Stop DAQ - let res = self.start_stop_sync(XcpClient::XCP_STOP_ALL).await; + let res = self.stop_all_daq_lists().await; // Send running=false throught the DAQ control channel to the receive task self.task_control.running = false; diff --git a/xcplib/src/xcpLite.c b/xcplib/src/xcpLite.c index b0565e6..977c0a9 100644 --- a/xcplib/src/xcpLite.c +++ b/xcplib/src/xcpLite.c @@ -1029,7 +1029,7 @@ void XcpDisconnect() if (isDaqRunning()) { ApplXcpStopDaq(); XcpStopAllDaq(); - XcpTlWaitForTransmitQueueEmpty(); // Wait until transmit queue empty + XcpTlWaitForTransmitQueueEmpty(); } gXcp.SessionStatus &= ~SS_CONNECTED; @@ -1598,29 +1598,27 @@ static uint8_t XcpAsyncCommand( BOOL async, const uint32_t* cmdBuf, uint8_t cmdL } break; - case CC_START_STOP_DAQ_LIST: + case CC_START_STOP_DAQ_LIST: // start, stop, select individual daq list { check_len(CRO_START_STOP_DAQ_LIST_LEN); uint16_t daq = CRO_START_STOP_DAQ_LIST_DAQ; if (daq >= gXcp.Daq.DaqCount) error(CRC_OUT_OF_RANGE); if ( (CRO_START_STOP_DAQ_LIST_MODE==1 ) || (CRO_START_STOP_DAQ_LIST_MODE==2) ) { // start or select DaqListState(daq) |= DAQ_STATE_SELECTED; - if (CRO_START_STOP_DAQ_LIST_MODE == 1) { // start individual daq list + if (CRO_START_STOP_DAQ_LIST_MODE == 1) { XcpStartDaq(daq); } CRM_LEN = CRM_START_STOP_DAQ_LIST_LEN; CRM_START_STOP_DAQ_LIST_FIRST_PID = 0; // Absolute DAQ, Relative ODT - DaqListFirstPid(daq); } else { - if (XcpStopDaq(daq)) { - XcpTlWaitForTransmitQueueEmpty(); // Event processing stopped - wait until transmit queue empty before sending command response - } + XcpStopDaq(daq); // stop individual daq list } } break; - case CC_START_STOP_SYNCH: + case CC_START_STOP_SYNCH: // prepare, start, stop selected daq lists or stop all { if ((0 == gXcp.Daq.DaqCount) || (0 == gXcp.Daq.OdtCount) || (0 == gXcp.Daq.OdtEntryCount)) error(CRC_DAQ_CONFIG); check_len(CRO_START_STOP_SYNCH_LEN); @@ -2433,7 +2431,7 @@ static void XcpPrintRes(const tXcpCto* crm) { break; default: - if (DBG_LEVEL >= 4) { + if (DBG_LEVEL >= 5) { printf("<- OK\n"); } break; @@ -2449,7 +2447,7 @@ static void XcpPrintDaqList( uint16_t daq ) if (daq>=gXcp.Daq.DaqCount) return; - printf("DAQ %u:\n",daq); + printf("DAQ %u:",daq); printf(" eventchannel=%04Xh,",DaqListEventChannel(daq)); printf(" ext=%02Xh,",DaqListAddrExt(daq)); printf(" firstOdt=%u,",DaqListFirstOdt(daq)); @@ -2462,8 +2460,10 @@ static void XcpPrintDaqList( uint16_t daq ) for (i=DaqListFirstOdt(daq);i<=DaqListLastOdt(daq);i++) { printf(" ODT %u (%u):",i-DaqListFirstOdt(daq),i); printf(" firstOdtEntry=%u, lastOdtEntry=%u, size=%u:\n", DaqListOdtFirstEntry(i), DaqListOdtLastEntry(i),DaqListOdtSize(i)); - for (e=DaqListOdtFirstEntry(i);e<=DaqListOdtLastEntry(i);e++) { - printf(" %08X,%u\n",OdtEntryAddr(e), OdtEntrySize(e)); + if (DBG_LEVEL >= 5) { + for (e=DaqListOdtFirstEntry(i);e<=DaqListOdtLastEntry(i);e++) { + printf(" %08X,%u\n",OdtEntryAddr(e), OdtEntrySize(e)); + } } } /* j */ } diff --git a/xcplib/src/xcpTlQueue.c b/xcplib/src/xcpTlQueue.c index bf065a7..87a502a 100644 --- a/xcplib/src/xcpTlQueue.c +++ b/xcplib/src/xcpTlQueue.c @@ -335,8 +335,11 @@ void XcpTlWaitForTransmitQueueEmpty() { uint16_t timeout = 0; do { sleepMs(20); - timeout++; - } while (XcpTlGetTransmitQueueLevel()!=0 && timeout<=50); // Wait max 1s until the transmit queue is empty + if (++timeout>50) { // Wait max 1s until the transmit queue is empty + DBG_PRINT_ERROR("XcpTlWaitForTransmitQueueEmpty: timeout\n"); + break; + }; + } while (XcpTlGetTransmitQueueLevel()!=0 ); }