jwang12340 opened a new pull request, #18039:
URL: https://github.com/apache/nuttx/pull/18039
## Summary
This comprehensive pull request introduces a complete enhancement to the CTU
CAN FD QEMU charcan driver through 6 sequential commits. The changes include:
1. **Bug fix**: CAN FD frame format flag inheritance
2. **Reliability improvement**: Complete TXMB status checking during
interrupt handling
3. **Foundation feature**: Register modification utility function (modreg)
4. **New functionality**: Transmit completion confirmation mechanism
5. **New functionality**: CAN message cancellation support
6. **New functionality**: Complete IOCTL interface for driver state control
## Background and Rationale
### Why These Changes Are Needed
The CTU CAN FD QEMU driver previously had several limitations:
1. **FDF Flag Issue**: When transmitting CAN FD frames, the driver hardcoded
FDF=0, making all frames appear as standard CAN format to the hardware,
preventing proper CAN FD feature utilization.
2. **Incomplete Interrupt Handling**: The interrupt handler could miss
completion events from some of the 4 available transmit mailboxes, potentially
causing transmission delays or hangs during high-frequency operations.
3. **Missing Register Operations**: There was no utility function for atomic
register bit modification, leading to code duplication and potential race
conditions in register operations.
4. **No Transmit Confirmation**: Applications had no standardized way to
know when their sent frames were successfully completed, limiting use in
real-time systems that need precise transmit acknowledgment.
5. **No Message Cancellation**: Once a frame was queued for transmission,
there was no way to cancel it, even before transmission started. This is
critical for real-time control systems that need to abort outdated commands.
6. **Limited Driver Control**: Applications lacked a standard interface to
control driver state (start/stop), recover from error conditions (BUS-OFF), or
manage transmit buffering.
## Impact
qemu ctu canfd charcan driver
## Testing
Test Environment: QEMU ARM v8-R (32-bit, Aarch32)
### Example Test Code
```c
#include <stdio.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <nuttx/can.h>
int main(void)
{
int fd = open("/dev/can0", O_RDWR);
unsigned long state;
struct can_msg_s msg;
printf("=== CTU CAN FD Driver Comprehensive Test ===\n\n");
// Test 1: Get state
ioctl(fd, CANIOC_GET_STATE, &state);
printf("Initial state: %lu\n", state);
// Test 2: Enable driver
state = CAN_STATE_START;
ioctl(fd, CANIOC_SET_STATE, state);
printf("Driver enabled\n");
// Test 3: Send CAN FD frame
msg.cm_hdr.ch_id = 0x123;
msg.cm_hdr.ch_dlc = 8;
msg.cm_hdr.ch_flags = CAN_FDF_FLAG;
memcpy(msg.cm_data, "FD_FRAME", 8);
write(fd, &msg, sizeof(msg));
printf("CAN FD frame sent\n");
// Test 4: Flush transmit buffer
ioctl(fd, CANIOC_OFLUSH, 0);
printf("Transmit buffer flushed\n");
// Test 5: Disable driver
state = CAN_STATE_STOP;
ioctl(fd, CANIOC_SET_STATE, state);
printf("Driver disabled\n");
close(fd);
printf("=== All tests completed successfully ===\n");
return 0;
}
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]