Commit 72068ae7 authored by Andrey Filippov's avatar Andrey Filippov

More Python code for testing hardware

parent 9a17dbfa
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
parameter HISTOGRAM_TOP = 8, // 2, // top parameter HISTOGRAM_TOP = 8, // 2, // top
parameter HISTOGRAM_WIDTH = 6, // width parameter HISTOGRAM_WIDTH = 6, // width
parameter HISTOGRAM_HEIGHT = 6, // height parameter HISTOGRAM_HEIGHT = 6, // height
parameter HISTOGRAM_STRAT_PAGE = 20'h12345, parameter HISTOGRAM_START_PAGE = 20'h12345,
parameter FRAME_WIDTH_ROUND_BITS = 9, // multiple of 512 pixels (32 16-byte bursts) (11 - ful SDRAM page) parameter FRAME_WIDTH_ROUND_BITS = 9, // multiple of 512 pixels (32 16-byte bursts) (11 - ful SDRAM page)
parameter WOI_WIDTH= 64, parameter WOI_WIDTH= 64,
......
...@@ -36,13 +36,13 @@ from verilog_utils import hx ...@@ -36,13 +36,13 @@ from verilog_utils import hx
from time import time from time import time
import vrlg import vrlg
enabled_channels=0 # currently enable channels #enabled_channels=0 # currently enable channels
cke_en=0 cke_en=0
cmda_en=0 cmda_en=0
sdrst_on=1 sdrst_on=1
mcntrl_en=0 mcntrl_en=0
refresh_en=0 refresh_en=0
channel_priority=[None]*16 #channel_priority=[None]*16
sequences_set=0 sequences_set=0
class X393AxiControlStatus(object): class X393AxiControlStatus(object):
DRY_MODE= True # True DRY_MODE= True # True
...@@ -68,16 +68,17 @@ class X393AxiControlStatus(object): ...@@ -68,16 +68,17 @@ class X393AxiControlStatus(object):
# Use 'import pickle' (exists in the camera) to save/restore state # Use 'import pickle' (exists in the camera) to save/restore state
def init_state(self): def init_state(self):
global enabled_channels, cke_en, cmda_en, sdrst_on, mcntrl_en, channel_priority, refresh_en, sequences_set # global enabled_channels, cke_en, cmda_en, sdrst_on, mcntrl_en, channel_priority, refresh_en, sequences_set
global cke_en, cmda_en, sdrst_on, mcntrl_en, refresh_en, sequences_set
""" """
reset state (as after bitstream load) reset state (as after bitstream load)
""" """
enabled_channels=0 # currently enable channels # enabled_channels=0 # currently enable channels
cke_en=0 cke_en=0
cmda_en=0 cmda_en=0
sdrst_on=1 sdrst_on=1
mcntrl_en=0 mcntrl_en=0
channel_priority=[None]*16 # channel_priority=[None]*16
refresh_en=0 refresh_en=0
sequences_set=0 sequences_set=0
if self.verbose>0: if self.verbose>0:
...@@ -122,20 +123,28 @@ class X393AxiControlStatus(object): ...@@ -122,20 +123,28 @@ class X393AxiControlStatus(object):
print ("REFRESH EN = %d"%refresh_en) print ("REFRESH EN = %d"%refresh_en)
return refresh_en return refresh_en
def get_enabled_channels(self,quiet=1): def get_enabled_channels(self,quiet=1):
global enabled_channels # global enabled_channels
enabled_channels = self.read_contol_register(vrlg.MCONTR_TOP_16BIT_ADDR + vrlg.MCONTR_TOP_16BIT_CHN_EN)
if quiet<2 : if quiet<2 :
print ("ENABLED_CHANNELS = 0x%x"%enabled_channels) print ("ENABLED_CHANNELS = 0x%x"%enabled_channels)
return enabled_channels return enabled_channels
def get_channel_priorities(self,quiet=1): def get_channel_priorities(self,quiet=1):
global channel_priority # global channel_priority
channel_priority = []
if quiet<2 : if quiet<2 :
print ("CHANNEL PRIORITIES:",end=" ") print ("CHANNEL PRIORITIES:",end=" ")
for chn in range (16):
v = self.read_contol_register(vrlg.MCONTR_ARBIT_ADDR + chn)
print ("%d"%v,end=" ")
channel_priority.append(v)
"""
for v in channel_priority: for v in channel_priority:
if v is None: if v is None:
print (" - ",end=" ") print (" - ",end=" ")
else: else:
print ("%d"%v,end=" ") print ("%d"%v,end=" ")
"""
print() print()
return channel_priority return channel_priority
...@@ -145,8 +154,8 @@ class X393AxiControlStatus(object): ...@@ -145,8 +154,8 @@ class X393AxiControlStatus(object):
'cmda_en': self.get_cmda_en(quiet), 'cmda_en': self.get_cmda_en(quiet),
'sdrst_on': self.get_sdrst_on(quiet), 'sdrst_on': self.get_sdrst_on(quiet),
'mcntrl_en': self.get_mcntrl_en(quiet), 'mcntrl_en': self.get_mcntrl_en(quiet),
'enabled_channels': self.get_enabled_channels(quiet), 'enabled_channels': self.get_enabled_channels(quiet), # updated
'channel_priorities': self.get_channel_priorities(quiet), 'channel_priorities': self.get_channel_priorities(quiet), # updated
'refresh_en': self.get_refresh_en(quiet), 'refresh_en': self.get_refresh_en(quiet),
'sequences_set': self.get_sequences_set(quiet) 'sequences_set': self.get_sequences_set(quiet)
} }
...@@ -388,7 +397,7 @@ class X393AxiControlStatus(object): ...@@ -388,7 +397,7 @@ class X393AxiControlStatus(object):
Enable memory controller channels (all at once control) Enable memory controller channels (all at once control)
<chnen> - 16-bit control word with per-channel enable bits (bit0 - chn0, ... bit15 - chn15) <chnen> - 16-bit control word with per-channel enable bits (bit0 - chn0, ... bit15 - chn15)
""" """
global enabled_channels # global enabled_channels
enabled_channels = chnen # currently enabled memory channels enabled_channels = chnen # currently enabled memory channels
self.write_contol_register(vrlg.MCONTR_TOP_16BIT_ADDR + vrlg.MCONTR_TOP_16BIT_CHN_EN, enabled_channels & 0xffff) # {16'b0,chnen}); self.write_contol_register(vrlg.MCONTR_TOP_16BIT_ADDR + vrlg.MCONTR_TOP_16BIT_CHN_EN, enabled_channels & 0xffff) # {16'b0,chnen});
if self.verbose > 0: if self.verbose > 0:
...@@ -402,7 +411,9 @@ class X393AxiControlStatus(object): ...@@ -402,7 +411,9 @@ class X393AxiControlStatus(object):
<chn> - 4-bit channel select <chn> - 4-bit channel select
<en> - 1 - enable, 0 - disable of the selected channel <en> - 1 - enable, 0 - disable of the selected channel
""" """
global enabled_channels # global enabled_channels
# Adding readback register
enabled_channels = self.read_contol_register(vrlg.MCONTR_TOP_16BIT_ADDR + vrlg.MCONTR_TOP_16BIT_CHN_EN)
if en: if en:
enabled_channels |= 1<<chn; enabled_channels |= 1<<chn;
else: else:
...@@ -419,9 +430,9 @@ class X393AxiControlStatus(object): ...@@ -419,9 +430,9 @@ class X393AxiControlStatus(object):
<chn> - 4-bit channel select <chn> - 4-bit channel select
<priority> - 16-bit priority value (higher value means more important) <priority> - 16-bit priority value (higher value means more important)
""" """
global channel_priority # global channel_priority
self.write_contol_register(vrlg.MCONTR_ARBIT_ADDR + chn, priority & 0xffff)# {16'b0,priority}); self.write_contol_register(vrlg.MCONTR_ARBIT_ADDR + chn, priority & 0xffff)# {16'b0,priority});
if self.verbose > 0: if self.verbose > 0:
print ("SET CHANNEL %d priority=0x%x"%(chn,priority)) print ("SET CHANNEL %d priority=0x%x"%(chn,priority))
channel_priority[chn]=priority # channel_priority[chn]=priority
...@@ -324,3 +324,93 @@ class X393Cmprs(object): ...@@ -324,3 +324,93 @@ class X393Cmprs(object):
self.x393_axi_tasks.write_contol_register( self.x393_axi_tasks.write_contol_register(
base_addr + vrlg.MCNTRL_TILED_MODE, base_addr + vrlg.MCNTRL_TILED_MODE,
mode); mode);
def compressor_run(self, # may use compressor_control with the same arguments
num_sensor,
run_mode):
"""
Compressor reset.run/single (alias of compressor_control)
@param num_sensor - sensor port number (0..3)
@param run_mode - 0 - reset, 2 - run single from memory, 3 - run repetitive
"""
self.compressor_control(
num_sensor = num_sensor, # sensor channel number (0..3)
run_mode = run_mode) #0 - reset, 2 - run single from memory, 3 - run repetitive
def setup_compressor_channel (self,
num_sensor,
qbank,
dc_sub,
cmode,
multi_frame,
bayer,
focus_mode,
num_macro_cols_m1,
num_macro_rows_m1,
left_margin,
colorsat_blue,
colorsat_red,
coring,
verbose=0):
"""
@param num_sensor - sensor port number (0..3)
@param qbank - quantization table page (0..15)
@param dc_sub - True - subtract DC before running DCT, False - no subtraction, convert as is,
@param cmode - color mode:
CMPRS_CBIT_CMODE_JPEG18 = 0 - color 4:2:0
CMPRS_CBIT_CMODE_MONO6 = 1 - mono 4:2:0 (6 blocks)
CMPRS_CBIT_CMODE_JP46 = 2 - jp4, 6 blocks, original
CMPRS_CBIT_CMODE_JP46DC = 3 - jp4, 6 blocks, dc -improved
CMPRS_CBIT_CMODE_JPEG20 = 4 - mono, 4 blocks (but still not actual monochrome JPEG as the blocks are scanned in 2x2 macroblocks)
CMPRS_CBIT_CMODE_JP4 = 5 - jp4, 4 blocks, dc-improved
CMPRS_CBIT_CMODE_JP4DC = 6 - jp4, 4 blocks, dc-improved
CMPRS_CBIT_CMODE_JP4DIFF = 7 - jp4, 4 blocks, differential
CMPRS_CBIT_CMODE_JP4DIFFHDR = 8 - jp4, 4 blocks, differential, hdr
CMPRS_CBIT_CMODE_JP4DIFFDIV2 = 9 - jp4, 4 blocks, differential, divide by 2
CMPRS_CBIT_CMODE_JP4DIFFHDRDIV2 = 10 - jp4, 4 blocks, differential, hdr,divide by 2
CMPRS_CBIT_CMODE_MONO1 = 11 - mono JPEG (not yet implemented)
CMPRS_CBIT_CMODE_MONO4 = 14 - mono 4 blocks
@param multi_frame - False - single-frame buffer, True - multi-frame video memory buffer,
@param bayer - Bayer shift (0..3)
@param focus_mode - focus mode - how to combine image with "focus quality" in the result image
@param num_macro_cols_m1 - number of macroblock colums minus 1
@param num_macro_rows_m1 - number of macroblock rows minus 1
@param left_margin - left margin of the first pixel (0..31) for 32-pixel wide colums in memory access
@param colorsat_blue - color saturation for blue (10 bits), 0x90 for 100%
@param colorsat_red - color saturation for red (10 bits), 0xb6 for 100%
@param coring - coring value
@param verbose - verbose level
"""
if verbose > 0:
print("COMPRESSOR_SETUP")
print ( "num_sensor = ",num_sensor)
print ( "qbank = ",qbank)
print ( "dc_sub = ",dc_sub)
print ( "cmode = ",cmode)
print ( "multi_frame = ",multi_frame)
print ( "bayer = ",bayer)
print ( "focus_mode = ",focus_mode)
self.compressor_control(
num_sensor = num_sensor, # sensor channel number (0..3)
qbank = qbank, # [6:3] quantization table page
dc_sub = dc_sub, # [8:7] subtract DC
cmode = cmode, # [13:9] color mode:
multi_frame = multi_frame, # [15:14] 0 - single-frame buffer, 1 - multiframe video memory buffer
bayer = bayer, # [20:18] # Bayer shift
focus_mode = focus_mode) # [23:21] Set focus mode
self.compressor_format(
num_sensor = num_sensor, # sensor channel number (0..3)
num_macro_cols_m1 = num_macro_cols_m1, # number of macroblock colums minus 1
num_macro_rows_m1 = num_macro_rows_m1, # number of macroblock rows minus 1
left_margin = left_margin) # left margin of the first pixel (0..31) for 32-pixel wide colums in memory access
self.compressor_color_saturation(
num_sensor = num_sensor, # sensor channel number (0..3)
colorsat_blue = colorsat_blue, # color saturation for blue (10 bits) #'h90 for 100%
colorsat_red = colorsat_red) # color saturation for red (10 bits) # 'b6 for 100%
self.compressor_coring(
num_sensor = num_sensor, # sensor channel number (0..3)
coring = coring); # coring value
...@@ -162,8 +162,8 @@ class X393CmprsAfi(object): ...@@ -162,8 +162,8 @@ class X393CmprsAfi(object):
def afi_mux_setup (self, def afi_mux_setup (self,
port_afi, port_afi,
chn_mask, chn_mask,
status_mode = 3, status_mode, # = 3,
report_mode = 0, report_mode, # = 0,
afi_cmprs0_sa, afi_cmprs0_sa,
afi_cmprs0_len, afi_cmprs0_len,
afi_cmprs1_sa, afi_cmprs1_sa,
......
This diff is collapsed.
...@@ -734,3 +734,5 @@ class X393Sensor(object): ...@@ -734,3 +734,5 @@ class X393Sensor(object):
((window_top & 0xffff) << 16) | (window_left & 0xffff)) #WINDOW_X0+ (WINDOW_Y0<<16)); ((window_top & 0xffff) << 16) | (window_left & 0xffff)) #WINDOW_X0+ (WINDOW_Y0<<16));
self.x393_axi_tasks.write_contol_register(base_addr + vrlg.MCNTRL_SCANLINE_WINDOW_STARTXY, 0) self.x393_axi_tasks.write_contol_register(base_addr + vrlg.MCNTRL_SCANLINE_WINDOW_STARTXY, 0)
self.x393_axi_tasks.write_contol_register(base_addr + vrlg.MCNTRL_SCANLINE_MODE, mode) self.x393_axi_tasks.write_contol_register(base_addr + vrlg.MCNTRL_SCANLINE_MODE, mode)
...@@ -51,7 +51,7 @@ class X393Utils(object): ...@@ -51,7 +51,7 @@ class X393Utils(object):
DEBUG_MODE=1 DEBUG_MODE=1
# vpars=None # vpars=None
x393_mem=None x393_mem=None
enabled_channels=0 # currently enabled channels # enabled_channels=0 # currently enabled channels
saveFileName=None saveFileName=None
x393_axi_tasks=None x393_axi_tasks=None
# verbose=1 # verbose=1
......
...@@ -2072,7 +2072,7 @@ task write_block_scanline_chn; // SuppressThisWarning VEditor : may be unused ...@@ -2072,7 +2072,7 @@ task write_block_scanline_chn; // SuppressThisWarning VEditor : may be unused
// write_block_incremtal (start_addr, num_bursts << 2, (startX<<2) + (startY<<16)); // 1 of startX is 8x16 bit, 16 bytes or 4 32-bit words // write_block_incremtal (start_addr, num_bursts << 2, (startX<<2) + (startY<<16)); // 1 of startX is 8x16 bit, 16 bytes or 4 32-bit words
end end
endtask endtask
// x393_mcntrl (no class)
function [11:0] func_encode_mode_tiled; // SuppressThisWarning VEditor - not used function [11:0] func_encode_mode_tiled; // SuppressThisWarning VEditor - not used
input disable_need; input disable_need;
input repetitive; input repetitive;
...@@ -2103,6 +2103,7 @@ function [11:0] func_encode_mode_tiled; // SuppressThisWarning VEditor - not us ...@@ -2103,6 +2103,7 @@ function [11:0] func_encode_mode_tiled; // SuppressThisWarning VEditor - not us
func_encode_mode_tiled = rslt; func_encode_mode_tiled = rslt;
end end
endfunction endfunction
// x393_mcntrl (no class)
function [11:0] func_encode_mode_scanline; // SuppressThisWarning VEditor - not used function [11:0] func_encode_mode_scanline; // SuppressThisWarning VEditor - not used
input disable_need; input disable_need;
input repetitive; input repetitive;
...@@ -2132,6 +2133,7 @@ endfunction ...@@ -2132,6 +2133,7 @@ endfunction
// Sensor - related tasks and functions // Sensor - related tasks and functions
// x393_sens_cmprs.py
task setup_sensor_channel; task setup_sensor_channel;
input [1:0] num_sensor; input [1:0] num_sensor;
...@@ -2205,6 +2207,7 @@ task setup_sensor_channel; ...@@ -2205,6 +2207,7 @@ task setup_sensor_channel;
// Enable arbitration of sensor-to-memory controller // Enable arbitration of sensor-to-memory controller
enable_memcntrl_en_dis(4'h8 + {2'b0,num_sensor}, 1); enable_memcntrl_en_dis(4'h8 + {2'b0,num_sensor}, 1);
// write_contol_register(MCONTR_TOP_16BIT_ADDR + MCONTR_TOP_16BIT_CHN_EN, {16'b0,ENABLED_CHANNELS});
compressor_run (num_sensor, 0); // reset compressor compressor_run (num_sensor, 0); // reset compressor
...@@ -2386,7 +2389,7 @@ task setup_sensor_channel; ...@@ -2386,7 +2389,7 @@ task setup_sensor_channel;
set_sensor_histogram_saxi_addr ( set_sensor_histogram_saxi_addr (
num_sensor, // input [1:0] num_sensor; // sensor channel number (0..3) num_sensor, // input [1:0] num_sensor; // sensor channel number (0..3)
0, // input [1:0] subchannel; // subchannel number (for multiplexed images) 0, // input [1:0] subchannel; // subchannel number (for multiplexed images)
HISTOGRAM_STRAT_PAGE); // input [19:0] page; //start address in 4KB pages (1 page - one subchannel histogram) HISTOGRAM_START_PAGE); // input [19:0] page; //start address in 4KB pages (1 page - one subchannel histogram)
set_sensor_histogram_saxi ( set_sensor_histogram_saxi (
1'b1, // input en; 1'b1, // input en;
...@@ -2498,6 +2501,8 @@ task write_cmd_frame_sequencer; ...@@ -2498,6 +2501,8 @@ task write_cmd_frame_sequencer;
// temporarily putting in the very end as it takes about 30 usec to program curves (TODO: see how to make it faster for simulation) // temporarily putting in the very end as it takes about 30 usec to program curves (TODO: see how to make it faster for simulation)
end end
endtask endtask
//x393_camsync.py //x393_camsync.py
task camsync_setup; task camsync_setup;
input [3:0] sensor_mask; input [3:0] sensor_mask;
...@@ -2640,6 +2645,7 @@ task afi_mux_setup; ...@@ -2640,6 +2645,7 @@ task afi_mux_setup;
end end
endtask endtask
//x393_cmprs.py
task setup_compressor_channel; task setup_compressor_channel;
input [ 1:0] num_sensor; // sensor channel number (0..3) input [ 1:0] num_sensor; // sensor channel number (0..3)
input [31:0] qbank; // [6:3] quantization table page input [31:0] qbank; // [6:3] quantization table page
...@@ -2699,9 +2705,10 @@ task setup_compressor_channel; ...@@ -2699,9 +2705,10 @@ task setup_compressor_channel;
end end
endtask endtask
// x393_cmprs.py
task compressor_run; task compressor_run;
input [ 1:0] num_sensor; // sensor channel number (0..3) input [ 1:0] num_sensor; // sensor channel number (0..3)
input [31:0] run_mode; // [6:3] quantization table page input [31:0] run_mode; // input [31:0] run_mode; // [2:0] < 0: nop, 0 - reset, 2 - run single from memory, 3 - run repetitive
begin begin
compressor_control( compressor_control(
num_sensor, // sensor channel number (0..3) num_sensor, // sensor channel number (0..3)
...@@ -2716,7 +2723,7 @@ task compressor_run; ...@@ -2716,7 +2723,7 @@ task compressor_run;
endtask endtask
// x393_sensor.py
task setup_sensor_memory; task setup_sensor_memory;
input [1:0] num_sensor; input [1:0] num_sensor;
input [31:0] frame_sa; // 22-bit frame start address ((3 CA LSBs==0. BA==0) input [31:0] frame_sa; // 22-bit frame start address ((3 CA LSBs==0. BA==0)
...@@ -2751,7 +2758,7 @@ task setup_sensor_memory; ...@@ -2751,7 +2758,7 @@ task setup_sensor_memory;
write_contol_register(base_addr + MCNTRL_SCANLINE_MODE, mode); write_contol_register(base_addr + MCNTRL_SCANLINE_MODE, mode);
end end
endtask endtask
// x393_cmprs.py
task setup_compressor_memory; task setup_compressor_memory;
input [1:0] num_sensor; input [1:0] num_sensor;
input [31:0]frame_sa; // 22-bit frame start address ((3 CA LSBs==0. BA==0) input [31:0]frame_sa; // 22-bit frame start address ((3 CA LSBs==0. BA==0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment