The eCos Component Writer's Guide
Prev |  | Next

# calculated

## Name

Property calculated — Used if the current option's value is not user-modifiable, but is calculated using a suitable CDL expression.

## Synopsis

    cdl_option <name> {
        calculated <expression>
        …
    }

## Description

In some cases it is useful to have a configuration option whose value cannot be modified directly by the user. This can be achieved using a calculated , which takes a CDL expression as argument (see the section called Ordinary Expressions in Chapter 3 for a description of expression syntax). The configuration system evaluates the expression when the current package is loaded and whenever there is a change to any other option referenced in the expression. The result depends on the option's flavor:

`flavor none`

  Options with this flavor have no value, so the calculated property is not applicable.

`flavor bool`

  If the expression evaluates to a non-zero result the option is enabled, otherwise it is disabled.

`flavor booldata`

  If the result of evaluating the expression is zero then the option is disabled, otherwise the option is enabled and its value is the result.

`flavor data`

  The value of the option is the result of evaluating the expression.

There are a number of valid uses for calculated options, and there are also many cases where some other CDL facility would be more appropriate. Valid uses of calculated options include the following:

- On some target hardware a particular feature may be user-configurable, while on other targets it is fixed. For example some processors can operate in either big-endian or little-endian mode, while other processors do not provide any choice. It is possible to have an option `CYGARC_BIGENDIAN` which is calculated in some architectural HAL packages but user-modifiable in others.

- Calculated options can provide an alternative way for one package to affect the behavior of another one. Suppose a package may provide two possible implementations, a preferred one involving self-modifying code and a slower alternative. If the system involves a ROM bootstrap then the slower alternative must be used, but it would be inappropriate to modify the startup option in every HAL to impose constraints on this package. Instead it is possible to have a calculated option whose value is `{ CYG_HAL_STARTUP == "ROM" }` , and which has appropriate consequences. Arguably this is a spurious example, and it should be a user choice whether or not to use self-modifying code with a default_value based on `CYG_HAL_STARTUP` , but that is for the component writer to decide.

- Sometimes it should be possible to perform a particular test at compile-time, for example by using a C preprocessor `#if` construct. However the preprocessor has only limited functionality, for example it cannot perform string comparisons. CDL expressions are more powerful.

- Occasionally a particular sub-expression may occur multiple times in a CDL script. If the sub-expression is sufficiently complex then it may be worthwhile to have a calculated option whose value is the sub-expression, and then reference that calculated option in the appropriate places.

Alternatives to using calculated options include the following:

- CDL interfaces are a form of calculated option intended as an abstraction mechanism. An interface can be used to express the concept of any scheduler , as opposed to a specific one such as the bitmap scheduler.

- If a calculated option would serve only to add additional information to a configuration header file, it may be possible to achieve the same effect using a define_proc property or one of the other properties related to header file generation.

> Tip: If the first entry in a calculated expression is a negative number, for example `calculated -1` then this can be misinterpreted as an option instead of as part of the expression. Currently the calculated property does not take any options, but this may change in future. Option processing halts at the sequence `--` , so the desired value can be expressed safely using `calculated -- -1`

Warning

Some of the CDL scripts in current eCos releases make excessive use of calculated options. This is partly because the recommended alternatives were not always available at the time the scripts were written. It is also partly because there is still some missing functionality, for example define_proc properties cannot yet access the configuration data so it may be necessary to use calculated properties to access the data and perform the desired manipulation via a CDL expression. New scripts should use calculated options only in accordance with the guidelines.

> Note: For options with the booldata flavor the current CDL syntax does not allow the enabled flag and the value to be calculated separately. Functionality to permit this may be added in a future release.

> Note: It has been suggested that having options which are not user-modifiable is potentially confusing, and that a top-level `cdl_constant` command should be added to the language instead of or in addition to the calculated property. Such a change is under consideration. However because the value of a calculated option can depend on other options, it is not necessarily constant.

## Example

    # A constant on some target hardware, perhaps user-modifiable on other
    # targets.
    cdl_option CYGNUM_HAL_RTC_PERIOD {
        display       "Real-time clock period"
        flavor        data
        calculated    12500
    }

## See Also

Properties default_value , flavor and legal_values ,

Prev | Home | Next
active_if | Up | compile