Skip to content

Add enums to the OpenBIOS SIO module and basic cleanup #1920

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

Merged
merged 5 commits into from
Apr 15, 2025

Conversation

NotExactlySiev
Copy link
Contributor

I copy pasted the enums from Psyqo. Tested it on Duckstation and it seems to be working fine.

Copy link
Contributor

coderabbitai bot commented Apr 10, 2025

Walkthrough

The changes remove the legacy SIO interface and its associated files while introducing a new SIO header with a refined interface. In detail, the old struct SIO and its macro in hwregs.h, along with the sio1.c and sio1.h files, have been deleted. A new header (sio.h) now defines a SIOPort structure, updated enumerations, and an inline function (exchangeByte) to manage SIO operations. Additionally, references to the deprecated files have been removed from the build system, and related driver files have been refactored to use the new constants and function.

Changes

File(s) Change Summary
src/mips/common/hardware/hwregs.h, src/mips/common/hardware/sio1.c, src/mips/common/hardware/sio1.h Removed legacy SIO interface definitions, including the struct SIO, associated macro, and SIO1 initialization and transmission functions/declarations.
src/mips/common/hardware/sio.h Introduced a new SIO interface with the SIOPort structure, a new SIOS macro, enumerations for control and status flags, and a static inline function exchangeByte for SIO data exchange.
src/mips/openbios/Makefile Removed the reference to the deprecated sio1.c file from the build sources.
src/mips/openbios/sio0/card.c Refactored SIO operations by replacing direct hardware register manipulation with calls to exchangeByte and using defined SIO control/status constants, streamlining the handling of serial communications.
src/mips/openbios/sio0/driver.c Updated control register assignments by replacing hardcoded values with defined SIO control and status constants, enhancing clarity in hardware communication operations.

Sequence Diagram(s)

sequenceDiagram
    participant App as Application (card.c/driver.c)
    participant Ex as exchangeByte
    participant SIO as SIO Hardware (SIOPort)

    App->>Ex: Call exchangeByte(byte)
    Ex->>SIO: Read current FIFO value
    Ex->>SIO: Write new byte to FIFO
    Ex-->>App: Return exchanged byte
Loading

Poem

In a burrow of code, I hopped around,
Bidding farewell to old structures once found.
With fresh fields and flags so bright,
My inline hops made everything light.
Code now sings in a new array—happy bugs, I'll never stay!
🐇💻


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0e6eda7 and b8a9080.

📒 Files selected for processing (7)
  • src/mips/common/hardware/hwregs.h (0 hunks)
  • src/mips/common/hardware/sio.h (1 hunks)
  • src/mips/common/hardware/sio1.c (0 hunks)
  • src/mips/common/hardware/sio1.h (0 hunks)
  • src/mips/openbios/Makefile (0 hunks)
  • src/mips/openbios/sio0/card.c (7 hunks)
  • src/mips/openbios/sio0/driver.c (10 hunks)
💤 Files with no reviewable changes (4)
  • src/mips/openbios/Makefile
  • src/mips/common/hardware/sio1.c
  • src/mips/common/hardware/sio1.h
  • src/mips/common/hardware/hwregs.h
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/mips/openbios/sio0/card.c (1)
src/mips/common/hardware/sio.h (1)
  • exchangeByte (73-73)
⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: pcsx-redux (x86_64-linux)
  • GitHub Check: pcsx-redux (aarch64-linux)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: build
  • GitHub Check: macos-build-and-test-toolchain
  • GitHub Check: cross-arm64
  • GitHub Check: coverage
  • GitHub Check: aur-build
  • GitHub Check: asan
  • GitHub Check: build-openbios
  • GitHub Check: toolchain
🔇 Additional comments (20)
src/mips/openbios/sio0/card.c (6)

33-33: Good addition of the new SIO header

Including the new SIO header is essential for accessing the new SIOPort structure and constants.


99-102: Good use of SIO constants to improve readability

Replacing hardcoded values with named constants (SIO_CTRL_PORTSEL, SIO_CTRL_TXEN, SIO_CTRL_ACKIRQEN, SIO_CTRL_DTR) makes the code more readable and maintainable.


103-161: Excellent refactoring with exchangeByte

The replacement of direct FIFO manipulations with calls to the exchangeByte function significantly improves code readability and maintainability. This change also centralizes the error reset and interrupt clearing logic, reducing the chance of inconsistencies.


179-181: Consistent use of enumeration constants

The consistent use of SIO_CTRL_* constants throughout both handler functions demonstrates good coding practice for hardware register manipulation.

Also applies to: 262-262


161-161: Improved readability with SIO_STAT_RXRDY

Replacing raw bit masks with the SIO_STAT_RXRDY enum constant makes the code more self-documenting and easier to maintain.

Also applies to: 228-228


280-280: Appropriate use of SIO_CTRL_ERRRES

Using SIO_CTRL_ERRRES instead of a hardcoded value for error reset improves code readability.

src/mips/openbios/sio0/driver.c (8)

29-29: Good inclusion of the new SIO header

Adding the SIO header provides access to the new SIOPort structure, constants, and utility functions.


99-99: Improved readability with SIO constants

Replacing hardcoded bit values with SIO_CTRL_DTR and SIO_CTRL_PORTSEL makes the control register manipulation more understandable.


109-110: Better mask expression using SIO constants

Using SIO_CTRL_PORTSEL for the mask and SIO_CTRL_DTR for the control register makes the code's intent clearer.


116-117: Enhanced control register setup with constants

Using bit flag constants for the control register setup and status check improves code readability and maintainability.


121-123: Consistent error handling and status checking

The consistent use of SIO_CTRL_ERRRES for error reset and SIO_STAT_RXRDY/SIO_STAT_TXRDY for status checks throughout the file makes the code more uniform and easier to maintain.

Also applies to: 137-140, 157-160, 180-187, 205-208


255-255: Improved mcHandler control register manipulation

Using the SIO constants for the control register in mcHandler enhances code readability.


319-321: Better SIO initialization in firstStageCardAction

Using SIO_CTRL_IR and calculating the baud rate rather than using magic numbers improves maintainability.


381-389: Cleaner SIO initialization in setupSIO0

The use of SIO constants for control register manipulation in setupSIO0 makes the initialization process more readable and maintainable.

src/mips/common/hardware/sio.h (6)

1-31: Well-structured header with proper licensing

The header includes the necessary MIT license and appropriate includes.


32-42: Good SIOPort structure definition

The SIOPort structure properly defines the memory layout for the serial port registers, which is essential for hardware interaction.


43-43: Appropriate use of volatile for hardware registers

The SIOS macro correctly uses volatile for accessing memory-mapped hardware registers, which is necessary to prevent compiler optimizations from affecting hardware interactions.


45-58: Excellent control register flag definitions

The enumeration for control register flags with descriptive comments greatly improves code readability and maintainability. Each flag's purpose is clearly documented.


60-71: Well-documented status register flags

The status register flag enumeration with clear comments makes it easy to understand the different status conditions that can be checked.


73-79: Efficient exchangeByte implementation

The inline exchangeByte function efficiently encapsulates the common pattern of reading from and writing to the SIO FIFO, while handling error reset and interrupt clearing. The always_inline attribute ensures optimal performance for this frequently called function.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@nicolasnoble nicolasnoble requested a review from Copilot April 10, 2025 23:48
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 6 out of 7 changed files in this pull request and generated no comments.

Files not reviewed (1)
  • src/mips/openbios/Makefile: Language not supported
Comments suppressed due to low confidence (2)

src/mips/openbios/sio0/driver.c:101

  • [nitpick] The busyloop delay values (e.g., 10, 20, 40) are used as magic numbers; consider defining named constants to improve readability and maintainability.
busyloop(10);

src/mips/openbios/sio0/card.c:110

  • [nitpick] Consider removing or revising the informal comment ('durr?') to provide a clearer, more professional explanation of the rationale behind resetting g_skipErrorOnNewCard.
g_skipErrorOnNewCard = 0;  // durr?

@nicolasnoble nicolasnoble enabled auto-merge April 15, 2025 03:55
@nicolasnoble nicolasnoble merged commit 34ea4f1 into grumpycoders:main Apr 15, 2025
21 of 22 checks passed
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