cdx_fast_io.h

Foreground model access to low-latency ADC snapshots and physical CAN.

Source code: View source

Contents

Typedefs

Typedef Description
CDX_ADC_SNAPSHOT Completed external ADC scan; channels are sequentially sampled.

Variables

Variable Description
CDX_model_adc_raw Model-owned ADC raw input cache, refreshed once before each model step.
CDX_model_adc_valid_mask Validity mask for the ADC raw input cache. Each bit corresponds to one channel.
CDX_model_adc_sequence Sequence number for the ADC snapshot.
CDX_model_adc_timestamp_us Timestamp of the ADC snapshot in microseconds.
CDX_model_adc_fresh Indicates whether the ADC snapshot is fresh for this session.

Functions

Function Description
CDX_adc_snapshot_read Copy a consistent external ADC scan without waiting for the Dash loop.
CDX_model_inputs_refresh Refresh the input cache with one bounded snapshot read.
CDX_can_tx_urgent_enqueue Copy an urgent physical CAN frame, bypassing Dash Output processing.

CDX_get_adc_1_raw

Read cached external input 1 in raw ADC counts.

Returns

Held 12-bit ADC counts; check CDX_get_adc_1_valid() before use.

Note: Foreground only; refresh the input cache once before the model step.

CDX_get_adc_2_raw

Read cached external input 2 in raw ADC counts.

Returns

Held 12-bit ADC counts; check CDX_get_adc_2_valid() before use.

Note: Foreground only; refresh the input cache once before the model step.

CDX_get_adc_3_raw

Read cached external input 3 in raw ADC counts.

Returns

Held 12-bit ADC counts; check CDX_get_adc_3_valid() before use.

Note: Foreground only; refresh the input cache once before the model step.

CDX_get_adc_4_raw

Read cached external input 4 in raw ADC counts.

Returns

Held 12-bit ADC counts; check CDX_get_adc_4_valid() before use.

Note: Foreground only; refresh the input cache once before the model step.

CDX_get_adc_5_raw

Read cached external input 5 in raw ADC counts.

Returns

Held 12-bit ADC counts; check CDX_get_adc_5_valid() before use.

Note: Foreground only; refresh the input cache once before the model step.

CDX_get_adc_6_raw

Read cached external input 6 in raw ADC counts.

Returns

Held 12-bit ADC counts; check CDX_get_adc_6_valid() before use.

Note: Foreground only; refresh the input cache once before the model step.

CDX_get_adc_7_raw

Read cached external input 7 in raw ADC counts.

Returns

Held 12-bit ADC counts; check CDX_get_adc_7_valid() before use.

Note: Foreground only; refresh the input cache once before the model step.

CDX_get_adc_8_raw

Read cached external input 8 in raw ADC counts.

Returns

Held 12-bit ADC counts; check CDX_get_adc_8_valid() before use.

Note: Foreground only; refresh the input cache once before the model step.

CDX_get_adc_1_voltage

Read cached external input 1 in nominal volts without calibration.

Returns

Held ADC counts times 0.001421 V/count; check CDX_get_adc_1_valid().

Note: Foreground only; refresh the input cache once before the model step.

CDX_get_adc_2_voltage

Read cached external input 2 in nominal volts without calibration.

Returns

Held ADC counts times 0.001421 V/count; check CDX_get_adc_2_valid().

Note: Foreground only; refresh the input cache once before the model step.

CDX_get_adc_3_voltage

Read cached external input 3 in nominal volts without calibration.

Returns

Held ADC counts times 0.001421 V/count; check CDX_get_adc_3_valid().

Note: Foreground only; refresh the input cache once before the model step.

CDX_get_adc_4_voltage

Read cached external input 4 in nominal volts without calibration.

Returns

Held ADC counts times 0.001421 V/count; check CDX_get_adc_4_valid().

Note: Foreground only; refresh the input cache once before the model step.

CDX_get_adc_5_voltage

Read cached external input 5 in nominal volts without calibration.

Returns

Held ADC counts times 0.001421 V/count; check CDX_get_adc_5_valid().

Note: Foreground only; refresh the input cache once before the model step.

CDX_get_adc_6_voltage

Read cached external input 6 in nominal volts without calibration.

Returns

Held ADC counts times 0.001421 V/count; check CDX_get_adc_6_valid().

Note: Foreground only; refresh the input cache once before the model step.

CDX_get_adc_7_voltage

Read cached external input 7 in nominal volts without calibration.

Returns

Held ADC counts times 0.001421 V/count; check CDX_get_adc_7_valid().

Note: Foreground only; refresh the input cache once before the model step.

CDX_get_adc_8_voltage

Read cached external input 8 in nominal volts without calibration.

Returns

Held ADC counts times 0.001421 V/count; check CDX_get_adc_8_valid().

Note: Foreground only; refresh the input cache once before the model step.

CDX_get_adc_1_valid

Test whether cached external input 1 is valid.

Returns

1 for valid cached data, otherwise 0, including stale/offline scans.

Note: Foreground only; no acquisition. Refresh the cache once before step.

CDX_get_adc_2_valid

Test whether cached external input 2 is valid.

Returns

1 for valid cached data, otherwise 0, including stale/offline scans.

Note: Foreground only; no acquisition. Refresh the cache once before step.

CDX_get_adc_3_valid

Test whether cached external input 3 is valid.

Returns

1 for valid cached data, otherwise 0, including stale/offline scans.

Note: Foreground only; no acquisition. Refresh the cache once before step.

CDX_get_adc_4_valid

Test whether cached external input 4 is valid.

Returns

1 for valid cached data, otherwise 0, including stale/offline scans.

Note: Foreground only; no acquisition. Refresh the cache once before step.

CDX_get_adc_5_valid

Test whether cached external input 5 is valid.

Returns

1 for valid cached data, otherwise 0, including stale/offline scans.

Note: Foreground only; no acquisition. Refresh the cache once before step.

CDX_get_adc_6_valid

Test whether cached external input 6 is valid.

Returns

1 for valid cached data, otherwise 0, including stale/offline scans.

Note: Foreground only; no acquisition. Refresh the cache once before step.

CDX_get_adc_7_valid

Test whether cached external input 7 is valid.

Returns

1 for valid cached data, otherwise 0, including stale/offline scans.

Note: Foreground only; no acquisition. Refresh the cache once before step.

CDX_get_adc_8_valid

Test whether cached external input 8 is valid.

Returns

1 for valid cached data, otherwise 0, including stale/offline scans.

Note: Foreground only; no acquisition. Refresh the cache once before step.

Typedefs

CDX_ADC_SNAPSHOT

Completed external ADC scan; channels are sequentially sampled.

1typedef struct CDX_ADC_SNAPSHOT_STRUCT CDX_ADC_SNAPSHOT

Variables

CDX_model_adc_raw

Model-owned ADC raw input cache, refreshed once before each model step.

1uint16_t CDX_model_adc_raw

Note: Bind read-only Simulink ImportedExtern data stores to these symbols. These values should not be modified by the model.

CDX_model_adc_valid_mask

Validity mask for the ADC raw input cache. Each bit corresponds to one channel.

1uint32_t CDX_model_adc_valid_mask

Each bit in CDX_model_adc_valid_mask corresponds to one channel in CDX_model_adc_raw. A set bit indicates that the corresponding ADC value is valid. > Note: Values are held on failure but the valid_mask is cleared.

CDX_model_adc_sequence

Sequence number for the ADC snapshot.

1uint32_t CDX_model_adc_sequence

Note: Incremented on each new snapshot.

CDX_model_adc_timestamp_us

Timestamp of the ADC snapshot in microseconds.

1uint32_t CDX_model_adc_timestamp_us

Note: Wraps at 2^32 microseconds.

CDX_model_adc_fresh

Indicates whether the ADC snapshot is fresh for this session.

1uint8_t CDX_model_adc_fresh

CDX_model_adc_fresh is true if the ADC snapshot was updated by the Dash processor.

Functions

CDX_adc_snapshot_read

Copy a consistent external ADC scan without waiting for the Dash loop.

1CDX_STATUS CDX_adc_snapshot_read(CDX_ADC_SNAPSHOT *snapshot)

Returns

OK, BAD_PARAM, IPC_OFFLINE for absent/stale fast extension, or NO_DATA for an invalid scan or concurrent publication after two bounded attempts.

Note: Model callbacks only; no concurrent callers. Repeated reads can return the same sequence. No engineering scaling is applied. Timestamp wraps at 2^32 microseconds and is not directly comparable with CDX_ticks_now().

Parameters

  • CDX_ADC_SNAPSHOT * snapshot: Nonnull output; unchanged on failure. Copy once at step entry.

Location: cdx_fast_io.h:70

CDX_model_inputs_refresh

Refresh the input cache with one bounded snapshot read.

1CDX_STATUS CDX_model_inputs_refresh(uint32_t now_us, uint32_t max_stale_us)

Returns

OK for usable cached data, TIMEOUT for stale data, or snapshot error.

Note: Foreground only. Timestamp remains CM7-local; staleness is measured independently using now_us. Rebinding the runtime resets this cache.

Parameters

  • uint32_t now_us: Current CM4-local microseconds, sampled once at step entry.
  • uint32_t max_stale_us: Maximum time without a new scan, 1..1000000 us.

Location: cdx_fast_io.h:79

CDX_can_tx_urgent_enqueue

Copy an urgent physical CAN frame, bypassing Dash Output processing.

1CDX_STATUS CDX_can_tx_urgent_enqueue(uint32_t port, CDX_CAN_TX_PARAMS const *params, CDX_DATA_64 const *data, uint32_t lifetime_us)

Returns

OK, BAD_PARAM, IPC_OFFLINE or QUEUE_FULL (newest request rejected).

Note: Model callbacks only, never interrupts or concurrent threads. Four frames per physical port. Acceptance is not delivery; unavailable ports, expiry, bus errors, stop/reset and session changes can discard requests. No completion callback or cancellation; an in-progress CAN frame cannot be preempted. Configured bus mode and CAN arbitration still apply.

Parameters

  • uint32_t port: Physical CAN port: 0 for CAN1, 1 for CAN2 (not logical IPC).
  • CDX_CAN_TX_PARAMS const * params: Nonnull frame description; deadline_ticks must be zero and only IDE, EDL and BRS flags are supported. FD lengths must match a CAN-FD DLC. Use lifetime_us for expiry instead.
  • CDX_DATA_64 const * data: Copied aligned payload; NULL only when length_bytes is zero.
  • uint32_t lifetime_us: Maximum age, 1..1000000 us, from the latest CM7 fast clock publication. Expiry is conservative by clock-publication age, not extended.

Location: cdx_fast_io.h:212