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

Fix UART config at OneWire init #3035

Merged
merged 1 commit into from
Nov 8, 2024

Conversation

josesimoes
Copy link
Member

@josesimoes josesimoes commented Nov 8, 2024

Description

  • UART config struct is not onlined anymore to set only the required elements.
  • Remove IRAM_ATTR attributes from OneWire API.

Motivation and Context

  • Need to address compiler warning (error) of element not set.
  • No need to keep those functions on RAM. Those were probably left from initial debugging and are only taking up RAM.

How Has This Been Tested?

Screenshots

Types of changes

  • Improvement (non-breaking change that improves a feature, code or algorithm)
  • Bug fix (non-breaking change which fixes an issue with code or algorithm)
  • New feature (non-breaking change which adds functionality to code)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Config and build (change in the configuration and build system, has no impact on code or features)
  • Dev Containers (changes related with Dev Containers, has no impact on code or features)
  • Dependencies/declarations (update dependencies or assembly declarations and changes associated, has no impact on code or features)
  • Documentation (changes or updates in the documentation, has no impact on code or features)

Checklist

  • My code follows the code style of this project (only if there are changes in source code).
  • My changes require an update to the documentation (there are changes that require the docs website to be updated).
  • I have updated the documentation accordingly (the changes require an update on the docs in this repo).
  • I have read the CONTRIBUTING document.
  • I have tested everything locally and all new and existing tests passed (only if there are changes in source code).

Summary by CodeRabbit

  • New Features
    • Improved initialization process for the OneWire driver, enhancing reliability.
  • Bug Fixes
    • Adjusted execution context for OneWire functions, potentially improving performance on ESP32 devices.
  • Refactor
    • Updated code style for UART configuration, maintaining functionality while enhancing readability.

@josesimoes josesimoes added the Platform: ESP32 Everything related specifically with ESP32 platform label Nov 8, 2024
Copy link

coderabbitai bot commented Nov 8, 2024

Walkthrough

The changes made in this pull request focus on the nf_dev_onewire_nanoFramework_Device_OneWire_OneWireHost.cpp file, specifically altering the oneWireStop and oneWireInit functions by removing the IRAM_ATTR attribute. This modification may influence the execution context on the ESP32 platform. Additionally, the initialization of the uart_config_t structure in oneWireInit has been updated to a step-by-step assignment style. Other functions related to the OneWire protocol remain unchanged, preserving their original logic and functionality.

Changes

File Path Change Summary
targets/ESP32/_nanoCLR/nanoFramework.Device.OneWire/nf_dev_onewire_nanoFramework_Device_OneWire_OneWireHost.cpp - Removed IRAM_ATTR from oneWireStop and oneWireInit method signatures.
- Changed uart_config_t initialization style in oneWireInit from aggregate to step-by-step assignment.
- No changes to oneWireTouchReset, oneWireTouchBit, oneWireTouchByte, oneWireFindFirst, and oneWireFindNext functions.

Suggested reviewers

  • Ellerbach

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c3300b1 and b742bd7.

📒 Files selected for processing (1)
  • targets/ESP32/_nanoCLR/nanoFramework.Device.OneWire/nf_dev_onewire_nanoFramework_Device_OneWire_OneWireHost.cpp (2 hunks)
🔇 Additional comments (3)
targets/ESP32/_nanoCLR/nanoFramework.Device.OneWire/nf_dev_onewire_nanoFramework_Device_OneWire_OneWireHost.cpp (3)

Line range hint 31-83: LGTM! Removing IRAM_ATTR is appropriate here

The initialization function doesn't need to be in IRAM as it's not called during critical sections or ISRs. This change helps optimize memory usage.


35-42: LGTM! Clear and explicit UART configuration

The field-by-field initialization:

  • Makes the configuration more explicit and easier to understand
  • Ensures all required fields are properly set
  • Follows ESP-IDF's recommended initialization pattern

Line range hint 22-29: Verify impact of removing IRAM_ATTR from oneWireStop

Since this function is registered as a soft reboot handler and might need to execute while flash is unavailable, removing IRAM_ATTR could potentially cause issues.

Let's check if other soft reboot handlers retain IRAM_ATTR:

✅ Verification successful

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

Removing IRAM_ATTR from oneWireStop is safe

The removal of IRAM_ATTR from oneWireStop is acceptable because:

  1. None of the other ESP32 cleanup/uninitialize handlers registered with HAL_AddSoftRebootHandler use IRAM_ATTR
  2. Other similar UART cleanup operations (like in System.IO.Ports) also call uart_driver_delete without IRAM_ATTR
  3. The uart_driver_delete operation is safe to execute from flash as it's not time-critical and doesn't need to run during flash operations
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other soft reboot handlers to verify IRAM_ATTR usage pattern
rg -l "HAL_AddSoftRebootHandler" | xargs rg "IRAM_ATTR.*\w+\s*\([^)]*\)\s*{" -B 5 -A 1

Length of output: 210


Script:

#!/bin/bash
# First, find files containing soft reboot handlers
rg -l "HAL_AddSoftRebootHandler"

Length of output: 1028


Script:

#!/bin/bash
# Then, let's look for IRAM_ATTR usage in ESP32 platform code
rg "IRAM_ATTR" "targets/ESP32"

Length of output: 620


Script:

#!/bin/bash
# Let's also check the implementation of HAL_AddSoftRebootHandler
rg -A 5 "HAL_AddSoftRebootHandler\(" 

Length of output: 8482


Script:

#!/bin/bash
# Look for the actual registration of oneWireStop as reboot handler
rg -B 5 -A 5 "HAL_AddSoftRebootHandler.*oneWireStop"

Length of output: 1494


Script:

#!/bin/bash
# Let's check the uninitialization handlers in ESP32 platform to see if they use IRAM_ATTR
rg -B 2 "void.*(?i:uninit|stop|cleanup|delete).*\{" "targets/ESP32" --type cpp

Length of output: 311


Script:

#!/bin/bash
# Check for any IRAM_ATTR usage in cleanup/stop functions
rg "IRAM_ATTR.*(?i:uninit|stop|cleanup|delete)" "targets/ESP32" --type cpp

Length of output: 74


Script:

#!/bin/bash
# Look for soft reboot implementation to understand the context
rg -A 10 "void.*HAL_EnterBooterMode" "targets/ESP32"

Length of output: 52


Script:

#!/bin/bash
# Let's look for the soft reboot implementation
rg -A 10 "void HAL_EnterBooterMode|void HAL_SoftReboot" "targets/ESP32"

Length of output: 71


Script:

#!/bin/bash
# Check how other cleanup handlers are implemented in ESP32
rg "void.*(?:Stop|Uninitialize|Cleanup).*\(" "targets/ESP32/_nanoCLR" -B 2

Length of output: 3607


Script:

#!/bin/bash
# Look for UART driver deletion patterns
rg "uart_driver_delete" "targets/ESP32" -B 5

Length of output: 2049


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.

- UART config struct is not onlined anymore to set only the required elements. (compiler warning of element not set)
- Remove IRAM_ATTR attributes from OneWire API. (no need for there, were left from initial debugging and are only taking up RAM)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform: ESP32 Everything related specifically with ESP32 platform Type: enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants