/// <summary> /// Starts execution on the connected .Net Micro Framework device at the supplied address (parameter entrypoint). /// This method is generally used after the Deploy method to jump into the code that was deployed. /// </summary> /// <param name="entrypoint">Entry point address for execution to begin</param> /// <returns>Returns false if execution fails, true otherwise /// Possible exceptions: MFDeviceNoResponseException /// </returns> public bool Execute(uint entryPoint) { if (m_eng == null) { throw new MFDeviceNoResponseException(); } _WP.Commands.Monitor_Ping.Reply reply = m_eng.GetConnectionSource(); if (reply == null) { throw new MFDeviceNoResponseException(); } // only execute if we are talking to the tinyBooter, otherwise reboot if (reply.m_source == _WP.Commands.Monitor_Ping.c_Ping_Source_TinyBooter) { return(m_eng.ExecuteMemory(entryPoint)); } else // if we are talking to the CLR then we simply did a deployment update, so reboot { m_eng.RebootDevice(_DBG.Engine.RebootOption.RebootClrOnly); } return(true); }
/// <summary> /// Attempts to talk to the connected .Net Micro Framework device /// </summary> /// <returns>returns ConnectionType if the device was responsive, false otherwise</returns> public PingConnectionType Ping() { PingConnectionType ret = PingConnectionType.NoConnection; if (m_eng != null) { _WP.Commands.Monitor_Ping.Reply reply = m_eng.GetConnectionSource(); if (reply != null) { switch (reply.m_source) { case _WP.Commands.Monitor_Ping.c_Ping_Source_TinyCLR: ret = PingConnectionType.TinyCLR; break; case _WP.Commands.Monitor_Ping.c_Ping_Source_TinyBooter: ret = PingConnectionType.TinyBooter; break; } } } return(ret); }
bool WireProtocol.IControllerHostLocal.ProcessMessage(WireProtocol.IncomingMessage msg, bool fReply) { msg.Payload = WireProtocol.Commands.ResolveCommandToPayload(msg.Header.m_cmd, fReply, m_capabilities); if (fReply == true) { Request reply = null; lock (m_requests.SyncRoot) { foreach (Request req in m_requests) { if (req.MatchesReply(msg)) { m_requests.Remove(req); reply = req; break; } } } if (reply != null) { reply.Signal(msg); return true; } } else { WireProtocol.Packet bp = msg.Header; switch (bp.m_cmd) { case WireProtocol.Commands.c_Monitor_Ping: { WireProtocol.Commands.Monitor_Ping.Reply cmdReply = new Microsoft.SPOT.Debugger.WireProtocol.Commands.Monitor_Ping.Reply(); cmdReply.m_source = WireProtocol.Commands.Monitor_Ping.c_Ping_Source_Host; cmdReply.m_dbg_flags = (m_stopDebuggerOnConnect ? WireProtocol.Commands.Monitor_Ping.c_Ping_DbgFlag_Stop : 0); msg.Reply(CreateConverter(), WireProtocol.Flags.c_NonCritical, cmdReply); m_evtPing.Set(); return true; } case WireProtocol.Commands.c_Monitor_Message: { WireProtocol.Commands.Monitor_Message payload = msg.Payload as WireProtocol.Commands.Monitor_Message; Debug.Assert(payload != null); if (payload != null) { QueueNotify(m_eventMessage, msg, payload.ToString()); } return true; } case WireProtocol.Commands.c_Debugging_Messaging_Query: case WireProtocol.Commands.c_Debugging_Messaging_Reply: case WireProtocol.Commands.c_Debugging_Messaging_Send: { Debug.Assert(msg.Payload != null); if (msg.Payload != null) { QueueRpc(msg); } return true; } } } if (m_eventCommand != null) { QueueNotify(m_eventCommand, msg, fReply); return true; } return false; }
/// <summary> /// Erases the deployment sectors of the connected .Net Micro Framework device /// </summary> /// <param name="options">Identifies which areas are to be erased, if no options are given, all /// user sectors will be erased. /// </param> /// <returns>Returns false if the erase fails, true otherwise /// Possible exceptions: MFUserExitException, MFDeviceNoResponseException /// </returns> public bool Erase(params EraseOptions[] options) { bool ret = false; bool fReset = false; if (m_eng == null) { throw new MFDeviceNoResponseException(); } EraseOptions optionFlags = 0; if (options == null || options.Length == 0) { optionFlags = (EraseOptions.Deployment | EraseOptions.FileSystem | EraseOptions.UserStorage); } else { foreach (EraseOptions opt in options) { optionFlags |= opt; } } if (!m_eng.TryToConnect(5, 100, true, _DBG.ConnectionSource.Unknown)) { throw new MFDeviceNoResponseException(); } if (!IsClrDebuggerEnabled()) { fReset = (Ping() == PingConnectionType.TinyCLR); ConnectToTinyBooter(); } _WP.Commands.Monitor_FlashSectorMap.Reply reply = m_eng.GetFlashSectorMap(); if (reply == null) { throw new MFDeviceNoResponseException(); } _WP.Commands.Monitor_Ping.Reply ping = m_eng.GetConnectionSource(); ret = true; long total = 0; long value = 0; bool isConnectedToCLR = ((ping != null) && (ping.m_source == _WP.Commands.Monitor_Ping.c_Ping_Source_TinyCLR)); if (isConnectedToCLR) { m_eng.PauseExecution(); } List <_WP.Commands.Monitor_FlashSectorMap.FlashSectorData> eraseSectors = new List <_WP.Commands.Monitor_FlashSectorMap.FlashSectorData>(); foreach (_WP.Commands.Monitor_FlashSectorMap.FlashSectorData fsd in reply.m_map) { if (EventCancel.WaitOne(0, false)) { throw new MFUserExitException(); } switch (fsd.m_flags & _WP.Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK) { case _WP.Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_DEPLOYMENT: if (EraseOptions.Deployment == (optionFlags & EraseOptions.Deployment)) { eraseSectors.Add(fsd); total++; } break; case _WP.Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_STORAGE_A: case _WP.Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_STORAGE_B: if (EraseOptions.UserStorage == (optionFlags & EraseOptions.UserStorage)) { eraseSectors.Add(fsd); total++; } break; case _WP.Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_FS: if (EraseOptions.FileSystem == (optionFlags & EraseOptions.FileSystem)) { eraseSectors.Add(fsd); total++; } break; } } foreach (_WP.Commands.Monitor_FlashSectorMap.FlashSectorData fsd in eraseSectors) { ret &= m_eng.EraseMemory(fsd.m_address, fsd.m_size); value++; if (OnProgress != null) { OnProgress(value, total, string.Format(Properties.Resources.StatusEraseSector, fsd.m_address)); } } // reset if we specifically entered tinybooter for the erase if (fReset) { m_eng.ExecuteMemory(0); } // reboot if we are talking to the clr if (isConnectedToCLR) { if (OnProgress != null) { OnProgress(0, 0, Properties.Resources.StatusRebooting); } m_eng.RebootDevice(_DBG.Engine.RebootOption.RebootClrOnly); m_eng.ResumeExecution(); } return(ret); }
/// <summary> /// Attempt to establish a connection with TinyBooter (with reboot if necessary) /// </summary> /// <returns>true connection was made, false otherwise</returns> public bool ConnectToTinyBooter() { bool ret = false; if (m_eng == null) { _DBG.PortDefinition pd = m_portTinyBooter; try { if (m_eng == null) { m_eng = new _DBG.Engine(pd); m_eng.OnNoise += new _DBG.NoiseEventHandler(OnNoiseHandler); m_eng.OnMessage += new _DBG.MessageEventHandler(OnMessage); m_eng.Start(); m_eng.TryToConnect(5, 100, true, _DBG.ConnectionSource.Unknown); } } catch { } } if (m_eng != null) { if (m_eng.ConnectionSource == _DBG.ConnectionSource.TinyBooter) { return(true); } m_eng.RebootDevice(_DBG.Engine.RebootOption.EnterBootloader); // tinyBooter is only com port so if (m_port is _DBG.PortDefinition_Tcp) { Disconnect(); m_port = m_portTinyBooter; // digi takes forever to reset if (!Connect(60000, true)) { Console.WriteLine(Properties.Resources.ErrorUnableToConnectToTinyBooterSerial); return(false); } } bool fConnected = false; for (int i = 0; i < 40; i++) { if (EventCancel.WaitOne(0, false)) { throw new MFUserExitException(); } if (fConnected = m_eng.TryToConnect(0, 500, true, _DBG.ConnectionSource.Unknown)) { _WP.Commands.Monitor_Ping.Reply reply = m_eng.GetConnectionSource(); ret = (reply.m_source == _WP.Commands.Monitor_Ping.c_Ping_Source_TinyBooter); break; } } if (!fConnected) { Console.WriteLine(Properties.Resources.ErrorUnableToConnectToTinyBooter); } } return(ret); }
private ArrayList FindGatewayStubsForMessage( _WP.IncomingMessage msg, bool fReply ) { ArrayList stubs = null; GatewayStub stub = null; bool fMulticast = false; msg.Payload = _WP.Commands.ResolveCommandToPayload( msg.Header.m_cmd, fReply, ((_WP.IController)this).Capabilities ); _WP.Packet bp = msg.Header; if(fReply) { stub = FindGatewayStubForReply( msg ); } else { switch(bp.m_cmd) { case _WP.Commands.c_Monitor_Ping: if((msg.Header.m_flags & _WP.Flags.c_NonCritical) == 0) { _WP.Commands.Monitor_Ping.Reply cmdReply = new _WP.Commands.Monitor_Ping.Reply(); cmdReply.m_source = _WP.Commands.Monitor_Ping.c_Ping_Source_Host; cmdReply.m_dbg_flags = (m_stopDebuggerOnBoot? _WP.Commands.Monitor_Ping.c_Ping_DbgFlag_Stop: 0); msg.Reply( null, _WP.Flags.c_NonCritical, cmdReply); } break; case _WP.Commands.c_Monitor_Message: case _WP.Commands.c_Monitor_ProgramExit: case _WP.Commands.c_Debugging_Button_Report: case _WP.Commands.c_Debugging_Execution_BreakpointHit: case _WP.Commands.c_Debugging_Lcd_NewFrame: case _WP.Commands.c_Debugging_Lcd_NewFrameData: fMulticast = true; break; case _WP.Commands.c_Debugging_Messaging_Query: case _WP.Commands.c_Debugging_Messaging_Reply: case _WP.Commands.c_Debugging_Messaging_Send: stub = FindGatewayStubForRpc( msg ); break; } } if(fMulticast) { stubs = CreateCopyOfStubs(); } else { stubs = new ArrayList(); if(stub != null) { stubs.Add( stub ); } } return stubs; }
private ArrayList FindGatewayStubsForMessage(_WP.IncomingMessage msg, bool fReply) { ArrayList stubs = null; GatewayStub stub = null; bool fMulticast = false; msg.Payload = _WP.Commands.ResolveCommandToPayload(msg.Header.m_cmd, fReply, ((_WP.IController) this).Capabilities); _WP.Packet bp = msg.Header; if (fReply) { stub = FindGatewayStubForReply(msg); } else { switch (bp.m_cmd) { case _WP.Commands.c_Monitor_Ping: if ((msg.Header.m_flags & _WP.Flags.c_NonCritical) == 0) { _WP.Commands.Monitor_Ping.Reply cmdReply = new _WP.Commands.Monitor_Ping.Reply(); cmdReply.m_source = _WP.Commands.Monitor_Ping.c_Ping_Source_Host; cmdReply.m_dbg_flags = (m_stopDebuggerOnBoot? _WP.Commands.Monitor_Ping.c_Ping_DbgFlag_Stop: 0); msg.Reply(null, _WP.Flags.c_NonCritical, cmdReply); } break; case _WP.Commands.c_Monitor_Message: case _WP.Commands.c_Monitor_ProgramExit: case _WP.Commands.c_Debugging_Button_Report: case _WP.Commands.c_Debugging_Execution_BreakpointHit: case _WP.Commands.c_Debugging_Lcd_NewFrame: case _WP.Commands.c_Debugging_Lcd_NewFrameData: fMulticast = true; break; case _WP.Commands.c_Debugging_Messaging_Query: case _WP.Commands.c_Debugging_Messaging_Reply: case _WP.Commands.c_Debugging_Messaging_Send: stub = FindGatewayStubForRpc(msg); break; } } if (fMulticast) { stubs = CreateCopyOfStubs(); } else { stubs = new ArrayList(); if (stub != null) { stubs.Add(stub); } } return(stubs); }
private void buttonEraseDeployment_Click(object sender, EventArgs e) { bool bWasStarted = EnsureDebuggerConnection(); Cursor old = Cursor.Current; Cursor = Cursors.WaitCursor; buttonEraseDeployment.Text = "Erasing..."; buttonEraseDeployment.Update(); NewText("Erasing Deployment Sector...\r\n"); try { _DBG.WireProtocol.Commands.Monitor_Ping.Reply ping = m_eng.GetConnectionSource(); if (ping == null) { NewText("Unable to connect to device\r\n"); return; } bool fClrConnection = ping.m_source == _DBG.WireProtocol.Commands.Monitor_Ping.c_Ping_Source_TinyCLR; if (fClrConnection) { m_eng.PauseExecution(); } _DBG.WireProtocol.Commands.Monitor_FlashSectorMap.Reply status = m_eng.GetFlashSectorMap() as _DBG.WireProtocol.Commands.Monitor_FlashSectorMap.Reply; if (status == null) { NewText("Erase Deployment may Not be supported on this device build\r\n"); } else { const uint c_deployFlag = _DBG.WireProtocol.Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_DEPLOYMENT; const uint c_usageMask = _DBG.WireProtocol.Commands.Monitor_FlashSectorMap.c_MEMORY_USAGE_MASK; foreach (_DBG.WireProtocol.Commands.Monitor_FlashSectorMap.FlashSectorData sector in status.m_map) { if (c_deployFlag == (c_usageMask & sector.m_flags)) { NewText(string.Format("Erasing sector at 0x{0:x08}\r\n", sector.m_address)); m_eng.EraseMemory(sector.m_address, sector.m_size); } } if (fClrConnection) { m_eng.RebootDevice(_DBG.Engine.RebootOption.RebootClrOnly); } NewText("Erase Deployment Successfull"); } } catch (Exception ex) { NewText("Exception: " + ex.Message + "\r\n"); } finally { buttonEraseDeployment.Text = "Erase Deployment"; Cursor = old; if (!bWasStarted) { m_eng.Stop(); m_eng = null; } } }