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

Add SpiBus, SpiDevice implementations #181

Draft
wants to merge 9 commits into
base: lpspi-refactor
Choose a base branch
from

Conversation

mciantyre
Copy link
Member

We implement all I/O in terms of transact. We'll manually flush at the
end of eh02 SPI writes. Since the SpiBus interface exposes a flush, we
have no need to perform an internal flush when transacting I/O.

Keep the spinning async state machines to manage the TX and FX FIFOs.
We introduce a schedule to eagerly execute transmit operations ahead of
receive operations. Without this ability, we'll stall the LPSPI bus.
(The NOSTALL field can change this behavior, but then we move complexity
into TX FIFO underrun handling.) There's some miri tests to simulate our
hardware utilization.

Our SpiDevice impls mimic the embedded-bus design. There's an
"exclusive" device that owns the bus and uses a hardware chip select.
There's a RefCellDevice that lets users share the bus and use hardware
chip selects. There's no critical section / mutex device, but it should
be straightforward to add that later.

Part of #142.

mciantyre and others added 9 commits December 1, 2024 12:03
We're testing unsafe code in the HAL. Make sure miri is happy with that
unsafe code.

We build with minimal optimizations by default, no matter the target.
Turn those off during the miri invocation.
When we support the embedded-hal 1.0 traits, we should distinguish
between the bus -- having the data and clock pins -- and the device(s),
which have the chip select. Removing the chip select type state is the
first step in supporting this interface.

Temporarily enable PCS0 in the board setup routines. This keeps the
examples working as expected.
We'll need something like this when we implement SPI devices.
This'll make it easier to associate bus state with each transaction.
Default behavior is unchanged, in that the mode is still set by the
user's `Lpspi::set_mode` value. But now users could define it as part
of a one-off transaction.
On the RT1180, these two fields are WO/RAZ. Since we can't trust the
hardware to retrieve these values for us, we cache them in memory.
Writes will behave as before. The driver ensures that all accesses on
CCR pass through the cache.
We implement all I/O in terms of `transact`. We'll manually flush at the
end of eh02 SPI writes. Since the `SpiBus` interface exposes a flush, we
have no need to perform an internal flush when transacting I/O.

Keep the spinning async state machines to manage the TX and FX FIFOs.
We introduce a schedule to eagerly execute transmit operations ahead of
receive operations. Without this ability, we'll stall the LPSPI bus.
(The NOSTALL field can change this behavior, but then we move complexity
into TX FIFO underrun handling.) There's some miri tests to simulate our
hardware utilization.

Our `SpiDevice` impls mimic the embedded-bus design. There's an
"exclusive" device that owns the bus and uses a hardware chip select.
There's a `RefCellDevice` that lets users share the bus and use hardware
chip selects. There's no critical section / mutex device, but it should
be straightforward to add that later.
@Finomnis
Copy link
Contributor

Thanks for working on this, I wasn't able to continue my work due to personal things, sorry :) glad to see you are still motivated <3

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.

2 participants