Skip to content

Conversation

@benpicco
Copy link
Contributor

@benpicco benpicco commented Mar 21, 2019

This implements an idea from C Preprocessor tricks, tips, and idioms to allow for conditional compilation of code depending on whether a parametrically assembled macro resolves to a real defined macro (from DTS) or not.

E.g. newer Atmel sam0 parts have 4 interrupts associated with a SERCOM peripheral while older ones only had one. The Interrupt setup code is assembled in a macro already to prevent copy & paste for all SERCOMs. This allows to use a nested macro for the actual interrupt enablement. If the Interrupt exists, the corresponding setup code is inserted. If it doesn't exist, the macro resolves to nothing.

@Sizurka expressed interest in this too - #14685 (review)

@benpicco benpicco changed the title Allow conditional macros to depend on whether a property in DTS exists misc: Allow conditional macros to depend on whether a property in DTS exists Mar 21, 2019
@benpicco benpicco changed the title misc: Allow conditional macros to depend on whether a property in DTS exists misc: util: Allow conditional macros to depend on whether a property in DTS exists Mar 21, 2019
@codecov-io
Copy link

codecov-io commented Mar 21, 2019

Codecov Report

Merging #14788 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #14788   +/-   ##
=======================================
  Coverage   52.51%   52.51%           
=======================================
  Files         309      309           
  Lines       45048    45048           
  Branches    10419    10419           
=======================================
  Hits        23656    23656           
  Misses      16584    16584           
  Partials     4808     4808
Impacted Files Coverage Δ
include/misc/util.h 50% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 373a42b...9ea093f. Read the comment docs.

Instead of

	#define DT_ATMEL_SAM0_UART_41012000_IRQ_0                54

make the script output

	#define DT_ATMEL_SAM0_UART_41012000_IRQ_0               (54)

This allows for some advanced macro magic.

Also make sure not to enclose strings in parentheses as this will
interfere with some other macro magic conjured by nrf52.

Signed-off-by: Benjamin Valentin <[email protected]>
Add a helper function that can be used together with COND_CODE_1.
If the macro parameter resolves to a real (parenthesized) variable,
this macro resolves to '1', if it resolves to a macro that can not be
resolved to a variable, it resolves to '0'.

Signed-off-by: Benjamin Valentin <[email protected]>
Signed-off-by: Derek Hageman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants