Constants and Data Structures Panel

Overview

There is one Constants and Data Structures panel for each task.

This panel is used to add, edit and remove user-defined constants and data structure members. The Task Code Editor Panels also show constants and data structure members defined by resources and by I/O mapping.

Panel Layout and Modes

The panel is divided into two sections, with Constants at the top, and Data Structures at the bottom. Drag the splitter bar up or down to adjust section sizes.

The panel has two modes:

  • Form mode:
    • Suitable for small/narrow screen resolution
    • List of all constants (name and value). Can view/edit the attributes for one constant at a time.
    • List of all data structure members (name, array size when applicable and initial value). Can view/edit the attributes for one data structure member at atime.
    • Select one of the data structure list entries to show guidelines
  • Table mode:
    • Suitable for large/wide screen resolution
    • Gives a complete overview, and allows for more efficient editing
    • Table shows attributes for all constants simultaneously, one row per constant
    • Table shows attributes for all data structure member simultaneously, one row per data structure member

Use the menu or tool bar commands to select panel mode:

  • Form Mode : Selects form mode
  • Table Mode : Selects table mode
  • Switch Mode - Ctrl+Tab : Switches back and forth between form mode and table mode

Constants

User-defined constants are available both for task code blocks within the task, and for the System CPU application. Constants must also be used as array size for array-type data structure members (see below).

The constants in the generated Sensor Controller Interface (SCIF) driver are prefixed to prevent name conflicts. These are listed in the tailored how-to-use guide, which is generated together with the driver.

Attributes

Each constant has the following attributes:

  • Name : The constant name, for example BUFFER_SIZE
    • Can only contain letters ( A-Z and a-z ), digits ( 0-9 ), and underscores ( _ )
    • Must start with a letter
  • Type : The constant type:
    • 16-bit unsigned, decimal
    • 16-bit signed, decimal
    • 16-bit unsigned, hexadecimal
      • Equivalent to 16-bit unsigned, decimal , but the value is displayed in hexadecimal format in Sensor Controller Studio
    • Resource configuration value
      • Equals the value of a resource configuration setting, for example the number I/O pins that the task shall iterate over
  • Value : One of the following:
    • A value expression, using the syntax described below
      • Numeric value: -123
      • Simple expression: PIN_COUNT * 2
      • Complex expression: ((A_PARAM + B_PARAM) & 0x003E) | (0x8000 | C_PARAM)
    • The resource configuration setting, either
      • “Resource Name -> Setting Name”, or
      • “Resource Name -> I/O Usage Name -> Setting Name”
  • Description : Optional description of the constant, for example “Size of the ADC sample buffer”
    • Included as comments in the generated SCIF driver

Support for Larger Constants

A warning will be displayed for constant values that exceed 16-bit range.

It is possible to specify constants within signed 32-bit range (that is [-0x80000000, 0x7FFFFFFF]). Such larger constants can be used in:

  • Value expressions for other constants
  • Value expressions for data structure members, as long as the result is in 16-bit range
  • Constant (sub-)expressions in task code, as long as the result is in 16-bit range

Other usage in task code can cause unintended behavior.

Value Expression Syntax

<expr>          ::= '(' <expr> ' ' <op2> ' ' <expr> ')'
                |   '(' <op1> <expr> ')'
                |   '(' <expr> ')'
                |   <value>

<op2>           ::= '<' | '<=' | '==' | '!=' | '>' | '>=' | '/' | '*' | '+' | '-' | '%'
                |   '|' | '||' | '&' | '&&' | '^' | '<<' | '>>'

<op1>           ::= '-' |
                |   '~' | '!'

<value>         ::= other user-defined constant (for example PIN_COUNT)
                |   hexadecimal (for example 0x12AB)
                |   decimal value (for example 14 or -42)

There is no operator precedence. A sub-expression can only contain one operator, and all sub-expressions must be enclosed in parentheses:

// Valid
(A + B) + (C + D)
((A | B) | C) | (~D)

// Not valid
A + B + C + D

A constant value expression must not:

  • Divide by zero
  • Introduce cyclic references, for example constant A has value B + 1 , and constant B has value A + 42

Constant Editor

The list or table contains one entry for each existing user-defined constant, and a “new” entry at the bottom for adding a new constant.

To add a new constant:

  • Do one of the following:
    • Form mode: Select the Add new constant entry in the constant list, and mouse click or press Tab to move to the name field
    • Table mode: Mouse click or press Tab to move to the name field of the “new” entry in the constant table
    • Use menu command Add Constant - Alt+N
  • Enter/select constant attributes in any order: Name, type, value and description
    • Another “new” entry will appear in the list when a valid name has been entered

To edit an existing constant:

  • Do one of the following:
    • Form mode: Select the existing entry in the constant list, and mouse click or press Tab to move to the desired attribute fields
    • Table mode: Mouse click or press Tab to move to the desired attribute field
  • Edit the constant attribute fields.
    • When renaming a constant, all the dependencies in the Constants and Data Structures panel will be updated as you type

To remove an existing constant:

  • Click on the action button (three dots) for the existing constant, and select Remove…
  • Confirm or cancel the removal

Errors and Warnings

Icons indicate the status for each constant:

  • Grey circle with a check mark: All constant attributes are OK
  • Blue plus: The “new” constant entry
  • Yellow warning sign: The constant value is out of range (for the selected type)
  • Red error sign: There is one or more error associated with this constant, or with another constants that are used in the value expression

Invalid calculated values are indicated by a question mark “?”.

Errors and warnings are shown differently in form mode and table mode:

  • Form mode: See the text box under the attribute fields
  • Table mode: Hover with the mouse pointer over the status icon

Name Conflicts

It is possible to enter a name that is already used by another user-defined constant.

When this happens and until the conflict is resolved, Sensor Controller Studio will not use the new name, but instead use the last valid name. The last valid name is shown in the form mode constant list.

Data Structure Members

The Sensor Controller data structures are used to store task data in the AUX RAM. The “data structure members” are accessible from:

  • Each task code block (for example Execution Code) within a single Sensor Controller task
  • The System CPU application

Data structure members can also be selected for graphical display during Task Testing and Run-Time Logging.

Attributes

Each data structure member has the following attributes:

  • Data structure : There are four different data structures, each with different properties:
    • cfg
      • Typical use: Run-time task configuration, set by the System CPU application before it starts the task
      • Special feature: Not cleared when task testing or run-time logging is restarted
    • input
      • Typical use: Transfer input data to the Sensor Controller task
    • output
      • Typical use: Transfer output data to the System CPU application
      • Special feature: Supports multiple buffers, using the Multi-Buffered Output Data Exchange resource
    • state
      • Typical use: Internal variables used to store the task’s state between iterations
      • Special feature: Must always be reset to initial values before a Sensor Controller task is restarted
  • Member name : The name of the data structure member, for example “adcValue” or “pAdcSampleBuffer”
    • Can only contain letters ( A-Z and a-z ) and digits ( 0-9 )
    • Must start with a letter
  • Type : Select one of the following:
    • 16-bit unsigned, decimal
    • 16-bit signed, decimal
    • 16-bit unsigned, hexadecimal
      • Equivalent to 16-bit unsigned, decimal , but the value is displayed in hexadecimal format in Sensor Controller Studio
    • 16-bit unsigned, boolean
      • Equivalent to 16-bit unsigned, decimal , but uses less vertical space in graphs during task testing and run-time logging
  • Array size : Either “Not array” for single data structure members, or the name of a user-defined constant for array data structure members
  • Value : A value expression, using the syntax described above
    • Numeric value: -123
    • Simple expression: PIN_COUNT * 2
    • Complex expression: ((A_PARAM + B_PARAM) & 0x003E) | (0x8000 | C_PARAM)
  • Description : Optional description of the data structure member, for example “ADC sample buffer”
    • Included as comments in the generated SCIF driver

Value Expression Syntax

<expr>          ::= '(' <expr> ' ' <op2> ' ' <expr> ')'
                |   '(' <op1> <expr> ')'
                |   '(' <expr> ')'
                |   <value>

<op2>           ::= '<' | '<=' | '==' | '!=' | '>' | '>=' | '/' | '*' | '+' | '-' | '%'
                |   '|' | '||' | '&' | '&&' | '^' | '<<' | '>>'

<op1>           ::= '-' |
                |   '~' | '!'

<value>         ::= user-defined constant (for example PIN_COUNT)
                |   hexadecimal (for example 0x12AB)
                |   decimal value (for example 14 or -42)

There is no operator precedence. A sub-expression can only contain one operator, and all sub-expressions must be enclosed in parentheses:

// Valid
(A + B) + (C + D)
((A | B) | C) | (~D)

// Not valid
A + B + C + D

A data structure member value expression must not:

  • Divide by zero

Data Structure Editor

The list or table contains one entry for each existing user-defined data structure member, and a “new” entry at the bottom of each data structure for adding a new member.

To add a new data structure member:

  • Do one of the following:
    • Form mode: Select the desired Add “…” Data Structure Member entry in the data structure list, and mouse click or press Tab to move to the member name field
    • Table mode: Mouse click or press Tab to move to the member name field of the desired “new” entry in the data structure table
    • Use menu command Add “cfg” Data Structure Member - Alt+C
    • Use menu command Add “input” Data Structure Member - Alt+I
    • Use menu command Add “output” Data Structure Member - Alt+O
    • Use menu command Add “state” Data Structure Member - Alt+S
  • Enter/select member attributes in any order: Name, type, array size, value and description
    • Another “new” entry will appear in the list when a valid name has been entered
    • For array size, select either “Not array”, or a user-defined constant from the top section of the panel

To edit an existing data structure member:

  • Do one of the following:
    • Form mode: Select the existing entry in the data structure list, and mouse click or press Tab to move to the desired attribute fields
    • Table mode: Mouse click or press Tab to move to the desired attribute field
  • Edit the member attribute fields.

To move an existing member to a different data structure:

  • Click on the action button (three dots) for the existing member, and select the desired Move to “…” command. A move is not allowed if it causes a name conflict.

To remove an existing data structure member:

  • Click on the action button (three dots) for the existing member, and select Remove…
  • Confirm or cancel the removal

Errors and Warnings

Icons indicate the status for each data structure member:

  • Grey circle with a check mark: All member attributes are OK
  • Blue plus: The “new” member entry
  • Yellow warning sign: The member value is out of range (for the selected type)
  • Red error sign: There is one or more error associated with this member, or with constants that are used in the value expression

Invalid calculated values and calculated array sizes are indicated by a question mark “?”.

Errors and warnings are shown differently in form mode and table mode:

  • Form mode: See the text box under the attribute fields
  • Table mode: Hover with the mouse pointer over the status icon

Name Conflicts

It is possible to enter a member name that is already used by another user-defined member in the same data structure.

When this happens and until the conflict is resolved, Sensor Controller Studio will not use the new member name, but instead use the last valid member name. The last valid member name is shown in the form mode data structure list.