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: Break conditions for waiting loops #3064

Closed
OlegHahm opened this issue May 26, 2015 · 10 comments
Closed

drivers: Break conditions for waiting loops #3064

OlegHahm opened this issue May 26, 2015 · 10 comments
Assignees
Labels
Area: drivers Area: Device drivers Discussion: RFC The issue/PR is used as a discussion starting point about the item of the issue/PR State: stale State: The issue / PR has no activity for >185 days Type: new feature The issue requests / The PR implemements a new feature for RIOT

Comments

@OlegHahm
Copy link
Member

As discussed in #2911 (comment): In many places in hardware dependent code, one has to wait for an undetermined time until e.g. a register is set. Typically this is done in a while loop, which, however, could cause an endless loop in case of a hardware failure. Ergo, I would strongly vote to introduce a simple counter or similar that breaks the loop if the expected state has not been reached after N tries.

@OlegHahm OlegHahm added Discussion: RFC The issue/PR is used as a discussion starting point about the item of the issue/PR Area: drivers Area: Device drivers labels May 26, 2015
@BytesGalore
Copy link
Member

I don't know if such approach would ease things.
If the hardware is blocked on a condition state, e.g. like discussed in #2911, and we break out this loop we continue into an undefined state.
My concern is that this will result in even more complicated situations/wait-states etc.

@OlegHahm
Copy link
Member Author

The driver should return with an error code then.

@PeterKietzmann
Copy link
Member

I partly agree with @BytesGalore that there might be a risk of undefined states. But in general I still think it's more comfortable to return somehow instead of running in an endless loop. Just returning and continuing the program should be avoided. The possibilities I see is either (i) return a defined error code, explicitly document it and check for this code or (ii) running into hard fault. With (i) there might be still a risk to run programs in an undefined state. (ii) feels a bit overstated to me.
Anyway, one needs to check several documentations to make a concrete statement as this is a hardware-specific thing.

@jnohlgard
Copy link
Member

I think returning an error code is the only sensible thing to do. If the application is critically dependent on a subsystem which gives an error code, then the application should be able to decide if/when to perform a system reset (which would be the end result of the hardfault alternative). I don't think we should force the system into a hardfault or similar because of e.g. a communication problem on an SPI bus.

@PeterKietzmann
Copy link
Member

So the consensus is to add a timeout or similar to all of these occurrences and return with an error then. Right?

@OlegHahm
Copy link
Member Author

I guess so.

@LudwigKnuepfer
Copy link
Member

This is also related to #3366

@PeterKietzmann
Copy link
Member

@gebart stated in #5282:

  • I2C: Agreed, clock stretching or misbehaving slave devices can potentially make a transaction stall, depending on the periph implementation this may hang indefinitely.
  • SPI: No, SPI only needs a timeout in slave mode which is not implemented right now (the master drives the clock, time to complete is always deterministic)
  • UART: the periph/uart API only supports RX via asynchronous callbacks per byte received, and UART TX is driven by the MCU clock, so the TX time is always deterministic.

@sdalu answered in #5282:

  • SPI: I guess slave mode is going to be implemented some days, if it will require changes to the existing SPI API to handle timeout, perhaps it would be better to prepare for it earlier and minimize futur code change.
  • UART: if flow control is enabled this could block TX

@PeterKietzmann
Copy link
Member

So we still need some (/one) volunteer(/s) to take over that routine work as well as someone to test it.

@stale
Copy link

stale bot commented Aug 10, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions.

@stale stale bot added the State: stale State: The issue / PR has no activity for >185 days label Aug 10, 2019
@stale stale bot closed this as completed Sep 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: drivers Area: Device drivers Discussion: RFC The issue/PR is used as a discussion starting point about the item of the issue/PR State: stale State: The issue / PR has no activity for >185 days Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

No branches or pull requests

6 participants