Main Content

XCP Page Switching for Tunable Parameters

The Universal Measurement and Calibration Protocol (XCP) is a network protocol that you can use to connect calibration systems to electronic control units (ECUs).

Simulink Real-Time supports XCP and ECU page switching operation that is described in section 4.4 Online Calibration in the ASAM MCD-1 XCP v 1.5.0 specification. A real-time application has an XCP page that communicates with MATLAB, an ECU page that communicates with the Speedgoat® target computer, and two memory pages (0,1) that you can connect with the XCP and ECU pages. Memory page 0 and 1 mapping to the XCP page or ECU page is independent of each other.

When running the real-time application, memory pages 0 and 1 each represents a set of tunable parameters. The pages start with identical content, and the initial mapped memory page for both XCP and ECU is page 0. The real-time application uses the parameters on the memory page (0 or 1) that is mapped to the ECU page. MATLAB communicates with parameter values on the memory page (0 or 1) that is mapped to the XCP page.

You use the page-related functions to copy pages, get the active ECU or XCP page, get the number of pages, or map the ECU or XCP page to memory page 0 or 1.

If working with Simulink Real-Time Explorer, the ECU and XCP page selection for page 0 or 1 need to match. For example, set both ECU and XCP pages to page 0. A page mismatch causes an error for the explorer, and a prompt appears in the app to let you synchronize the page selection.

For examples that demonstrate how to work with ECU and XCP pages, see functions copyPage, getECUPage, getNumPages, getXCPPage, setECUPage, setXCPPage, and setECUAndXCPPage.

Use XCP and ECU Pages for Parameters

This example shows a possible workflow for applying different parameter values on multiple XCP and ECU pages.

  1. Open the model, build the real-time application, and load the real-time application.

    openExample('slrt_ex_param_tuning');
    slbuild('slrt_ex_param_tuning');
    tg = slrealtime;
    load(tg,'slrt_ex_param_tuning');
  2. Get memory page mapping of ECU page.

    mappingOfECUpage = getECUPage(tg)
    ans =
    
      uint8
    
       0
  3. Get memory page mapping of XCP page.

    mappingOfXCPpage = getXCPPage(tg)
    ans =
    
      uint8
    
       0
  4. Map XCP page to memory page 1.

    setXCPPage(tg,1);
    
  5. Start real-time application.

    start(tg);
  6. Use the setparam function to change a parameter value and notice that the parameter change is not reflected in the running application. This behavior occurs because setparam affects the parameters in the XCP page. This page is currently mapped to memory page 1, but the ECU page is mapped to memory page 0. So, the parameter value change is not reflected in the application.

    setparam(tg,'slrt_ex_param_tuning/Gain2','Gain',1200000);
  7. Use getsignal function to show that the parameter values on memory page 1 have not taken effect on the running application. Because the output of the Gain block is a square wave, the value is either 4000000 or -4000000.

    getsignal(tg,'slrt_ex_param_tuning/Gain2',1)
    ans =
    
         4000000
  8. Map the ECU page to memory page 1 and notice that the parameter value changes take effect in the real-time application. This behavior occurs because memory page 1 is mapped to both the ECU page and XCP page.

    setECUPage(tg,1);
    
  9. Use getsignal function to show that the parameter values on memory page 1 (now mapped to ECU page) have applied on the running application. Because the output of the Gain block is a square wave, the updated value is either 4800000 or -4800000.

    getsignal(tg,'slrt_ex_param_tuning/Gain2',1)
    ans =
    
        4800000
    

See Also

| | | | | |

Related Topics