def controler(thread): print "controler:", gs.time(), "start" print "controler:", gs.time(), "waiting 5 ns to pause thread", thread.name gs.wait(5, gs.NS) print "controler:", gs.time(), "pausing thread", thread.name, "NOW!" thread.pause() print "controler:", gs.time(), "waiting 3 ns to resume thread", thread.name gs.wait(3) print "controler:", gs.time(), "resuming thread", thread.name, "NOW!" thread.resume() print "controler:", gs.time(), "waiting 5 ns to pause thread", thread.name gs.wait(5, gs.NS) print "controler:", gs.time(), "pausing thread", thread.name, "NOW!" thread.pause() print "controler:", gs.time(), "waiting 3 ns to resume thread", thread.name gs.wait(3) print "controler:", gs.time(), "resuming thread", thread.name, "NOW!" thread.resume() print "controler:", gs.time(), "waiting 10 ns to kill thread", thread.name gs.wait(10) print "controler:", gs.time(), "killing thread", thread.name, "NOW!" thread.kill()
def f(wt,nm): it = 0 while True: print nm, "reached iteration", it gs.wait(wt,gs.NS) it = it + 1 mysig.write(it)
def fork_example_args(): gs.wait(100) print "fork_example_args:", gs.time(), " start" gs.fork([counter]*4, args=[("a",9),("bb",5),(),()], keyargs=[{},{},dict(name="ccc",last=7),dict(name="dddd",last=15)]) print "fork_example_args:", gs.time(), " finish"
def producer(): print "producer:", gs.time(), "start" counter = 0 while True: print "producer:", gs.time(), "counter", counter counter += 1 gs.wait(1)
def doit(self): while True: while self.in1.num_available() < 3 and self.in2.num_available() < 3: print "adder: waiting for more numbers at input fifos (in1 has", self.in1.num_available(), "; in2 has", self.in2.num_available(), ")" gs.wait(self.in1.write_event() | self.in2.write_event()) print "adder: writing the 3 last results to output fifo" for i in range(0,3): self.out.write(self.in1.read() + self.in2.read())
def consumer(): print "consumer:", gs.time(), "start" print "consumer:", gs.time(), "read signal prod default:", prod.read() print "consumer:", gs.time(), "wait for input (write_event on prod)" gs.wait(prod.write_event()) print "consumer:", gs.time(), "read signal prod again:", prod.read() print "consumer:", gs.time(), "double the input value and write back" cons.write(prod.read() * 2) print "consumer:", gs.time(), "end"
def producer(): print "producer:", gs.time(), "start" print "producer:", gs.time(), "write 3 to prod" prod.write(3) print "producer:", gs.time(), "read signal cons default:", cons.read() print "producer:", gs.time(), "wait for reply (write_event on cons)" gs.wait(cons.write_event()) print "producer:", gs.time(), "read signal cons again:", cons.read() print "producer:", gs.time(), "end"
def sender(self): dest = gs.findReceiver("sc-bidir.sc-bidir") x = 0 while True: msg = gs.message(sender = "python", command = "test", data = x) x += 1 print " send new msg", x, "to", dest.num_free() while not dest.nb_write(msg): gs.wait(dest.data_read_event());
def doit(self): k = False while True: gs.wait(self.in1.write_event() | self.in2.write_event()) print "diff is", self.in1.read() - self.in2.read(), an_int print "->", self.h(), self.m() gs.wait(30,gs.NS) if not k: k = gs.param("another") print "-->", k()
def doit(self): k = False while True: gs.wait(self.in1.write_event() | self.in2.write_event()) print "diff is", self.in1.read() - self.in2.read(), an_int print "->", self.h(), self.m() gs.wait(30, gs.NS) if not k: k = gs.param("another") print "-->", k()
def fork_example_args(): gs.wait(100) print "fork_example_args:", gs.time(), " start" gs.fork([counter] * 4, args=[("a", 9), ("bb", 5), (), ()], keyargs=[{}, {}, dict(name="ccc", last=7), dict(name="dddd", last=15)]) print "fork_example_args:", gs.time(), " finish"
def consumer(): print "consumer:", gs.time(), "start" print "consumer:", gs.time(), "read signal prod default:", prod.read() print "consumer:", gs.time(), "wait for input (write_event on prod)" gs.wait(prod.write_event()) print "consumer:", gs.time(), "read signal prod again:", prod.read() print "consumer:", gs.time(), "double the input value and write back" cons.write(prod.read()*2) print "consumer:", gs.time(), "end"
def doit(self): print "producer:", gs.time(), "start" print "producer:", gs.time(), "write 3 to output" self.output.write(3) print "producer:", gs.time(), "read input signal:", self.input.read() print "producer:", gs.time(), "wait for reply (write_event)" gs.wait(self.input.write_event()) print "producer:", gs.time(), "read input signal again:", self.input.read() print "producer:", gs.time(), "end"
def sender(self): dest = gs.findReceiver("sc-bidir.sc-bidir") x = 0 while True: msg = gs.message(sender="python", command="test", data=x) x += 1 print " send new msg", x, "to", dest.num_free() while not dest.nb_write(msg): gs.wait(dest.data_read_event())
def doit(self): print "consumer:", gs.time(), "start" print "consumer:", gs.time(), "read input signal:", self.input.read() print "consumer:", gs.time(), "wait for input (write_event)" gs.wait(self.input.write_event()) print "consumer:", gs.time(), "read input signal again:", self.input.read() print "consumer:", gs.time(), "double the input value and write to output" self.output.write(self.input.read()*2) print "consumer:", gs.time(), "end"
def pop(self): while True: gs.wait(1.0,gs.NS) if self.nu > 0: self.nu -= 1 self.nf += 1 self.m_data_read_event.notify() if tiresome.prev["fish"] == 81: break
def doit(self): while True: while self.in1.num_available() < 3 and self.in2.num_available( ) < 3: print "adder: waiting for more numbers at input fifos (in1 has", self.in1.num_available( ), "; in2 has", self.in2.num_available(), ")" gs.wait(self.in1.write_event() | self.in2.write_event()) print "adder: writing the 3 last results to output fifo" for i in range(0, 3): self.out.write(self.in1.read() + self.in2.read())
def controler(thread): print "controler:", gs.time(), "start" print "controler:", gs.time(), "waiting 5 ns to reset thread", thread.name gs.wait(5, gs.NS) print "controler:", gs.time(), "reseting thread", thread.name, "NOW!" thread.reset() print "controler:", gs.time(), "waiting 3 ns to kill thread", thread.name gs.wait(3) print "controler:", gs.time(), "killing thread", thread.name, "NOW!" thread.kill()
def doit(self): print "producer:", gs.time(), "start" print "producer:", gs.time(), "write 3 to output" self.output.write(3) print "producer:", gs.time(), "read input signal:", self.input.read() print "producer:", gs.time(), "wait for reply (write_event)" gs.wait(self.input.write_event()) print "producer:", gs.time( ), "read input signal again:", self.input.read() print "producer:", gs.time(), "end"
def doit(self): k = False while True: gs.wait(self.in1.write_event() | self.in2.write_event()) self.out.write(self.in1.read() + self.in2.read()) print "adder out", self.out.read(), an_int gs.wait(10,gs.NS) print "->", self.h(), self.m() if not k: k = gs.param("test") print "-->", k()
def compare(self): # compare expected results for i in range(0,len(expect)): gs.wait(self.in1.write_event()) print "expected", expect[i], print "read", self.in1.read(), if expect[i] == self.in1.read(): print "(ok)" else: print "(ERROR!)"
def doit(self): k = False while True: gs.wait(self.in1.write_event() | self.in2.write_event()) self.out.write(self.in1.read() + self.in2.read()) print "adder out", self.out.read(), an_int gs.wait(10, gs.NS) print "->", self.h(), self.m() if not k: k = gs.param("test") print "-->", k()
def cons_unlim(): y = 0 while True: s = False if random.random() > 0.02: (s,x) = unlimited.nb_read() if not s: print "Read to", y gs.wait(unlimited.write_event()) else: y = x
def prod_unlim(): x = 100 while x < 1000: gs.wait(1,gs.US) nr_to_write = x + random.randint(1,50) print "P Load now", unlimited.num_available() print "Writing to", nr_to_write-1 while x < nr_to_write: unlimited.write(x) x += 1
def doit(self): print "consumer:", gs.time(), "start" print "consumer:", gs.time(), "read input signal:", self.input.read() print "consumer:", gs.time(), "wait for input (write_event)" gs.wait(self.input.write_event()) print "consumer:", gs.time( ), "read input signal again:", self.input.read() print "consumer:", gs.time( ), "double the input value and write to output" self.output.write(self.input.read() * 2) print "consumer:", gs.time(), "end"
def g(): it = 0 while True: print "faster", "reached iteration", it gs.wait(33,gs.NS) it = it + 1 print "loop starts" for i in range(40): print 'p', for j in range(1000): pass print print "signal is now", mysig.read()
def sender(self): gs.wait(10,gs.NS) print self.name(), ": sending a message" msg = gs.message() msg["command"] = "hello" msg["value"] = 2.1734 msg["reply"] = self.msg2fifo.name() msg["boolt"] = True msg["boolf"] = False ss = gs.message(hello = 10, fish = "james") msg["sub"] = ss remote = gs.findReceiver("sc-bidir.sc-bidir") remote.write(msg) print self.name(), ": waiting for messages on", self.msg2fifo.name() msg1 = self.msg2fifo.read() print self.name(), ": got a reply", msg1["command"], ". Field foo.pi =", msg1["foo.pi"]
def internal(self): gs.wait(3,gs.NS) tmp = no_process("py_no_process") tmp.debug = test_debug gs.wait(35,gs.NS) m = gs.findReceiver("gs_module.py_no_process") # can use "tmp" directly of course # for i in range(10): ms = gs.message() ms["fish"] = i*i m.nb_write(ms) gs.wait(5,gs.NS) gs.stop()
def test2(): print "test2:", gs.time(), " start" print "test2:", gs.time(), " waiting for e1" gs.wait(e1) print "test2:", gs.time(), " e1 fired" print "test2:", gs.time(), " waiting for e2" gs.wait(e2) print "test2:", gs.time(), " e2 fired" print "test2:", gs.time(), " waiting for e3" gs.wait(e3) print "test2:", gs.time(), " e3 fired" print "test2:", gs.time(), " end"
def f(): while True: print "f" gs.wait(15, gs.NS)
def f(): while True: print "f" gs.wait(15,gs.NS)
def receiver(self): while True: gs.wait(21,gs.NS); while rx.num_available() == 0: gs.wait(rx.write_event()) print "PY received msg", rx.read()["data"]
def doit(self): while True: gs.wait(self.in1.write_event() | self.in2.write_event()) self.out.write(self.in1.read() + self.in2.read())
def generate(self): # generate input for i in range(0,len(expect)): self.out1.write(gen1[i]) self.out2.write(gen2[i]) gs.wait(0)
def goon(): for i in range(4): gs.wait(25 + 25 * i, gs.NS) print gs.simulation_time()
def doit(self): while True: gs.wait(self.in1.write_event()) # avoid pending read() at the end addr = self.in1.read() self.out.write(self.MEM[addr]())
def test1(): print "test1:", gs.time(), "start" print "test1:", gs.time(), "wait for 10 default units (ns)" gs.wait(10) print "test1:", gs.time(), "notify e1 in the same delta" e1.notify() print "test1:", gs.time(), "wait for one delta" gs.wait(0) print "test1:", gs.time(), "at this delta e1 was already notified" print "test1:", gs.time(), "wait for 10 default units (ns)" gs.wait(10) print "test1:", gs.time(), "notify e2 in the next delta" e2.notify(0) print "test1:", gs.time(), "wait for one delta" gs.wait(0) print "test1:", gs.time(), "at this same delta e2 gets notified" print "test1:", gs.time(), "wait for 10 default units (ns)" gs.wait(10) print "test1:", gs.time(), "notify e3 delayed by 5 us" e3.notify(5, gs.US) print "test1:", gs.time(), "wait for 4 us" gs.wait(4, gs.US) print "test1:", gs.time(), "at this time e3 wasn't notifyed yet" print "test1:", gs.time(), "wait for 10 default units (ns)" gs.wait(10) print "test1:", gs.time(), "end"
def write(self, message): print "hey I got a message with fish =", message["fish"], blocker.prev["fish"] gs.wait(1,gs.NS) blocker.prev = message
def counter(name, last): for num in range(1, last + 1): print gs.time(), name + "\t", num if num <> last: gs.wait(1) print gs.time(), name + "\t", "finished"
def goon(): for i in range(4): gs.wait(25+25*i,gs.NS) print gs.simulation_time()
def receiver(self): while True: gs.wait(21, gs.NS) while rx.num_available() == 0: gs.wait(rx.write_event()) print "PY received msg", rx.read()["data"]
def counter(name,last): for num in range(1,last+1): print gs.time(), name+"\t", num if num <> last: gs.wait(1) print gs.time(), name+"\t", "finished"