mirror of
https://github.com/myhdl/myhdl.git
synced 2024-12-14 07:44:38 +08:00
partial check in
This commit is contained in:
parent
42f26ccded
commit
cacdd4e884
@ -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():
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user