-
Notifications
You must be signed in to change notification settings - Fork 8.3k
drivers: spi: SPI API extension draft #22371
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
Conversation
A draft of SPI API extension. Following API introduces: - transaction concept. Transaction consists of SPI configuration and messages - transaction can be scheduled and canceled - message is simplex (one direction) and with additional flags it configures: - cs0 control (set/nop on start, clear/nop on end) - direction - delay - pausing after completion (e.g. to wait for rdy pin, spi_resume() resumes) - optional cs1 control (e.g. to control cmd/data pin) - two driver specific functions: - spi_single_transfer() - asynchronous raw spi transfer - spi_configure() - spi configuration - generic spi functions (vendor agnostic) - spi_schedule() - spi_cancel() - spi_resume() - helper macros for creating set of spi messages Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
|
Some checks failed. Please fix and resubmit. checkpatch (informational only, not a failure)Gitlint issues4: UC4 Line exceeds max length (77>72): "- transaction concept. Transaction consists of SPI configuration and messages" Documentation issuesTip: The bot edits this comment instead of posting a new one, so you can check the comment's history to see earlier messages. |
|
Hum there is a wind of bloating API in Zephyr these days. About #21641 I still don't see why you do not create a transaction manager outside of i2c/SPI APIs. First because, at least with SPI, there is no need of an API change: an API above it could simply add the transaction scheme and keep track of things. I believe it could be done for i2c as well. Second because part of what is being addressed by this issue is not a specific i2c/SPI issue: the capability to cancel a call and/or handling a proper timeout etc... Are GENERIC device driver issue. But as usual people (you are not the only one) prefer to address the issue case by case instead of looking at the big picture and fixing generically which would avoid bloating each and every API, add clarity, stability etc... That said, my mistake as well: as many of us, I have know these issues for a long time. Did I fix it? ... (same goes to PM etc...) Anyway, point is: for bus APIs it's far better to have a short API doing only what it is meant to do (i.e. handling i/o messages) and everything else should be above. If such transaction manager would be above i2c/SPI/ it would provide you much better flexibility in configuring various aspects of it like scheduling (which bus has higher priority for instance, or should it be transaction wise) or scaling (should it run under 1 thread, or one per bus type, etc...). You have to get a solution ready for hundreds of sensors as well as for just 3-4. Please reconsider your approach. You did find out an actual serious issue in #21538 but I think it would deserve to go one step beyond i2c and SPI. |
I complete agree with this, which is why I still want the queued operation manager infrastructure to come first, then a generic transaction manager developed to requirements identified by the needs of multiple driver APIs. As soon as topic-gpio gets settled I think the first step can be made available fairly quickly. |
|
@tbursztyka thanks for your comment.
It's going that direction. Note that underneath there is
Note that new SPI proposal limits vendor specific API to two functions ( I actually, hoped that discussion in that PR will go into that direction (generic bus/transaction manager) so i think we are on the same (or similar) page. Lets wait for other comments. |
|
"where driver is doing only vendor specific stuff" You don't want vendor specific hooks in a generic API. This is always a bad idea because once one uses it, the code is in fact not generic anymore and cannot be easily ported to other platforms. That said, I understand that business customers might want to access some vendor specific features. then do so via include/drivers/spi/<vendor_model>.h |
@nordic-krch so this functionality would effectively be added to |
|
@tbursztyka i think i was not clear on that. What I meant was that driver needs to implement 2 functions: configuring spi, scheduling asynchronous transfer which seemed like most low level driver functions to implement: all generic stuff (delays, pins, access control, etc.) is outside. |
Note that only cancelling an API call and handling an API call timeout should be generic enough to be part of device.h. For the transaction, I think its place is above all the other specific API it is providing a service for. |
I don't think so. transactions are not that generic. Not sure which APIs would use it except for i2c and spi. ipm? can? |
Well, I think it's worth considering it. Maybe CAN (CC @alexanderwachter) maybe I2S? |
ADC, flash, fs, display, LED, even GPIO. A transaction manager has relevance in these circumstances:
The data required for and behavior of transactions will be specific to an API, or even a use case, but a manager can be a generic solution with wide application. |
|
For CAN, I already started to pull out common functions from the drivers and put them into zephyr/drivers/can/can_common.c.
It would be great if we could share some of the common functions. |
|
@tbursztyka @nordic-krch @pabigot @alexanderwachter |
|
regarding:
I'm not sure if you already have idea how to do that but i came with following proposal: #22409 Short summary:
|
This PR is created to focus on API review. It is extracted from #21641 which contains reference implementation on nRF SPIM peripheral.
A draft of SPI API extension. Following API introduces:
spi_single_transfer()- asynchronous raw spi transferspi_configure()- spi configurationspi_schedule()spi_cancel()spi_resume()Note that:
qop_mngris queued operation manager. A module which will be responsible for managing execution of asynchronous operations which are requested by multiple asynchronous users.async_clientis a generic asynchronous client seestruct onoff_clientininclude/sys/onoff.hAdding this extension brings following improvements:
Signed-off-by: Krzysztof Chruscinski krzysztof.chruscinski@nordicsemi.no