Skip to content

Update Runtime.Native #3028

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 1 commit into from
Oct 10, 2024
Merged

Conversation

josesimoes
Copy link
Member

@josesimoes josesimoes commented Oct 10, 2024

Description

  • Add implementation for RebootDevice overload with parameter for reboot option.
  • Update native.runtime assembly declaration.
  • Change declaration of ExecutionEngine::Reboot to accept reboot option instead of just hard reset parameter.
  • Update implementation of ExecutionEngine::Reboot to deal with reboot option.

Motivation and Context

How Has This Been Tested?

  • At several real boards.

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).

CC @gligorov

Summary by CodeRabbit

  • New Features

    • Enhanced reboot functionality with more granular control through new reboot options.
    • Introduced a new enumeration for reboot options, providing clarity on available reboot types.
  • Bug Fixes

    • Improved logic in the reboot method for better handling of reboot conditions.
  • Documentation

    • Added comments to maintain synchronization between managed code components.
  • Version Updates

    • Updated assembly version to reflect new changes and improvements.

- Add implementation for RebootDevice overload with parameter for reboot option.
- Update native.runtime assembly declaration.
- Change declaration of ExecutionEngine::Reboot to accept reboot option instead of just hard reset parameter.
- Update implementation of ExecutionEngine::Reboot to deal with reboot option.
@nfbot nfbot added Type: enhancement Area: Config-and-Build Type: dependencies Pull requests that update a dependency file(s) or version labels Oct 10, 2024
@josesimoes josesimoes added Area: Common libs Everything related with common libraries hacktoberfest-accepted labels Oct 10, 2024
Copy link

coderabbitai bot commented Oct 10, 2024

Walkthrough

The pull request introduces significant modifications to the Reboot method within the CLR_RT_ExecutionEngine class, changing its signature from a boolean parameter to a uint16_t parameter for more detailed reboot options. This change is reflected across multiple files, including updates to related method signatures and the addition of a new enumeration for reboot options. The changes enhance the reboot functionality by allowing specific reboot behaviors based on the flags set in the new parameter.

Changes

File Path Change Summary
src/CLR/Core/Execution.cpp Updated Reboot method signature from bool fHard to uint16_t rebootOptions. Logic restructured for reboot behavior based on flags.
src/CLR/Include/nanoCLR_Debugging.h Added comment for synchronization with nanoFramework.Runtime.Native.WireProtocol.RebootOption.
src/CLR/Include/nanoCLR_Runtime.h Updated Reboot method signature from static void Reboot(bool fHard); to static void Reboot(uint16_t rebootOptions);.
src/nanoFramework.Runtime.Native/nf_rt_native.cpp Updated NativeReboot method signature to accept nanoFrameworkRuntimeNativeRebootOption. Changed assembly version identifiers.
src/nanoFramework.Runtime.Native/nf_rt_native.h Added new RebootOption enum with four options and updated NativeReboot method signature.
src/nanoFramework.Runtime.Native/nf_rt_native_nanoFramework_Runtime_Native_Power.cpp Updated NativeReboot method to accept reboot options and simplified method structure.

Possibly related PRs

Suggested labels

Platform: STM32, Platform: ESP32

Suggested reviewers

  • josesimoes

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: 1

🧹 Outside diff range and nitpick comments (4)
src/nanoFramework.Runtime.Native/nf_rt_native.cpp (2)

45-45: LGTM: Updated assembly version identifier.

The change in the version identifier from 0x109F6F22 to 0x0EAE898B is consistent with the assembly update.

Please ensure that any documentation or dependent components referencing this version identifier are also updated accordingly.


47-47: LGTM: Incremented assembly version number.

The version number update from { 100, 0, 9, 0 } to { 100, 0, 10, 0 } correctly reflects a minor version bump.

Please ensure that the changelog or release notes are updated to reflect this version increment and the new features added in this release.

src/nanoFramework.Runtime.Native/nf_rt_native.h (1)

13-19: LGTM! Consider adding a documentation comment.

The new RebootOption enum is well-defined and aligns with the PR objectives. The use of power-of-2 values (except for 0) is a good practice, allowing for potential bitwise operations in the future.

Consider adding a brief documentation comment above the enum to explain its purpose and usage. For example:

/// @brief Defines the available reboot options for the system.
/// These options can be used with the NativeReboot method to specify the desired reboot behavior.
typedef enum __nfpack RebootOption
{
    // ... (enum members)
} RebootOption;
src/CLR/Core/Execution.cpp (1)

301-312: Consider handling multiple reboot options when multiple flags are set

Currently, the if-else if structure means that if both c_EnterNanoBooter and c_EnterProprietaryBooter flags are set in rebootOptions, only the first condition will be executed, and the second one will be ignored. If the intended behavior is to allow handling multiple reboot options simultaneously, consider using separate if statements to check each flag independently.

Apply this diff to handle multiple reboot options:

-if (CLR_DBG_Commands::Monitor_Reboot::c_EnterNanoBooter ==
-    (rebootOptions & CLR_DBG_Commands::Monitor_Reboot::c_EnterNanoBooter))
+if (rebootOptions & CLR_DBG_Commands::Monitor_Reboot::c_EnterNanoBooter)
 {
     RequestToLaunchNanoBooter(0);
 }
-else if (
-    CLR_DBG_Commands::Monitor_Reboot::c_EnterProprietaryBooter ==
-    (rebootOptions & CLR_DBG_Commands::Monitor_Reboot::c_EnterProprietaryBooter))
+if (rebootOptions & CLR_DBG_Commands::Monitor_Reboot::c_EnterProprietaryBooter)
 {
     RequestToLaunchProprietaryBootloader();
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c224f7d and d163a7b.

📒 Files selected for processing (6)
  • src/CLR/Core/Execution.cpp (1 hunks)
  • src/CLR/Include/nanoCLR_Debugging.h (1 hunks)
  • src/CLR/Include/nanoCLR_Runtime.h (1 hunks)
  • src/nanoFramework.Runtime.Native/nf_rt_native.cpp (2 hunks)
  • src/nanoFramework.Runtime.Native/nf_rt_native.h (2 hunks)
  • src/nanoFramework.Runtime.Native/nf_rt_native_nanoFramework_Runtime_Native_Power.cpp (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/CLR/Include/nanoCLR_Debugging.h
🧰 Additional context used
🔇 Additional comments (7)
src/nanoFramework.Runtime.Native/nf_rt_native_nanoFramework_Runtime_Native_Power.cpp (2)

9-10: Function signature updated to include reboot option

The function signature has been correctly updated to include the nanoFrameworkRuntimeNativeRebootOption parameter. This change aligns with the PR objectives and allows for more flexible reboot behavior.


14-14: Reboot option retrieval and usage implemented correctly

The reboot option is properly retrieved from the stack argument and used in the Reboot call. This implementation allows for different reboot behaviors based on the provided option, enhancing the functionality as intended.

To ensure the RebootOption enum is correctly defined and the Reboot method signature has been updated accordingly, run the following script:

Also applies to: 16-16

src/nanoFramework.Runtime.Native/nf_rt_native.cpp (1)

22-22: LGTM: Updated NativeReboot method signature.

The change to include nanoFrameworkRuntimeNativeRebootOption as a parameter aligns with the PR objectives and enhances the reboot functionality.

Let's verify the consistency of this change across the codebase:

✅ Verification successful

Verified: NativeReboot method signature is consistently updated across the codebase.
All instances of NativeReboot have been correctly modified to include the nanoFrameworkRuntimeNativeRebootOption parameter, ensuring consistency and enhancing reboot functionality.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the consistency of the NativeReboot method signature change.

# Test: Search for NativeReboot method declarations/definitions
rg --type cpp -A 5 $'NativeReboot'

Length of output: 1710

src/nanoFramework.Runtime.Native/nf_rt_native.h (1)

Line range hint 1-85: Summary: Enhancements to reboot functionality

The changes in this file successfully implement the new reboot options as described in the PR objectives. The addition of the RebootOption enum and the update to the NativeReboot method signature provide a more flexible and detailed control over the reboot process.

These changes lay the groundwork for implementing the enhanced reboot functionality in the rest of the codebase. Ensure that these new options are properly utilized in the implementation files and that appropriate documentation is added to guide developers on using these new reboot options.

src/CLR/Include/nanoCLR_Runtime.h (1)

3691-3691: Approved: Function signature updated to support multiple reboot options.

The Reboot function signature has been updated to accept a uint16_t rebootOptions parameter, which aligns with the PR objective of enhancing the RebootDevice method to include a reboot option parameter. This change allows for more granular control over the reboot process.

Please ensure that the implementation of this function correctly handles the new rebootOptions parameter. You may want to add a comment explaining the possible values for rebootOptions and their meanings.

src/CLR/Core/Execution.cpp (2)

314-315: Confirm that m_iReboot_Options is correctly utilized elsewhere

The rebootOptions are stored in g_CLR_RT_ExecutionEngine.m_iReboot_Options, which implies they are used in subsequent processing. Ensure that m_iReboot_Options is appropriately utilized later in the execution flow to apply the specified reboot options.

Run the following script to verify the usage of m_iReboot_Options:

#!/bin/bash
# Description: Verify that `m_iReboot_Options` is used after being set.

# Search for references to `m_iReboot_Options` outside of its assignment.
rg --type cpp 'm_iReboot_Options' -A 5 | grep -v 'g_CLR_RT_ExecutionEngine\.m_iReboot_Options = rebootOptions;'

297-297: Verify that all calls to Reboot method are updated to the new signature

The Reboot method signature has changed from accepting a bool parameter to a uint16_t parameter rebootOptions. Ensure that all calls to CLR_RT_ExecutionEngine::Reboot throughout the codebase are updated to match the new signature to prevent potential compile-time or runtime errors.

Run the following script to find any calls to Reboot that may still be using the old bool parameter:

@josesimoes josesimoes merged commit 57d477b into nanoframework:main Oct 10, 2024
29 checks passed
@josesimoes josesimoes deleted the update-native-runtime branch October 10, 2024 02:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Common libs Everything related with common libraries Area: Config-and-Build hacktoberfest-accepted Type: dependencies Pull requests that update a dependency file(s) or version Type: enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants