public void ProgramAVR(IntelHex program, statusUpdate target) { //program each non-bootloader section of Flash sequentially for(ushort addr = 0; addr < AVR.HW.FlashSize - AVR.HW.BootloadSize; addr += AVR.HW.PageSize) { //Write the page to the AVR. device.WriteAVRPage(addr, program.GetPage(addr)); //If a delegate has been provided to accept status updates, inform it of the update. if(target != null) target((float) addr / (float)(AVR.HW.FlashSize - AVR.HW.BootloadSize)); } //and then reset the microprocessor device.ResetAVR(true); //indicate completion if(target!=null) target(1); }
public void ProgramAVR(IntelHex program, statusUpdate target) { //program each non-bootloader section of Flash sequentially for (int i = 0; i < CurrentLabKit.WriteableFlash / CurrentLabKit.PageSize; ++i) { //Write the page to the AVR. device.WriteAVRPage(i*128, program.GetPage(i)); //If a delegate has been provided to accept status updates, inform it of the update. if(target != null) target((i * 128.0f) / (float)(CurrentLabKit.WriteableFlash)); } //and then reset the microprocessor device.ResetAVR(true); //indicate completion if(target!=null) target(1); }
public void ProgramAVR(IntelHex program) { ProgramAVR(program, null); }
/// <summary> /// Compares one IntelHex record to another to determine equivalence. /// </summary> /// <param name="a"> /// The IntelHex record to compare with this one. /// </param> /// <returns> /// True iff the two records are identical. /// </returns> public bool Equals(IntelHex a) { //This item cannot equal null. if(a==null) return false; //To compare to IntelHex records, compare their memory maps. byte[] memoryA = a.GetPage(0, a.MemoryLength); byte[] memoryB = this.GetPage(0, this.MemoryLength); //Array with nonequal length cannot be equivalent if(memoryA.Length != memoryB.Length) return false; //Search for any inequalities in the two arrays. for(int i=0; i < memoryA.Length; ++i) if(memoryA[i] != memoryB[i]) return false; //Otherwise, they must be equal. return true; }
/// <summary> /// Creates an Intel Hex record from a readable stream. /// </summary> /// <param name="file"> /// An input stream (usually a file). /// </param> /// <returns> /// An Intel Hex record. /// </returns> public static IntelHex FromStream(StreamReader file) { IntelHex data = new IntelHex(); //For each line in the File/Stream while(!file.EndOfStream) { //read the line String line = file.ReadLine(); //If we've reached an EOF record, break. if(line.StartsWith(EOF)) break; //otherwise, parse the line and continue data.AddLine(line); } //return the IntelHex file created return data; }
/// <summary> /// Handles the user's request to load a Hex file. /// </summary> void HandleFileHexFileSet(object sender, EventArgs e) { if(!File.Exists(fileHex.Filename)) return; //Open a stream connected to the input hex file. FileStream hexFile = new FileStream(fileHex.Filename, FileMode.Open); //And wrap it with a StreamReader StreamReader hexStream = new StreamReader(hexFile); //Parse the file stream to yield an intel hex file. IntelHex newRecord = IntelHex.FromStream(hexStream); //Close the stream/file. hexStream.Close(); hexFile.Close(); //If the new record matches the old, show a warning. if(newRecord.Equals(hexRecord)) lblOldHexWarning.Show(); else lblOldHexWarning.Hide(); //and accept the new record hexRecord = newRecord; //Derive statistics from the hex record. deriveStatistics(); //enable the relevant buttons btnHexProgram.Sensitive = true; btnHexRefresh.Sensitive = true; }