/// <summary> /// Create regmap from local excel data without bitfield /// </summary> /// <param name="_dsExcel"></param> private RegisterMap CreateRegMap(DataSet _dsExcel) { RegisterMap _regmap = new RegisterMap(); ds_display.Clear(); DataTable dt = _dsExcel.Tables[regmapName]; // Get Device Address if (dt.Rows[0][0].ToString().ToUpper() == devAddrName) { this.devAddr = Convert.ToUInt32(dt.Rows[0][1].ToString().TrimStart("7'b".ToCharArray()), 2); _regmap.DevAddr = devAddr; } // judge if this is a crazy mode reg map, if crazy mode, then there is one more column for num. of bytes of 1 register if (dt.Rows[0][2].ToString().ToUpper() == devRegMode) { if (dt.Rows[0][3].ToString().ToUpper() == "CRAZY") { crazyMode = true; } } DataRowCollection drc = dt.Rows; int rowsCount = dt.Rows.Count; string regGroup = ""; string regName = ""; string regAddr = ""; string numOfBytes = ""; string defaultValue = ""; object[] items; List <object> temp_bf = new List <object> { }; int valid_count = 0; RWProperty rw = RWProperty.RW; for (int ix = 2; ix < rowsCount;) { #region normal register map if (!crazyMode) { // New reg group generated here if (drc[ix].ItemArray[(int)itemIx.regGroup].ToString() != "") { regGroup = drc[ix].ItemArray[(int)itemIx.regGroup].ToString().Replace("\n", ""); _regmap.AddGroup(regGroup); } // Get all valid bit field name and store in a long array items = drc[ix++].ItemArray; valid_count = 0; temp_bf.Clear(); for (int bit_ix = (int)itemIx.bit7; bit_ix <= (int)itemIx.bit0; bit_ix++) { if (items[bit_ix].ToString() != "") { valid_count++; temp_bf.Add(items[bit_ix]); } } if (valid_count == 0) { continue; } // copy the true valid bit field name to new bitfield name array object[] bfs = new object[valid_count]; for (int bf_ix = 0; bf_ix < valid_count; bf_ix++) { bfs[bf_ix] = temp_bf[bf_ix]; } if (items[(int)itemIx.rw].ToString() == "R") { rw = RWProperty.R; } else if (items[3].ToString() == "W") { rw = RWProperty.W; } else { rw = RWProperty.RW; } _regmap.Add(new Register(regGroup, items[(int)itemIx.regName].ToString(), items[(int)itemIx.regAddr].ToString(), rw, items[(int)itemIx.defaultRegValue].ToString(), bfs)); } #endregion #region crazy register map mode else { // New reg group generated here if (drc[ix].ItemArray[(int)itemIx_Crazy.regGroup].ToString() != "") { regGroup = drc[ix].ItemArray[(int)itemIx_Crazy.regGroup].ToString().Replace("\n", ""); _regmap.AddGroup(regGroup); } // New Reg start from here, get regName, regAddr and number of bytes if (drc[ix].ItemArray[(int)itemIx_Crazy.regName].ToString() != "") { regName = drc[ix].ItemArray[(int)itemIx_Crazy.regName].ToString(); regAddr = drc[ix].ItemArray[(int)itemIx_Crazy.regAddr].ToString(); numOfBytes = drc[ix].ItemArray[(int)itemIx_Crazy.byteCount].ToString(); defaultValue = drc[ix].ItemArray[(int)itemIx_Crazy.defaultRegValue].ToString(); } if (regName.ToUpper() == "RESERVED") { ix++; continue; } // Get all valid bit field name and store in a long array temp_bf.Clear(); valid_count = 0; do { items = drc[ix].ItemArray; for (int bit_ix = (int)itemIx_Crazy.bit7; bit_ix <= (int)itemIx_Crazy.bit0; bit_ix++) { if (items[bit_ix].ToString() != "" && items[bit_ix].ToString().ToUpper() != "RESERVED") { valid_count++; temp_bf.Add(items[bit_ix]); } } } while ((++ix < rowsCount) && (drc[ix].ItemArray[(int)itemIx_Crazy.regName].ToString() == "")); // copy the true valid bit field name to new bitfield name array object[] bfs = new object[valid_count]; for (int bf_ix = 0; bf_ix < valid_count; bf_ix++) { bfs[bf_ix] = temp_bf[bf_ix]; } if (items[(int)itemIx_Crazy.rw].ToString() == "R") { rw = RWProperty.R; } else if (items[3].ToString() == "W") { rw = RWProperty.W; } else { rw = RWProperty.RW; } _regmap.Add(new Register(regGroup, regName, regAddr, rw, numOfBytes, defaultValue, bfs)); } #endregion } return(_regmap); }