public state(byte[] DataStream) { Buffer.BlockCopy(DataStream, 0, state_base_b, 0, 112); Buffer.BlockCopy(DataStream, 112, state_ext_b, 0, 96); this.state_base = new state_o(state_base_b); this.state_ext = new state_e(state_ext_b); }
public void DisplayPacket(state_e state_E) { Console.WriteLine(state_E.speed.x); Console.WriteLine(state_E.accel.p); Console.WriteLine(state_E.spare[2]); Console.WriteLine(Environment.NewLine); }
public byte[] Serialize(state_e state_E) { List <byte> DataStream = new List <byte>(); byte[] realspeed = Serialize(state_E.speed); DataStream.AddRange(realspeed); byte[] realaccel = Serialize(state_E.accel); DataStream.AddRange(realaccel); DataStream.AddRange(BitConverter.GetBytes(state_E.traveledDist)); DataStream.AddRange(BitConverter.GetBytes(state_E.spare[0])); DataStream.AddRange(BitConverter.GetBytes(state_E.spare[1])); DataStream.AddRange(BitConverter.GetBytes(state_E.spare[2])); return(DataStream.ToArray()); }
/// <summary> /// enters shift-IR state /// </summary> public void state_shiftIr() { switch (this.state) { case state_e.testLogicReset: this.TMS(data: false, nClockCycles: 5, tmsLsbFirst: 0x06, tmsFinalState: false); // TMS: 0-1-1-0-0 break; case state_e.runTestIdle: this.TMS(data: false, nClockCycles: 4, tmsLsbFirst: 0x03, tmsFinalState: false); // TMS: 1-1-0-0 break; default: throw new Exception("unsupported state transition from " + this.state); } this.state = state_e.shiftIr; }
public static byte[] CatchPacket(double simTime, UInt32 id, geo geo, coord pos, coord speed, coord accel, UInt32 counter, wheel_o[] wheel_O) { Packet pkt = new Packet(); header_m[] header_M = new header_m[4]; header_c header_C; state_o state_O = new state_o(id, 1, 1, 0x6, hp.myname, geo, pos, 0, 0, 0); state_e state_E = new state_e(speed, accel, 498.55f, hp.spare); state state = new state(state_O, state_E); header_M[3] = new header_m(0, 0, 2, 0x0000); header_M[2] = new header_m(176, 44, 14, 0x0000); header_M[1] = new header_m(208, 208, 9, 0x1); header_M[0] = new header_m(0, 0, 1, 0x0000); header_C = new header_c(448, counter, simTime); byte[] stream = pkt.FormPacketArray(header_C, header_M[0], header_M[1], state, header_M[2], wheel_O, header_M[3]); return(stream); }
public static byte[] CatchPacket(geo geo, coord pos, coord speed, coord accel, UInt32 counter) { Packet pkt = new Packet(); header_m[] header_M = new header_m[3]; state_o state_O = new state_o(3, 255, 255, 3, hp.myname, geo, pos, 3, 3, 8); state_e state_E = new state_e(speed, accel, 498.55f, hp.spare); state state = new state(state_O, state_E); header_M[2] = new header_m(0, 0, 2, 99); header_M[1] = new header_m(208 + header_M[2].headerSize, 208 + header_M[2].headerSize, 9, 99); header_M[0] = new header_m(header_M[1].headerSize + header_M[1].dataSize, header_M[1].headerSize + header_M[1].dataSize, 1, 99); header_c header_C = new header_c(header_M[0].headerSize + header_M[0].dataSize, counter); int[] lens = { (int)header_C.headerSize, (int)header_M[0].headerSize, (int)header_M[1].headerSize, (int)header_M[1].dataSize - (int)header_M[2].headerSize, (int)header_M[2].headerSize }; byte[] stream = pkt.FormPacketArray(header_C, header_M[0], header_M[1], state, header_M[2]); return(stream); }
public ppreprocessor(psource_collection_t sources, ppreprocessor_defines_map_type defines = null) { m_sources = sources; m_if_flag = 0; m_if_seen = 0; m_elif = 0; m_if_level = 0; m_state = state_e.PROCESS; m_comment = false; m_expr_sep.emplace_back("!"); m_expr_sep.emplace_back("("); m_expr_sep.emplace_back(")"); m_expr_sep.emplace_back("+"); m_expr_sep.emplace_back("-"); m_expr_sep.emplace_back("*"); m_expr_sep.emplace_back("/"); m_expr_sep.emplace_back("&&"); m_expr_sep.emplace_back("||"); m_expr_sep.emplace_back("=="); m_expr_sep.emplace_back(","); m_expr_sep.emplace_back(";"); m_expr_sep.emplace_back("."); m_expr_sep.emplace_back("##"); m_expr_sep.emplace_back("#"); m_expr_sep.emplace_back(" "); m_expr_sep.emplace_back("\t"); m_expr_sep.emplace_back("\""); if (defines != null) { m_defines = defines; } m_defines.insert("__PLIB_PREPROCESSOR__", new define_t("__PLIB_PREPROCESSOR__", "1")); var idx = m_defines.find("__PREPROCESSOR_DEBUG__"); m_debug_out = idx != default; }
/// <summary> /// enters test logic reset state from any other state by 5 consecutive 1s on TMS /// </summary> public void state_testLogicReset() { this.TMS(data: false, nClockCycles: 5, tmsLsbFirst: 0x1F, tmsFinalState: false); this.state = state_e.testLogicReset; }
/// <summary> /// write bitstream (LSB first) /// </summary> /// <param name="nBits">number of bits, e.g. nBytes x 8</param> /// <param name="data">bytestream</param> /// <param name="read">Whether to read back. Returns integer number of bytes.</param> public void rwNBits(int nBits, byte[] data, bool read) { if (nBits == 0) { return; } if (this.state != state_e.shiftDr && this.state != state_e.shiftIr) { throw new Exception("unsupported state (need shiftIr or shiftDr, got " + this.state + ")"); } nBits -= 1; // final bit raises TMS (special case) int nBytes = nBits >> 3; nBits &= 0x7; // === handle 65k blocks === int nb = nBytes; int offset = 0; while (nb > 0) { int nBlock = Math.Min(nb, 65536); // === handle 8-bit chunks === int nLow = (nBlock - 1) & 0xFF; int nHigh = (nBlock - 1) >> 8; this.tmpBuf256[0] = (byte)(read ? 0x39 : 0x19); // clock BYTES (and read) this.tmpBuf256[1] = (byte)nLow; this.tmpBuf256[2] = (byte)nHigh; this.io.wr(this.tmpBuf256, nWrite: 3); this.io.wr(data, nWrite: nBlock, nRead: read ? nBlock : 0, nOffset: offset); nb -= nBlock; offset += nBlock; } // === handle remaining bits excluding the final bit === if (nBits > 0) { this.tmpBuf256[0] = (byte)(read ? 0x3B : 0x1B); // clock BITS (and read) this.tmpBuf256[1] = (byte)(nBits - 1); this.tmpBuf256[2] = (byte)data[nBytes]; this.io.wr(this.tmpBuf256, nWrite: 3, nRead: read? 1 : 0); if (read) { this.io.addReadSel(mask: 0xFF, shift: 8 - nBits, mergeWithPrevious: false); } } // === handle final bit in parallel with the first bit of 1-1-0 on TMS to return to IDLE === this.tmpBuf256[0] = (byte)(read ? 0x6B : 0x4B); // clock TMS (and read) this.tmpBuf256[1] = 0x02; // length minus one (3 clock cycles) this.tmpBuf256[2] = (data[nBytes] & (1 << nBits)) != 0? (byte)0x83 : (byte)0x03; // data (LSB to MSB; first unused bit sets final TMS state; bit 7 sets data state) this.io.wr(this.tmpBuf256, nWrite: 3, nRead: read? 1 : 0); if (read) { this.io.addReadSel(mask: 0x20, shift: 5 - nBits, mergeWithPrevious: nBits > 0); } this.state = state_e.runTestIdle; }
protected core_terminal_t(core_device_t dev, string aname, state_e state, nldelegate delegate_) : base(dev, dev.name() + "." + aname) {
public logic_t(device_t dev, string aname, state_e terminal_state, nldelegate delegate_) : base(dev, aname, terminal_state, delegate_) { m_logic_family = dev.logic_family(); //, logic_family_t(dev.logic_family()) }
std.pair <string, bool> process_line(string line_in) { bool line_cont = plib.pg.right(line_in, 1) == "\\"; string line = line_cont ? plib.pg.left(line_in, line_in.length() - 1) : line_in; if (m_state == state_e.LINE_CONTINUATION) { m_line += line; } else { m_line = line; } if (line_cont) { m_state = state_e.LINE_CONTINUATION; return(new std.pair <string, bool>("", false)); } m_state = state_e.PROCESS; line = process_comments(m_line); string lt = plib.pg.trim(plib.pg.replace_all(line, "\t", " ")); if (plib.pg.startsWith(lt, "#")) { ppreprocessor_string_list lti = plib.pg.psplit(lt, ' ', true); if (lti[0] == "#if") { m_if_level++; m_if_seen |= (1U << m_if_level); if (m_if_flag == 0) { lt = replace_macros(lt); simple_iter t = new simple_iter(this, tokenize(lt.substr(3), m_expr_sep, true, true)); //simple_iter<ppreprocessor> t(this, tokenize(lt.substr(3), m_expr_sep, true, true)); var val = (int)prepro_expr(t, 255); t.skip_ws(); if (!t.eod()) { error("found unprocessed content at end of line"); } if (val == 0) { m_if_flag |= (1U << m_if_level); } else { m_elif |= (1U << m_if_level); } } } else if (lti[0] == "#ifdef") { m_if_level++; m_if_seen |= (1U << m_if_level); if (get_define(lti[1]) == null) { m_if_flag |= (1U << m_if_level); } else { m_elif |= (1U << m_if_level); } } else if (lti[0] == "#ifndef") { m_if_level++; m_if_seen |= (1U << m_if_level); if (get_define(lti[1]) != null) { m_if_flag |= (1U << m_if_level); } else { m_elif |= (1U << m_if_level); } } else if (lti[0] == "#else") // basically #elif (1) { if ((m_if_seen & (1U << m_if_level)) == 0) { error("#else without #if"); } if ((m_elif & (1U << m_if_level)) != 0) // elif disabled { m_if_flag |= (1U << m_if_level); } else { m_if_flag &= ~(1U << m_if_level); } m_elif |= (1U << m_if_level); } else if (lti[0] == "#elif") { if ((m_if_seen & (1U << m_if_level)) == 0) { error("#elif without #if"); } //if ((m_if_flag & (1 << m_if_level)) == 0) // m_if_flag ^= (1 << m_if_level); if ((m_elif & (1U << m_if_level)) != 0) // elif disabled { m_if_flag |= (1U << m_if_level); } else { m_if_flag &= ~(1U << m_if_level); } if (m_if_flag == 0) { //m_if_flag ^= (1 << m_if_level); lt = replace_macros(lt); simple_iter t = new simple_iter(this, tokenize(lt.substr(5), m_expr_sep, true, true)); //simple_iter<ppreprocessor> t(this, tokenize(lt.substr(5), m_expr_sep, true, true)); var val = (int)prepro_expr(t, 255); t.skip_ws(); if (!t.eod()) { error("found unprocessed content at end of line"); } if (val == 0) { m_if_flag |= (1U << m_if_level); } else { m_elif |= (1U << m_if_level); } } } else if (lti[0] == "#endif") { if ((m_if_seen & (1U << m_if_level)) == 0) { error("#else without #if"); } m_if_seen &= ~(1U << m_if_level); m_elif &= ~(1U << m_if_level); m_if_flag &= ~(1U << m_if_level); m_if_level--; } else if (lti[0] == "#include") { if (m_if_flag == 0) { string arg = ""; for (size_t i = 1; i < lti.size(); i++) { arg += (lti[i] + " "); } arg = plib.pg.trim(arg); if (plib.pg.startsWith(arg, "\"") && plib.pg.endsWith(arg, "\"")) { arg = arg.substr(1, arg.length() - 2); // first try local context var l = plib.util.buildpath(m_stack.back().m_local_path, arg); var lstrm = m_sources.get_stream(l); if (!lstrm.empty()) { m_stack.emplace_back(new input_context(lstrm, plib.util.path(l), l)); //m_stack.emplace_back(input_context(lstrm.release_stream(), plib::util::path(l), l)); } else { var strm = m_sources.get_stream(arg); if (!strm.empty()) { m_stack.emplace_back(new input_context(strm, plib.util.path(arg), arg)); //m_stack.emplace_back(input_context(strm.release_stream(), plib::util::path(arg), arg)); } else { error("include not found:" + arg); } } } else { error("include misspelled:" + arg); } string linemarker = new pfmt("# {0} \"{1}\" 1\n").op(m_stack.back().m_lineno, m_stack.back().m_name); push_out(linemarker); } } else if (lti[0] == "#pragma") { if (m_if_flag == 0 && lti.size() > 3 && lti[1] == "NETLIST") { if (lti[2] == "warning") { error("NETLIST: " + catremainder(lti, 3, " ")); } } } else if (lti[0] == "#define") { if (m_if_flag == 0) { if (lti.size() < 2) { error("define needs at least one argument"); } simple_iter args = new simple_iter(this, tokenize(lt.substr(8), m_expr_sep, false, false)); //simple_iter<ppreprocessor> args(this, tokenize(lt.substr(8), m_expr_sep, false, false)); string n = args.next(); if (!is_valid_token(n)) { error("define expected identifier"); } var prevdef = get_define(n); if (lti.size() == 2) { if (prevdef != null && !prevdef.m_replace.empty()) { error("redefinition of " + n); } m_defines.insert(n, new define_t(n, "")); } else if (args.next_ws() == "(") { define_t def = new define_t(n); def.m_has_params = true; var token = args.next(); while (true) { if (token == ")") { break; } def.m_params.push_back(token); token = args.next(); if (token != "," && token != ")") { error(new pfmt("expected , or ), found <{0}>").op(token)); } if (token == ",") { token = args.next(); } } string r = ""; while (!args.eod()) { r += args.next_ws(); } def.m_replace = r; if (prevdef != null && prevdef.m_replace != r) { error("redefinition of " + n); } m_defines.insert(n, def); } else { string r = ""; while (!args.eod()) { r += args.next_ws(); } if (prevdef != null && prevdef.m_replace != r) { error("redefinition of " + n); } m_defines.insert(n, new define_t(n, r)); } } } else if (lti[0] == "#undef") { if (m_if_flag == 0) { if (lti.size() < 2) { error("undef needs at least one argument"); } simple_iter args = new simple_iter(this, tokenize(lt.substr(7), m_expr_sep, false, false)); //simple_iter<ppreprocessor> args(this, tokenize(lt.substr(7), m_expr_sep, false, false)); string n = args.next(); if (!is_valid_token(n)) { error("undef expected identifier"); } m_defines.erase(n); } } else { if (m_if_flag == 0) { error("unknown directive"); } } return(new std.pair <string, bool>("", false)); } if (m_if_flag == 0) { return(new std.pair <string, bool>(replace_macros(lt), true)); } return(new std.pair <string, bool>("", false)); }
public state(state_o state_base, state_e state_ext) { this.state_base = state_base; this.state_ext = state_ext; }
protected analog_t(core_device_t dev, string aname, state_e state, nldelegate delegate_) : base(dev, aname, state, delegate_) { }