You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2019/02/20 15:23:27 UTC

[GitHub] andrzej-kaczmarek opened a new pull request #270: Allow choice settings in syscfg

andrzej-kaczmarek opened a new pull request #270: Allow choice settings in syscfg
URL: https://github.com/apache/mynewt-newt/pull/270
 
 
   This adds support to have syscfg settings which can be set to one of predefined values. This allows to simplify some settings which now have separate syscfg defined for each choice. With this new setting
   newt can guarantee that only single setting for selected choice is configured in `syscfg.h`.
   
   I'm not sure if this is good approach, so perhaps someone has better idea how to achieve the same result. The main disadvantage of current implementation is that it breaks compatibility with old `newt` versions since they do not know how to handle `$validchoice` requirements and will fail. Anyway, let me explain how this works.
   
   Sample settings looks like this:
   ```
       MCU_LFCLK_SOURCE:
           description: >
               Selected source for low frequency clock (LFCLK).
           value:
           restrictions:
               - $validchoice
           choices:
               - lfrc      # 32.768 kHz RC oscillator (LFRC)
               - lfxo      # 32.768 kHz crystal oscillator (LFXO)
               - lfsynth   # 32.768 kHz synthesized from HFCLK (LFSYNT)
   ```
   
   `$validchoice` restriction enforces that `value`, if set, should be one of those listed in `choices`. It is valid to leave value empty, thus `$notnull` must be used if setting requires a valid value. List of choices is a list of strings (letters, numbers and underscores allowed) and internally they are converted to lower-case strings. It is invalid to specify only one of `$validchoice` requirement or `choices` list for a setting.
   
   Setting defined as above will generate following defines in `syscfg.h`:
   ```
   /* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */
   #ifndef MYNEWT_VAL_MCU_LFCLK_SOURCE__lfrc
   #define MYNEWT_VAL_MCU_LFCLK_SOURCE__lfrc (0)
   #endif
   #ifndef MYNEWT_VAL_MCU_LFCLK_SOURCE__lfxo
   #define MYNEWT_VAL_MCU_LFCLK_SOURCE__lfxo (1)
   #endif
   #ifndef MYNEWT_VAL_MCU_LFCLK_SOURCE__lfsynth
   #define MYNEWT_VAL_MCU_LFCLK_SOURCE__lfsynth (0)
   #endif
   #ifndef MYNEWT_VAL_MCU_LFCLK_SOURCE
   #define MYNEWT_VAL_MCU_LFCLK_SOURCE (1)
   #endif
   ```
   
   Main sysycfg name is ehtier `1` when any value is set or `0` otherwise. Each choice listed have separate define which consists of syscfg name and choice name (in lowercase) set to `1` if this is the selected value or `0` otherwise. To make checks easier, `MYNEWT_VAL_CHOICE(_name, _val)` macro is defined which checks for given choice on syscfg value.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services