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 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
Use XCP and ECU Pages for Parameters
This example shows a possible workflow for applying different parameter values on multiple XCP and ECU pages.
Open the model, build the real-time application, and load the real-time application.
open_system('slrt_ex_param_tuning'); slbuild('slrt_ex_param_tuning'); tg = slrealtime; load(tg,'slrt_ex_param_tuning');
Get memory page mapping of ECU page.
mappingOfECUpage = getECUPage(tg)
ans = uint8 0
Get memory page mapping of XCP page.
mappingOfXCPpage = getXCPPage(tg)
ans = uint8 0
Map XCP page to memory page 1.
Start real-time application.
setparamfunction to change a parameter value and notice that the parameter change is not reflected in the running application. This behavior occurs because
setparamaffects 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.
getsignalfunction 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
ans = 4000000
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.
getsignalfunction 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
ans = 4800000