x393_mcntrl_tests.py 50.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
from __future__ import print_function
'''
# Copyright (C) 2015, Elphel.inc.
# Methods that mimic Verilog tasks used for simulation  
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http:#www.gnu.org/licenses/>.

@author:     Andrey Filippov
@copyright:  2015 Elphel, Inc.
@license:    GPLv3.0+
@contact:    andrey@elphel.coml
@deffield    updated: Updated
'''
__author__ = "Andrey Filippov"
__copyright__ = "Copyright 2015, Elphel, Inc."
__license__ = "GPL"
__version__ = "3.0+"
__maintainer__ = "Andrey Filippov"
__email__ = "andrey@elphel.com"
__status__ = "Development"
from x393_mem                import X393Mem
32
import x393_axi_control_status
33 34 35
from x393_pio_sequences      import X393PIOSequences
from x393_mcntrl_timing      import X393McntrlTiming
from x393_mcntrl_buffers     import X393McntrlBuffers
36
from verilog_utils import concat,convert_w32_to_mem16 #, getParWidth
37
import vrlg
38
import x393_mcntrl
39 40 41 42 43 44 45 46 47 48 49 50 51
class X393McntrlTests(object):
    DRY_MODE= True # True
    DEBUG_MODE=1
    x393_mem=None
    x393_axi_tasks=None #x393X393AxiControlStatus
    x393_pio_sequences=None
    x393_mcntrl_timing=None
    x393_mcntrl_buffers=None
    verbose=1
    def __init__(self, debug_mode=1,dry_mode=True):
        self.DEBUG_MODE=  debug_mode
        self.DRY_MODE=    dry_mode
        self.x393_mem=            X393Mem(debug_mode,dry_mode)
52
        self.x393_axi_tasks=x393_axi_control_status.X393AxiControlStatus(debug_mode,dry_mode)
53 54 55
        self.x393_pio_sequences=  X393PIOSequences(debug_mode,dry_mode)
        self.x393_mcntrl_timing=  X393McntrlTiming(debug_mode,dry_mode)
        self.x393_mcntrl_buffers= X393McntrlBuffers(debug_mode,dry_mode)
56
#        self.x393_mcntrl_adjust=  X393McntrlAdjust(debug_mode,dry_mode)
57
        try:
58
            self.verbose=vrlg.VERBOSE
59 60
        except:
            pass
61
    '''
62 63 64 65 66 67 68 69
    def func_encode_mode_tiled(self,         # function [6:0] 
                               byte32,       # input       byte32; # 32-byte columns (0 - 16-byte columns)
                               keep_open,    # input       keep_open; # for 8 or less rows - do not close page between accesses
                               extra_pages,  # input [1:0] extra_pages; # number of extra pages that need to stay (not to be overwritten) in the buffer
                                             # can be used for overlapping tile read access
                               write_mem,    # input       write_mem;   # write to memory mode (0 - read from memory)
                               enable,       # input       enable;      # enable requests from this channel ( 0 will let current to finish, but not raise want/need)
                               chn_reset):   # input       chn_reset;       # immediately reset all the internal circuitry
70 71 72 73 74 75 76 77 78 79 80
        """
        Combines arguments to create a 7-bit encoded data for tiled mode memory R/W
        <byte32>        use 32-byte wide columns (0 - use 16-byte ones)
        <keep_open>,    do not close page between accesses (for 8 or less rows only)
        <extra_pages>,  2-bit number of extra pages that need to stay (not to be overwritten) in the buffer
                        This argument can be used for  read access with horizontal overlapping tiles
        <write_mem>,    write to memory mode (0 - read from memory)
        <enable>,       enable requests from this channel ( 0 will let current to finish, but not raise want/need)
        <chn_reset>):   immediately reset all the internal circuitry
        
        """
Andrey Filippov's avatar
Andrey Filippov committed
81
        return concat ((
82 83 84 85 86
                       ((0,1)[byte32],   1), # byte32,
                       ((0,1)[keep_open],1), # keep_open,
                       (extra_pages,     2), # extra_pages,
                       ((0,1)[write_mem],1), # write_mem,
                       ((0,1)[enable],   1), #enable,
87
                       ((1,0)[chn_reset],1)))[0]# ~chn_reset};
88 89 90 91 92 93 94

    def func_encode_mode_scanline(self,      # function [4:0] 
                               extra_pages,  # input [1:0] extra_pages; # number of extra pages that need to stay (not to be overwritten) in the buffer
                                             # can be used for overlapping tile read access
                               write_mem,    # input       write_mem;   # write to memory mode (0 - read from memory)
                               enable,       # input       enable;      # enable requests from this channel ( 0 will let current to finish, but not raise want/need)
                               chn_reset):   # input       chn_reset;       # immediately reset all the internal circuitry
95 96 97 98 99 100 101 102 103
        """
        Combines arguments to create a 5-bit encoded data for scanline mode memory R/W
        <extra_pages>,  2-bit number of extra pages that need to stay (not to be overwritten) in the buffer
                        This argument can be used for  read access with horizontal overlapping tiles
        <write_mem>,    write to memory mode (0 - read from memory)
        <enable>,       enable requests from this channel ( 0 will let current to finish, but not raise want/need)
        <chn_reset>):   immediately reset all the internal circuitry
        
        """
104
        return concat ((
105 106 107
                       (extra_pages,     2), # extra_pages,
                       ((0,1)[write_mem],1), # write_mem,
                       ((0,1)[enable],   1), #enable,
108
                       ((1,0)[chn_reset],1)))[0] # ~chn_reset};
109
    '''    
110
    def test_write_levelling(self,
111 112 113 114
                            dqs_odly= None,
                            wbuf_dly = None,
                            wait_complete=1, # Wait for operation to complete
                            quiet=0):       
115 116
        """
        Test write levelling mode 
117 118 119 120
        <dqs_dly>  DQS output delay for write levelling mode. If it is not None,
                   the default DQS output delay will be restored in the end
        <wbuf_dly> Write buffer latency (currently 9)  If it is not None,
                   the default wbuf delay will be restored in the end
121
        <wait_complete> wait write levelling operation to complete (0 - may initiate multiple PS PIO operations)
122 123
        <quiet>    reduce output
        returns a pair of ratios for getting "1" for 2 lanes and problem marker (should be 0)
124
        """
125 126
        self.x393_pio_sequences.set_write_lev(16) # write leveling, 16 times   (full buffer - 128) 

127 128 129 130 131 132 133 134
        if not dqs_odly is None:
            self.x393_mcntrl_timing.axi_set_dqs_odelay(dqs_odly)
# Set write buffer (from DDR3) WE signal delay for write leveling mode
        if not wbuf_dly is None:
            self.x393_mcntrl_timing.axi_set_wbuf_delay(wbuf_dly)
            
        rslt= self.x393_pio_sequences.write_levelling(
                     wait_complete,
135
                     16, # number of 8-bursts
136 137 138 139
                     quiet)
        #restore values to defaults (only if changed)
        if not dqs_odly is None:
            self.x393_mcntrl_timing.axi_set_dqs_odelay()
140
# Set write buffer (from DDR3) WE signal delay for write leveling mode
141 142 143 144
        if not wbuf_dly is None:
            self.x393_mcntrl_timing.axi_set_wbuf_delay()
#        if quiet <2:
#            print ("WLEV lanes ratios: %f %f, non 0x00/0x01 bytes: %f"%(rslt[0],rslt[1],rslt[2]))   
145 146 147
        return rslt
   
    def test_read_pattern(self,
148 149 150
                          dq_idelay=None,
                          dqs_idelay=None,
                          wait_complete=1): # Wait for operation to complete
151
        """
152 153 154
        Test read pattern mode
        <dq_idelay>  set DQ input delays if provided ([] - skip, single number - both lanes, 2 element list - per/lane)
        <dqs_idelay> set DQS input delays if provided ([] - skip, single number - both lanes, 2 element list - per/lane)
155 156 157
        <wait_complete> wait read pattern operation to complete (0 - may initiate multiple PS PIO operations)
        returns list of the read data
        """
158 159 160 161 162 163 164 165
        if (not dq_idelay is None) and (dq_idelay != []):
            self.x393_mcntrl_timing.axi_set_dq_idelay(dq_idelay)
        if (not dqs_idelay is None) and (dqs_idelay != []):
            self.x393_mcntrl_timing.axi_set_dqs_idelay(dqs_idelay)
        return self.x393_pio_sequences.read_pattern(
                     32, # num
                     1, # show_rslt,
                     wait_complete) #  # Wait for operation to complete
166
    def test_write_block(self,
167 168 169
                         dq_odelay=None,
                         dqs_odelay=None,
                         wait_complete=1): # Wait for operation to complete
170 171
        """
        Test write block in PS PIO mode 
172 173
        <dq_odelay>  set DQ output delays if provided ([] - skip, single number - both lanes, 2 element list - per/lane)
        <dqs odelay> set DQS output delays if provided ([] - skip, single number - both lanes, 2 element list - per/lane)
174 175
        <wait_complete> wait write block operation to complete (0 - may initiate multiple PS PIO operations)
        """
176 177 178 179
        if (not dq_odelay is None) and (dq_odelay != []):
            self.x393_mcntrl_timing.axi_set_dq_odelay(dq_odelay)
        if (not dqs_odelay is None) and (dqs_odelay != []):
            self.x393_mcntrl_timing.axi_set_dqs_odelay(dqs_odelay)
180
        return self.x393_pio_sequences.write_block(0,wait_complete) # Wait for operation to complete
181 182

    def test_read_block(self,
183 184 185
                        dq_idelay=None,
                        dqs_idelay=None,
                        wait_complete=1): # Wait for operation to complete
186 187
        """
        Test read block in PS PIO mode 
188 189
        <dq_idelay>  set DQ input delays if provided ([] - skip, single number - both lanes, 2 element list - per/lane)
        <dqs_idelay> set DQS input delays if provided ([] - skip, single number - both lanes, 2 element list - per/lane)
190 191 192
        <wait_complete> wait read block operation to complete (0 - may initiate multiple PS PIO operations)
        returns list of the read data
        """
193 194 195 196
        if (not dq_idelay is None) and (dq_idelay != []):
            self.x393_mcntrl_timing.axi_set_dq_idelay(dq_idelay)
        if (not dqs_idelay is None) and (dqs_idelay != []):
            self.x393_mcntrl_timing.axi_set_dqs_idelay(dqs_idelay)
197
        rd_buf = self.x393_pio_sequences.read_block(
198
                     256,           # num,
199
                     0,             # show_rslt,
200
                     wait_complete) # Wait for operation to complete
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
        sum_rd_buf=0
        for d in rd_buf:
            sum_rd_buf+=d
        print("read buffer: (0x%x):"%sum_rd_buf)
        for i in range(len(rd_buf)):
            if (i & 0xf) == 0:
                print("\n%03x:"%i,end=" ")
            print("%08x"%rd_buf[i],end=" ")
        print("\n")        
        return rd_buf
        
    def test_read_block16(self,
                        dq_idelay=None,
                        dqs_idelay=None,
                        wait_complete=1): # Wait for operation to complete
        """
        Test read block in PS PIO mode, convert data to match DDR3 16-bit output words  
        <dq_idelay>  set DQ input delays if provided ([] - skip, single number - both lanes, 2 element list - per/lane)
        <dqs_idelay> set DQS input delays if provided ([] - skip, single number - both lanes, 2 element list - per/lane)
        <wait_complete> wait read block operation to complete (0 - may initiate multiple PS PIO operations)
        returns list of the read data
        """
        if (not dq_idelay is None) and (dq_idelay != []):
            self.x393_mcntrl_timing.axi_set_dq_idelay(dq_idelay)
        if (not dqs_idelay is None) and (dqs_idelay != []):
            self.x393_mcntrl_timing.axi_set_dqs_idelay(dqs_idelay)
        rd_buf = self.x393_pio_sequences.read_block(
                     256,           # num,
                     0,             # show_rslt,
                     wait_complete) # Wait for operation to complete
231
        read16=convert_w32_to_mem16(rd_buf) # 512x16 bit, same as DDR3 DQ over time
232 233 234 235 236 237 238 239 240 241
        sum_read16=0
        for d in read16:
            sum_read16+=d
        print("read16 (0x%x):"%sum_read16)
        for i in range(len(read16)):
            if (i & 0x1f) == 0:
                print("\n%03x:"%i,end=" ")
            print("%04x"%read16[i],end=" ")
        print("\n")
        return read16
242
        
243 244 245 246 247 248 249 250
    def test_scanline_write(self, #
                            channel,       # input            [3:0] channel;
                            extra_pages,   # input            [1:0] extra_pages;
                            wait_done,     # input                  wait_done;
                            window_width,  # input [15:0]           window_width;
                            window_height, # input [15:0]           window_height;
                            window_left,   # input [15:0]           window_left;
                            window_top):   # input [15:0]           window_top;
251 252 253 254 255 256 257 258 259 260
        """
        Test scanline write (frame size/row increment is set in parameters) 
        <channel> channel number to use. Valid values: 1, 3
        <extra_pages>    2-bit number of extra pages that need to stay (not to be overwritten) in the buffer
        <wait_done>      for operation finished
        <window_width>   13-bit window width in 8-bursts (16 bytes)
        <window_height>  16 bit window height
        <window_left>,   13-bit window left margin in 8-bursts (16 bytes)
        <window_top>     16-bit window top margin
        """
261 262
#   integer startx,starty; # temporary - because of the vdt bug with integer ports
#        pages_per_row= (window_width>>NUM_XFER_BITS)+((window_width[NUM_XFER_BITS-1:0]==0)?0:1);
263
        pages_per_row= (window_width>>vrlg.NUM_XFER_BITS)+(1,0)[(window_width & ((1<<vrlg.NUM_XFER_BITS))-1)==0] # (window_width>>NUM_XFER_BITS)+((window_width[NUM_XFER_BITS-1:0]==0)?0:1);
264 265
        print("====== test_scanline_write: channel=%d, extra_pages=%d,  wait_done=%d"%
                                                (channel,    extra_pages,     wait_done))
266
        '''
267
        if   channel == 1:
268 269 270 271
            start_addr=             vrlg.MCNTRL_SCANLINE_CHN1_ADDR
            status_address=         vrlg.MCNTRL_TEST01_STATUS_REG_CHN1_ADDR
            status_control_address= vrlg.MCNTRL_TEST01_ADDR + vrlg.MCNTRL_TEST01_CHN1_STATUS_CNTRL
            test_mode_address=      vrlg.MCNTRL_TEST01_ADDR + vrlg.MCNTRL_TEST01_CHN1_MODE
272 273
        '''            
        if channel ==  3:
274 275 276 277
            start_addr=             vrlg.MCNTRL_SCANLINE_CHN3_ADDR
            status_address=         vrlg.MCNTRL_TEST01_STATUS_REG_CHN3_ADDR
            status_control_address= vrlg.MCNTRL_TEST01_ADDR + vrlg.MCNTRL_TEST01_CHN3_STATUS_CNTRL
            test_mode_address=      vrlg.MCNTRL_TEST01_ADDR + vrlg.MCNTRL_TEST01_CHN3_MODE
278
        else:
279
            print("**** ERROR: Invalid channel, only 3 is valid")
280
            start_addr=             vrlg.MCNTRL_SCANLINE_CHN1_ADDR
281 282 283
            status_address=         vrlg.MCNTRL_TEST01_STATUS_REG_CHN3_ADDR
            status_control_address= vrlg.MCNTRL_TEST01_ADDR + vrlg.MCNTRL_TEST01_CHN3_STATUS_CNTRL
            test_mode_address=      vrlg.MCNTRL_TEST01_ADDR + vrlg.MCNTRL_TEST01_CHN3_MODE
284

285
        '''
286 287 288 289 290
        mode=   self.func_encode_mode_scanline(
                    extra_pages,
                    1,  # write_mem,
                    1,  # enable
                    0)  # chn_reset
291 292
        '''
        mode=   x393_mcntrl.func_encode_mode_scan_tiled(
293
                                   skip_too_late = False,
294 295 296
                                   disable_need = False,
                                   repetitive=    True,
                                   single =       False,
297
                                   reset_frame =  True, # False,
298 299 300
                                   extra_pages =  extra_pages,
                                   write_mem =    True,
                                   enable =       True,
301 302
                                   chn_reset =    False,
                                   abort_late =   False)
303 304
            
                                
305 306 307 308 309 310 311
        self.x393_axi_tasks.write_control_register(start_addr + vrlg.MCNTRL_SCANLINE_MODE, 0); # reset channel, including page address
        self.x393_axi_tasks.write_control_register(start_addr + vrlg.MCNTRL_SCANLINE_STARTADDR,        vrlg.FRAME_START_ADDRESS); # RA=80, CA=0, BA=0 22-bit frame start address (3 CA LSBs==0. BA==0) 
        self.x393_axi_tasks.write_control_register(start_addr + vrlg.MCNTRL_SCANLINE_FRAME_FULL_WIDTH, vrlg.FRAME_FULL_WIDTH);
        self.x393_axi_tasks.write_control_register(start_addr + vrlg.MCNTRL_SCANLINE_WINDOW_WH,        (window_height<<16) | window_width); #WINDOW_WIDTH + (WINDOW_HEIGHT<<16));
        self.x393_axi_tasks.write_control_register(start_addr + vrlg.MCNTRL_SCANLINE_WINDOW_X0Y0,      (window_top<<16) | window_left); #WINDOW_X0+ (WINDOW_Y0<<16));
        self.x393_axi_tasks.write_control_register(start_addr + vrlg.MCNTRL_SCANLINE_WINDOW_STARTXY,   vrlg.SCANLINE_STARTX+(vrlg.SCANLINE_STARTY<<16));
        self.x393_axi_tasks.write_control_register(start_addr + vrlg.MCNTRL_SCANLINE_MODE,             mode); 
312 313 314
        self.x393_axi_tasks.configure_channel_priority(channel,0);    # lowest priority channel 3
#        enable_memcntrl_channels(16'h000b); # channels 0,1,3 are enabled
        self.x393_axi_tasks.enable_memcntrl_en_dis(channel,1);
315
        self.x393_axi_tasks.write_control_register(test_mode_address,            vrlg.TEST01_START_FRAME);
316
        for ii in range(0,vrlg.TEST_INITIAL_BURST): # for (ii=0;ii<TEST_INITIAL_BURST;ii=ii+1) begin
317 318 319
# VDT bugs: 1:does not propagate undefined width through ?:, 2: - does not allow to connect it to task integer input, 3: shows integer input width as 1
            if   pages_per_row > 1:
                if (ii % pages_per_row) < (pages_per_row-1):
320
                    xfer_size= 1 << vrlg.NUM_XFER_BITS
321
                else:
322
                    xfer_size= window_width % (1<<vrlg.NUM_XFER_BITS)
323 324 325 326
            else:
                xfer_size= window_width & 0xffff
                
            print("########### test_scanline_write block %d: channel=%d"%(ii, channel));
327
            startx=window_left + ((ii % pages_per_row) << vrlg.NUM_XFER_BITS)
328 329 330 331 332 333 334 335 336
            starty=window_top + (ii / pages_per_row);
            self.x393_mcntrl_buffers.write_block_scanline_chn(
                                                              channel,
                                                              (ii & 3),
                                                              xfer_size,
                                                              startx,    #window_left + ((ii % pages_per_row)<<NUM_XFER_BITS),  # SCANLINE_CUR_X,
                                                              starty)    # window_top + (ii / pages_per_row)); # SCANLINE_CUR_Y);\
            
        for ii in range(window_height * pages_per_row): # for (ii=0;ii< (window_height * pages_per_row) ;ii = ii+1) begin # here assuming 1 page per line
337
            if (ii >= vrlg.TEST_INITIAL_BURST):         #  begin # wait page ready and fill page after first 4 are filled
338 339 340
                self.x393_axi_tasks.wait_status_condition (
                                                           status_address,                   # MCNTRL_TEST01_STATUS_REG_CHN3_ADDR,
                                                           status_control_address,           # MCNTRL_TEST01_ADDR + MCNTRL_TEST01_CHN3_STATUS_CNTRL,
341 342
                                                           vrlg.DEFAULT_STATUS_MODE,
                                                           (ii-vrlg.TEST_INITIAL_BURST)<<16, # 4-bit page number
343 344
                                                           0xf << 16,                        #'hf << 16,  # mask for the 4-bit page number
                                                           1,                                # not equal to
345
                                                           (0,1)[ii == vrlg.TEST_INITIAL_BURST]) # synchronize sequence number - only first time, next just wait fro auto update
346 347
                if   pages_per_row > 1:
                    if (ii % pages_per_row) < (pages_per_row-1):
348
                        xfer_size= 1 << vrlg.NUM_XFER_BITS
349
                    else:
350
                        xfer_size= window_width % (1<<vrlg.NUM_XFER_BITS)
351 352 353 354
                else:
                    xfer_size= window_width & 0xffff
                    
                print("########### test_scanline_write block %d: channel=%d"%(ii, channel));
355
                startx=window_left + ((ii % pages_per_row) << vrlg.NUM_XFER_BITS);
356 357 358 359 360 361 362
                starty=window_top + (ii / pages_per_row);
                self.x393_mcntrl_buffers.write_block_scanline_chn(
                                                                  channel,
                                                                  (ii & 3),
                                                                  xfer_size,
                                                                  startx,  # window_left + ((ii % pages_per_row)<<NUM_XFER_BITS),  # SCANLINE_CUR_X,
                                                                  starty) # window_top + (ii / pages_per_row)); # SCANLINE_CUR_Y);
363
            self.x393_axi_tasks.write_control_register(test_mode_address,            vrlg.TEST01_NEXT_PAGE)
364 365 366 367
        if wait_done:
            self.x393_axi_tasks.wait_status_condition ( # may also be read directly from the same bit of mctrl_linear_rw (address=5) status
                                                        status_address, # MCNTRL_TEST01_STATUS_REG_CHN3_ADDR,
                                                        status_control_address, # MCNTRL_TEST01_ADDR + MCNTRL_TEST01_CHN3_STATUS_CNTRL,
368 369 370
                                                        vrlg.DEFAULT_STATUS_MODE,
                                                        2 << vrlg.STATUS_2LSB_SHFT, # bit 24 - busy, bit 25 - frame done
                                                        2 << vrlg.STATUS_2LSB_SHFT,  # mask for the 4-bit page number
371 372 373 374 375 376 377 378 379 380 381
                                                        0, # equal to
                                                        0); # no need to synchronize sequence number
#     enable_memcntrl_en_dis(channel,0); # disable channel

    def test_scanline_read(self, # SuppressThisWarning VEditor - may be unused
                            channel,       # input            [3:0] channel;
                            extra_pages,   # input            [1:0] extra_pages;
                            show_data,     # input                  extra_pages;
                            window_width,  # input [15:0]           window_width;
                            window_height, # input [15:0]           window_height;
                            window_left,   # input [15:0]           window_left;
382 383 384
                            window_top,    # input [15:0]           window_top;
                            frame_start_addr = 0x0, # 1000,
                            frame_full_width = 0xc0):
385 386
        """
        Test scanline read (frame size/row increment is set in parameters) 
387 388
        @param channel channel number to use. Valid values: 1, 3
        @param extra_pages    2-bit number of extra pages that need to stay (not to be overwritten) in the buffer
389
        @param show_data      print read data 
390 391 392 393
        @param window_width   13-bit window width in 8-bursts (16 bytes)
        @param window_height  16 bit window height
        @param window_left,   13-bit window left margin in 8-bursts (16 bytes)
        @param window_top     16-bit window top margin
394 395
        @param frame_start_addr - frame start address (was 0x1000)
        @param frame_full_width - frame full width in bursts (16 bytes) - was 0xc0
396
        @return read data as list
397
        """
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
        if show_data==2:
            result=self.test_scanline_read (channel = channel,       # input            [3:0] channel;
                                            extra_pages = extra_pages,   # input            [1:0] extra_pages;
                                            show_data = 0,     # input                  extra_pages;
                                            window_width = window_width,  # input [15:0]           window_width;
                                            window_height = window_height, # input [15:0]           window_height;
                                            window_left = window_left,   # input [15:0]           window_left;
                                            window_top = window_top)
            for line_no,line in enumerate(result):
                print("%03x:"%(line_no),end=" ")
                for i in range(len(line)//2):
                    d = line[2*i] + (line[2*i+1] << 32)
                    print("%16x"%(d),end=" ")
                print()    
            return result
413
        
414 415 416
        result=[] # will be a 2-d array
    
#        pages_per_row= (window_width>>NUM_XFER_BITS)+((window_width[NUM_XFER_BITS-1:0]==0)?0:1);
417
        pages_per_row= (window_width>>vrlg.NUM_XFER_BITS)+(1,0)[(window_width & ((1<<vrlg.NUM_XFER_BITS))-1)==0] # (window_width>>NUM_XFER_BITS)+((window_width[NUM_XFER_BITS-1:0]==0)?0:1);
418 419 420

        print("====== test_scanline_read: channel=%d, extra_pages=%d,  show_data=%d"%
                                             (channel,    extra_pages,     show_data))
421
        '''
422
        if   channel == 1:
423 424 425 426
            start_addr=             vrlg.MCNTRL_SCANLINE_CHN1_ADDR
            status_address=         vrlg.MCNTRL_TEST01_STATUS_REG_CHN1_ADDR
            status_control_address= vrlg.MCNTRL_TEST01_ADDR + vrlg.MCNTRL_TEST01_CHN1_STATUS_CNTRL
            test_mode_address=      vrlg.MCNTRL_TEST01_ADDR + vrlg.MCNTRL_TEST01_CHN1_MODE
427 428
        '''
        if channel == 3:
429 430 431 432
            start_addr=             vrlg.MCNTRL_SCANLINE_CHN3_ADDR
            status_address=         vrlg.MCNTRL_TEST01_STATUS_REG_CHN3_ADDR
            status_control_address= vrlg.MCNTRL_TEST01_ADDR + vrlg.MCNTRL_TEST01_CHN3_STATUS_CNTRL
            test_mode_address=      vrlg.MCNTRL_TEST01_ADDR + vrlg.MCNTRL_TEST01_CHN3_MODE
433
        else:
434
            print("**** ERROR: Invalid channel, only 3 is valid")
435
            start_addr=             vrlg.MCNTRL_SCANLINE_CHN3_ADDR
436 437 438
            status_address=         vrlg.MCNTRL_TEST01_STATUS_REG_CHN3_ADDR
            status_control_address= vrlg.MCNTRL_TEST01_ADDR + vrlg.MCNTRL_TEST01_CHN3_STATUS_CNTRL
            test_mode_address=      vrlg.MCNTRL_TEST01_ADDR + vrlg.MCNTRL_TEST01_CHN3_MODE
439
        '''    
440 441 442 443 444
        mode=   self.func_encode_mode_scanline(
                                               extra_pages,
                                               0, # write_mem,
                                               1, # enable
                                               0)  # chn_reset
445 446
        '''
        mode=   x393_mcntrl.func_encode_mode_scan_tiled(
447
                                   skip_too_late = False,
448 449 450
                                   disable_need = False,
                                   repetitive=    True,
                                   single =       False,
451
                                   reset_frame =  True, # False,
452 453 454
                                   extra_pages =  extra_pages,
                                   write_mem =    False,
                                   enable =       True,
455 456
                                   chn_reset =    False,
                                   abort_late =   False)
457
            
458
# program to the
459
        self.x393_axi_tasks.write_control_register(start_addr + vrlg.MCNTRL_SCANLINE_MODE, 0); # reset channel, including page address
460 461
        self.x393_axi_tasks.write_control_register(start_addr + vrlg.MCNTRL_SCANLINE_STARTADDR,        frame_start_addr); # RA=80, CA=0, BA=0 22-bit frame start address (3 CA LSBs==0. BA==0) 
        self.x393_axi_tasks.write_control_register(start_addr + vrlg.MCNTRL_SCANLINE_FRAME_FULL_WIDTH, frame_full_width);
462 463 464 465
        self.x393_axi_tasks.write_control_register(start_addr + vrlg.MCNTRL_SCANLINE_WINDOW_WH,        (window_height << 16) | window_width); #WINDOW_WIDTH + (WINDOW_HEIGHT<<16));
        self.x393_axi_tasks.write_control_register(start_addr + vrlg.MCNTRL_SCANLINE_WINDOW_X0Y0,      (window_top    << 16) | window_left); #WINDOW_X0+ (WINDOW_Y0<<16));
        self.x393_axi_tasks.write_control_register(start_addr + vrlg.MCNTRL_SCANLINE_WINDOW_STARTXY,   vrlg.SCANLINE_STARTX+(vrlg.SCANLINE_STARTY<<16));
        self.x393_axi_tasks.write_control_register(start_addr + vrlg.MCNTRL_SCANLINE_MODE,             mode);# set mode register: {extra_pages[1:0],enable,!reset}
466 467
        self.x393_axi_tasks.configure_channel_priority(channel,0);    # lowest priority channel 3
        self.x393_axi_tasks.enable_memcntrl_en_dis(channel,1);
468
        self.x393_axi_tasks.write_control_register(test_mode_address,            vrlg.TEST01_START_FRAME);
469 470 471
        for ii in range(window_height * pages_per_row): # for (ii=0;ii<(window_height * pages_per_row);ii = ii+1) begin
            if   pages_per_row > 1:
                if (ii % pages_per_row) < (pages_per_row-1):
472
                    xfer_size= 1 << vrlg.NUM_XFER_BITS
473
                else:
474
                    xfer_size= window_width % (1<<vrlg.NUM_XFER_BITS)
475 476 477 478 479
            else:
                xfer_size= window_width & 0xffff
            self.x393_axi_tasks.wait_status_condition (
                                                       status_address, #MCNTRL_TEST01_STATUS_REG_CHN2_ADDR,
                                                       status_control_address, # MCNTRL_TEST01_ADDR + MCNTRL_TEST01_CHN2_STATUS_CNTRL,
480
                                                       vrlg.DEFAULT_STATUS_MODE,
481 482 483
                                                       (ii) << 16, # -TEST_INITIAL_BURST)<<16, # 4-bit page number
                                                       0xf << 16, #'hf << 16,  # mask for the 4-bit page number
                                                       1, # not equal to
484 485
                                                       (0,1)[ii == 0]) # synchronize sequence number - only first time, next just wait for auto update
            # read block (if needed), for now just skip  
486 487 488 489 490 491
            if (show_data): 
                print("########### test_scanline_read block %d: channel=%d"%(ii, channel));
            result.append(self.x393_mcntrl_buffers.read_block_buf_chn (
                                                                       channel,
                                                                       (ii & 3),
                                                                       xfer_size <<2,
492
#                                                                       1, # chn=0, page=3, number of 32-bit words=256, show_rslt
493
                                                                       show_data))
494
            self.x393_axi_tasks.write_control_register(test_mode_address,            vrlg.TEST01_NEXT_PAGE)
495 496
        return result    

497
  
498 499 500 501 502 503 504 505 506 507 508 509 510
    def test_tiled_write(self,          #
                         channel,       # input            [3:0] channel;
                         byte32,        # input                  byte32;
                         keep_open,     # input                  keep_open;
                         extra_pages,   # input            [1:0] extra_pages;
                         wait_done,     # input                  wait_done;
                         window_width,  # input [15:0]           window_width;
                         window_height, # input [15:0]           window_height;
                         window_left,   # input [15:0]           window_left;
                         window_top,    # input [15:0]           window_top;
                         tile_width,    # input [ 7:0]           tile_width;
                         tile_height,   # input [ 7:0]           tile_height;
                         tile_vstep):   # input [ 7:0]           tile_vstep;
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526
        """
        Test tiled mode write (frame size/row increment is set in parameters) 
        <channel> channel number to use. Valid values: 2, 4
        <byte32>        use 32-byte wide columns (0 - use 16-byte ones)
        <keep_open>,    do not close page between accesses (for 8 or less rows only)
        <extra_pages>    2-bit number of extra pages that need to stay (not to be overwritten) in the buffer
        <wait_done>      wait for operation finished
        <window_width>   13-bit window width in 8-bursts (16 bytes)
        <window_height>  16 bit window height
        <window_left>,   13-bit window left margin in 8-bursts (16 bytes)
        <window_top>     16-bit window top margin
        <tile_width>     6-bit tile width in 8-bursts (16 bytes) (0 -> 64)
        <tile_height>    6-bit tile_height (0->64)
        <tile_vstep>     6-bit tile vertical step (0->64) to control tole vertical overlap
        """
        
527 528 529 530 531 532 533 534 535 536 537
#        tiles_per_row= (window_width/tile_width)+  ((window_width % tile_width==0)?0:1);
        tiles_per_row= (window_width/tile_width)+  (0,1)[(window_width % tile_width)==0]
        tile_rows_per_window= ((window_height-1)/tile_vstep) + 1
        tile_size= tile_width*tile_height;
        channel=   (0,1)[channel]
        keep_open= (0,1)[keep_open]
        wait_done= (0,1)[wait_done]
        
        print("====== test_tiled_write: channel=%d, byte32=%d, keep_open=%d, extra_pages=%d,  wait_done=%d"%
                                           (channel,    byte32,    keep_open,    extra_pages,     wait_done))
        if   channel == 2:
538 539 540 541
            start_addr=             vrlg.MCNTRL_TILED_CHN2_ADDR
            status_address=         vrlg.MCNTRL_TEST01_STATUS_REG_CHN2_ADDR
            status_control_address= vrlg.MCNTRL_TEST01_ADDR + vrlg.MCNTRL_TEST01_CHN2_STATUS_CNTRL
            test_mode_address=      vrlg.MCNTRL_TEST01_ADDR + vrlg.MCNTRL_TEST01_CHN2_MODE
542
        elif channel == 4:
543 544 545 546
            start_addr=             vrlg.MCNTRL_TILED_CHN4_ADDR;
            status_address=         vrlg.MCNTRL_TEST01_STATUS_REG_CHN4_ADDR;
            status_control_address= vrlg.MCNTRL_TEST01_ADDR + vrlg.MCNTRL_TEST01_CHN4_STATUS_CNTRL;
            test_mode_address=      vrlg.MCNTRL_TEST01_ADDR + vrlg.MCNTRL_TEST01_CHN4_MODE;
547 548
        else:
            print("**** ERROR: Invalid channel, only 2 and 4 are valid");
549 550 551 552
            start_addr=             vrlg.MCNTRL_TILED_CHN2_ADDR;
            status_address=         vrlg.MCNTRL_TEST01_STATUS_REG_CHN2_ADDR;
            status_control_address= vrlg.MCNTRL_TEST01_ADDR + vrlg.MCNTRL_TEST01_CHN2_STATUS_CNTRL;
            test_mode_address=      vrlg.MCNTRL_TEST01_ADDR + vrlg.MCNTRL_TEST01_CHN2_MODE;
553
        '''    
554 555 556 557 558 559 560
        mode=   self.func_encode_mode_tiled(
                                            byte32,
                                            keep_open,
                                            extra_pages,
                                            1,           # write_mem,
                                            1,           # enable
                                            0)           # chn_reset
561 562
        '''
        mode=   x393_mcntrl.func_encode_mode_scan_tiled(
563
                                   skip_too_late = False,
564 565 566
                                   disable_need = False,
                                   repetitive=    True,
                                   single =       False,
567
                                   reset_frame =  True, # False,
568 569 570 571 572
                                   byte32 =       byte32,
                                   keep_open =    keep_open,
                                   extra_pages =  extra_pages,
                                   write_mem =    True,
                                   enable =       True,
573 574
                                   chn_reset =    False,
                                   abort_late =   False)
575
                                                        
576 577
        self.x393_axi_tasks.write_control_register(start_addr + vrlg.MCNTRL_TILED_MODE, 0); # reset channel, including page address
        self.x393_axi_tasks.write_control_register(start_addr + vrlg.MCNTRL_TILED_STARTADDR,
578
                                                  vrlg.FRAME_START_ADDRESS) # RA=80, CA=0, BA=0 22-bit frame start address (3 CA LSBs==0. BA==0) 
579
        self.x393_axi_tasks.write_control_register(start_addr + vrlg.MCNTRL_TILED_FRAME_FULL_WIDTH,
580
                                                  vrlg.FRAME_FULL_WIDTH)
581
        self.x393_axi_tasks.write_control_register(start_addr + vrlg.MCNTRL_TILED_WINDOW_WH,
Andrey Filippov's avatar
Andrey Filippov committed
582
                                                  concat(((window_height,16),
583
                                                          (window_width, 16)))[0]) # {window_height,window_width});
584
        self.x393_axi_tasks.write_control_register(start_addr + vrlg.MCNTRL_TILED_WINDOW_X0Y0,
Andrey Filippov's avatar
Andrey Filippov committed
585
                                                  concat(((window_top,  16),
586
                                                          (window_left, 16)))[0])  #  {window_top,window_left});
587
        self.x393_axi_tasks.write_control_register(start_addr + vrlg.MCNTRL_TILED_WINDOW_STARTXY,
588
                                                  concat(((vrlg.TILED_STARTY, 16),
589
                                                          (vrlg.TILED_STARTX, 16)))[0])  #  TILED_STARTX+(TILED_STARTY<<16));
590
        self.x393_axi_tasks.write_control_register(start_addr + vrlg.MCNTRL_TILED_TILE_WHS,
Andrey Filippov's avatar
Andrey Filippov committed
591 592
                                                  concat(((tile_vstep, 8),
                                                          (tile_height, 8),
593
                                                          (tile_width, 8)))[0]) # {8'b0,tile_vstep,tile_height,tile_width});#tile_width+(tile_height<<8)+(tile_vstep<<16));
594
        self.x393_axi_tasks.write_control_register(start_addr + vrlg.MCNTRL_TILED_MODE, mode);# set mode register: {extra_pages[1:0],enable,!reset}
595 596
        self.x393_axi_tasks.configure_channel_priority(channel,0)    # lowest priority channel 3
        self.x393_axi_tasks.enable_memcntrl_en_dis(channel,1);
597
        self.x393_axi_tasks.write_control_register(test_mode_address,            vrlg.TEST01_START_FRAME);
598
    
599
        for ii in range(vrlg.TEST_INITIAL_BURST): # for (ii=0;ii<TEST_INITIAL_BURST;ii=ii+1) begin
600 601 602 603 604 605 606 607 608 609 610
            print("########### test_tiled_write block %d: channel=%d"%( ii, channel))
            startx = window_left + ((ii % tiles_per_row) * tile_width)
            starty = window_top + (ii / tile_rows_per_window)         # SCANLINE_CUR_Y);
            self.x393_mcntrl_buffers.write_block_scanline_chn( # TODO: Make a different tile buffer data, matching the order
                                                               channel, # channel
                                                               (ii & 3),
                                                               tile_size,
                                                               startx, #window_left + ((ii % tiles_per_row) * tile_width),
                                                               starty); #window_top + (ii / tile_rows_per_window)); # SCANLINE_CUR_Y);\
    
        for ii in range(tiles_per_row * tile_rows_per_window): # for (ii=0;ii<(tiles_per_row * tile_rows_per_window);ii = ii+1) begin
611
            if ii >= vrlg.TEST_INITIAL_BURST: # ) begin # wait page ready and fill page after first 4 are filled
612 613 614
                self.x393_axi_tasks.wait_status_condition (
                                                           status_address,                   # MCNTRL_TEST01_STATUS_REG_CHN5_ADDR,
                                                           status_control_address,           # MCNTRL_TEST01_ADDR + MCNTRL_TEST01_CHN5_STATUS_CNTRL,
615 616
                                                           vrlg.DEFAULT_STATUS_MODE,
                                                           (ii-vrlg.TEST_INITIAL_BURST)<<16, # 4-bit page number
617 618
                                                           0xf << 16,                        # 'hf << 16,  # mask for the 4-bit page number
                                                           1,                                # not equal to
619
                                                           (0,1)[ii == vrlg.TEST_INITIAL_BURST]); # synchronize sequence number - only first time, next just wait fro auto update
620 621 622 623 624 625 626 627 628
                print("########### test_tiled_write block %d: channel=%d"%(ii, channel))
                startx = window_left + ((ii % tiles_per_row) * tile_width);
                starty = window_top + (ii / tile_rows_per_window);
                self.x393_mcntrl_buffers.write_block_scanline_chn( # TODO: Make a different tile buffer data, matching the order
                                                                   channel,  # channel
                                                                   (ii & 3),
                                                                   tile_size,
                                                                   startx,   # window_left + ((ii % tiles_per_row) * tile_width),
                                                                   starty)   # window_top + (ii / tile_rows_per_window)); # SCANLINE_CUR_Y);\
629
            self.x393_axi_tasks.write_control_register(test_mode_address, vrlg.TEST01_NEXT_PAGE);
630 631 632 633
        if wait_done:
            self.x393_axi_tasks.wait_status_condition( # may also be read directly from the same bit of mctrl_linear_rw (address=5) status
                                                       status_address,             # MCNTRL_TEST01_STATUS_REG_CHN3_ADDR,
                                                       status_control_address,     # MCNTRL_TEST01_ADDR + MCNTRL_TEST01_CHN3_STATUS_CNTRL,
634 635 636
                                                       vrlg.DEFAULT_STATUS_MODE,
                                                       2 << vrlg.STATUS_2LSB_SHFT, # bit 24 - busy, bit 25 - frame done
                                                       2 << vrlg.STATUS_2LSB_SHFT, # mask for the 4-bit page number
637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653
                                                       0,                          # equal to
                                                       0)                          # no need to synchronize sequence number
#     enable_memcntrl_en_dis(channel,0); # disable channel

    def test_tiled_read(self, #\
                        channel,       # input            [3:0] channel;
                        byte32,        # input                  byte32;
                        keep_open,     # input                  keep_open;
                        extra_pages,   # input            [1:0] extra_pages;
                        show_data,     # input                  show_data;
                        window_width,  # input [15:0]           window_width;
                        window_height, # input [15:0]           window_height;
                        window_left,   # input [15:0]           window_left;
                        window_top,    # input [15:0]           window_top;
                        tile_width,    # input [ 7:0]           tile_width;
                        tile_height,   # input [ 7:0]           tile_height;
                        tile_vstep):   # input [ 7:0]           tile_vstep;
654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669
        """
        Test tiled mode write (frame size/row increment is set in parameters) 
        <channel> channel number to use. Valid values: 2, 4
        <byte32>        use 32-byte wide columns (0 - use 16-byte ones)
        <keep_open>,    do not close page between accesses (for 8 or less rows only)
        <extra_pages>    2-bit number of extra pages that need to stay (not to be overwritten) in the buffer
        <show_data>      print read data
        <window_width>   13-bit window width in 8-bursts (16 bytes)
        <window_height>  16 bit window height
        <window_left>,   13-bit window left margin in 8-bursts (16 bytes)
        <window_top>     16-bit window top margin
        <tile_width>     6-bit tile width in 8-bursts (16 bytes) (0 -> 64)
        <tile_height>    6-bit tile_height (0->64)
        <tile_vstep>     6-bit tile vertical step (0->64) to control tole vertical overlap
        Returns read data as a list
        """
670 671 672 673 674 675 676 677 678 679 680
        result=[] # will be a 2-d array
#        tiles_per_row= (window_width/tile_width)+  ((window_width % tile_width==0)?0:1);
        tiles_per_row= (window_width/tile_width)+  (0,1)[(window_width % tile_width)==0]
        tile_rows_per_window= ((window_height-1)/tile_vstep) + 1
        tile_size= tile_width*tile_height;
        channel=   (0,1)[channel]
        keep_open= (0,1)[keep_open]
        show_data= (0,1)[show_data]
        print("====== test_tiled_read: channel=%d, byte32=%d, keep_open=%d, extra_pages=%d,  show_data=%d"%
                                          (channel,      byte32,  keep_open,    extra_pages,     show_data))
        if   channel == 2:
681 682 683 684
            start_addr=             vrlg.MCNTRL_TILED_CHN2_ADDR;
            status_address=         vrlg.MCNTRL_TEST01_STATUS_REG_CHN2_ADDR;
            status_control_address= vrlg.MCNTRL_TEST01_ADDR + vrlg.MCNTRL_TEST01_CHN2_STATUS_CNTRL;
            test_mode_address=      vrlg.MCNTRL_TEST01_ADDR + vrlg.MCNTRL_TEST01_CHN2_MODE;
685
        elif channel == 4:
686 687 688 689
            start_addr=             vrlg.MCNTRL_TILED_CHN4_ADDR;
            status_address=         vrlg.MCNTRL_TEST01_STATUS_REG_CHN4_ADDR;
            status_control_address= vrlg.MCNTRL_TEST01_ADDR + vrlg.MCNTRL_TEST01_CHN4_STATUS_CNTRL;
            test_mode_address=      vrlg.MCNTRL_TEST01_ADDR + vrlg.MCNTRL_TEST01_CHN4_MODE;
690 691
        else:
            print("**** ERROR: Invalid channel, only 2 and 4 are valid");
692 693 694 695
            start_addr=             vrlg.MCNTRL_TILED_CHN2_ADDR;
            status_address=         vrlg.MCNTRL_TEST01_STATUS_REG_CHN2_ADDR;
            status_control_address= vrlg.MCNTRL_TEST01_ADDR + vrlg.MCNTRL_TEST01_CHN2_STATUS_CNTRL;
            test_mode_address=      vrlg.MCNTRL_TEST01_ADDR + vrlg.MCNTRL_TEST01_CHN2_MODE;
696

697
        '''
698 699 700 701 702 703 704
        mode=   self.func_encode_mode_tiled(
                                            byte32,
                                            keep_open,
                                            extra_pages,
                                            0, # write_mem,
                                            1, # enable
                                            0)  # chn_reset
705 706
        '''
        mode=   x393_mcntrl.func_encode_mode_scan_tiled(
707
                                   skip_too_late = False,                     
708 709 710
                                   disable_need = False,
                                   repetitive=    True,
                                   single =       False,
711
                                   reset_frame =  True, # False,
712 713 714 715 716
                                   byte32 =       byte32,
                                   keep_open =    keep_open,
                                   extra_pages =  extra_pages,
                                   write_mem =    False,
                                   enable =       True,
717 718
                                   chn_reset =    False,
                                   abort_late =   False)
719
            
720 721
        self.x393_axi_tasks.write_control_register(start_addr + vrlg.MCNTRL_TILED_MODE, 0); # reset channel, including page address
        self.x393_axi_tasks.write_control_register(start_addr + vrlg.MCNTRL_TILED_STARTADDR,
722
                                                  vrlg.FRAME_START_ADDRESS) # RA=80, CA=0, BA=0 22-bit frame start address (3 CA LSBs==0. BA==0) 
723
        self.x393_axi_tasks.write_control_register(start_addr + vrlg.MCNTRL_TILED_FRAME_FULL_WIDTH,
724
                                                  vrlg.FRAME_FULL_WIDTH)
725
        self.x393_axi_tasks.write_control_register(start_addr + vrlg.MCNTRL_TILED_WINDOW_WH,
Andrey Filippov's avatar
Andrey Filippov committed
726
                                                  concat(((window_height,16),
727
                                                          (window_width, 16)))[0]) # {window_height,window_width});
728
        self.x393_axi_tasks.write_control_register(start_addr + vrlg.MCNTRL_TILED_WINDOW_X0Y0,
Andrey Filippov's avatar
Andrey Filippov committed
729
                                                  concat(((window_top,  16),
730
                                                          (window_left, 16)))[0])  #  {window_top,window_left});
731
        self.x393_axi_tasks.write_control_register(start_addr + vrlg.MCNTRL_TILED_WINDOW_STARTXY,
732
                                                  concat(((vrlg.TILED_STARTY, 16),
733
                                                          (vrlg.TILED_STARTX, 16)))[0])  #  TILED_STARTX+(TILED_STARTY<<16));
734
        self.x393_axi_tasks.write_control_register(start_addr + vrlg.MCNTRL_TILED_TILE_WHS,
Andrey Filippov's avatar
Andrey Filippov committed
735 736
                                                  concat(((tile_vstep, 8),
                                                          (tile_height, 8),
737
                                                          (tile_width, 8)))[0]) # {8'b0,tile_vstep,tile_height,tile_width});#tile_width+(tile_height<<8)+(tile_vstep<<16));
738
        self.x393_axi_tasks.write_control_register(start_addr + vrlg.MCNTRL_TILED_MODE, mode);# set mode register: {extra_pages[1:0],enable,!reset}
739 740
        self.x393_axi_tasks.configure_channel_priority(channel,0)    # lowest priority channel 3
        self.x393_axi_tasks.enable_memcntrl_en_dis(channel,1);
741
        self.x393_axi_tasks.write_control_register(test_mode_address,            vrlg.TEST01_START_FRAME);
742 743 744 745
        for ii in range(tiles_per_row * tile_rows_per_window): # (ii=0;ii<(tiles_per_row * tile_rows_per_window);ii = ii+1) begin
            self.x393_axi_tasks.wait_status_condition (
                                                       status_address, # MCNTRL_TEST01_STATUS_REG_CHN4_ADDR,
                                                       status_control_address, # MCNTRL_TEST01_ADDR + MCNTRL_TEST01_CHN4_STATUS_CNTRL,
746
                                                       vrlg.DEFAULT_STATUS_MODE,
747 748 749 750 751 752 753 754 755 756
                                                       ii << 16, # -TEST_INITIAL_BURST)<<16, # 4-bit page number
                                                       0xf<< 16, #'hf << 16,  # mask for the 4-bit page number
                                                       1, # not equal to
                                                       (0,1)[ii == 0]) # synchronize sequence number - only first time, next just wait fro auto update
            if (show_data): 
                print("########### test_tiled_read block %d: channel=%d"%(ii, channel))
                    
            result.append(self.x393_mcntrl_buffers.read_block_buf_chn (channel,
                                                                       (ii & 3),
                                                                       tile_size <<2,
757
#                                                                       1, # chn=0, page=3, number of 32-bit words=256, show_rslt
758
                                                                       show_data))
759
            self.x393_axi_tasks.write_control_register(test_mode_address, vrlg.TEST01_NEXT_PAGE);
760 761
#     enable_memcntrl_en_dis(channel,0); # disable channel
        return result