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

gimlet_seq: separate error type for read_fpga_regs #1600

Closed
wants to merge 2 commits into from

Conversation

hawkw
Copy link
Member

@hawkw hawkw commented Jan 27, 2024

Inspired by this comment from @cbiffle.

Currently, the Gimlet Sequencer API has one error enum that's returned
by all API methods. This enum contains a bunch of error variants that
are specific to actually setting the sequencer state, and a
ReadRegsFailed variant that's returned by the read_fpga_regs API
method. This means that, currently, calls to set the sequencer state
have to handle the ReadRegsFailed variant, even though it's never
actually returned by the code that sets the sequencer state, and,
conversely, code that reads the FPGA registers has to handle a bunch of
error variants that aren't related to FPGA register reads.

This commit separates the error types of the read_fpga_regs and
set_state APIs into two separate enums that only contain the errors
returned by that API. I didn't touch the other API methods, although (as
far as I can tell), get_state, fans_on, and fans_off never
actually return any errors and could be changed to
core::convert::Infallible a la send_hardware_nmi. I didn't want to
mess with these, though, based on the assumption that the SeqError
error type was chosen to avoid having to change the API if these methods
changed to return errors. Let me know if that's not the case --- I'm
happy to change them as well.

Inspired by [this comment][1] from @cbiffle.

Currently, the Gimlet Sequencer API has one error enum that's returned
by all API methods. This enum contains a bunch of error variants that
are specific to actually setting the sequencer state, and a
`ReadRegsFailed` variant that's returned by the `read_fpga_regs` API
method. This means that, currently, calls to set the sequencer state
have to handle the `ReadRegsFailed` variant, even though it's never
actually returned by the code that sets the sequencer state, and,
conversely, code that reads the FPGA registers has to handle a bunch of
error variants that aren't related to FPGA register reads.

This commit separates the error types of the `read_fpga_regs` and
`set_state` APIs into two separate enums that only contain the errors
returned by that API. I didn't touch the other API methods, although (as
far as I can tell), `get_state`, `fans_on`, and `fans_off` never
actually return any errors and could be changed to
`core::convert::Infallible` a la `send_hardware_nmi`. I didn't want to
mess with these, though, based on the assumption that the `SeqError`
error type was chosen to avoid having to change the API if these methods
changed to return errors. Let me know if that's not the case --- I'm
happy to change them as well.

[1]: #1597 (comment)
@hawkw hawkw requested a review from cbiffle January 29, 2024 17:20
/// Errors returned by `read_fpga_regs`.
#[derive(Copy, Clone, Debug, FromPrimitive, Eq, PartialEq, IdolError)]
pub enum ReadFpgaRegsError {
Failed = 1,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe add a comment noting that this variant is probably illusory because of the SPI error API issue, with a TODO to revisit it.

Copy link
Member Author

Choose a reason for hiding this comment

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

will do!

hawkw added a commit that referenced this pull request Mar 25, 2024
Currently, the `gimlet_seq` IPC API has a bunch of IPCs that return
errors that aren't really necessary. The `SeqError` enum is returned by
all the sequencer's IPCs, but most of its variants are only ever
relevant to the `Sequencer::set_state` IPC. The
`Sequencer::read_fpga_regs` only ever returns a
`SeqError::ReadRegsFailed` error if the SPI driver returns an error, and
the other IPCs don't return errors at all.

This branch cleans this up a bit by removing all the error return values
from the IPC operations that don't return errors. Now that PR #1656 has
been merged, the `Spi::read` IPC now only errors if the SPI driver is
restarted or if the transfer is too large. Since
`Sequencer::read_fpga_regs` only does small reads, we can now unwrap
this and make that IPC infallible as well. And, since the
`Sequencer::read_fpga_regs` and `Sequencer::get_state` just read a value
and return it, I figured that we could make them idempotent, as well.
This makes the IPC interface much simpler and allows several callers of
it to avoid handling errors that aren't ever actually returned.

Closes #1600, which this obsoletes.
@hawkw hawkw closed this in #1681 Mar 29, 2024
hawkw added a commit that referenced this pull request Mar 29, 2024
Currently, the `gimlet_seq` IPC API has a bunch of IPCs that return
errors that aren't really necessary. The `SeqError` enum is returned by
all the sequencer's IPCs, but most of its variants are only ever
relevant to the `Sequencer::set_state` IPC. The
`Sequencer::read_fpga_regs` only ever returns a
`SeqError::ReadRegsFailed` error if the SPI driver returns an error, and
the other IPCs don't return errors at all.

This branch cleans this up a bit by removing all the error return values
from the IPC operations that don't return errors. Now that PR #1656 has
been merged, the `Spi::read` IPC now only errors if the SPI driver is
restarted or if the transfer is too large. Since
`Sequencer::read_fpga_regs` only does small reads, we can now unwrap
this and make that IPC infallible as well. And, since the
`Sequencer::read_fpga_regs` and `Sequencer::get_state` just read a value
and return it, I figured that we could make them idempotent, as well.
This makes the IPC interface much simpler and allows several callers of
it to avoid handling errors that aren't ever actually returned.

Closes #1600, which this obsoletes.
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