Skip to content

Commit

Permalink
Improve write memory operation (#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
josesimoes committed Dec 2, 2021
1 parent 5f90540 commit 5fcb85a
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 24 deletions.
4 changes: 2 additions & 2 deletions USB Test App WPF/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ private INFSerialDebugClientService CreateSerialDebugClient()

var composite = PortBase.CreateInstanceForComposite(new[]
{
PortBase.CreateInstanceForSerial(devicesToExclude),
PortBase.CreateInstanceForSerial(false, devicesToExclude),
//PortBase.CreateInstanceForNetwork()
});
}, true);

return new NFSerialDebugClientService(composite);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ private bool VerifyMemory(
uint address,
IProgress<string> progress = null)
{
if (!DebugEngine.CheckMemory(address, buffer))
if (!DebugEngine.PerformWriteMemoryCheck(address, buffer))
{
progress?.Report($"Verification failed.");

Expand Down
57 changes: 37 additions & 20 deletions nanoFramework.Tools.DebugLibrary.Shared/WireProtocol/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -717,18 +717,14 @@ internal Task<IncomingMessage> PerformRequestAsync(OutgoingMessage message, int

try
{
// Start a background task that will complete tcs1.Task
Task.Factory.StartNew(() =>
if (!request.PerformRequest(_controlller))
{
if (!request.PerformRequest(_controlller))
{
// report failure
request.RequestAborted();
// report failure
request.RequestAborted();

// send failed...
request.TaskCompletionSource.SetException(new InvalidOperationException());
}
});
// send failed...
request.TaskCompletionSource.SetException(new InvalidOperationException());
}
}
catch (Exception ex)
{
Expand Down Expand Up @@ -1587,14 +1583,36 @@ public TargetInfo GetMonitorTargetInfo()

DebuggerEventSource.Log.EngineWriteMemory(address, packetLength);

IncomingMessage reply = PerformSyncRequest(Commands.c_Monitor_WriteMemory, 0, cmd, 2 * DefaultTimeout);
IncomingMessage reply = PerformSyncRequest(
Commands.c_Monitor_WriteMemory,
Flags.c_NoFlags,
cmd,
3 * DefaultTimeout);

if (reply != null)
{
Commands.Monitor_WriteMemory.Reply cmdReply = reply.Payload as Commands.Monitor_WriteMemory.Reply;

if (!reply.IsPositiveAcknowledge() ||
(AccessMemoryErrorCodes)cmdReply.ErrorCode != AccessMemoryErrorCodes.NoError)
// check for no reply
if (reply is null)
{
progress?.Report(new MessageWithProgress(""));
log?.Report($"Error writing to device @ 0x{address:X8} ({packetLength} bytes). No reply from nanoDevice.");

return (AccessMemoryErrorCodes.NoError, false);
}

// check for negative reply
if (!reply.IsPositiveAcknowledge())
{
progress?.Report(new MessageWithProgress(""));
log?.Report($"Error writing to device @ 0x{address:X8} ({packetLength} bytes). Write operation failed.");

return (AccessMemoryErrorCodes.NoError, false);
}

// check for error code in memory access
if ((AccessMemoryErrorCodes)cmdReply.ErrorCode != AccessMemoryErrorCodes.NoError)
{
progress?.Report(new MessageWithProgress(""));
log?.Report($"Error writing to device @ 0x{address:X8} ({packetLength} bytes). Error code: {cmdReply.ErrorCode}.");
Expand All @@ -1613,6 +1631,8 @@ public TargetInfo GetMonitorTargetInfo()

return (AccessMemoryErrorCodes.Unknown, false);
}

Thread.Sleep(1);
}

return (AccessMemoryErrorCodes.NoError, true);
Expand Down Expand Up @@ -1662,7 +1682,7 @@ public bool CheckMemory(uint address, byte[] buf, int offset, int length)
return false;
}

public bool CheckMemory(uint address, byte[] buf)
public bool PerformWriteMemoryCheck(uint address, byte[] buf)
{
return CheckMemory(address, buf, 0, buf.Length);
}
Expand Down Expand Up @@ -3201,12 +3221,9 @@ private bool DeploymentExecuteIncremental(
return false;
}

if (System.Diagnostics.Debugger.IsAttached)
{
// check memory
var memCheck = CheckMemory((uint)block.StartAddress, block.DeploymentData);
Debug.Assert(memCheck, "Memory check Failed.");
}
// check memory
var memCheck = PerformWriteMemoryCheck((uint)block.StartAddress, block.DeploymentData);
Debug.Assert(memCheck, "Memory check Failed.");

deployedBytes += block.DeploymentData.Length;
}
Expand Down
5 changes: 5 additions & 0 deletions nanoFramework.Tools.DebugLibrary.Shared/WireProtocol/Flags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ namespace nanoFramework.Tools.Debugger.WireProtocol
{
public class Flags
{
/// <summary>
/// Constant for empty flags.
/// </summary>
public const ushort c_NoFlags = 0;

public const ushort c_NonCritical = 0x0001; // This doesn't need an acknowledge.
public const ushort c_Reply = 0x0002; // This is the result of a command.
public const ushort c_BadHeader = 0x0004;
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "2.0.0-preview.{height}",
"version": "2.1.0-preview.{height}",
"assemblyVersion": {
"precision": "revision"
},
Expand Down

0 comments on commit 5fcb85a

Please sign in to comment.