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

update hpmicro port files #274

Merged
merged 2 commits into from
Nov 18, 2024
Merged

Conversation

chenzhihong007
Copy link
Contributor

@chenzhihong007 chenzhihong007 commented Nov 18, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced USB video streaming functionality with a new video descriptor and initialization process.
    • Improved USB host controller initialization and interrupt handling.
    • Streamlined USB device handling with updated interrupt service routines.
  • Bug Fixes

    • Removed busy-wait loop in the remote wakeup function to improve responsiveness.
  • Documentation

    • Updated declarations for new and modified functions related to USB handling.

Copy link

coderabbitai bot commented Nov 18, 2024

Walkthrough

The changes in this pull request enhance USB functionality across three files. In video_static_h264_template.c, a new USB video descriptor and initialization function are introduced, along with updates to existing functions for better state management during video streaming. The usb_glue_hpm.c file sees improvements in USB host controller initialization, including a new configuration option and adjustments to the USB PHY initialization process. Lastly, usb_dc_hpm.c adds new interrupt service routine declarations for USB interrupts and simplifies the usbd_set_remote_wakeup function by removing a busy-wait loop.

Changes

File Path Change Summary
demo/video_static_h264_template.c - Added function: void video_init(uint8_t busid, uintptr_t reg_base)
- Updated signatures for usbd_video_open, usbd_video_close, usbd_video_iso_callback (no parameter changes)
- Added variables: struct usbd_interface intf0, struct usbd_interface intf1
port/ehci/usb_glue_hpm.c - Added configuration option: CONFIG_USB_HOST_FORCE_FULL_SPEED
- Updated function signature: void usb_phy_init(USB_Type *ptr) to void usb_phy_init(USB_Type *ptr, bool param)
- Updated ISR declarations for IRQn_USB0 and IRQn_USB1 to follow ISR definitions
port/hpm/usb_dc_hpm.c - Added ISR declarations: void isr_usbd0(void) and void isr_usbd1(void)
- Removed previous ISR declarations for IRQn_USB0 and IRQn_USB1
- Modified usbd_set_remote_wakeup to eliminate busy-wait loop

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant USB_Device
    participant USB_Host_Controller

    User->>USB_Device: Connect
    USB_Device->>USB_Host_Controller: Initialize
    USB_Host_Controller->>USB_Device: Set Configuration
    USB_Device->>USB_Host_Controller: Register Video Descriptor
    USB_Host_Controller->>USB_Device: Start Video Streaming
    USB_Device->>User: Stream Video Data
Loading

🐇 "In the code, we hop and play,
New descriptors lead the way.
USB streams with joy abound,
As data flows, the bytes are found.
With every change, we leap and cheer,
For smoother connections, far and near!" 🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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 resolve resolve all the CodeRabbit review comments.
  • @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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
port/ehci/usb_glue_hpm.c (1)

94-105: LGTM! Consider adding error handling

The ISR declarations and implementations look good. The code properly handles both USB0 and USB1 interrupts with correct bus ID mapping.

Consider adding error logging in the ISRs to catch potential invalid bus IDs:

 void isr_usbh0(void)
 {
+    if (_hcd_busid[0] >= CONFIG_USBHOST_MAX_BUS) {
+        // Log error or handle invalid bus ID
+        return;
+    }
     USBH_IRQHandler(_hcd_busid[0]);
 }
port/hpm/usb_dc_hpm.c (1)

Line range hint 315-359: Consider enhancing error handling in the interrupt handler.

The interrupt handler could benefit from more detailed error reporting and recovery mechanisms:

  1. The error case only logs "usbd intr error" without specific details
  2. Transfer errors could include more diagnostic information

Consider enhancing the error handling:

 if (int_status & intr_error) {
-    USB_LOG_ERR("usbd intr error!\r\n");
+    USB_LOG_ERR("USB error: status=0x%08x\r\n", usb_device_get_error_status(handle));
+    usb_device_clear_error_status(handle);
 }
 if (p_qtd->halted || p_qtd->xact_err || p_qtd->buffer_err) {
-    USB_LOG_ERR("usbd transfer error!\r\n");
+    USB_LOG_ERR("Transfer error: ep=%02x halt=%d xact=%d buf=%d\r\n",
+                ep_idx, p_qtd->halted, p_qtd->xact_err, p_qtd->buffer_err);
     ep_cb_req = false;
     break;
 }
🧰 Tools
🪛 cppcheck

[error] 363-363: There is an unknown macro here somewhere. Configuration is required. If SDK_DECLARE_EXT_ISR_M is a macro then please configure it.

(unknownMacro)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 6517919 and b8fcc86.

📒 Files selected for processing (3)
  • demo/video_static_h264_template.c (0 hunks)
  • port/ehci/usb_glue_hpm.c (3 hunks)
  • port/hpm/usb_dc_hpm.c (1 hunks)
💤 Files with no reviewable changes (1)
  • demo/video_static_h264_template.c
🧰 Additional context used
🪛 cppcheck
port/hpm/usb_dc_hpm.c

[error] 363-363: There is an unknown macro here somewhere. Configuration is required. If SDK_DECLARE_EXT_ISR_M is a macro then please configure it.

(unknownMacro)

🔇 Additional comments (4)
port/ehci/usb_glue_hpm.c (2)

61-61: Document the purpose of the new boolean parameter

The usb_phy_init function now takes an additional boolean parameter set to true, but its purpose is unclear. This change could affect USB hardware initialization.

Please:

  1. Document the purpose of this parameter
  2. Verify if this change affects both host and device modes
  3. Consider adding an enum instead of a boolean for better code clarity if there are multiple initialization modes
#!/bin/bash
# Search for other usb_phy_init calls to ensure consistent usage
ast-grep --pattern 'usb_phy_init($_, $_)'

38-41: Verify implications of forcing full-speed mode

The addition of CONFIG_USB_HOST_FORCE_FULL_SPEED to force USB full-speed mode could impact device compatibility and performance. While the implementation is correct, this change needs careful consideration.

Consider:

  1. Adding documentation explaining when to use this option
  2. Verifying that dependent devices support full-speed mode
  3. Adding a warning log when this mode is enabled
✅ Verification successful

Based on the search results, I can now provide a final response:

Force full-speed mode option is correctly implemented with appropriate hardware support

The implementation of CONFIG_USB_HOST_FORCE_FULL_SPEED is valid and well-supported by the hardware. The codebase shows:

  1. The HPM EHCI controller has proper hardware support via USB_PORTSC1_PFSC_MASK register bit
  2. The speed forcing is consistent with other USB controllers in the codebase that support similar functionality
  3. The implementation follows standard USB speed negotiation patterns seen across other ports

The code change is safe to use when full-speed mode is specifically required, though it should be noted that this will prevent high-speed operation even if both host and device support it.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any device-specific speed requirements or dependencies
rg -l "USB_SPEED_(HIGH|FULL)" --type c

Length of output: 43


Script:

#!/bin/bash
# Search for USB speed related constants and configurations
rg -i "speed.*usb|usb.*speed" --type c -A 2

# Look for USB related configuration options
fd -e Kconfig -X cat

Length of output: 60444

port/hpm/usb_dc_hpm.c (2)

Line range hint 89-100: LGTM! Improved remote wakeup implementation.

The removal of the busy-wait loop and addition of suspend state verification makes the implementation more robust and non-blocking.

🧰 Tools
🪛 cppcheck

[error] 363-363: There is an unknown macro here somewhere. Configuration is required. If SDK_DECLARE_EXT_ISR_M is a macro then please configure it.

(unknownMacro)


363-375: Verify interrupt handler registration with the SDK.

The ISR declarations look correct, but please ensure:

  1. The SDK_DECLARE_EXT_ISR_M macro is properly defined in the SDK headers
  2. The interrupt priorities are appropriate for USB handling
✅ Verification successful

Let me gather more information about the SDK macro definition and interrupt handling setup.


Let me check for any USB initialization code in the HPM port to see how the interrupts are configured.


Based on the gathered information, I can now provide the final response:

ISR declarations are correctly implemented and integrated with the HPM SDK

The implementation is verified to be correct because:

  • The SDK_DECLARE_EXT_ISR_M macro is consistently used across both USB device (usb_dc_hpm.c) and host (usb_glue_hpm.c) implementations
  • Interrupt initialization is properly handled in usb_dc_init() with:
    • Correct IRQ number assignment based on USB controller (IRQn_USB0/1)
    • Proper interrupt mask configuration
    • Explicit interrupt enabling via intc_m_enable_irq()
  • USB1 support is correctly guarded with HPM_USB1_BASE conditional compilation
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify SDK interrupt handler macro definition and usage

# Check for SDK interrupt handler macro definition
rg -l "SDK_DECLARE_EXT_ISR_M" --type c --type h

# Check for other USB ISR declarations to ensure consistency
rg "SDK_DECLARE.*IRQn_USB[01]" --type c --type h

Length of output: 415


Script:

#!/bin/bash
# Check for SDK macro definition in SDK headers
fd -e h -e c | xargs rg -A 5 "SDK_DECLARE_EXT_ISR"

# Check USB interrupt priority setup
rg -B 5 "IRQn_USB[01].*priority" --type c --type h

# Look for related interrupt configuration
rg "NVIC.*USB" --type c --type h

Length of output: 1453


Script:

#!/bin/bash
# Look for USB initialization and interrupt setup in HPM files
rg -B 10 -A 10 "usb.*init|dcd.*init" port/hpm/

# Check for interrupt priority definitions
rg "IRQ.*PRIORITY.*USB" --type c --type h

# Look for any interrupt configuration in the HPM port
rg "intc.*config|interrupt.*config" port/hpm/

Length of output: 2621

🧰 Tools
🪛 cppcheck

[error] 363-363: There is an unknown macro here somewhere. Configuration is required. If SDK_DECLARE_EXT_ISR_M is a macro then please configure it.

(unknownMacro)

@sakumisu sakumisu merged commit 093a183 into cherry-embedded:master Nov 18, 2024
2 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