Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kconfig: BT: Default to using BT_CTLR when BT #9499

Merged

Conversation

SebastianBoe
Copy link
Collaborator

As reported in issue #9494, BT samples are using the off-chip
UART-based BT controller on 52810. But the on-chip BT controller is
supported on 52810, so this is the reasonable default when BT is
enabled.

This patch enables BT_CTLR by default when BT is enabled.

This resolves #9494.

Signed-off-by: Sebastian Bøe [email protected]

Copy link
Collaborator

@ulfalizer ulfalizer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will enable BT_CTLR even if BT isn't enabled, because the default that gets added to BT_CTLR symbol after dependency propagation is default y if BOARD_NRF52810_PCA10040.

That should be fine as long as no code makes decisions based on BT_CTLR without looking at BT first though.

If it's not fine, an if BT could be added. This aspect of Kconfig.defconfig files is a bit wonky. They work more like an OR than an AND.

@@ -11,4 +11,12 @@ config BOARD_ENABLE_DCDC
select SOC_DCDC_NRF52X
default y

if BT
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A space after an if and before an endif looks less cramped, imo.

@SebastianBoe
Copy link
Collaborator Author

This will enable BT_CTLR even if BT isn't enabled
If it's not fine, an if BT could be added.

That is not fine, added an if. Thank you for catching this.

I wonder what the cleanest solution here is.

I am not familiar with BT, but if there are multiple implementations of the controller available, e.g. off-chip, or on-chip. And it only makes sense to enable one of them, then I wonder if a choice statement and maybe different defaults depending on the board would be the cleanest solution.

@ulfalizer
Copy link
Collaborator

Looks like there's also a dependency on BT_HCI on the base definition of BT_CTLR. Don't know if that matters here.

@ulfalizer
Copy link
Collaborator

That is not fine, added an if. Thank you for catching this.

I wonder what the cleanest solution here is.

I am not familiar with BT, but if there are multiple implementations of the controller available, e.g. off-chip, or on-chip. And it only makes sense to enable one of them, then I wonder if a choice statement and maybe different defaults depending on the board would be the cleanest solution.

If there's only two options, a plain bool is the cleanest solution (Use on-chip Bluetooth controller or the like). Otherwise, a choice might make sense.

@SebastianBoe
Copy link
Collaborator Author

SebastianBoe commented Aug 17, 2018

If there's only two options

I believe there are several, but a BT expert would have to chime in.

# BT_CTLR depends on BT. When BT is enabled we should default to also
# enabling the controller.
config BT_CTLR
default y
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also do default y if BT by the way, which saves some lines. No super strong opinions though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, no need of if BT, use default y if BT.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

# BT_CTLR depends on BT. When BT is enabled we should default to also
# enabling the controller.
config BT_CTLR
default y
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, no need of if BT, use default y if BT.

As reported in issue zephyrproject-rtos#9494, BT samples are using the off-chip
UART-based BT controller on 52810. But the on-chip BT controller is
supported on 52810, so this is the reasonable default when BT is
enabled.

This patch enables BT_CTLR by default when BT is enabled.

This resolves zephyrproject-rtos#9494.

Signed-off-by: Sebastian Bøe <[email protected]>
@SebastianBoe
Copy link
Collaborator Author

@ulfalizer : While we are on the topic.

What is the cleanest way to have boards affect the defaults of the kernel?

E.g. how should a board change the default choice in a Kconfig like this?

config FEATURE
       bool

if FEATURE

choice
	prompt "Feature implementation selection"
	default FEATURE_IMPLEMENTATION_2

config FEATURE_IMPLEMENTATION_1
       bool

config FEATURE_IMPLEMENTATION_2
       bool
       
endchoice

endif # FEATURE

What I have done in this patch is not clean, as you need to duplicate the dependency information of the original config.

@ulfalizer
Copy link
Collaborator

ulfalizer commented Aug 17, 2018

E.g. how should a board change the default choice in a Kconfig like this?

The choice would have to have a name:

config FEATURE
	bool

if FEATURE

choice FEATURE_IMPLEMENTATION
	prompt "Feature implementation selection"
	default FEATURE_IMPLEMENTATION_2

config FEATURE_IMPLEMENTATION_1
	...

config FEATURE_IMPLEMENTATION_2
	...
       
endchoice

endif # FEATURE

The default could then be changed with an additional definition in a Kconfig.defconfig file:

choice FEATURE_IMPLEMENTATION
	default FEATURE_IMPLEMENTATION_1
endchoice

(In this case, there's no need to repeat the dependency information, because the choice symbols won't be visible unless FEATURE is enabled.)

What I have done in this patch is not clean, as you need to duplicate the dependency information of the original config.

Yeah, that's a drawback of Kconfig.defconfig files in general I think. The extra symbol definitions can't "limit" the base definition of the symbol/choice, only extend it. That means you might have to duplicate a bunch of dependency information.

For symbols that you know will be visible (that have satisfied dependencies), it's cleaner to set them in a *_defconfig file.

Setting a only potentially visible symbol (a symbol with that has a prompt that but might not be visible by default) in a *_defconfig file would also work as a way of giving it a default whenever it becomes visible. That would trigger the was-assigned-the-value-x-got-the-value-y warning if the symbol isn't visible though, so it gets a bit hairy. That warning is useful in other cases.

(Setting a value in a *_defconfig/.config file sets the "user value" of the symbol, which is another input when the symbol value is calculated.)

@codecov-io
Copy link

Codecov Report

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

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #9499   +/-   ##
=======================================
  Coverage   52.22%   52.22%           
=======================================
  Files         212      212           
  Lines       25948    25948           
  Branches     5577     5577           
=======================================
  Hits        13551    13551           
  Misses      10140    10140           
  Partials     2257     2257

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 aaaf20e...d98c2f0. Read the comment docs.

@ulfalizer
Copy link
Collaborator

ulfalizer commented Aug 17, 2018

Knowing how dependency propagation works might clarify why it works like that.

Say you have a symbol with two definitions:

if DEP_1

config SYM
	bool "sym"
	default DEF_1 if DEP_2
	default DEF_2
	select SEL_1

endif

...

menu "menu"
	depends on DEP_3

config SYM
	default DEF_3
	select SEL_2

endmenu

(I just made it a menu instead of an if in the second example to show that it works the same way.)

Those definitions are logically equivalent to the following definitions (this is what happens internally as well):

config SYM
	bool "sym" if DEP_1  (prompt only visible if DEP_1 is enabled)
	default DEF_1 if DEP_2 && DEP_1
	default DEF_2 if DEP_1
	select SEL_1 if DEP_1

config SYM
	default DEF_3 if DEP_3
	select SEL_2 if DEP_3

Symbols with multiple definitions just get all the properties from the different definition locations, so the symbol finally ends up like this:

config SYM
	bool "sym" if DEP_1
	default DEF_1 if DEP_2 && DEP_1
	default DEF_2 if DEP_1
	default DEF_3 if DEP_3
	select SEL_1 if DEP_1
	select SEL_2 if DEP_3

Note that the properties from the second definition did not get a dependency on DEP_1. They're fully independent.

@SebastianBoe
Copy link
Collaborator Author

Thank you for the explanation.

(In this case, there's no need to repeat the dependency information, because the choice symbols won't be visible unless FEATURE is enabled.)

I don't understand the difference between the situation with FEATURE and the situation with BT_CTLR. Is it because one uses 'choice' symbols, and the other uses normal symbols? Because BT_CTLR is also invisible unless BT is enabled.

@ulfalizer
Copy link
Collaborator

ulfalizer commented Aug 17, 2018

I don't understand the difference between the situation with FEATURE and the situation with BT_CTLR. Is it because one uses 'choice' symbols, and the other uses normal symbols? Because BT_CTLR is also invisible unless BT is enabled.

Yeah, it's just a subtlety specific to choices.

When FEATURE isn't enabled, the choice won't be visible (you get prompt "Feature implementation selection" if FEATURE after dependency propagation, and FEATURE is n). Choices that aren't visible ignore their defaults, so it won't matter that the default FEATURE_IMPLEMENTATION_1 property has a satisfied condition.

Choices are a bit wonky in general. Lots of complexity around them...

@SebastianBoe
Copy link
Collaborator Author

Never mind, I understood it now, your explanation was great.

(In this case, there's no need to repeat the dependency information, because the choice symbols won't be visible unless FEATURE is enabled.)

@SebastianBoe
Copy link
Collaborator Author

@cvinayak : Review comments have been addressed. Please re-evaluate the review.

Copy link
Member

@ioannisg ioannisg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks OK, just minor suggestions from me.

# BT_CTLR depends on BT. When BT is enabled we should default to also
# enabling the controller.
config BT_CTLR
default y if BT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now this looks better, @SebastianBoe (with the dependence on BT)

@@ -11,4 +11,9 @@ config BOARD_ENABLE_DCDC
select SOC_DCDC_NRF52X
default y

# BT_CTLR depends on BT. When BT is enabled we should default to also
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove "should"

Copy link
Contributor

@cvinayak cvinayak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nashif nashif merged commit 9e18b4f into zephyrproject-rtos:master Aug 17, 2018
@SebastianBoe SebastianBoe deleted the fix_bt_samples_on_nrf_52810 branch August 20, 2018 08:07
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.

Nordic nrf52810_pca10040 is missing default bluetooth configuration options
6 participants