diff --git a/example/manual/fsm.py b/example/manual/fsm.py index eb0b4970..5cc1f01b 100644 --- a/example/manual/fsm.py +++ b/example/manual/fsm.py @@ -1,8 +1,5 @@ -from __future__ import generators - from myhdl import * -# SEARCH, CONFIRM, SYNC = range(3) ACTIVE_LOW = 0 FRAME_SIZE = 8 t_State = enum('SEARCH', 'CONFIRM', 'SYNC') @@ -21,42 +18,39 @@ def FramerCtrl(SOF, state, syncFlag, clk, reset_n): index = Signal(0) # position in frame + @always(clk.posedge, reset_n.negedge) def FSM(): - while 1: - yield posedge(clk), negedge(reset_n) - - if reset_n == ACTIVE_LOW: - SOF.next = 0 - index.next = 0 - state.next = t_State.SEARCH - - else: - index.next = (index + 1) % FRAME_SIZE - SOF.next = 0 - - if state == t_State.SEARCH: - index.next = 1 - if syncFlag: - state.next = t_State.CONFIRM - - elif state == t_State.CONFIRM: - if index == 0: - if syncFlag: - state.next = t_State.SYNC - else: - state.next = t_State.SEARCH - - elif state == t_State.SYNC: - if index == 0: - if not syncFlag: - state.next = t_State.SEARCH - SOF.next = (index == FRAME_SIZE-1) - - else: - raise ValueError("Undefined state") + if reset_n == ACTIVE_LOW: + SOF.next = 0 + index.next = 0 + state.next = t_State.SEARCH - FSM_1 = FSM() - return FSM_1 + else: + index.next = (index + 1) % FRAME_SIZE + SOF.next = 0 + + if state == t_State.SEARCH: + index.next = 1 + if syncFlag: + state.next = t_State.CONFIRM + + elif state == t_State.CONFIRM: + if index == 0: + if syncFlag: + state.next = t_State.SYNC + else: + state.next = t_State.SEARCH + + elif state == t_State.SYNC: + if index == 0: + if not syncFlag: + state.next = t_State.SEARCH + SOF.next = (index == FRAME_SIZE-1) + + else: + raise ValueError("Undefined state") + + return FSM def testbench(): diff --git a/example/manual/hello1.py b/example/manual/hello1.py index 5671cd0a..3042e856 100644 --- a/example/manual/hello1.py +++ b/example/manual/hello1.py @@ -1,8 +1,10 @@ from myhdl import Signal, delay, always, now, Simulation def HelloWorld(): + + interval = delay(10) - @always(delay(10)) + @always(interval) def sayHello(): print "%s Hello World!" % now() diff --git a/example/manual/hello2.py b/example/manual/hello2.py index 19471da8..227fb8ba 100644 --- a/example/manual/hello2.py +++ b/example/manual/hello2.py @@ -2,7 +2,9 @@ from myhdl import Signal, delay, always, now, Simulation def ClkDriver(clk): - @always(delay(10)) + halfPeriod = delay(10) + + @always(halfPeriod) def driveClk(): clk.next = not clk