Skip to content

Commit 4cf4cf5

Browse files
committed
Add reboot option to RebootDevice API
- Add enum with reboot options. - Add new overloaded methods in Power class. - Update native method caller. - Bump version and AssemblyNativeVersion.
1 parent bbeda14 commit 4cf4cf5

File tree

5 files changed

+64
-14
lines changed

5 files changed

+64
-14
lines changed

nanoFramework.Runtime.Native/Power.cs

+17-10
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,26 @@ public class Power
2222
/// Occurs before the device reboots.
2323
/// </summary>
2424
/// <remarks>
25-
/// The event handlers may have an execution constraint placed on them by the caller of the <see cref="RebootDevice()"/> method.
25+
/// The event handlers may have an execution constraint placed on them by the caller of the <see cref="RebootDevice(RebootOption)"/> method.
2626
/// Therefore, it is recommended that the event handlers perform short, atomic operations.
2727
/// </remarks>
2828
public static event RebootEventHandler OnRebootEvent;
2929

3030
/// <summary>
31-
/// Forces a reboot of the device.
31+
/// Forces a reboot of the device using the optional <paramref name="rebootOption"/> parameter.
3232
/// </summary>
3333
/// <remarks>
34+
/// <para>
3435
/// 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.
35-
/// To set a timeout for the handlers to complete, use the <see cref="RebootDevice(int)"/> method and specify an execution constraint.
36+
/// To set a timeout for the handlers to complete, use the <see cref="RebootDevice(int, RebootOption)"/> method and specify an execution constraint.
37+
/// </para>
38+
/// <para>
39+
/// If the rebootOptions parameter is set to an option other than <see cref="RebootOption.ClrOnly"/>, any ongoing debug session will be terminated.
40+
/// </para>
3641
/// </remarks>
37-
public static void RebootDevice()
38-
{
39-
RebootDevice(-1);
40-
}
42+
public static void RebootDevice(RebootOption rebootOption = RebootOption.NormalReboot) => RebootDevice(
43+
-1,
44+
rebootOption);
4145

4246
/// <summary>
4347
/// Forces a reboot of the device with an execution constraint timeout for event handlers.
@@ -46,7 +50,10 @@ public static void RebootDevice()
4650
/// The execution constraint timeout, in milliseconds, for the event handlers to complete.
4751
/// If the event handlers take longer than the allotted time, they will be aborted and the reboot will be executed.
4852
/// </param>
49-
public static void RebootDevice(int exeConstraintTimeout)
53+
/// <param name="rebootOption">The reboot options. </param>
54+
public static void RebootDevice(
55+
int exeConstraintTimeout,
56+
RebootOption rebootOption = RebootOption.NormalReboot)
5057
{
5158
try
5259
{
@@ -59,14 +66,14 @@ public static void RebootDevice(int exeConstraintTimeout)
5966
}
6067
finally
6168
{
62-
NativeReboot();
69+
NativeReboot(rebootOption);
6370
}
6471
}
6572

6673
#region external methods declarations
6774

6875
[MethodImpl(MethodImplOptions.InternalCall)]
69-
internal static extern void NativeReboot();
76+
internal static extern void NativeReboot(RebootOption rebootOption);
7077

7178
#endregion
7279
}

nanoFramework.Runtime.Native/Properties/AssemblyInfo.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
////////////////////////////////////////////////////////////////
1616
// update this whenever the native assembly signature changes //
17-
[assembly: AssemblyNativeVersion("100.0.9.0")]
17+
[assembly: AssemblyNativeVersion("100.0.10.0")]
1818
////////////////////////////////////////////////////////////////
1919

2020
// Setting ComVisible to false makes the types in this assembly not visible
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace nanoFramework.Runtime.Native
5+
{
6+
///////////////////////////////////////////////////////////////////////////////////////
7+
// !!! KEEP IN SYNC WITH nanoFramework.Tools.Debugger.WireProtocol.RebootOptions !!! //
8+
///////////////////////////////////////////////////////////////////////////////////////
9+
10+
/// <summary>
11+
/// Specifies the reboot options for a .NET nanoFramework device.
12+
/// </summary>
13+
public enum RebootOption
14+
{
15+
/// <summary>
16+
/// Perform a normal reboot of the CPU. This is an hard reset.
17+
/// </summary>
18+
#pragma warning disable S2346 // Need this to be 0 because of native implementation
19+
NormalReboot = 0,
20+
#pragma warning restore S2346 // Flags enumerations zero-value members should be named "None"
21+
22+
/// <summary>
23+
/// Reboot and enter the nanoBooter.
24+
/// </summary>
25+
EnterNanoBooter = 1,
26+
27+
/// <summary>
28+
/// Reboot the Common Language Runtime (CLR) only.
29+
/// </summary>
30+
ClrOnly = 2,
31+
32+
//////////////////////////////
33+
// can't use option value 4 //
34+
//////////////////////////////
35+
36+
/// <summary>
37+
/// Reboot and enter the proprietary bootloader.
38+
/// </summary>
39+
EnterProprietaryBooter = 8,
40+
};
41+
}

nanoFramework.Runtime.Native/nanoFramework.Runtime.Native.nfproj

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
<ProjectGuid>4C4AA37C-19D9-4C41-ADD0-BA83A0E593DA</ProjectGuid>
1313
<OutputType>Library</OutputType>
1414
<FileAlignment>512</FileAlignment>
15-
<RootNamespace></RootNamespace>
15+
<RootNamespace>
16+
</RootNamespace>
1617
<AssemblyName>nanoFramework.Runtime.Native</AssemblyName>
1718
<TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
1819
<NF_IsCoreLibrary>True</NF_IsCoreLibrary>
@@ -42,6 +43,7 @@
4243
</ItemGroup>
4344
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.props')" />
4445
<ItemGroup>
46+
<Compile Include="RebootOption.cs" />
4547
<Compile Include="Power.cs" />
4648
<Compile Include="GC.cs" />
4749
<Compile Include="SystemInfo.cs" />

version.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
{
1+
{
22
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
3-
"version": "1.6",
3+
"version": "1.7",
44
"assemblyVersion": {
55
"precision": "build"
66
},

0 commit comments

Comments
 (0)