private void CreateBF_DT_Crazy(RegisterMap _regMap) { DataTableCollection allDT = ds_excel.Tables; DataTable tempDT, desc_DT = null; for (int ix = 0; ix < _regMap.GroupCount; ix++) { // Get the sheet with register group name foreach (DataTable dt in allDT) { Console.WriteLine(dt.TableName); if (dt.TableName.ToUpper().Contains(_regMap.GetGroupName(ix).ToUpper())) { desc_DT = dt; break; } } ds_display.Tables.Add(new DataTable(_regMap.GetGroupName(ix))); //Create new data table for GUI display tempDT = ds_display.Tables[ds_display.Tables.Count - 1]; tempDT.Columns.Add("ADDR(Hex)"); tempDT.Columns.Add("BIT"); tempDT.Columns.Add("Name"); tempDT.Columns.Add("BFValue(Hex)"); tempDT.Columns.Add("RegValue(Hex)"); DataRowCollection drc = desc_DT.Rows; int rowsCount = desc_DT.Rows.Count; int bfAddedCount = 0; Register tempReg = null; BitField tempBF; object[] tempRowItems; for (int ix_row = 1; ix_row < rowsCount; ix_row++) { tempRowItems = drc[ix_row].ItemArray; // New reg start from here if (tempRowItems[(int)itemIx_BF_Crazy.regName].ToString() != "") { // Judge if last register's bf all initialized if (tempReg != null) { if (tempReg.BFCount > bfAddedCount) { MessageBox.Show("Register 0x" + tempReg.RegAddress.ToString("X2") + " has some bit fields doesn't initialized in description sheet"); } else if (tempReg.BFCount < bfAddedCount) { MessageBox.Show("Register 0x" + tempReg.RegAddress.ToString("X2") + " bit field count less than in description sheet"); } } bfAddedCount = 0; tempReg = _regMap[tempRowItems[(int)itemIx_BF_Crazy.regName].ToString()]; // Just for regmap debugging if (tempReg == null) { MessageBox.Show("Register " + tempRowItems[(int)itemIx_BF_Crazy.regAddr].ToString() + " name mismatched in regmap and description sheet"); continue; } // Add row for register: RegAddress, "", RegName,"", RegValue if (tempReg.DisplayRegValueCell) { tempDT.Rows.Add(new object[] { tempReg.RegAddress.ToString("X2"), "", tempReg.RegName, "", "" }); //if use byte array, no reg data displayed on GUI } else { tempDT.Rows.Add(new object[] { tempReg.RegAddress.ToString("X2"), "", tempReg.RegName, "", tempReg.RegValueString }); } } if (tempReg == null) { continue; } if (tempRowItems[(int)itemIx_BF_Crazy.bfName].ToString() == "" || tempRowItems[(int)itemIx_BF_Crazy.bfName].ToString() == "RESERVED") { continue; } tempBF = tempReg[tempRowItems[(int)itemIx_BF_Crazy.bfName].ToString()]; // just for regmap Debugging if (tempBF == null) { MessageBox.Show("Can't find " + tempRowItems[(int)itemIx_BF_Crazy.bfName].ToString() + " in register 0x" + tempReg.RegAddress.ToString("X2")); continue; } // Initialize bit field bfAddedCount++; if (tempReg.ByteCount <= 4) { tempBF.InitiBF(tempReg, tempRowItems[(int)itemIx_BF_Crazy.bit].ToString(), tempReg.ByteCount, tempRowItems[(int)itemIx_BF_Crazy.bfName].ToString(), tempRowItems[(int)itemIx_BF_Crazy.Description].ToString().Replace("\n", "\r\n"), tempReg.RegValueString); } else { tempBF.InitiBF(tempReg, tempRowItems[(int)itemIx_BF_Crazy.bit].ToString(), tempReg.ByteCount, tempRowItems[(int)itemIx_BF_Crazy.bfName].ToString(), tempRowItems[(int)itemIx_BF_Crazy.Description].ToString().Replace("\n", "\r\n"), tempRowItems[(int)itemIx_BF_Crazy.DefaultBFValue].ToString()); } // Add row for bitfield: "", BIT, Name, BFValue, "" tempDT.Rows.Add(new object[] { "", tempRowItems[(int)itemIx_BF_Crazy.bit].ToString(), tempRowItems[(int)itemIx_BF_Crazy.bfName].ToString(), tempBF.BFValueString, "" }); } } }
private void CreateBF_DT(RegisterMap _regMap) { DataTableCollection allDT = ds_excel.Tables; DataTable tempDT, desc_DT = null; for (int ix = 0; ix < _regMap.GroupCount; ix++) { // Get the sheet with register group name foreach (DataTable dt in allDT) { Console.WriteLine(dt.TableName); if (dt.TableName.ToUpper().Contains(_regMap.GetGroupName(ix).ToUpper())) { desc_DT = dt; break; } } ds_display.Tables.Add(new DataTable(_regMap.GetGroupName(ix))); //Create new data table for GUI display tempDT = ds_display.Tables[ds_display.Tables.Count - 1]; tempDT.Columns.Add("ADDR(Hex)"); tempDT.Columns.Add("BIT"); tempDT.Columns.Add("Name"); tempDT.Columns.Add("BFValue(Hex)"); tempDT.Columns.Add("RegValue(Hex)"); DataRowCollection drc = desc_DT.Rows; int rowsCount = desc_DT.Rows.Count; Register tempReg = null; BitField tempBF; object[] tempRowItems; for (int ix_row = 1; ix_row < rowsCount; ix_row++) { tempRowItems = drc[ix_row].ItemArray; // New reg start from here if (tempRowItems[(int)itemIx_BF.regName].ToString() != "") { tempReg = _regMap[tempRowItems[(int)itemIx_BF.regName].ToString()]; // Add row for register: RegAddress, "", RegName,"", RegValue tempDT.Rows.Add(new object[] { tempReg.RegAddress.ToString("X2"), "", tempReg.RegName, "", tempReg.RegValueString }); } if (tempReg == null) { continue; } if (tempRowItems[(int)itemIx_BF.bfName].ToString() == "") { continue; } tempBF = tempReg[tempRowItems[(int)itemIx_BF.bfName].ToString()]; // Initialize bit field tempBF.InitiBF(tempReg, tempRowItems[(int)itemIx_BF.bit].ToString(), tempReg.ByteCount, tempRowItems[(int)itemIx_BF.bfName].ToString(), tempRowItems[(int)itemIx_BF.Description].ToString().Replace("\n", "\r\n"), tempReg.RegValueString); // Add row for bitfield: "", BIT, Name, BFValue, "" tempDT.Rows.Add(new object[] { "", tempRowItems[(int)itemIx_BF.bit].ToString(), tempRowItems[(int)itemIx_BF.bfName].ToString(), tempBF.BFValueString, "" }); } } }