Skip to content

Add reboot option to RebootDevice API #140

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions nanoFramework.Runtime.Native/Power.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,26 @@ public class Power
/// Occurs before the device reboots.
/// </summary>
/// <remarks>
/// The event handlers may have an execution constraint placed on them by the caller of the <see cref="RebootDevice()"/> method.
/// The event handlers may have an execution constraint placed on them by the caller of the <see cref="RebootDevice(RebootOption)"/> method.
/// Therefore, it is recommended that the event handlers perform short, atomic operations.
/// </remarks>
public static event RebootEventHandler OnRebootEvent;

/// <summary>
/// Forces a reboot of the device.
/// Forces a reboot of the device using the optional <paramref name="rebootOption"/> parameter.
/// </summary>
/// <remarks>
/// <para>
/// This method raises the <see cref="OnRebootEvent"/>. If there are any handlers subscribing to <see cref="OnRebootEvent"/>, the reboot will occur only after all handlers complete their execution, regardless of the time taken.
/// To set a timeout for the handlers to complete, use the <see cref="RebootDevice(int)"/> method and specify an execution constraint.
/// To set a timeout for the handlers to complete, use the <see cref="RebootDevice(int, RebootOption)"/> method and specify an execution constraint.
/// </para>
/// <para>
/// If the rebootOptions parameter is set to an option other than <see cref="RebootOption.ClrOnly"/>, any ongoing debug session will be terminated.
/// </para>
/// </remarks>
public static void RebootDevice()
{
RebootDevice(-1);
}
public static void RebootDevice(RebootOption rebootOption = RebootOption.NormalReboot) => RebootDevice(
-1,
rebootOption);

/// <summary>
/// Forces a reboot of the device with an execution constraint timeout for event handlers.
Expand All @@ -46,7 +50,10 @@ public static void RebootDevice()
/// The execution constraint timeout, in milliseconds, for the event handlers to complete.
/// If the event handlers take longer than the allotted time, they will be aborted and the reboot will be executed.
/// </param>
public static void RebootDevice(int exeConstraintTimeout)
/// <param name="rebootOption">The reboot options. </param>
public static void RebootDevice(
int exeConstraintTimeout,
RebootOption rebootOption = RebootOption.NormalReboot)
{
try
{
Expand All @@ -59,14 +66,14 @@ public static void RebootDevice(int exeConstraintTimeout)
}
finally
{
NativeReboot();
NativeReboot(rebootOption);
}
}

#region external methods declarations

[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void NativeReboot();
internal static extern void NativeReboot(RebootOption rebootOption);

#endregion
}
Expand Down
2 changes: 1 addition & 1 deletion nanoFramework.Runtime.Native/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

////////////////////////////////////////////////////////////////
// update this whenever the native assembly signature changes //
[assembly: AssemblyNativeVersion("100.0.9.0")]
[assembly: AssemblyNativeVersion("100.0.10.0")]
////////////////////////////////////////////////////////////////

// Setting ComVisible to false makes the types in this assembly not visible
Expand Down
41 changes: 41 additions & 0 deletions nanoFramework.Runtime.Native/RebootOption.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace nanoFramework.Runtime.Native
{
///////////////////////////////////////////////////////////////////////////////////////
// !!! KEEP IN SYNC WITH nanoFramework.Tools.Debugger.WireProtocol.RebootOptions !!! //
///////////////////////////////////////////////////////////////////////////////////////

/// <summary>
/// Specifies the reboot options for a .NET nanoFramework device.
/// </summary>
public enum RebootOption
{
/// <summary>
/// Perform a normal reboot of the CPU. This is an hard reset.
/// </summary>
#pragma warning disable S2346 // Need this to be 0 because of native implementation
NormalReboot = 0,
#pragma warning restore S2346 // Flags enumerations zero-value members should be named "None"

/// <summary>
/// Reboot and enter the nanoBooter.
/// </summary>
EnterNanoBooter = 1,

/// <summary>
/// Reboot the Common Language Runtime (CLR) only.
/// </summary>
ClrOnly = 2,

//////////////////////////////
// can't use option value 4 //
//////////////////////////////

/// <summary>
/// Reboot and enter the proprietary bootloader.
/// </summary>
EnterProprietaryBooter = 8,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
<ProjectGuid>4C4AA37C-19D9-4C41-ADD0-BA83A0E593DA</ProjectGuid>
<OutputType>Library</OutputType>
<FileAlignment>512</FileAlignment>
<RootNamespace></RootNamespace>
<RootNamespace>
</RootNamespace>
<AssemblyName>nanoFramework.Runtime.Native</AssemblyName>
<TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
<NF_IsCoreLibrary>True</NF_IsCoreLibrary>
Expand Down Expand Up @@ -42,6 +43,7 @@
</ItemGroup>
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.props')" />
<ItemGroup>
<Compile Include="RebootOption.cs" />
<Compile Include="Power.cs" />
<Compile Include="GC.cs" />
<Compile Include="SystemInfo.cs" />
Expand Down
4 changes: 2 additions & 2 deletions version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "1.6",
"version": "1.7",
"assemblyVersion": {
"precision": "build"
},
Expand Down