77#-------------------------------------------------------------------------------
88# BRAM interface
99#-------------------------------------------------------------------------------
10- class BramInterface (Interface ):
11- def __init__ (self , m , prefix = '' , postfix = '' , addrwidth = 10 , datawidth = 32 , direction = 'in ' ):
12- Interface .__init__ (self , m , prefix , postfix )
10+ class BramInterface (lib . Interface ):
11+ def __init__ (self , m , prefix = '' , postfix = '' , addrwidth = 10 , datawidth = 32 , direction = 'child ' ):
12+ lib . Interface .__init__ (self , m , prefix , postfix )
1313
14- if direction != 'in ' and direction != 'out ' :
15- raise ValueError ("direction should be 'in or 'out ''" )
14+ if direction != 'child ' and direction != 'parent ' :
15+ raise ValueError ("direction should be 'in or 'parent ''" )
1616 self .direction = direction
1717
1818 self .addrwidth = self .Parameter ('ADDR_WIDTH' , addrwidth )
1919 self .datawidth = self .Parameter ('DATA_WIDTH' , datawidth )
2020
21- In = self .Input if self .direction == 'in ' else self .Reg # self.Wire
22- Out = self .Output if self .direction == 'in ' else self .Wire
21+ In = self .Input if self .direction == 'child ' else self .Reg # self.Wire
22+ Out = self .Output if self .direction == 'child ' else self .Wire
2323
2424 self .addr = In ('addr' , addrwidth )
2525 self .datain = In ('datain' , datawidth )
2626 self .write = In ('write' )
2727 self .dataout = Out ('dataout' , datawidth )
28-
28+
29+ def init (self ):
30+ if self .direction == 'parent' :
31+ return self .addr (0 ), self .datain (0 ), self .write (0 )
32+ raise Exception ("init() is not allowed." )
33+
2934#-------------------------------------------------------------------------------
3035# BRAM module
3136#-------------------------------------------------------------------------------
@@ -36,7 +41,7 @@ def mkBram(name):
3641 datawidth = m .Parameter ('DATA_WIDTH' , 32 )
3742
3843 clk = m .Input ('CLK' )
39- bramif = BramInterface (m , addrwidth = addrwidth , datawidth = datawidth , direction = 'in ' )
44+ bramif = BramInterface (m , addrwidth = addrwidth , datawidth = datawidth , direction = 'child ' )
4045
4146 d_addr = m .Reg ('d_' + bramif .addr .name , datawidth )
4247 mem = m .Reg ('mem' , datawidth , Int (2 )** addrwidth )
@@ -61,7 +66,7 @@ def mkTop():
6166 rst = m .Input ('RST' )
6267
6368 bramif = BramInterface (m , prefix = 'bram_' ,
64- addrwidth = addrwidth , datawidth = datawidth , direction = 'out ' )
69+ addrwidth = addrwidth , datawidth = datawidth , direction = 'parent ' )
6570
6671 params = collections .OrderedDict ()
6772 params .update (bramif .connect_all_parameters ())
@@ -76,7 +81,7 @@ def mkTop():
7681 fsm = lib .FSM (m , 'fsm' )
7782 init = fsm .get_index ()
7883
79- fsm ( bramif .addr ( 0 ), bramif . datain ( 0 ), bramif . write ( 0 ), fsm .next () )
84+ fsm ( bramif .init ( ), fsm .next () )
8085 first = fsm .get_index ()
8186
8287 fsm ( bramif .datain (bramif .datain + 4 ), fsm .next () )
0 commit comments