Custom Signal Sequences
The CanDisturbanceSequence class allows users to define custom signal patterns and inject them direct onto the CAN bus. This approach is highly efficient for generating specific bus physical layer errors with minimal code overhead.
testcase ExecuteBusDisturbance()
{
CanDisturbanceSequence disturbancePattern;
dword deviceHandle = 1;
char logEntry[128];
int status;
disturbancePattern.Clear();
// Append a 320-tick sequence with a dominant level ('d')
// 1 tick = 6.25 ns (based on 160MHz FPGA clock)
// At 500kb/s, 1 bit = 2000 ns. 2000 / 6.25 = 320 ticks.
status = disturbancePattern.AppendToSequence(320, 'd');
// Trigger the sequence immediately
status = canDisturbanceTriggerNow(deviceHandle, disturbancePattern);
snprintf(logEntry, elcount(logEntry), "Execution status: %d at %f", status, timeNow()/100000.0);
testCaseComment(logEntry);
}
When the sequence injects a dominant level on an idle bus, the protocol controllers interpret it as a Start of Frame (SOF) bit. Since the subsequent data structure is invalid, the bus nodes trigger a stuff error. Note that injecting a recessive level ('r') does not cause this error as the bus idle state is already recessive.
Injecting Custom CAN Frames
The CanDisturbanceFrameSequence class enables the transmission of defined CAN frames when a trigger condition is met.
testcase InjectArbitraryFrame()
{
CanDisturbanceFrameSequence framePayload;
message 0x100 customMsg;
dword deviceHandle = 1;
long result;
customMsg.dlc = 4;
framePayload.SetMessage(deviceHandle, customMsg);
// Output the frame onto the bus
result = canDisturbanceTriggerNow(deviceHandle, framePayload);
testCaseComment("Frame injection result: ", result);
}
The SetMessage method configures the payload sent to the bus. Advanced overrides exist to specify custom bit lengths for the arbitration and data fields, which can be used to simulate baud rate mismatches or protocol violatiosn by overriding the standard timing defined by the bus configuration.
Advanced Bit-Level Manipulation
For fine-grained control over individual CAN/CAN-FD frame segments, developers may utilize the CanDisturbanceFrameSequenceField and CanDisturbanceBitSequence classes. These components provide low-level access to the frame structure, allowing for the precise manipulation of specific bits, which is essential for sophisticated stress testing and physcial layer robustness validation.