/// <summary> /// Creates the RexBoard and all components within it. /// </summary> public RexBoard() { //Initialise busses mDataBus = new Bus(); mAddressBus = new Bus(); mIrqs = new Bus(); //Initialise other components CPU = new SimpleWrampCpu(mAddressBus, mDataBus, mIrqs, mCs); //Memory and Memory-mapped IO RAM = new MemoryDevice(0x00000, 0x20000, mAddressBus, mDataBus, "Memory (RAM)"); Serial1 = new SerialIO(0x70000, 5, mAddressBus, mDataBus, "Serial Port 1"); Serial2 = new SerialIO(0x71000, 5, mAddressBus, mDataBus, "Serial Port 2"); Timer = new Timer(0x72000, 4, mAddressBus, mDataBus, "Timer"); Parallel = new ParallelIO(0x73000, 6, mAddressBus, mDataBus, "Parallel Port"); ROM = new MemoryDevice(0x80000, 0x40000, mAddressBus, mDataBus, "Memory (ROM)"); InterruptButton = new ButtonInterrupt(0x7f000, 1, mAddressBus, mDataBus, "Interrupt Button"); //IRQs InterruptButton.AttachIRQ(mIrqs, 1, 0); Timer.AttachIRQ(mIrqs, 2, 3); Parallel.AttachIRQ(mIrqs, 3, 5); Serial1.AttachIRQ(mIrqs, 4, 4); Serial2.AttachIRQ(mIrqs, 5, 4); Reset(); }
/// <summary> /// Function to transmit the UBL and application for flash /// </summary> private static Boolean TransmitAPP() { Byte[] imageData; UARTBOOT_Header ackHeader = new UARTBOOT_Header(); try { // Now Send the application image that will be written to flash Console.WriteLine("Sending the Application image"); imageData = FileIO.GetFileData(cmdParams.APPFileName); ackHeader.magicNum = ((UInt32)MagicFlags.UBL_MAGIC_BIN_IMG); ackHeader.startAddr = cmdParams.APPStartAddr; ackHeader.byteCnt = (UInt32)imageData.Length; ackHeader.loadAddr = cmdParams.APPLoadAddr; if (!TransmitImage(imageData, ackHeader)) { return(false); } // ^^^DONE\0 that indicates that application flashing is complete if (!SerialIO.waitForSequence(" DONE\0", "BOOTUBL\0", MySP, true)) { return(false); } return(true); } catch (ObjectDisposedException e) { Console.WriteLine(e.StackTrace); throw e; } }
/// <summary> /// Load settings from file and store it's data in the CoreState instance /// </summary> public static void LoadSettings() { if (!CheckSettingsData()) { CoreState.SettingsInstance = new Settings(); } else { JsonSerializer serializer = new JsonSerializer(); using (StreamReader sr = new StreamReader(string.Format("{0}/{1}/{2}", AppContext.BaseDirectory, SettingsPath, SettingsFileName))) using (JsonReader reader = new JsonTextReader(sr)) { Settings settings = serializer.Deserialize <Settings>(reader); CoreState.SettingsInstance = settings; if (SerialIO.GetPortNames().Contains(settings.COMPort) && !settings.useWifi) { SerialManager.ManagerInstance.Start(); } if (settings.useWifi) { WifiManager.ManagerInstance.Start(); } } } }
static void Main(string[] args) { //$logger = New-Logger -FileName "c:\temp\netomity-log.txt" var logger = new Logger(@"C:\temp\netomity-log.txt"); var ns = NetomitySystem.Factory(); //$insteonPort = New-SerialIO -Name "InsteonSerial" -PortName "COM5" -PortSpeed 19200 var insteonPort = new SerialIO(portName: "COM5", portSpeed: 19200); //$w800Port = New-SerialIO -Name "W800Serial" -PortName "COM4" -PortSpeed 4800 var w800Port = new SerialIO(portName: "COM4", portSpeed: 4800); //$insteonTCP = New-TCPServer -Name "InsteonTCP" -PortNumber 3333 var insteonTCP = new TCPServer(3333); //$w800TCP = New-TCPServer -Name "W800TCP" -PortNumber 3334 var W800TCP = new TCPServer(3334); //$insteonBC = New-BasicConnector -Name "InsteonBC" -Interfaces $insteonPort, $insteonTCP var insteonBC = new BasicConnector(insteonPort, insteonTCP); //$w800BC = New-BasicConnector -Name "W800BC" -Interfaces $w800Port, $w800TCP var w800BC = new BasicConnector(w800Port, W800TCP); //$insteonTask = $insteonBC.Open() var insteonTask = insteonBC.Open(); //$w800Task = $w800BC.Open() var w800Task = w800BC.Open(); //$insteonTask.Wait(); // insteonTask.Wait(); // Thread.Sleep(60000); ns.Run(); }
void Start() { trackedController = gameObject.GetComponent <SteamVR_TrackedController>(); uiCtrl = FindObjectOfType <UICtrl>(); trackedObject = GetComponent <SteamVR_TrackedObject>(); device = SteamVR_Controller.Input((int)trackedObject.index); UH = FindObjectOfType <DemoScript>(); gameCtrl = FindObjectOfType <GameCtrl>(); serial = FindObjectOfType <SerialIO>(); chargeEff.SetActive(false); nowPos = transform.position; prePos = transform.position; if (trackedController == null) { trackedController = gameObject.AddComponent <SteamVR_TrackedController>(); } trackedController.MenuButtonClicked += new ClickedEventHandler(DoMenuButtonClicked); trackedController.MenuButtonUnclicked += new ClickedEventHandler(DoMenuButtonUnClicked); trackedController.TriggerClicked += new ClickedEventHandler(DoTriggerClicked); trackedController.TriggerUnclicked += new ClickedEventHandler(DoTriggerUnclicked); trackedController.SteamClicked += new ClickedEventHandler(DoSteamClicked); trackedController.PadClicked += new ClickedEventHandler(DoPadClicked); trackedController.PadUnclicked += new ClickedEventHandler(DoPadClicked); trackedController.PadTouched += new ClickedEventHandler(DoPadTouched); trackedController.PadUntouched += new ClickedEventHandler(DoPadTouched); trackedController.Gripped += new ClickedEventHandler(DoGripped); trackedController.Ungripped += new ClickedEventHandler(DoUngripped); }
void Update() { SerialIO.Write(on ? "1" : "0"); on = !on; string rString = SerialIO.Read(); Debug.Log(rString); }
/// <summary> /// Function to transmit the application code via the SLT, which is now /// running on the device. This code is specific to the supplied SLT. /// If the the TI supplied SLT is modified or a different boot loader is /// used, this code will need to be modified. /// </summary> private static Boolean TransmitImage(Byte[] imageData, UARTBOOT_Header ackHeader) { try { Console.WriteLine("Waiting for SENDIMG sequence..."); if (!SerialIO.waitForSequence("SENDIMG\0", "BOOTUBL\0", MySP, cmdParams.verbose)) { return(false); } Console.WriteLine("SENDIMG received. Returning ACK and header for image data..."); // Output 36 Bytes for the ACK sequence and header // 8 bytes acknowledge sequence = " ACK\0" MySP.Write(" ACK\0"); // 8 bytes of magic number MySP.Write(String.Format("{0:X8}", ackHeader.magicNum)); // 8 bytes of binary execution address = ASCII string of 8 hex characters MySP.Write(String.Format("{0:X8}", ackHeader.startAddr)); // 8 bytes of data size = ASCII string of 8 hex characters MySP.Write(String.Format("{0:X8}", ackHeader.byteCnt)); // 8 bytes of binary load address = ASCII string of 8 hex characters MySP.Write(String.Format("{0:X8}", ackHeader.loadAddr)); // 4 bytes of constant zeros = "0000" MySP.Write("0000"); Console.WriteLine("ACK command sent. Waiting for BEGIN command... "); // Wait for the ^^BEGIN\0 sequence if (!SerialIO.waitForSequence(" BEGIN\0", "BOOTUBL\0", MySP, cmdParams.verbose)) { return(false); } Console.WriteLine("BEGIN commmand received. Sending the image data..."); // Send the image data MySP.Write(imageData, 0, (Int32)ackHeader.byteCnt); Console.WriteLine("Image data sent. Waiting for DONE..."); // Wait for first ^^^DONE\0 to indicate data received if (!SerialIO.waitForSequence(" DONE\0", "BOOTUBL\0", MySP, cmdParams.verbose)) { return(false); } Console.WriteLine("DONE received. All bytes of image data received..."); } catch (ObjectDisposedException e) { Console.WriteLine(e.StackTrace); throw e; } return(true); }
public override void OnGet(HttpListenerRequest request, HttpListenerResponse response) { JObject obj = new JObject() { { "result", true }, { "ports", new JArray(SerialIO.GetPortNames().ToArray()) }, { "wifi", CoreState.SettingsInstance.useWifi } }; ResponseFactory.GenerateResponse(response, obj.ToString()); }
public HardDriveController(Stream stream, SerialIO mserial) { StreamReader reader = new StreamReader(stream); int read = reader.Read(disk, 0, SIZE); this.mserial = mserial; if (read != SIZE) { Console.WriteLine("unable to read byte"); Console.Write(disk[SIZE - 1]); } }
/// <summary> /// Send command and wait for erase response. (NOR and NAND global erase) /// </summary> private static Boolean TransmitErase() { try { // ^^^DONE\0 that indicates command was executed successfully if (!SerialIO.waitForSequence(" DONE\0", "BOOTUBL\0", MySP, true)) { return(false); } } catch (ObjectDisposedException e) { Console.WriteLine(e.StackTrace); throw e; } return(true); }
// ------------------------------------------------------------------------ // Invoked whenever the SerialController gameobject is deactivated. // It stops and destroys the thread that was reading from the serial device. // ------------------------------------------------------------------------ public virtual void Shutdown() { // The serialThread reference should never be null at this point, // unless an Exception happened in the OnEnable(), in which case I've // no idea what face Unity will make. if (serialThread != null) { serialThread.RequestStop(); serialThread = null; } if (thread != null) { thread.Join(); thread = null; } }
/// <summary> /// Constructor. /// </summary> /// <param name="port">The Serial device to communicate with.</param> public BasicSerialPortForm(SerialIO port) { InitializeComponent(); this.mSerialPort = port; this.Text = mSerialPort.Name; mRecvBuffer = new StringBuilder(); mScreenBuffer = new char[NUM_ROWS, NUM_COLS]; mCX = mCY = 0; ClearScreen(); serialLabel.AllowDrop = true; serialLabel.DragDrop += new DragEventHandler(serialLabel_DragDrop); serialLabel.DragEnter += new DragEventHandler(serialLabel_DragEnter); mSerialPort.SerialDataTransmitted += new EventHandler <SerialIO.SerialEventArgs>(mSerialPort_SerialDataTransmitted); updateTimer.Start(); }
public EmuGB(ConfigsGB aConfigs) { m_configs = aConfigs; m_cpu = new CPU(); m_ppu = new PPU(); m_apu = new APU(); m_mem = new MEM(); m_dmaController = new DMAController(); m_timerController = new TimerController(); m_joypad = new Joypad(); m_serialIO = new SerialIO(); // Start paused m_paused = true; // Temp binding DrawDisplay = (aPPU) => { }; DrawDisplayLine = (aPPU, aScanline) => { }; m_mem.AttachCPU(m_cpu); m_mem.AttachPPU(m_ppu); m_mem.AttachAPU(m_apu); m_mem.AttachDMAController(m_dmaController); m_mem.AttachTimerController(m_timerController); m_mem.AttachJoypad(m_joypad); m_mem.AttachSerialIO(m_serialIO); m_cpu.ProcessorState.BindCyclesStep(m_ppu.CyclesStep); m_cpu.ProcessorState.BindCyclesStep(m_apu.CyclesStep); m_cpu.ProcessorState.BindCyclesStep(m_dmaController.CyclesStep); m_cpu.ProcessorState.BindCyclesStep(m_timerController.CyclesStep); m_cpu.ProcessorState.BindCyclesStep(m_serialIO.CyclesStep); m_ppu.BindRequestIRQ(m_cpu.RequestIRQ); m_timerController.BindRequestIRQ(m_cpu.RequestIRQ); m_joypad.BindRequestIRQ(m_cpu.RequestIRQ); m_serialIO.BindRequestIRQ(m_cpu.RequestIRQ); //m_ppu.BindDrawDisplayLine(DrawDisplayLine); }
/// <summary> /// 初始化串行流切换组件对象 /// </summary> /// <param name="SerialIOs">要管理的流对象</param> /// <remarks>需要在初始化此对象前初始化传入的流对象,不必打开,可以使用此对象的打开函数一起打开所有流对象</remarks> public SerialIOSwitch(SerialIO RS232Obj, SerialIO FileObj) { this.RS232Obj = RS232Obj; this.FileObj = FileObj; if (RS232Obj != null) { ReadSwitch = ReadWay.RS232; CurrSerialObj = RS232Obj; } else if (FileObj != null) { ReadSwitch = ReadWay.File; CurrSerialObj = FileObj; } else { ReadSwitch = ReadWay.None; CurrSerialObj = null; } }
/// <summary> /// 初始化串行流切换组件对象 /// </summary> /// <param name="SerialIOs">要管理的流对象</param> /// <remarks>需要在初始化此对象前初始化传入的流对象,不必打开,可以使用此对象的打开函数一起打开所有流对象</remarks> public SerialIOSwitch(SerialIO RS232Obj, SerialIO FileObj) { this.RS232Obj = RS232Obj; this.FileObj = FileObj; if (RS232Obj != null) { ReadSwitch = ReadWay.RS232; CurrSerialObj = RS232Obj; } else if (FileObj != null) { ReadSwitch = ReadWay.File; CurrSerialObj = FileObj; } else { ReadSwitch = ReadWay.None; CurrSerialObj = null; } }
/// <summary> /// Constructor. /// </summary> /// <param name="port">The Serial device to communicate with.</param> public BasicSerialPortForm(SerialIO port, RexSimulatorGui.Forms.RexBoardForm rexBoardForm) { InitializeComponent(); this.mSerialPort = port; this.Text = mSerialPort.Name; this.mRexBoardForm = rexBoardForm; mRecvBuffer = new StringBuilder(); mScreenBuffer = new char[NUM_ROWS, NUM_COLS]; mCX = mCY = 0; ClearScreen(); serialLabel.AllowDrop = true; serialLabel.DragDrop += new DragEventHandler(serialLabel_DragDrop); serialLabel.DragEnter += new DragEventHandler(serialLabel_DragEnter); resendFileToolStripMenuItem.Enabled = false; mSerialPort.SerialDataTransmitted += new EventHandler <SerialIO.SerialEventArgs>(mSerialPort_SerialDataTransmitted); updateTimer.Start(); }
public virtual void Init() { if (!isActive) { return; } InitInterpreter(); GetInterpreter().systemEvents += OnSystemEvent; // if an old one is running shut it down before starting a new connection if (serialThread != null) { Shutdown(); } serialThread = new SerialIO(portName, baudRate, parity, dataBits, stopBits, reconnectionDelay, GetInterpreter()); thread = new Thread(new ThreadStart(serialThread.RunForever)); thread.Name = "SerialThread " + portName; thread.Start(); }
//********************************************************************************** //********************************************************************************** #region Code for UART interfacing thread /// <summary> /// The main function of the thread where all the cool stuff happens /// to interface with the device /// </summary> public static void WorkerThreadStart() { switch (cmdParams.CMDMagicFlag) { case MagicFlags.SLT_MAGIC_LOADIMAGE_IRAM: { TransmitAppToIRAM(); break; } case MagicFlags.SLT_MAGIC_LOADIMAGE_DDR: { // Send SLT and the app to DDR TransmitSLTAndApp(); // Wait for second ^^^DONE that indicates SLT is done if (!SerialIO.waitForSequence(" DONE\0", "BOOTUBL\0", MySP, true)) { throw new Exception("Final DONE not returned. Operation failed."); } break; } default: { Console.WriteLine("Command not recognized!"); break; } } // Clean up any embedded files we extracted EmbeddedFileIO.CleanUpEmbeddedFiles(); // Everything worked, so change boolean status workerThreadSucceeded = true; }
/// <summary>Contructor</summary> public ModbusServerFunctionPortAdapter(string partID, SerialIO.PortConfig portConfig, IModbusFCServer fcServer, ADUType aduType, byte unitID, bool responseToAllUnits) : base(partID, TimeSpan.FromSeconds(0.2)) { this.fcServer = fcServer; Timeout = portConfig.ReadTimeout; portConfig.ReadTimeout = TimeSpan.FromSeconds(Math.Min(0.1, Timeout.TotalSeconds)); port = SerialIO.Factory.CreatePort(portConfig); portBaseStateObserver = new SequencedRefObjectSourceObserver<IBaseState, Int32>(port.BaseStateNotifier); IPortBehavior portBehavior = port.PortBehavior; IDictionary<string, Logging.IMesgEmitter> emitters = new Dictionary<string,Logging.IMesgEmitter>() { { "Issue", Log.Error }, {"Debug", Log.Debug}, {"Trace", Log.Trace} }; serverFunctionContainer = new ServerFunctionContainer() { ADUType = aduType, Emitters = emitters, UnitID = unitID, RTUAddr = unitID, MBAPUnitID = unitID, RespondToAllTargets = responseToAllUnits }; FlushPeriod = (portBehavior.IsDatagramPort ? TimeSpan.FromSeconds(0.0) : TimeSpan.FromSeconds(0.1)); portReadAction = port.CreateReadAction(portReadActionParam = new ReadActionParam() { WaitForAllBytes = false }); portWriteAction = port.CreateWriteAction(portWriteActionParam = new WriteActionParam()); portFlushAction = port.CreateFlushAction(FlushPeriod); portReadAction.NotifyOnComplete.AddItem(threadWakeupNotifier); portWriteAction.NotifyOnComplete.AddItem(threadWakeupNotifier); portFlushAction.NotifyOnComplete.AddItem(threadWakeupNotifier); port.BaseStateNotifier.NotificationList.AddItem(threadWakeupNotifier); AddExplicitDisposeAction(() => Fcns.DisposeOfObject(ref port)); }
/// <summary> /// 初始化协议处理对象 /// </summary> /// <param name="SerialObject">抽象输入输出流</param> /// <remarks>只有当流已打开有输入数据,再执行Start()之后,此处理对象才会运作.</remarks> public ZProtocolProcess(SerialIO SerialObject) { this.SerialObject = SerialObject; Reset(); }
public void AttachSerialIO(SerialIO aSerialIO) { m_serialIO = aSerialIO; }
/// <summary> /// Function used to handle the -load2DDR command-line option private static void TransmitSLTAndApp() { // Local Variables for holding file data Byte[] imageData; UARTBOOT_Header ackHeader = new UARTBOOT_Header(); // Extract the embedded SLT EmbeddedFileIO.ExtractFile(System.Reflection.Assembly.GetExecutingAssembly(), "slt_" + devString + ".bin", true); // Read the extracted embedded SLT data that we will transmit imageData = FileIO.GetFileData("slt_" + devString + ".bin"); ackHeader.startAddr = 0x0100; // Default for SLT ackHeader.byteCnt = (UInt32)imageData.Length; ackHeader.loadAddr = 0x0020; // Not used here, but this what the RBL uses TransmitUBL(imageData, ackHeader); // Sleep in case we need to abort Thread.Sleep(200); // Code to perform specified command try { BOOTUBLSEQ1: // Send the UBL command // Clear input buffer so we can start looking for BOOTUBL MySP.DiscardInBuffer(); Console.WriteLine("\nWaiting for SLT on the " + devString + "..."); // Wait for the UBL on the device to send the ^BOOTUBL\0 sequence if (!SerialIO.waitForSequence("BOOTUBL\0", "BOOTUBL\0", MySP, true)) { goto BOOTUBLSEQ1; } Console.WriteLine("BOOTUBL commmand received. Returning CMD and command..."); // 8 bytes acknowledge sequence = " CMD\0" MySP.Write(" CMD\0"); // 8 bytes of magic number MySP.Write(((UInt32)cmdParams.CMDMagicFlag).ToString("X8")); Console.WriteLine("CMD value sent. Waiting for DONE..."); // Wait for ^^^DONE letting us know the command was accepted if (!SerialIO.waitForSequence(" DONE\0", "BOOTUBL\0", MySP, cmdParams.verbose)) { goto BOOTUBLSEQ1; } Console.WriteLine("DONE received. Command was accepted."); // Local Variables for reading APP file imageData = FileIO.GetFileData(cmdParams.APPFileName); ackHeader.startAddr = cmdParams.APPStartAddr; // App entry point ackHeader.loadAddr = cmdParams.APPLoadAddr; // App load address ackHeader.byteCnt = (UInt32)imageData.Length; // App byte cnt if (!TransmitImage(imageData, ackHeader)) { goto BOOTUBLSEQ1; } } catch (Exception e) { if (e is ThreadAbortException) { Thread.Sleep(1000); } else { Console.WriteLine(e.Message); } return; } }
/// <summary> /// Function to transmit the application code via the SLT, which is now /// running on the device. This code is specific to the supplied SLT. /// If the the TI supplied SLT is modified or a different boot loader is /// used, this code will need to be modified. /// </summary> private static Boolean TransmitImage(Byte[] imageData, UARTBOOT_Header ackHeader) { ProgressBar progressBar; UInt32 blockCnt; try { Console.WriteLine("Waiting for SENDIMG sequence..."); if (!SerialIO.waitForSequence("SENDIMG\0", "BOOTUBL\0", MySP, cmdParams.verbose)) { return(false); } Console.WriteLine("SENDIMG received. Returning ACK and header for image data..."); // Output 36 Bytes for the ACK sequence and header // 8 bytes acknowledge sequence = " ACK\0" MySP.Write(" ACK\0"); // 8 bytes of binary execution address = ASCII string of 8 hex characters MySP.Write(String.Format("{0:X8}", ackHeader.startAddr)); // 8 bytes of data size = ASCII string of 8 hex characters MySP.Write(String.Format("{0:X8}", ackHeader.byteCnt)); // 8 bytes of binary load address = ASCII string of 8 hex characters MySP.Write(String.Format("{0:X8}", ackHeader.loadAddr)); // 4 bytes of constant zeros = "0000" MySP.Write("0000"); Console.WriteLine("ACK command sent. Waiting for BEGIN command... "); // Wait for the ^^BEGIN\0 sequence if (!SerialIO.waitForSequence(" BEGIN\0", "BOOTUBL\0", MySP, cmdParams.verbose)) { return(false); } Console.WriteLine("BEGIN commmand received."); // Send the image data progressBar = new ProgressBar(); progressBar.Update(0.0, "Sending Image data..."); blockCnt = ackHeader.byteCnt / 128; for (int i = 0; i < (blockCnt * 128); i += 128) { MySP.Write(imageData, i, 128); progressBar.Percent = (((Double)(i + 1)) / ackHeader.byteCnt); } // Write last (possibly partial) block MySP.Write(imageData, (Int32)(blockCnt * 128), (Int32)(ackHeader.byteCnt - (blockCnt * 128))); progressBar.Update(100.0, "Image data sent."); Console.WriteLine("Waiting for DONE..."); // Wait for first ^^^DONE\0 to indicate data received if (!SerialIO.waitForSequence(" DONE\0", "BOOTUBL\0", MySP, cmdParams.verbose)) { return(false); } Console.WriteLine("DONE received. All bytes of image data received..."); } catch (ObjectDisposedException e) { Console.WriteLine(e.StackTrace); throw e; } return(true); }
/// <summary> /// Function to Transmit the UBL via the device ROM Serial boot /// </summary> private static void TransmitUBL(Byte[] imageData, UARTBOOT_Header ackHeader) { // Local Variables for building up output StringBuilder UBLsb; CRC32 MyCRC; ProgressBar progressBar; Int32 blockCnt; UBLsb = new StringBuilder(imageData.Length * 2); // Read the data from the UBL file into the appropriate structures for (int i = 0; i < imageData.Length; i += sizeof(UInt32)) { UBLsb.AppendFormat("{0:X8}", System.BitConverter.ToUInt32(imageData, i)); } // Create CRC object and use it to calculate the UBL file's CRC // Note that this CRC is not quite the standard CRC-32 algorithm // commonly in use since the final register value is not XOR'd // with 0xFFFFFFFF. As a result the CRC value returned here // will be the bitwise inverse of the standard CRC-32 value. MyCRC = new CRC32(0x04C11DB7, 0xFFFFFFFF, 0x00000000, true, 1, CRCType.ONESHOT, CRCCalcMethod.LUT); ackHeader.crcVal = MyCRC.CalculateCRC(imageData); ackHeader.byteCnt = (UInt32)imageData.Length; try { BOOTMESEQ: Console.WriteLine("\nWaiting for the " + devString + "..."); // Wait for the device to send the ^BOOTME/0 sequence if (SerialIO.waitForSequence(" BOOTME\0", " BOOTME\0", MySP, cmdParams.verbose)) { Console.WriteLine("BOOTME commmand received. Returning ACK and header..."); } else { goto BOOTMESEQ; } // Output 28 Bytes for the ACK sequence and header // 8 bytes acknowledge sequence = " ACK\0" #if (DM35x_REVB || DM36x_REVA) MySP.Write(" ACK"); #else MySP.Write(" ACK\0"); #endif // 8 bytes of CRC data = ASCII string of 8 hex characters MySP.Write(ackHeader.crcVal.ToString("X8")); // 4 bytes of UBL data size = ASCII string of 4 hex characters (3800h = 14336d) MySP.Write(ackHeader.byteCnt.ToString("X4")); // 4 bytes of start address = ASCII string of 4 hex characters (>=0100h) MySP.Write(ackHeader.startAddr.ToString("X4")); // 4 bytes of constant zeros = "0000" MySP.Write("0000"); Console.WriteLine("ACK command sent. Waiting for BEGIN command... "); // Wait for the BEGIN sequence if (SerialIO.waitForSequence(" BEGIN\0", " BOOTME\0", MySP, true)) { Console.WriteLine("BEGIN commmand received. Sending CRC table..."); } else { goto BOOTMESEQ; } // Send the 1024 byte (256 word) CRC table progressBar = new ProgressBar(); progressBar.Update(0.0, "Sending CRC table..."); for (int i = 0; i < MyCRC.Length; i++) { MySP.Write(MyCRC[i].ToString("x8")); progressBar.Percent = (((Double)(i + 1)) / MyCRC.Length); } progressBar.Update(100.0, "CRC table sent."); Console.WriteLine("Waiting for DONE..."); // Wait for the first DONE sequence if (SerialIO.waitForSequence(" DONE\0", " BOOTME\0", MySP, cmdParams.verbose)) { Console.WriteLine("DONE received. Sending the UBL..."); } else { goto BOOTMESEQ; } // Send the contents of the UBL file (as hex text) progressBar = new ProgressBar(); progressBar.Update(0.0, "Sending UBL..."); blockCnt = UBLsb.Length / 128; for (int i = 0; i < (blockCnt * 128); i += 128) { MySP.Write(UBLsb.ToString(i, 128)); progressBar.Percent = (((Double)(i + 1)) / UBLsb.Length); } // Write last (possibly partial) block MySP.Write(UBLsb.ToString(blockCnt * 128, UBLsb.Length - (blockCnt * 128))); progressBar.Update(100.0, "UBL sent."); // Wait for the second DONE sequence if (SerialIO.waitForSequence(" DONE\0", " BOOTME\0", MySP, cmdParams.verbose)) { Console.WriteLine("DONE received. UBL was accepted."); } else { goto BOOTMESEQ; } Console.WriteLine("UBL transmitted successfully.\n"); } catch (ObjectDisposedException e) { Console.WriteLine(e.StackTrace); throw e; } }
//********************************************************************************** //********************************************************************************** #region Code for UART interfacing thread /// <summary> /// The main function of the thread where all the cool stuff happens /// to interface with the device /// </summary> public static void WorkerThreadStart() { Boolean status; // Try transmitting the first stage boot-loader (UBL) via the RBL try { String srchStr; Byte[] imageData; UARTBOOT_Header ackHeader = new UARTBOOT_Header(); if (cmdParams.UBLFlashType == FlashType.NAND) { srchStr = "sft_" + devString + "_nand.bin"; } else { srchStr = "sft_" + devString + "_nor.bin"; } // Extract the embedded SLT EmbeddedFileIO.ExtractFile(System.Reflection.Assembly.GetExecutingAssembly(), srchStr, true); // Read the extracted embedded SFT data that we will transmit imageData = FileIO.GetFileData(srchStr); ackHeader.startAddr = 0x0100; // Default for SFT ackHeader.loadAddr = 0x0020; // Not used here, but this what the RBL uses ackHeader.byteCnt = (UInt32)imageData.Length; TransmitUBL(imageData, ackHeader); } catch (Exception e) { if (e is ThreadAbortException) { Thread.Sleep(1000); } else { Console.WriteLine(e.Message); } return; } // Sleep in case we need to abort Thread.Sleep(200); // Code to perform specified command try { BOOTUBLSEQ1: // Clear input buffer so we can start looking for BOOTUBL MySP.DiscardInBuffer(); Console.WriteLine("\nWaiting for SFT on the " + devString + "..."); // Wait for the SFT on the device to send the ^BOOTUBL\0 sequence if (!SerialIO.waitForSequence("BOOTUBL\0", "BOOTUBL\0", MySP, true)) { goto BOOTUBLSEQ1; } Console.WriteLine("BOOTUBL commmand received. Returning CMD and command..."); // 8 bytes acknowledge sequence = " CMD\0" MySP.Write(" CMD\0"); // 8 bytes of magic number MySP.Write(((UInt32)cmdParams.CMDMagicFlag).ToString("X8")); Console.WriteLine("CMD value sent. Waiting for DONE..."); if (!SerialIO.waitForSequence(" DONE\0", "BOOTUBL\0", MySP, true)) { goto BOOTUBLSEQ1; } Console.WriteLine("DONE received. Command was accepted."); // Take appropriate action depending on command switch (cmdParams.CMDMagicFlag) { case MagicFlags.UBL_MAGIC_NAND_FLASH: { status = TransmitUBLandAPP(); break; } case MagicFlags.UBL_MAGIC_NOR_FLASH: { status = TransmitUBLandAPP(); break; } case MagicFlags.UBL_MAGIC_NOR_FLASH_NO_UBL: { status = TransmitAPP(); break; } case MagicFlags.UBL_MAGIC_NOR_ERASE: { status = TransmitErase(); break; } case MagicFlags.UBL_MAGIC_NAND_ERASE: { status = TransmitErase(); break; } default: { Console.WriteLine("Command not recognized!"); status = false; break; } } if (!status) { goto BOOTUBLSEQ1; } } catch (Exception e) { if (e is ThreadAbortException) { Thread.Sleep(1000); } else { Console.WriteLine(e.Message); } return; } // Wait for ^^^DONE that indicates SFT is exiting and so can this host program if (!SerialIO.waitForSequence(" DONE\0", "BOOTUBL\0", MySP, true)) { throw new Exception("Final DONE not returned. Operation failed."); } // Clean up any embedded files we extracted EmbeddedFileIO.CleanUpEmbeddedFiles(); // Everything worked, so change boolean status workerThreadSucceeded = true; }
/// <summary> /// 初始化协议处理对象 /// </summary> /// <param name="SerialObject">抽象输入输出流</param> /// <remarks>只有当流已打开有输入数据,再执行Start()之后,此处理对象才会运作.</remarks> public ZProtocolProcess(SerialIO SerialObject) { this.SerialObject = SerialObject; Reset(); }