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

drivers/periph_spi: let spi_acquire return void #15902

Merged
merged 6 commits into from
Sep 2, 2021

Conversation

maribu
Copy link
Member

@maribu maribu commented Feb 1, 2021

Contribution description

  • Changed signature from int spi_acquire(...) to void spi_acquire(...)
    • Most SPI implementations and 99.9% of all users treat it like this anyway
    • By adding assert()s to verify parameters, this actually increases error checking compared to before, where both SPI implementations and user mostly didn't care about errors
  • Updated soft_spi to match the periph_spi API
  • Updated implementations
  • Updated the few users, which actually checked the return value
    • Most checked the return value only during <foo>_init(), but afterwards never again
    • This is updated to add a pair of spi_acquire() and spi_release() if and only if NDEBUG is not defined.
    • The reasoning is: If assert()ions are disabled anyway, we won't trigger them no matter how hard we try :-)

Testing procedure

This should be mostly unscary. However, without assert()ions enabled, timing behavior changes a bit during initilization, as a useless pair of spi_acquire() and spi_release() is simply dropped.

Issues/PRs references

Depends on and includes:

@maribu maribu added State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet Process: API change Integration Process: PR contains or issue proposes an API change. Should be handled with care. Area: drivers Area: Device drivers Area: cpu Area: CPU/MCU ports Process: needs >1 ACK Integration Process: This PR requires more than one ACK labels Feb 1, 2021
@maribu
Copy link
Member Author

maribu commented Feb 1, 2021

Let's see if the CI finds any implementations / users that I missed.

Beware: While the WIP label is still present, I will squash without further notice ;-) I'll drop the WIP label once the CI is green.

@maribu maribu added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Feb 1, 2021
@maribu maribu changed the title drivers/periph_spi: Let spi_acquire return void drivers/periph_spi: let spi_acquire return void Feb 1, 2021
@maribu maribu force-pushed the spi-api-change-1 branch 4 times, most recently from f76eba8 to a8401a6 Compare February 2, 2021 07:25
@maribu maribu force-pushed the spi-api-change-1 branch 2 times, most recently from 0645dc9 to 64e2878 Compare February 2, 2021 07:48
@maribu maribu added State: waiting for other PR State: The PR requires another PR to be merged first and removed State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet labels Feb 2, 2021
@maribu
Copy link
Member Author

maribu commented Feb 2, 2021

The remaining failed build is an CI hiccup, so this is no longer WIP.

@github-actions github-actions bot added Area: sys Area: System Area: tests Area: tests and testing framework labels Sep 1, 2021
@maribu
Copy link
Member Author

maribu commented Sep 1, 2021

Cherry-picked review fixes that address @hugueslarrive's review in #15904 into this PR as well

drivers/bmx280/bmx280.c Outdated Show resolved Hide resolved
Copy link
Member

@dylad dylad left a comment

Choose a reason for hiding this comment

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

LGTM.
Please squash !

@@ -78,10 +78,11 @@ void spi_init_pins(spi_t bus)
#endif
}

int spi_acquire(spi_t bus, spi_cs_t cs, spi_mode_t mode, spi_clk_t clk)
void spi_acquire(spi_t bus, spi_cs_t cs, spi_mode_t mode, spi_clk_t clk)
{
(void)bus;
Copy link
Member Author

Choose a reason for hiding this comment

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

Note that if an argument is used by an assert() only, it will be unused once the assert is disabled via NDEBUG. The reason is that assert() is (as required by the C standard) implement as a preprocessor macro.

@fjmolinas
Copy link
Contributor

Go!

@fjmolinas fjmolinas merged commit a1cbcc9 into RIOT-OS:master Sep 2, 2021
@maribu
Copy link
Member Author

maribu commented Sep 2, 2021

Thanks!

@maribu maribu deleted the spi-api-change-1 branch September 2, 2021 07:02
hugueslarrive added a commit to hugueslarrive/RIOT that referenced this pull request Sep 2, 2021
hugueslarrive added a commit to hugueslarrive/RIOT that referenced this pull request Sep 2, 2021
dylad added a commit that referenced this pull request Sep 2, 2021
Remove duplicated includes introduced in #15902
@gschorcht
Copy link
Contributor

Shouldn't we do the same for i2c_acquire? All implementations just return 0 with only one exception

int i2c_acquire(i2c_t dev)
{
DEBUG("%s\n", __FUNCTION__);
if (dev < I2C_NUMOF) {
mutex_lock(&lock);
return 0;
}
return -1;
}
which is a typical case for an assert. This was already the topic of a discussion in issue #10673, but after we removed the return value of spi_acquire, there is no argument to keep it for i2c_acquire.

@maribu
Copy link
Member Author

maribu commented Nov 24, 2021

I totally agree!

@gschorcht
Copy link
Contributor

Ok, I will try to provide a PR in next weeks.

chrysn added a commit to RIOT-OS/rust-riot-sys that referenced this pull request May 31, 2022
It wasn't handled particularly well anyway here.

[15902]: RIOT-OS/RIOT#15902
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: arduino API Area: Arduino wrapper API Area: cpu Area: CPU/MCU ports Area: drivers Area: Device drivers Area: sys Area: System Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: ARM Platform: This PR/issue effects ARM-based platforms Platform: AVR Platform: This PR/issue effects AVR-based platforms Platform: ESP Platform: This PR/issue effects ESP-based platforms Platform: MSP Platform: This PR/issue effects MSP-based platforms Platform: native Platform: This PR/issue effects the native platform Platform: RISC-V Platform: This PR/issue effects RISC-V-based platforms Process: API change Integration Process: PR contains or issue proposes an API change. Should be handled with care. Process: needs >1 ACK Integration Process: This PR requires more than one ACK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants