@@ -153,11 +153,7 @@ def read(self, fsm, global_addr):
153153 if self .use_global_base_addr :
154154 global_addr = self .global_base_addr + global_addr
155155
156- ret = self .read_request (global_addr , length = 1 , cond = fsm )
157- if isinstance (ret , (tuple )):
158- ack , counter = ret
159- else :
160- ack = ret
156+ ack = self .read_request (global_addr , length = 1 , cond = fsm )
161157 fsm .If (ack ).goto_next ()
162158
163159 ret = self .read_data (cond = fsm )
@@ -177,11 +173,7 @@ def write(self, fsm, global_addr, value):
177173 if self .use_global_base_addr :
178174 global_addr = self .global_base_addr + global_addr
179175
180- ret = self .write_request (global_addr , length = 1 , cond = fsm )
181- if isinstance (ret , (tuple )):
182- ack , counter = ret
183- else :
184- ack = ret
176+ ack = self .write_request (global_addr , length = 1 , cond = fsm )
185177 fsm .If (ack ).goto_next ()
186178
187179 ret = self .write_data (value , cond = fsm )
@@ -473,7 +465,7 @@ def _synthesize_read_fsm_same(self, ram, port, ram_method, ram_datawidth):
473465 cur_global_addr , cur_size , rest_size )
474466
475467 # state 2
476- ack , counter = self .read_request (cur_global_addr , cur_size , cond = fsm )
468+ ack , counter = self .read_request_counter (cur_global_addr , cur_size , cond = fsm )
477469 fsm .If (ack ).goto_next ()
478470
479471 # state 3
@@ -611,7 +603,7 @@ def _synthesize_read_fsm_narrow(self, ram, port, ram_method, ram_datawidth):
611603 cur_global_addr , cur_size , rest_size )
612604
613605 # state 2
614- ack , counter = self .read_request (cur_global_addr , cur_size , cond = fsm )
606+ ack , counter = self .read_request_counter (cur_global_addr , cur_size , cond = fsm )
615607 fsm .If (ack ).goto_next ()
616608
617609 # state 3
@@ -772,7 +764,7 @@ def _synthesize_read_fsm_wide(self, ram, port, ram_method, ram_datawidth):
772764 last_done (0 )
773765 )
774766
775- ack , counter = self .read_request (cur_global_addr , cur_size , cond = fsm )
767+ ack , counter = self .read_request_counter (cur_global_addr , cur_size , cond = fsm )
776768 fsm .If (ack ).goto_next ()
777769
778770 # state 3
@@ -1046,7 +1038,7 @@ def _synthesize_write_fsm_same(self, ram, port, ram_method, ram_datawidth):
10461038 cur_global_addr , cur_size , rest_size )
10471039
10481040 # state 2
1049- ack , counter = self .write_request (cur_global_addr , cur_size , cond = fsm )
1041+ ack , counter = self .write_request_counter (cur_global_addr , cur_size , cond = fsm )
10501042 self .write_data_counter = counter
10511043 fsm .If (ack ).goto_next ()
10521044
@@ -1190,7 +1182,7 @@ def _synthesize_write_fsm_narrow(self, ram, port, ram_method, ram_datawidth):
11901182 cur_global_addr , cur_size , rest_size )
11911183
11921184 # state 2
1193- ack , counter = self .write_request (cur_global_addr , cur_size , cond = fsm )
1185+ ack , counter = self .write_request_counter (cur_global_addr , cur_size , cond = fsm )
11941186 fsm .If (ack ).goto_next ()
11951187
11961188 # state 3
@@ -1375,7 +1367,7 @@ def _synthesize_write_fsm_wide(self, ram, port, ram_method, ram_datawidth):
13751367 cur_global_addr , cur_size , rest_size )
13761368
13771369 # state 2
1378- ack , counter = self .write_request (cur_global_addr , cur_size , cond = fsm )
1370+ ack , counter = self .write_request_counter (cur_global_addr , cur_size , cond = fsm )
13791371 fsm .If (ack ).goto_next ()
13801372
13811373 # state 3
@@ -1568,11 +1560,7 @@ def read(self, fsm, global_addr):
15681560 if self .use_global_base_addr :
15691561 global_addr = self .global_base_addr + global_addr
15701562
1571- ret = self .read_request (global_addr , length = 1 , cond = fsm )
1572- if isinstance (ret , (tuple )):
1573- ack , counter = ret
1574- else :
1575- ack = ret
1563+ ack = self .read_request (global_addr , length = 1 , cond = fsm )
15761564 fsm .If (ack ).goto_next ()
15771565
15781566 ret = self .read_data (cond = fsm )
@@ -1592,11 +1580,7 @@ def write(self, fsm, global_addr, value):
15921580 if self .use_global_base_addr :
15931581 global_addr = self .global_base_addr + global_addr
15941582
1595- ret = self .write_request (global_addr , length = 1 , cond = fsm )
1596- if isinstance (ret , (tuple )):
1597- ack , counter = ret
1598- else :
1599- ack = ret
1583+ ack = self .write_request (global_addr , length = 1 , cond = fsm )
16001584 fsm .If (ack ).goto_next ()
16011585
16021586 ret = self .write_data (value , cond = fsm )
@@ -2069,11 +2053,13 @@ def __init__(self, m, name, clk, rst, datawidth=32, addrwidth=32,
20692053 self .read_narrow_pack_counts = OrderedDict () # key: pack_size
20702054 self .read_narrow_data_wires = OrderedDict () # key: pack_size
20712055 self .read_narrow_valid_wires = OrderedDict () # key: pack_size
2056+ self .read_narrow_rest_size_wires = OrderedDict () # key: pack_size
20722057
20732058 self .read_wide_fsms = OrderedDict () # key: pack_size
20742059 self .read_wide_pack_counts = OrderedDict () # key: pack_size
20752060 self .read_wide_data_wires = OrderedDict () # key: pack_size
20762061 self .read_wide_valid_wires = OrderedDict () # key: pack_size
2062+ self .read_wide_rest_size_wires = OrderedDict () # key: pack_size
20772063
20782064 def read (self , fsm ):
20792065 data , last , _id , user , dest , valid = self .read_data (cond = fsm )
@@ -2330,7 +2316,7 @@ def _synthesize_read_fsm_same(self, ram, port, ram_method, ram_datawidth):
23302316 rest_size .dec ()
23312317 )
23322318
2333- fsm .If (valid , vtypes . Ors ( rest_size <= 1 , last ) ).goto_next ()
2319+ fsm .If (valid , rest_size <= 1 ).goto_next ()
23342320
23352321 for _ in range (self .num_data_delay ):
23362322 fsm .goto_next ()
@@ -2393,7 +2379,7 @@ def _synthesize_read_fsm_narrow(self, ram, port, ram_method, ram_datawidth):
23932379 wvalid (0 ),
23942380 pack_count .inc ()
23952381 )
2396- fsm .If (valid_cond , vtypes . Ors ( pack_count == pack_size - 1 , last ) )(
2382+ fsm .If (valid_cond , pack_count == pack_size - 1 )(
23972383 wdata (vtypes .Cat (data , wdata [self .datawidth :ram_datawidth ])),
23982384 wvalid (1 ),
23992385 pack_count (0 )
@@ -2451,7 +2437,7 @@ def _synthesize_read_fsm_narrow(self, ram, port, ram_method, ram_datawidth):
24512437 wvalid (0 ),
24522438 pack_count .inc ()
24532439 )
2454- fsm .If (valid_cond , vtypes . Ors ( pack_count == pack_size - 1 , last ) )(
2440+ fsm .If (valid_cond , pack_count == pack_size - 1 )(
24552441 wdata (vtypes .Cat (data , wdata [self .datawidth :ram_datawidth ])),
24562442 wvalid (1 ),
24572443 pack_count (0 )
@@ -2460,7 +2446,7 @@ def _synthesize_read_fsm_narrow(self, ram, port, ram_method, ram_datawidth):
24602446 rest_size .dec ()
24612447 )
24622448
2463- fsm .If (valid , vtypes . Ors ( rest_size <= 1 , last ) ).goto_next ()
2449+ fsm .If (valid , rest_size <= 1 ).goto_next ()
24642450
24652451 for _ in range (self .num_data_delay ):
24662452 fsm .goto_next ()
@@ -2572,7 +2558,7 @@ def _synthesize_read_fsm_wide(self, ram, port, ram_method, ram_datawidth):
25722558 self .read_wide_pack_counts [pack_size ] = pack_count
25732559
25742560 cond = vtypes .Ands (fsm .here , pack_count == 0 )
2575- data , last , _id , user , dest , valid = self .read_data (cond = fsm )
2561+ data , last , _id , user , dest , valid = self .read_data (cond = cond )
25762562 self .read_wide_data_wires [pack_size ] = data
25772563 self .read_wide_valid_wires [pack_size ] = valid
25782564
@@ -2602,12 +2588,11 @@ def _synthesize_read_fsm_wide(self, ram, port, ram_method, ram_datawidth):
26022588 pack_count (0 )
26032589 )
26042590
2605- fsm .If (valid_cond )(
2591+ fsm .If (pack_count == 0 , valid_cond )(
26062592 rest_size .dec ()
26072593 )
26082594
2609- fsm .If (pack_count == pack_size - 1 ,
2610- vtypes .Ors (rest_size == 0 , wlast )).goto_next ()
2595+ fsm .If (pack_count == pack_size - 1 , rest_size == 0 ).goto_next ()
26112596
26122597 for _ in range (self .num_data_delay ):
26132598 fsm .goto_next ()
@@ -3378,7 +3363,7 @@ def _get_write_op_id(self, ram, port, ram_method):
33783363 return op_id
33793364
33803365
3381- class AXIM_AXIStreamIn (AXIM ):
3366+ class AXIM_for_AXIStreamIn (AXIM ):
33823367
33833368 def __init__ (self , streamin , name ,
33843369 waddr_id_width = 0 , wdata_id_width = 0 , wresp_id_width = 0 ,
@@ -3561,9 +3546,15 @@ def _synthesize_read_fsm(self):
35613546 cur_global_addr , cur_size , rest_size )
35623547
35633548 # state 2
3564- ack , counter = self .read_request (cur_global_addr , cur_size , cond = fsm )
3565- fsm .If (ack , rest_size > 0 ).goto (check_state )
3566- fsm .If (ack , rest_size == 0 ).goto_next ()
3549+ ack = self .read_request (cur_global_addr , cur_size , cond = fsm )
3550+ fsm .If (ack ).goto_next ()
3551+
3552+ accept = vtypes .Ands (self .raddr .arvalid , self .raddr .arready )
3553+ fsm .If (accept )(
3554+ cur_global_addr .add (optimize (cur_size * (self .datawidth // 8 )))
3555+ )
3556+ fsm .If (accept , rest_size > 0 ).goto (check_state )
3557+ fsm .If (accept , rest_size == 0 ).goto_next ()
35673558
35683559 for _ in range (self .num_data_delay ):
35693560 fsm .goto_next ()
@@ -3577,7 +3568,7 @@ def _synthesize_read_fsm(self):
35773568 fsm .goto_init ()
35783569
35793570
3580- class AXIM_AXIStreamOut (AXIM ):
3571+ class AXIM_for_AXIStreamOut (AXIM ):
35813572
35823573 def __init__ (self , streamout , name ,
35833574 waddr_id_width = 0 , wdata_id_width = 0 , wresp_id_width = 0 ,
@@ -3768,7 +3759,7 @@ def _synthesize_write_fsm(self):
37683759 cur_global_addr , cur_size , rest_size )
37693760
37703761 # state 2
3771- ack , counter = self .write_request (cur_global_addr , cur_size , cond = fsm )
3762+ ack , counter = self .write_request_counter (cur_global_addr , cur_size , cond = fsm )
37723763 self .write_data_counter = counter
37733764 fsm .If (ack ).goto_next ()
37743765
@@ -3793,6 +3784,114 @@ def _synthesize_write_fsm(self):
37933784 fsm .goto_init ()
37943785
37953786
3787+ class AXIM2 (AXIM_for_AXIStreamIn ):
3788+
3789+ def __init__ (self , m , name , clk , rst , datawidth = 32 , addrwidth = 32 ,
3790+ waddr_id_width = 0 , wdata_id_width = 0 , wresp_id_width = 0 ,
3791+ raddr_id_width = 0 , rdata_id_width = 0 ,
3792+ waddr_user_width = 2 , wdata_user_width = 0 , wresp_user_width = 0 ,
3793+ raddr_user_width = 2 , rdata_user_width = 0 ,
3794+ waddr_burst_mode = axi .BURST_INCR , raddr_burst_mode = axi .BURST_INCR ,
3795+ waddr_cache_mode = axi .AxCACHE_NONCOHERENT , raddr_cache_mode = axi .AxCACHE_NONCOHERENT ,
3796+ waddr_prot_mode = axi .AxPROT_NONCOHERENT , raddr_prot_mode = axi .AxPROT_NONCOHERENT ,
3797+ waddr_user_mode = axi .AxUSER_NONCOHERENT , wdata_user_mode = axi .xUSER_DEFAULT ,
3798+ raddr_user_mode = axi .AxUSER_NONCOHERENT ,
3799+ noio = False ,
3800+ enable_async = True , use_global_base_addr = False ,
3801+ num_cmd_delay = 0 , num_data_delay = 0 ,
3802+ op_sel_width = 8 , fsm_as_module = False ):
3803+
3804+ streamin = AXIStreamIn (m , '_' .join (['' , name , 'streamin' ]), clk , rst , datawidth , addrwidth ,
3805+ with_last = True ,
3806+ id_width = rdata_id_width , user_width = rdata_user_width , dest_width = 0 ,
3807+ noio = True ,
3808+ enable_async = enable_async ,
3809+ num_cmd_delay = num_cmd_delay , num_data_delay = num_data_delay ,
3810+ op_sel_width = op_sel_width , fsm_as_module = fsm_as_module )
3811+
3812+ AXIM .__init__ (self , m , name , clk , rst , datawidth , addrwidth ,
3813+ waddr_id_width , wdata_id_width , wresp_id_width ,
3814+ raddr_id_width , rdata_id_width ,
3815+ waddr_user_width , wdata_user_width , wresp_user_width ,
3816+ raddr_user_width , rdata_user_width ,
3817+ waddr_burst_mode , raddr_burst_mode ,
3818+ waddr_cache_mode , raddr_cache_mode ,
3819+ waddr_prot_mode , raddr_prot_mode ,
3820+ waddr_user_mode , wdata_user_mode ,
3821+ raddr_user_mode ,
3822+ noio ,
3823+ enable_async , use_global_base_addr ,
3824+ num_cmd_delay , num_data_delay ,
3825+ op_sel_width , fsm_as_module )
3826+
3827+ self .streamin = streamin
3828+ self .streamin .connect_master_rdata (self )
3829+
3830+ def dma_read (self , fsm , ram , local_addr , global_addr , size ,
3831+ local_stride = 1 , port = 0 , ram_method = None ):
3832+
3833+ if ram_method is None :
3834+ ram_method = getattr (ram , 'write_dataflow' )
3835+
3836+ ram_method_name = (ram_method .func .__name__
3837+ if isinstance (ram_method , functools .partial ) else
3838+ ram_method .__name__ )
3839+ ram_datawidth = (ram .datawidth if ram_method is None else
3840+ ram .orig_datawidth if 'bcast' in ram_method_name else
3841+ ram .orig_datawidth if 'block' in ram_method_name else
3842+ ram .datawidth )
3843+
3844+ if ram_datawidth == self .datawidth :
3845+ dma_size = size
3846+ elif ram_datawidth > self .datawidth :
3847+ pack_size = ram_datawidth // self .datawidth
3848+ dma_size = (size << int (math .log (pack_size , 2 ))
3849+ if math .log (pack_size , 2 ) % 1.0 == 0.0 else
3850+ size * pack_size )
3851+ else :
3852+ pack_size = self .datawidth // ram_datawidth
3853+ shamt = int (math .log (pack_size , 2 ))
3854+ res = vtypes .Mux (
3855+ vtypes .And (size , 2 ** shamt - 1 ) > 0 , 1 , 0 )
3856+ dma_size = (size >> shamt ) + res
3857+
3858+ AXIM_for_AXIStreamIn .dma_read_async (self , fsm , global_addr , dma_size )
3859+ self .streamin .read_stream (fsm , ram , local_addr , size ,
3860+ local_stride , port , ram_method )
3861+
3862+ def dma_read_async (self , fsm , ram , local_addr , global_addr , size ,
3863+ local_stride = 1 , port = 0 , ram_method = None ):
3864+
3865+ if ram_method is None :
3866+ ram_method = getattr (ram , 'write_dataflow' )
3867+
3868+ ram_method_name = (ram_method .func .__name__
3869+ if isinstance (ram_method , functools .partial ) else
3870+ ram_method .__name__ )
3871+ ram_datawidth = (ram .datawidth if ram_method is None else
3872+ ram .orig_datawidth if 'bcast' in ram_method_name else
3873+ ram .orig_datawidth if 'block' in ram_method_name else
3874+ ram .datawidth )
3875+
3876+ if ram_datawidth == self .datawidth :
3877+ dma_size = size
3878+ elif ram_datawidth > self .datawidth :
3879+ pack_size = ram_datawidth // self .datawidth
3880+ dma_size = (size << int (math .log (pack_size , 2 ))
3881+ if math .log (pack_size , 2 ) % 1.0 == 0.0 else
3882+ size * pack_size )
3883+ else :
3884+ pack_size = self .datawidth // ram_datawidth
3885+ shamt = int (math .log (pack_size , 2 ))
3886+ res = vtypes .Mux (
3887+ vtypes .And (size , 2 ** shamt - 1 ) > 0 , 1 , 0 )
3888+ dma_size = (size >> shamt ) + res
3889+
3890+ AXIM_for_AXIStreamIn .dma_read_async (self , fsm , global_addr , dma_size )
3891+ self .streamin .read_stream_async (fsm , ram , local_addr , size ,
3892+ local_stride , port , ram_method )
3893+
3894+
37963895def add_mux (targ , cond , value ):
37973896 prev_assign = targ ._get_assign ()
37983897 if not prev_assign :
0 commit comments