Application Template

CD6 Project Template

This handwritten starter receives dash analogue values through Ginmake-generated IPC getters and sends calculated values back every 5 ms using setters. It has no console output. The Quickstart creates a project from it, builds it and runs it on a CD6. This page explains how it works and how to replace it with your own model.

Project Layout

 1project-template/
 2  cdx-runtime/         Extract the runtime here; replace as a whole for updates
 3  main/                Application callbacks and model-owned headers
 4  ipc/                 DBC definitions shared with Dash Design
 5  model-generated/     Optional Embedded Coder C sources
 6  ginmake-generated/   Created automatically during the build
 7  build/               Build output
 8  CMakeLists.txt       Your application build and packaging commands
 9  CMakePresets.json    Release and Debug presets
10  cdx-project.json     CLI workflow defaults
11  model-ipc.json5.in   Your Ginmake configuration

Build

Copy this example outside cdx-runtime and extract the runtime ZIP into the copy. Install the tools listed in Installing Tools. From the project root:

1.\cdx-runtime\setup-cdx.ps1
2cdx compile

compile configures CMake automatically. Without terminal setup:

1cdx-runtime\bin\cdx.exe compile

If the toolchain is not on PATH, point CDX_RT_TOOLCHAIN_BIN at its bin directory:

1cmake --preset cm4-release -DCDX_RT_TOOLCHAIN_BIN="C:\Tools\arm-gcc-15.3.rel2\bin"
2cdx-runtime\bin\cdx.exe compile

Ginmake runs automatically. Outputs:

  • build/cm4-release/CD6-project-template.cdxmodel
  • Finalized build/cm4-release/MDL_FIRM.bin. Never deploy MDL_FIRM.raw.bin.

Use cm4-debug for Debug. Build configurations share ginmake-generated, so build sequentially.

Migration: Use cdx compile for this starter and no-MATLAB scripts. cdx build includes incremental MATLAB generation and requires explicit model/initialization configuration.

Try On A CD6

Follow Run It on a CD6 in the Quickstart. In summary:

  1. In a new Dash Design setup for your CD6, use Setup > CDX Model > Load CDX Model… to load build/cm4-release/CD6-project-template.cdxmodel with Embedded in setup.
  2. Dash Design matches the packaged dash Tx DBC, CD6-Main-IPC-sample.dbc (model input), to the setup’s Analogue 1 to Analogue 8 channels and sends them in frames 0x001 and 0x002. It creates channels for the dash Rx DBC, CD6-Model-IPC-sample.dbc (model output), received in frame 0x200.
  3. Display MDL_CTR on a gauge, then upload the setup, including the embedded model firmware, to a CD6 with model-runtime support.
  4. Apply nonzero Analogue 1 input. MDL_CTR should mirror input frame 0x001’s first raw 16 bits. MDL_CPU_TEMP and MDL_CPU_LOAD are demo input calculations, not measured processor statistics.

Keep setup and model DBCs identical. After interface changes, regenerate, rebuild and reload the model. Confirm editor/dash firmware support before deployment.

Use Your Model

Set REV_NAME and REV_VERSION in main/version.h for model and generated A2L identification.

Call your model’s initialization and base-rate step from main/generated.c. Stage Embedded Coder sources through CDX. The build uses model-generated/cdx-generated.cmake when present, preserving source/include layout. Legacy flat .c files are supported except ert_main.c. Keep model-specific type headers in your application. Replace sample DBC paths in both the Ginmake configuration and CDX_RT_configure_model. This IPC adapter is not a complete Simulink model.

The commented build file controls application choices:

  • CDX_RT_configure_model: common linking and the runtime’s compiled packaging command. DBC directions use the dash perspective.
  • CDX_RT_generate_ipc: generated sources and build dependencies.

Follow the Ginmake workflow for Simulink workspace generation. Simulink Projects covers initialization scripts, model settings and Dash Design CDX Project Tools builds. The single-rate runtime calls all five CDX_app_* callbacks serially. Keep callbacks bounded. Never call CDX APIs from interrupts.

Model Station Name

The XCP station ID (GET_ID ASCII) defaults to the model target name, normally ${PROJECT_NAME}. To override it, add STATION_NAME to the existing CDX_RT_configure_model(...) call in CMakeLists.txt:

1CDX_RT_configure_model(${PROJECT_NAME}
2    ...
3    STATION_NAME "My Custom Model")
  • Use up to 63 printable ASCII characters.
  • STATION_NAME is separate from NAME, which sets the package display name. Changing only the package name does not change the station name.
  • The name is compiled into the model identity, independently of the EPK hash. Rebuild and deploy the model after changing it.
  • Named images need display firmware and packaging tools that support image descriptor versions 3/4. Older model images still load on updated firmware and report CD6 as their station name.

Use a runtime containing cdx_fast_io.h and updated Ginmake. Old Ginmake lacks urgent_tx. Rebuilding this repository does not update installed Ginmake: select the updated executable in project tooling or install its release.

ADC input signals

Add cdx-runtime\matlab to the path, then call cdx.inputs('base') in your initialization script. For data dictionaries, signals = cdx.inputs() returns signal definitions.

Channels 1..8 expose these getter-style scalar signals:

Signal names Type Units or values
CDX_adc_1_raw through CDX_adc_8_raw uint16 counts
CDX_adc_1_voltage through CDX_adc_8_voltage single V
CDX_adc_1_valid through CDX_adc_8_valid uint8 0 or 1

Signals use the shared cdx.inputSignal factory and getter-only GetSet bindings in cdx_fast_io.h. Getters share one cached snapshot without reacquisition. Voltage is raw multiplied by 0.001421 V/count (nominal CD6 sample-DBC factor, not individually calibrated).

Invalid raw/voltage values stay held. Check validity before use. Stale/offline input clears validity. The target model must not write these signals.

Aggregate ADC data stores

For compatibility, you can still read these global data stores:

  • CDX_model_adc_raw: eight uint16 values.
  • CDX_model_adc_valid_mask: bit 0 means input 1.
  • CDX_model_adc_sequence.
  • CDX_model_adc_timestamp_us (uint32): Dash clock, not model clock.
  • CDX_model_adc_fresh (uint8): newly observed scan, not necessarily every step.

Use Data Store Read blocks directly or connect them to algorithm input ports. The adapter updates stores once before each step. The target must not write them. Acquisition failure holds raw values and clears validity. Choose an invalid-input safe state for your algorithm.

Simulation harness

Supply synthetic or recorded inputs in a Simulink test harness. cdx.adcSample(raw, sequence, timestampUs, validMask, fresh) returns values with matching names, types and dimensions for Data Store Write blocks or algorithm input ports. It installs no source block. Select sources only in the harness and exclude their writes from target builds. Test invalid masks, repeated sequences and stale data. The native CDX simulator does not emulate hardware fast I/O.

Urgent physical CAN transmit

Select physical DBC messages explicitly in Ginmake’s can configuration:

{
   port: 1,
   tx: ['PhysicalCommands.dbc'],
   urgent_tx: [
      {frame: 'TorqueRequest', port: 0, policy: 'step', lifetime_us: 2000},
      {frame: 'Heartbeat', port: 0, policy: 'periodic', period_us: 1000, lifetime_us: 3000},
      {frame: 'ShiftRequest', port: 0, policy: 'triggered', lifetime_us: 2000}
   ]
}

The outer port selects the Ginmake DBC group. Urgent port selects physical CAN: 0 = CAN1, 1 = CAN2. Keep ordinary IPC messages in port: 'IPC'. Never reinterpret IPC IDs/payloads as physical commands.

Urgent messages leave ordinary TX rate groups. Multiplexed urgent messages and payloads outside 1..64 bytes are rejected.

The generated workspace declares an ImportedExtern uint8 trigger, CDX_<packed-frame-prefix>urgent_request. Update DBC signals before setting it nonzero. The sender consumes each request even if enqueue fails.

Call the sender once per step:

urgent_tx policy When it sends
step Every call.
periodic First call, then when the interval elapses. Skips missed releases and rearms from current time.
triggered Nonzero request trigger.

Periods below the model period cannot create extra model executions. Failed attempts are dropped, not retried. The generated TX header exports per-message urgent_status, urgent_accepted and urgent_rejected diagnostics. Counters wrap at 32 bits. Accepted means queued, not delivered. Budget for four-entry queues, bus configuration, arbitration and expiry.

Model timing

Use a fixed-step discrete solver, disable multitasking and set an explicit base step, e.g. 0.0005 or 0.001 seconds. cdx.generate:

  • Reads configured FixedStep, resolving model-workspace expressions.
  • Requires integer-microsecond timing. Rejects auto.
  • Stages cdx_model_timing.h with generated sources.

It determines timing without compiling or inspecting individual block sample times. Simulink checks model/code-generation compatibility during slbuild. Period changes require model regeneration, not just a runtime callback change.

CMake adapter

Include model-generated/cdx-generated.cmake, remove main/generated.c from target sources, then call the adapter helper once per target:

1CDX_RT_configure_simulink(${PROJECT_NAME}
2      HEADER ACT1.h INITIALIZE ACT1_initialize STEP ACT1_step
3      ADC_MAX_STALE_US 5000)

Entry points must be void(void). Keep the ipc_model_ Ginmake prefix, CDX_RT_configure_model and CDX_RT_generate_ipc. Each model step:

flowchart LR
    inputs["Refresh cached inputs: ADC snapshot, IPC RX"] --> step["Model step"]
    step --> urgent["Urgent physical CAN sends"]
    urgent --> ipc["Ordinary IPC TX"]

Input failures, urgent rejection and ordinary IPC queue-full/no-data results are nonfatal. Use validity and TX diagnostics for application policy. No asynchronous model task is created.

For legacy imported C without staged timing metadata, set LEGACY_PERIOD_US 10000 to match its generation period. The helper rejects overrides when generated timing metadata exists. Do not duplicate CDX_app_* callbacks.

Validation

With Simulink and Embedded Coder, run: addpath('model-runtime/matlab'); runtests('model-runtime/matlab/tests'). Then generate and build your model. Helpers were not run on the development PC without MATLAB. Before deployment, confirm the generated interface and measure end-to-end ADC-to-CAN latency on hardware. Automated build tests have not verified physical-hardware operation.

CLI workflows

cdx-runtime\bin\cdx.exe --help lists stages and workflows. Before matlab+compile or matlab+compile+embed, configure explicit model/initialization and setup/deployment paths in the project.

Command Purpose
compile+embed Prepare staged code without MATLAB.
compile+deploy Compile, implicitly embed and upload.
deploy Upload a prepared setup only.
compile Compile without launching MATLAB or programming hardware.

See the runtime CLI guide for current-session MATLAB helpers, scoped cleaning and explicit device selection.

Runtime updates

Follow the runtime’s verified upgrade and backup sequence. Replace cdx-runtime/ without merging versions. Move old build/IPC outputs aside. Keep application code, staged model sources, DBCs and presets in the project root. Regenerate the deployment setup before uploading.