Changes between Version 63 and Version 64 of Developer/Simulators/QEMU/CANEmulation


Ignore:
Timestamp:
Sep 12, 2013, 11:49:33 AM (6 years ago)
Author:
Jinyang
Comment:

/* Step 3: Build a Basic PCI-CAN device in qemu */

Legend:

Unmodified
Added
Removed
Modified
  • Developer/Simulators/QEMU/CANEmulation

    v63 v64  
    356356We use QEMU Object Model(QOM, formerly Qdev) to simulate the SJA1000 hardware. You can get some useful information from [http://wiki.qemu.org/Features/QOM QEMU Object Model] which intruduce the QOM.
    357357
     358
     359There are some files that need to be modified to make a basic PCI-CAN device: default-configs/pci.mak, hw/Makefile.objs, qemu-char.c, hw/can-pci.c.
     360 *  default-configs/pci.mak add default compiling options
     361 *  hw/Makefile.objs needs to be modified to add the object to the qemu build
     362 *  qemu-char.c is the file that is used for the can-char driver
     363 *  hw/can-pci.c is the can-pci device
     364
     365
    358366The specification of the pci-can device lists in following.
    359367  Name : pci-can
     
    369377  # default-configs/pci.mak
    370378  CONFIG_CAN_PCI=y
    371 
    372 
    373 
    374 
    375 
    376 
    377 
     379=  Add the PCI-CAN structure  =
     380
     381We can add a basic PCI-CAN device through the following code, the function can_pci_class_initfn() is used to initialize the device. There is a [https://github.com/qemu/qemu/blob/master/hw/misc/pci-testdev.c PCI TestDev] in QEMU as a reference.
     382
     383  static const TypeInfo can_pci_info = {
     384      .name               = "pci-can",
     385      .parent             = TYPE_PCI_DEVICE,
     386      .instance_size      = sizeof(PCICanState),
     387      .class_init         = can_pci_class_initfn,
     388  };
     389  static void can_pci_register_types(void)
     390  {
     391      type_register_static(&can_pci_info);
     392  }
     393  type_init(can_pci_register_types)
     394=  Add Start Options  =
     395
     396When start QEMU, we can change the device properties through start options. Structure Property is used to set the device properties. There are some macros in hw/qdev-properties.h that help us to initialize the property. We take the following code as an example.
     397{{{
     398static Property can_pci_properties[] = {
     399    DEFINE_PROP_CHR("chardev",  PCICanState, state.chr),
     400        DEFINE_PROP_STRING("model",  PCICanState, model),
     401    DEFINE_PROP_END_OF_LIST(),
     402};}}}
     403When start QEMU, we could change the PCI-CAN's properties through **chardev=xxx,model=xxxx**. The argument model is optinal, we use SJA1000 as default and only SJA1000 support now.
     404=  Add CAN back-end  =
     405
     406Before add the function for SJA1000, we would introduce how to add the back-end in QEMU at first. To add the CAN back-end we should modefy the qemu-char.c file, this will be introduced step by step.
     407==  Change backend_table[]  ==
     408
     409We should add a variable to backend_table[] to support a new backend just like following.
     410   { .name = "CAN",          .open = qemu_chr_open_can },
     411The qemu_char_open_can() function is used to initialize the backend including analyzing the start options, allocating some memory, opening the SocketCAN device, setting the CAN filter etc.
     412==  Add writing routine  ==
     413
     414The writing routine is simple. We add the can_chr_write() function as writing routine.
    378415
    379416
     
    396433
    397434written by Jin Yang during the summer of 2013
    398 =  Writing the Patches for a Basic PCI-CAN device  =
    399 
    400 
    401 There are some files that need to be modified to make a basic PCI-CAN device: hw/Makefile.objs, qemu-char.c, hw/can-pci.c.
    402  *  hw/Makefile.objs needs to be modified to add the object to the qemu build
    403  *  qemu-char.c is the file that is used for the can-char driver
    404  *  hw/can-pci.c is the can-pci device
     435
    405436==  hw/Makefile.objs  ==
    406437
     
    767798
    768799Source file located at examples-v2/ and before runing, rtems-grub.cfg should be edited too.
    769 = Adding Qemu to the RTEMS Source Builder =
     800= =Adding Qemu to the RTEMS Source Builder ==
    770801
    771802Although not necessarily part of the CAN project one interesting issue that came up was the need to hook qemu into the RTEMS Source Builder for gcc-testing purposes.
     
    784815Some resources for building on Mac are:
    785816# http://www.rubenerd.com/qemu-1-macosx/
    786 References  =
     817= References ==
    787818
    788819# https://lists.gnu.org/archive/html/qemu-devel/2013-05/threads.html