public fmMain() { InitializeComponent(); DevFile = null;// new DeviceFile(); //ListEditor.DevFile = DevFile; }
public static DeviceFile.DevicePartParams NewPart24r2(DeviceFile DevFile, string basePartName, string partName, DeviceTemplate template) { DeviceFile.DevicePartParams newPart = DevFile.PartsList.First(p => p.PartName == basePartName); // These can be easily found from the family programmer's manual newPart.PartName = partName; newPart.DeviceID = template.deviceId; newPart.ProgramMem = template.family.programSize / 2 + 1; // Size of program FLASH. Not sure what units this is newPart.ConfigAddr = template.family.configAddr * 2; // Address of the highest config register (ie. CONFIG4) newPart.ConfigWords = 4; // Number of config registers // Mask out unused bits. // This can be found in the PIC datasheet. Reserved bits should be masked out. // Configuration registers are in reverse order, ie. { CONFIG4, CONFIG3, CONFIG2, CONFIG1 }, with the CONFIG4 at the LOWEST address. newPart.ConfigMasks = new ushort[8] { 0x0000, 0xFFFF, 0xFFF3, 0x7BFF, 0, 0, 0, 0 }; newPart.ConfigBlank = new ushort[8] { 0xFFFF, 0xFFFF, 0xFFF3, 0x7BFF, 0, 0, 0, 0 }; // Default configuration (Check the datasheet to see what the reserved bits should be set to) //NOTE: Above only tested with PIC24FJ256DA206. // Code-protect detection (only used in PicKit2 GUI?) newPart.CPConfig = 4; // Which config contains the code-protect bits. This corresponds to CONFIG1 newPart.CPMask = 0x3000; // There are two CP-config bits, if either are 0 then CP is active. // PIC Family newPart.Family = DevFile.Families.First(f => f.FamilyName == "PIC24r2").FamilyID; // Update scripts to PIC24r2 newPart.ChipEraseScript = DevFile.Scripts.First(s => s.ScriptName == "24r2_ChpErase450ms.1").ScriptNumber; newPart.ProgMemAddrSetScript = DevFile.Scripts.First(s => s.ScriptName == "24r2_SetAddr.1").ScriptNumber; newPart.ProgMemRdScript = DevFile.Scripts.First(s => s.ScriptName == "24r2_ProgMemRd32.1").ScriptNumber; newPart.ProgMemWrPrepScript = DevFile.Scripts.First(s => s.ScriptName == "24r2_ProgMemWrPrep.1").ScriptNumber; newPart.ProgMemWrScript = DevFile.Scripts.First(s => s.ScriptName == "24r2_ProgMemWr64.1").ScriptNumber; return newPart; }
public static void exportTblScripts(DeviceFile.DeviceScripts[] fScripts, String filename) { DTBL tblScripts= new DTBL("Scripts"); setupTblScripts( tblScripts); System.Data.DataRow myNewRow; for (int i = 0; i < fScripts.Length; i++) { myNewRow = tblScripts.NewRow(); myNewRow["ScriptNumber"] = fScripts[i].ScriptNumber; //UInt16(); myNewRow["ScriptName"] = fScripts[i].ScriptName; //String(); myNewRow["ScriptVersion"] = fScripts[i].ScriptVersion; //UInt16(); myNewRow["UNUSED1"] = fScripts[i].UNUSED1; //UInt32(); myNewRow["ScriptLength"] = fScripts[i].ScriptLength; //UInt16(); myNewRow["Script"] = fScripts[i].Script; //Unit16[]; myNewRow["Comment"] = fScripts[i].Comment; //String(); tblScripts.Rows.Add(myNewRow); } tblScripts.WriteXml(filename, System.Data.XmlWriteMode.WriteSchema); }
public fmPartWizard(DeviceFile DevFile) { InitializeComponent(); this.DevFile = DevFile; this.step = 1; }
/// <summary> /// Patches the device file to add new PIC24r2 scripts and support /// for various devices. Note that "PIC24r2" is not an official name, /// I made it to distinguish it from the regular PIC24 chips since they /// seem to have changed stuff. /// </summary> /// <param name="DevFile">The device file to patch</param> public static void PatchDeviceFile(DeviceFile DevFile) { //// 1. Duplicate 24F scripts and patch //// // Skip the script patching if they've already been patched if (DevFile.Scripts.Where(s => s.ScriptName.StartsWith("24r2_")).Count() == 0) { // Get the PIC24 scripts var PIC24Scripts = DevFile.Scripts.Where(s => s.ScriptName.StartsWith("24_")); var newScripts = new List<DeviceFile.DeviceScripts>(); ushort sidx = (ushort)DevFile.Scripts.Length; foreach (var script in PIC24Scripts) { DeviceFile.DeviceScripts newScript = script; // Rename and re-index sidx++; newScript.ScriptName = "24r2_" + newScript.ScriptName.Substring(3); newScript.ScriptNumber = sidx; newScript.Script = (ushort[])newScript.Script.Clone(); // Patch the opcodes: // TBLPAG address has changed from 0x32 to 0x54 // eg. MOV W0, TBLPAG instruction has changed from 0x880190 to 0x8802A0 List<DeviceFile.Opcode> opcodes = newScript.ParseScript(); foreach (DeviceFile.Opcode opcode in opcodes) { if ((OPCODES)opcode.opcode == OPCODES._COREINST24) { uint operand = (uint)(((uint)opcode.data[0] << 16) | ((uint)opcode.data[1] << 8) | opcode.data[2]); // MOV W0, TBLPAG // 88 01 90 -> 99 02 A0 if (operand == 0x880190) { int idx = opcode.index; newScript.Script[idx + 2] = (ushort)((newScript.Script[idx + 2] & 0xFF00) | 0x02); newScript.Script[idx + 1] = (ushort)((newScript.Script[idx + 1] & 0xFF00) | 0xA0); } } } newScripts.Add(newScript); } // Update DeviceFile DevFile.Scripts = DevFile.Scripts.Concat(newScripts).ToArray(); DevFile.Info.NumberScripts += newScripts.Count; } //// 2. Add new PIC24 family //// if (DevFile.Families.Where(f => f.FamilyName == "PIC24r2").Count() == 0) { var PIC24Family = DevFile.Families.First(f => f.FamilyName == "PIC24"); DeviceFile.DeviceFamilyParams newFamily = PIC24Family; newFamily.FamilyName = "PIC24r2"; newFamily.FamilyID = (ushort)DevFile.Families.Length; newFamily.FamilyType = newFamily.FamilyID; // Assign new scripts newFamily.ProgEntryScript = DevFile.Scripts.First(s => s.ScriptName == "24r2_ProgEntry.1").ScriptNumber; newFamily.ReadDevIDScript = DevFile.Scripts.First(s => s.ScriptName == "24r2_RdDevID.1").ScriptNumber; // Update DeviceFile DevFile.Families = DevFile.Families.Concat(new DeviceFile.DeviceFamilyParams[1] { newFamily }).ToArray(); DevFile.Info.NumberFamilies++; } //// 3. Add new PIC24 chips //// var newParts = new List<DeviceFile.DevicePartParams>(); foreach (var dev in devices) { // Make sure the chip doesn't already exist if (DevFile.PartsList.Where(p => p.PartName == dev.partName).Count() == 0) { // Add a chip by template newParts.Add(NewPart24r2(DevFile, basePart, dev.partName, dev)); } } DevFile.PartsList = DevFile.PartsList.Concat(newParts).ToArray(); DevFile.Info.NumberParts += newParts.Count; }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { DevFile = new DeviceFile(); if (DevFile.LoadFromFile(openFileDialog1.FileName)) { DeviceFileLoaded(); } } }
private void DisplayScript(DeviceFile.DeviceScripts script) { int columnCount = 3; int columnWidth = dataGridViewScript.Width / columnCount; int rowCount = script.ScriptLength / columnCount; // Set up columns dataGridViewScript.ColumnCount = columnCount; dataGridViewScript.Columns[0].MinimumWidth = 80; dataGridViewScript.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; dataGridViewScript.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; dataGridViewScript.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; // Set up rows dataGridViewScript.Rows.Clear(); dataGridViewScript.RowCount = script.ScriptLength; var opcodes = script.ParseScript(); // Load the script int col = 0; int row = 0; foreach (var opcode in opcodes) { dataGridViewScript[0, row].Value = opcode; dataGridViewScript[1, row].Value = opcode.Parse(); dataGridViewScript[2, row].Value = opcode.ParseInst(); row++; } }
private void Form1_Load(object sender, EventArgs e) { DevFile = new DeviceFile(); bool result = false; result = DevFile.LoadFromFile("PK2DeviceFile.dat"); /* if (!result) result = DevFile.LoadFromFile("C:\\Program Files\\Microchip\\PICkit 2\\PK2DeviceFile.dat"); if (!result) result = DevFile.LoadFromFile("C:\\Program Files\\Microchip\\PICkit 2 v2\\PK2DeviceFile.dat"); if (!result) result = DevFile.LoadFromFile("C:\\Program Files (x86)\\Microchip\\PICkit 2\\PK2DeviceFile.dat"); if (!result) result = DevFile.LoadFromFile("C:\\Program Files (x86)\\Microchip\\PICkit 2 v2\\PK2DeviceFile.dat"); */ if (!result) { if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { result = DevFile.LoadFromFile(openFileDialog1.FileName); } } if (result) DeviceFileLoaded(); }
private void DisplayRawScript(DeviceFile.DeviceScripts script) { int columnCount = 8; int columnWidth = (dataGridHex.Width - 32) / columnCount; int rowCount = script.ScriptLength / columnCount; // Set up columns dataGridHex.ColumnCount = columnCount; for (int i = 0; i < 8; i++) { dataGridHex.Columns[i].Width = columnWidth; } // Set up rows dataGridHex.Rows.Clear(); dataGridHex.RowCount = rowCount + 1; // Load the script bytes int col = 0; int row = 0; foreach (var v in script.Script) { dataGridHex[col, row].Value = string.Format("{0:X4}", v); if (col++ == columnCount - 1) { col = 0; row++; } } }
private static void addTblScripts(DTBL tblScripts, DeviceFile.DeviceScripts[] fScripts) { System.Data.DataRow myNewRow; for (int i = 0; i < fScripts.Length; i++) { myNewRow = tblScripts.NewRow(); myNewRow["ScriptNumber"] = fScripts[i].ScriptNumber; //UInt16(); myNewRow["ScriptName"] = fScripts[i].ScriptName; //String(); myNewRow["ScriptVersion"] = fScripts[i].ScriptVersion; //UInt16(); myNewRow["UNUSED1"] = fScripts[i].UNUSED1; //UInt32(); myNewRow["ScriptLength"] = fScripts[i].ScriptLength; //UInt16(); myNewRow["Script"] = fScripts[i].Script; //Unit16[]; myNewRow["Comment"] = fScripts[i].Comment; //String(); tblScripts.Rows.Add(myNewRow); } }
private static void addTblPartsList(DTBL tblPartsList, DeviceFile.DevicePartParams[] fPartsList) { System.Data.DataRow myNewRow; for (int i = 0; i < fPartsList.Length; i++) { myNewRow = tblPartsList.NewRow(); myNewRow["PartName"] = fPartsList[i].PartName; //String(); myNewRow["Family"] = fPartsList[i].Family; //UInt16(); myNewRow["DeviceID"] = fPartsList[i].DeviceID; //UInt32(); myNewRow["ProgramMem"] = fPartsList[i].ProgramMem; //UInt32(); myNewRow["EEMem"] = fPartsList[i].EEMem; //UInt16(); myNewRow["EEAddr"] = fPartsList[i].EEAddr; //UInt32(); myNewRow["ConfigWords"] = fPartsList[i].ConfigWords; //Byte(); myNewRow["ConfigAddr"] = fPartsList[i].ConfigAddr; //UInt32(); myNewRow["UserIDWords"] = fPartsList[i].UserIDWords; //Byte(); myNewRow["UserIDAddr"] = fPartsList[i].UserIDAddr; //UInt32(); myNewRow["BandGapMask"] = fPartsList[i].BandGapMask; //UInt32(); // Init config arrays myNewRow["ConfigMasks"] = fPartsList[i].ConfigMasks; myNewRow["ConfigBlank"] = fPartsList[i].ConfigBlank; myNewRow["CPMask"] = fPartsList[i].CPMask; //UInt16(); myNewRow["CPConfig"] = fPartsList[i].CPConfig; //Byte(); myNewRow["OSSCALSave"] = fPartsList[i].OSSCALSave; //Boolean(); myNewRow["IgnoreAddress"] = fPartsList[i].IgnoreAddress; //UInt32(); myNewRow["VddMin"] = fPartsList[i].VddMin; //Single(); myNewRow["VddMax"] = fPartsList[i].VddMax; //Single(); myNewRow["VddErase"] = fPartsList[i].VddErase; //Single(); myNewRow["CalibrationWords"] = fPartsList[i].CalibrationWords; //Byte(); myNewRow["ChipEraseScript"] = fPartsList[i].ChipEraseScript; //UInt16(); myNewRow["ProgMemAddrSetScript"] = fPartsList[i].ProgMemAddrSetScript; //UInt16(); myNewRow["ProgMemAddrBytes"] = fPartsList[i].ProgMemAddrBytes; //Byte(); myNewRow["ProgMemRdScript"] = fPartsList[i].ProgMemRdScript; //UInt16(); myNewRow["ProgMemRdWords"] = fPartsList[i].ProgMemRdWords; //UInt16(); myNewRow["EERdPrepScript"] = fPartsList[i].EERdPrepScript; //UInt16(); myNewRow["EERdScript"] = fPartsList[i].EERdScript; //UInt16(); myNewRow["EERdLocations"] = fPartsList[i].EERdLocations; //UInt16(); myNewRow["UserIDRdPrepScript"] = fPartsList[i].UserIDRdPrepScript; //UInt16(); myNewRow["UserIDRdScript"] = fPartsList[i].UserIDRdScript; //UInt16(); myNewRow["ConfigRdPrepScript"] = fPartsList[i].ConfigRdPrepScript; //UInt16(); myNewRow["ConfigRdScript"] = fPartsList[i].ConfigRdScript; //UInt16(); myNewRow["ProgMemWrPrepScript"] = fPartsList[i].ProgMemWrPrepScript; //UInt16(); myNewRow["ProgMemWrScript"] = fPartsList[i].ProgMemWrScript; //UInt16(); myNewRow["ProgMemWrWords"] = fPartsList[i].ProgMemWrWords; //UInt16(); myNewRow["ProgMemPanelBufs"] = fPartsList[i].ProgMemPanelBufs; //Byte(); myNewRow["ProgMemPanelOffset"] = fPartsList[i].ProgMemPanelOffset; //UInt32(); myNewRow["EEWrPrepScript"] = fPartsList[i].EEWrPrepScript; //UInt16(); myNewRow["EEWrScript"] = fPartsList[i].EEWrScript; //UInt16(); myNewRow["EEWrLocations"] = fPartsList[i].EEWrLocations; //UInt16(); myNewRow["UserIDWrPrepScript"] = fPartsList[i].UserIDWrPrepScript; //UInt16(); myNewRow["UserIDWrScript"] = fPartsList[i].UserIDWrScript; //UInt16(); myNewRow["ConfigWrPrepScript"] = fPartsList[i].ConfigWrPrepScript; //UInt16(); myNewRow["ConfigWrScript"] = fPartsList[i].ConfigWrScript; //UInt16(); myNewRow["OSCCALRdScript"] = fPartsList[i].OSCCALRdScript; //UInt16(); myNewRow["OSCCALWrScript"] = fPartsList[i].OSCCALWrScript; //UInt16(); myNewRow["DPMask"] = fPartsList[i].DPMask; //UInt16(); myNewRow["WriteCfgOnErase"] = fPartsList[i].WriteCfgOnErase; //Boolean(); myNewRow["BlankCheckSkipUsrIDs"] = fPartsList[i].BlankCheckSkipUsrIDs; //Boolean(); myNewRow["IgnoreBytes"] = fPartsList[i].IgnoreBytes; //UInt16(); myNewRow["ChipErasePrepScript"] = fPartsList[i].ChipErasePrepScript; //UInt16(); myNewRow["BootFlash"] = fPartsList[i].BootFlash; //UInt32(); myNewRow["Config9Mask"] = fPartsList[i].Config9Mask; //UInt16(); myNewRow["Config9Blank"] = fPartsList[i].Config9Blank; //UInt16(); myNewRow["ProgMemEraseScript"] = fPartsList[i].ProgMemEraseScript; //UInt16(); myNewRow["EEMemEraseScript"] = fPartsList[i].EEMemEraseScript; //UInt16(); myNewRow["ConfigMemEraseScript"] = fPartsList[i].ConfigMemEraseScript; //UInt16(); myNewRow["reserved1EraseScript"] = fPartsList[i].reserved1EraseScript; //UInt16(); myNewRow["reserved2EraseScript"] = fPartsList[i].reserved2EraseScript; //UInt16(); myNewRow["TestMemoryRdScript"] = fPartsList[i].TestMemoryRdScript; //UInt16(); myNewRow["TestMemoryRdWords"] = fPartsList[i].TestMemoryRdWords; //UInt16(); myNewRow["EERowEraseScript"] = fPartsList[i].EERowEraseScript; //UInt16(); myNewRow["EERowEraseWords"] = fPartsList[i].EERowEraseWords; //UInt16(); myNewRow["ExportToMPLAB"] = fPartsList[i].ExportToMPLAB; //Boolean(); myNewRow["DebugHaltScript"] = fPartsList[i].DebugHaltScript; //UInt16(); myNewRow["DebugRunScript"] = fPartsList[i].DebugRunScript; //UInt16(); myNewRow["DebugStatusScript"] = fPartsList[i].DebugStatusScript; //UInt16(); myNewRow["DebugReadExecVerScript"] = fPartsList[i].DebugReadExecVerScript; //UInt16(); myNewRow["DebugSingleStepScript"] = fPartsList[i].DebugSingleStepScript; //UInt16(); myNewRow["DebugBulkWrDataScript"] = fPartsList[i].DebugBulkWrDataScript; //UInt16(); myNewRow["DebugBulkRdDataScript"] = fPartsList[i].DebugBulkRdDataScript; //UInt16(); myNewRow["DebugWriteVectorScript"] = fPartsList[i].DebugWriteVectorScript; //UInt16(); myNewRow["DebugReadVectorScript"] = fPartsList[i].DebugReadVectorScript; //UInt16(); myNewRow["DebugRowEraseScript"] = fPartsList[i].DebugRowEraseScript; //UInt16(); myNewRow["DebugRowEraseSize"] = fPartsList[i].DebugRowEraseSize; //UInt16(); myNewRow["DebugReserved5Script"] = fPartsList[i].DebugReserved5Script; //UInt16(); myNewRow["DebugReserved6Script"] = fPartsList[i].DebugReserved6Script; //UInt16(); myNewRow["DebugReserved7Script"] = fPartsList[i].DebugReserved7Script; //UInt16(); myNewRow["DebugReserved8Script"] = fPartsList[i].DebugReserved8Script; //UInt16(); myNewRow["LVPScript"] = fPartsList[i].LVPScript; //UInt16(); tblPartsList.Rows.Add(myNewRow); } }
private static void addTblFamilies(DTBL tblFamilies, DeviceFile.DeviceFamilyParams[] fFamilies) { System.Data.DataRow myNewRow; for (int i = 0; i < fFamilies.Length; i++) { myNewRow = tblFamilies.NewRow(); myNewRow["FamilyID"] = fFamilies[i].FamilyID; //UInt16(); myNewRow["FamilyType"] = fFamilies[i].FamilyType; //UInt16(); myNewRow["SearchPriority"] = fFamilies[i].SearchPriority; //UInt16(); myNewRow["FamilyName"] = fFamilies[i].FamilyName; //String(); myNewRow["ProgEntryScript"] = fFamilies[i].ProgEntryScript; //UInt16(); myNewRow["ProgExitScript"] = fFamilies[i].ProgExitScript; //UInt16(); myNewRow["ReadDevIDScript"] = fFamilies[i].ReadDevIDScript; //UInt16(); myNewRow["DeviceIDMask"] = fFamilies[i].DeviceIDMask; //UInt32(); myNewRow["BlankValue"] = fFamilies[i].BlankValue; //UInt32(); myNewRow["BytesPerLocation"] = fFamilies[i].BytesPerLocation; //Byte(); myNewRow["AddressIncrement"] = fFamilies[i].AddressIncrement; //Byte(); myNewRow["PartDetect"] = fFamilies[i].PartDetect; //Boolean(); myNewRow["ProgEntryVPPScript"] = fFamilies[i].ProgEntryVPPScript; //UInt16(); myNewRow["UNUSED1"] = fFamilies[i].UNUSED1; //UInt16(); myNewRow["EEMemBytesPerWord"] = fFamilies[i].EEMemBytesPerWord; //Byte(); myNewRow["EEMemAddressIncrement"] = fFamilies[i].EEMemAddressIncrement; //Byte(); myNewRow["UserIDHexBytes"] = fFamilies[i].UserIDHexBytes; //Byte(); myNewRow["UserIDBytes"] = fFamilies[i].UserIDBytes; //Byte(); myNewRow["ProgMemHexBytes"] = fFamilies[i].ProgMemHexBytes; //Byte(); myNewRow["EEMemHexBytes"] = fFamilies[i].EEMemHexBytes; //Byte(); myNewRow["ProgMemShift"] = fFamilies[i].ProgMemShift; //Byte(); myNewRow["TestMemoryStart"] = fFamilies[i].TestMemoryStart; //UInt32(); myNewRow["TestMemoryLength"] = fFamilies[i].TestMemoryLength; //UInt16(); myNewRow["Vpp"] = fFamilies[i].Vpp; //Single(); tblFamilies.Rows.Add(myNewRow); } }
private static void addTblInfo(DTBL tblInfo, DeviceFile.DeviceFileParams fInfo) { System.Data.DataRow myNewRow; myNewRow = tblInfo.NewRow(); myNewRow["VersionMajor"] = fInfo.VersionMajor; //Int32(); myNewRow["VersionMinor"] = fInfo.VersionMinor; //Int32(); myNewRow["VersionDot"] = fInfo.VersionDot; //Int32(); myNewRow["VersionNotes"] = fInfo.VersionNotes; //String(); myNewRow["NumberFamilies"] = fInfo.NumberFamilies; //Int32(); myNewRow["NumberParts"] = fInfo.NumberParts; //Int32(); myNewRow["NumberScripts"] = fInfo.NumberScripts; //Int32(); myNewRow["Compatibility"] = fInfo.Compatibility; //Byte(); myNewRow["UNUSED1A"] = fInfo.UNUSED1A; //Byte(); myNewRow["UNUSED1B"] = fInfo.UNUSED1B; //UInt16(); myNewRow["UNUSED2"] = fInfo.UNUSED2; //UInt32(); tblInfo.Rows.Add(myNewRow); }