Skip to content

sensor creator init split#2445

Merged
kasjer merged 2 commits into
apache:masterfrom
kasjer:kasjer/sensor_creator-init-split
Dec 19, 2020
Merged

sensor creator init split#2445
kasjer merged 2 commits into
apache:masterfrom
kasjer:kasjer/sensor_creator-init-split

Conversation

@kasjer
Copy link
Copy Markdown
Contributor

@kasjer kasjer commented Dec 18, 2020

This solves the problem of sensor_creator usage along with SPI flash that is present in flash map.

If BSP uses SPI flash and sensor creator with SPI devices that are connected to the same
SPI bus as flash, not initializing chip select pin for those other devices may lead to wrong
reads from flash.
It happens when uninitialized yet GPIO is still perceived by sensor as active and sensor responds
to requests that should be answered by flash.

This adds sensor_dev_init() that has initialization code taken from sensor_dev_create().
Thai also changes flash_map initialization stage to accommodate for other initialization that
could be needed before flash_map can be initialized.

sysinit stage for flash map is currently 2.
It leaves very little space for additional code
that should be executed before flash_map is initialized
but after OS is created.

If some package initialization is to be executed before
flash_map, setting its stage to 1 is risky since OS is
stage 1.
This splits existing function sensor_dev_create().
All the devices are still created in this function but code
that actually accessed them is moved to separate function
sensor_dev_init().

This is really needed in case when SPI flash is used in flash map.
Flash map is initialized in early stage. If by that time
devices that are connected to the same SPI bus are not created yet,
GPIO that is used for chip selection may be perceived as active since
it was not configured yet. In such case two devices (SPI flash and some
SPI sensor) could try to respond at the same time and SPI flash command
responses can be corrupted.
@apache-mynewt-bot
Copy link
Copy Markdown

Style check summary

No suggestions at this time!

Copy link
Copy Markdown
Contributor

@vrahane vrahane left a comment

Choose a reason for hiding this comment

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

Looks good. That was a really good catch. The config for the sensors should have taken care of this situation as it would configure the spi accordingly but this seems like a cleaner solution.

@kasjer kasjer merged commit c8b8737 into apache:master Dec 19, 2020
@kasjer kasjer deleted the kasjer/sensor_creator-init-split branch December 19, 2020 16:06
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.

3 participants