Skip to content

Commit

Permalink
CLOCK_MONOTONIC_RAW
Browse files Browse the repository at this point in the history
  • Loading branch information
RainerZ committed Oct 28, 2024
1 parent 6bc717b commit 50ab981
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 34 deletions.
8 changes: 4 additions & 4 deletions tests/xcp_test_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 19 additions & 17 deletions xcp_client/src/xcp_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

Expand Down Expand Up @@ -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?;
Expand All @@ -1359,15 +1361,15 @@ 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(())
}

/// 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;
Expand Down
22 changes: 11 additions & 11 deletions xcplib/src/xcpLite.c
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ void XcpDisconnect()
if (isDaqRunning()) {
ApplXcpStopDaq();
XcpStopAllDaq();
XcpTlWaitForTransmitQueueEmpty(); // Wait until transmit queue empty
XcpTlWaitForTransmitQueueEmpty();
}

gXcp.SessionStatus &= ~SS_CONNECTED;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -2433,7 +2431,7 @@ static void XcpPrintRes(const tXcpCto* crm) {
break;

default:
if (DBG_LEVEL >= 4) {
if (DBG_LEVEL >= 5) {
printf("<- OK\n");
}
break;
Expand All @@ -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));
Expand All @@ -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 */
}
Expand Down
7 changes: 5 additions & 2 deletions xcplib/src/xcpTlQueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

}

Expand Down

0 comments on commit 50ab981

Please sign in to comment.