PCIe CTU CAN FD support on x86 architecture to allow tests run on mainline QEMU
The RTEMS QEMU supported target configuration capable to access PCI/PCIe mapped devices allows to test new RTEMS CAN subsystem thanks to mainline QEMU support for CAN bus controllers (see QEMU CAN bus documentation).
RTEMS supports PCI on i386 family for pc386..pc686 BSPs. The RTEMS x86_64 amd64 target would be interesting as well but its support seems to be minimal only (without PCI support).
The RTEMS configuration which has been tested to work is attached i386-rtems-sys.cfg.
QEMU can be started by next command
qemu-system-x86_64 -m 512M -enable-kvm -kernel rtems_app_elf.elf \
-vga cirrus \
-append "--console=/dev/com1" \
-netdev user,id=n1 -device i82557b,netdev=n1 \
-object can-bus,id=canbus0-bus \
-object can-host-socketcan,if=can0,canbus=canbus0-bus,id=canbus0-socketcan \
-device kvaser_pci,canbus=canbus0-bus \
-device ctucan_pci,canbus0=canbus0-bus,canbus1=canbus0-bus \
-serial stdio \
-nographic \
When argument '-s' in appended then GDB debugging is activated, when '-s -S' is appended, QEMU stops and waits for GDB connection. GDB can be started with path to the application image ``rtems_app_elf.elf and next command attaches debugger
target remote localhost:1234
The breakpoints can be specified by hbreak
command which does not need to modify emulated target memory and is breakpoint is resolved on QEMU emulation level.
PCI CAN controller card can be found by
int bus;
int dev;
int fun;
int status;
int instance = 0;
status = pci_find_device(
0x1760, // for CTU CAN FD, 0x10e8 for Kvaser SJA1000
0xff00, // for CTU CAN FD, 0x8406 for Kvaser SJA1000
instance,
&bus,
&dev,
&fun
);
if status == PCIB_ERR_SUCCESS
, device has been found.
Use next sequence to read base address from given found device
uint32_t base0;
uint32_t base1;
uint8_t irq;
pci_read_config_dword( bus, dev, fun, PCI_BASE_ADDRESS_0, &base0 );
pci_read_config_dword( bus, dev, fun, PCI_BASE_ADDRESS_1, &base1 );
pci_read_config_byte( bus, dev, fun, PCI_INTERRUPT_LINE, &irq );
The BAR0 is used for information and MSI support setup.
Actual CTU CAN FD cores are mapped through BAR1. QEMU emulates configuration with two controllers, the first one starts at BAR1 offset 0x0000 and the second at BAR1 offset 0x4000.