Commit 3d7d6607 authored by Andrey Filippov's avatar Andrey Filippov

Adding vignetting correction module

parent aa331d14
...@@ -326,7 +326,7 @@ ...@@ -326,7 +326,7 @@
parameter SENSIO_STATUS_REG_REL = 1, // 4 locations" 'h21, 'h23, 'h25, 'h27 parameter SENSIO_STATUS_REG_REL = 1, // 4 locations" 'h21, 'h23, 'h25, 'h27
parameter SENSOR_NUM_HISTOGRAM= 3, // number of histogram channels parameter SENSOR_NUM_HISTOGRAM= 3, // number of histogram channels
parameter HISTOGRAM_RAM_MODE = "NOBUF", // valid: "NOBUF" (32-bits, no buffering), "BUF18", "BUF32" parameter HISTOGRAM_RAM_MODE = "NOBUF", // valid: "NOBUF" (32-bits, no buffering), "BUF18", "BUF32"
parameter SENS_GAMMA_NUM_CHN = 3, // number of subchannels for his sensor ports (1..4) parameter SENS_NUM_SUBCHN = 3, // number of subchannels for his sensor ports (1..4)
parameter SENS_GAMMA_BUFFER = 0, // 1 - use "shadow" table for clean switching, 0 - single table per channel parameter SENS_GAMMA_BUFFER = 0, // 1 - use "shadow" table for clean switching, 0 - single table per channel
// parameters defining address map // parameters defining address map
...@@ -382,7 +382,31 @@ ...@@ -382,7 +382,31 @@
parameter SENS_GAMMA_MODE_REPET = 4, parameter SENS_GAMMA_MODE_REPET = 4,
parameter SENS_GAMMA_MODE_TRIG = 5, parameter SENS_GAMMA_MODE_TRIG = 5,
parameter SENSIO_RADDR = 8, //'h308 .. 'h30c // Vignetting correction / pixel value scaling - controlled via single data word (same as in 252), some of bits [23:16]
// are used to select register, bits 25:24 - select sub-frame
parameter SENS_LENS_RADDR = 'h3c,
parameter SENS_LENS_ADDR_MASK = 'h7fc,
parameter SENS_LENS_COEFF = 'h3, // set vignetting/scale coefficients (
parameter SENS_LENS_AX = 'h00, // 00000...
parameter SENS_LENS_AX_MASK = 'hf8,
parameter SENS_LENS_AY = 'h08, // 00001...
parameter SENS_LENS_AY_MASK = 'hf8,
parameter SENS_LENS_C = 'h10, // 00010...
parameter SENS_LENS_C_MASK = 'hf8,
parameter SENS_LENS_BX = 'h20, // 001.....
parameter SENS_LENS_BX_MASK = 'he0,
parameter SENS_LENS_BY = 'h40, // 010.....
parameter SENS_LENS_BY_MASK = 'he0,
parameter SENS_LENS_SCALES = 'h60, // 01100...
parameter SENS_LENS_SCALES_MASK = 'hf8,
parameter SENS_LENS_FAT0_IN = 'h68, // 01101000
parameter SENS_LENS_FAT0_IN_MASK = 'hff,
parameter SENS_LENS_FAT0_OUT = 'h69, // 01101001
parameter SENS_LENS_FAT0_OUT_MASK = 'hff,
parameter SENS_LENS_POST_SCALE = 'h6a, // 01101010
parameter SENS_LENS_POST_SCALE_MASK = 'hff,
parameter SENSIO_RADDR = 8, //'h408 .. 'h40f
parameter SENSIO_ADDR_MASK = 'h7f8, parameter SENSIO_ADDR_MASK = 'h7f8,
// sens_parallel12 registers // sens_parallel12 registers
parameter SENSIO_CTRL = 'h0, parameter SENSIO_CTRL = 'h0,
...@@ -408,8 +432,8 @@ ...@@ -408,8 +432,8 @@
parameter SENSIO_DELAYS = 'h4, // 'h4..'h7 parameter SENSIO_DELAYS = 'h4, // 'h4..'h7
// 4 of 8-bit delays per register // 4 of 8-bit delays per register
// sensor_i2c_io command/data write registers s (relative to SENSOR_GROUP_ADDR) // sensor_i2c_io command/data write registers s (relative to SENSOR_GROUP_ADDR)
parameter SENSI2C_ABS_RADDR = 'h10, // 'h310..'h31f parameter SENSI2C_ABS_RADDR = 'h10, // 'h410..'h41f
parameter SENSI2C_REL_RADDR = 'h20, // 'h320..'h32f parameter SENSI2C_REL_RADDR = 'h20, // 'h420..'h42f
parameter SENSI2C_ADDR_MASK = 'h7f0, // both for SENSI2C_ABS_ADDR and SENSI2C_REL_ADDR parameter SENSI2C_ADDR_MASK = 'h7f0, // both for SENSI2C_ABS_ADDR and SENSI2C_REL_ADDR
// sens_hist registers (relative to SENSOR_GROUP_ADDR) // sens_hist registers (relative to SENSOR_GROUP_ADDR)
......
This diff is collapsed.
...@@ -21,9 +21,9 @@ ...@@ -21,9 +21,9 @@
`timescale 1ns/1ps `timescale 1ns/1ps
module sens_gamma #( module sens_gamma #(
parameter SENS_GAMMA_NUM_CHN = 3, // number of subchannels for his sensor ports (1..4) parameter SENS_NUM_SUBCHN = 3, // number of subchannels for his sensor ports (1..4)
parameter SENS_GAMMA_BUFFER = 0, // 1 - use "shadow" table for clean switching, 0 - single table per channel parameter SENS_GAMMA_BUFFER = 0, // 1 - use "shadow" table for clean switching, 0 - single table per channel
parameter SENS_GAMMA_ADDR = 'h338, parameter SENS_GAMMA_ADDR = 'h438,
parameter SENS_GAMMA_ADDR_MASK = 'h7fc, parameter SENS_GAMMA_ADDR_MASK = 'h7fc,
parameter SENS_GAMMA_CTRL = 'h0, parameter SENS_GAMMA_CTRL = 'h0,
parameter SENS_GAMMA_ADDR_DATA = 'h1, // bit 20 ==1 - table address, bit 20==0 - table data (18 bits) parameter SENS_GAMMA_ADDR_DATA = 'h1, // bit 20 ==1 - table address, bit 20==0 - table data (18 bits)
...@@ -65,7 +65,9 @@ module sens_gamma #( ...@@ -65,7 +65,9 @@ module sens_gamma #(
// programming interface // programming interface
input mclk, // global clock, half DDR3 clock, synchronizes all I/O through the command port input mclk, // global clock, half DDR3 clock, synchronizes all I/O through the command port
input [7:0] cmd_ad, // byte-serial command address/data (up to 6 bytes: AL-AH-D0-D1-D2-D3 input [7:0] cmd_ad, // byte-serial command address/data (up to 6 bytes: AL-AH-D0-D1-D2-D3
input cmd_stb // strobe (with first byte) for the command a/d input cmd_stb, // strobe (with first byte) for the command a/d
output [1:0] bayer_out // for lens_flat module - separate them?
); );
wire [1:0] cmd_a; wire [1:0] cmd_a;
wire [31:0] cmd_data; wire [31:0] cmd_data;
...@@ -182,9 +184,13 @@ module sens_gamma #( ...@@ -182,9 +184,13 @@ module sens_gamma #(
assign sof_masked= sof_in && (pend_trig || repet_mode) && en_input; assign sof_masked= sof_in && (pend_trig || repet_mode) && en_input;
assign trig = trig_in || trig_soft; assign trig = trig_in || trig_soft;
assign bayer_out = bayer;
always @ (posedge mclk) begin always @ (posedge mclk) begin
if (mrst) tdata <= 0; if (mrst) tdata <= 0;
else if (set_taddr_w) tdata <= cmd_data[17:0]; // else if (set_taddr_w) tdata <= cmd_data[17:0];
else if (set_tdata_w) tdata <= cmd_data[17:0];
if (mrst) set_tdata_r <= 0; if (mrst) set_tdata_r <= 0;
else set_tdata_r <= set_tdata_w; else set_tdata_r <= set_tdata_w;
...@@ -256,7 +262,7 @@ module sens_gamma #( ...@@ -256,7 +262,7 @@ module sens_gamma #(
ram_chn_d <= ram_chn; ram_chn_d <= ram_chn;
ram_chn_d2 <= ram_chn_d; ram_chn_d2 <= ram_chn_d;
inc_line <= hact_d[0] && !hact_in && (sensor_subchn < SENS_GAMMA_NUM_CHN); inc_line <= hact_d[0] && !hact_in && (sensor_subchn < SENS_NUM_SUBCHN);
sof_r <= sof_in; sof_r <= sof_in;
...@@ -265,6 +271,7 @@ module sens_gamma #( ...@@ -265,6 +271,7 @@ module sens_gamma #(
if (sof_r) line_cntr <= height0_m1; if (sof_r) line_cntr <= height0_m1;
else if (inc_line && (line_cntr == 0)) line_cntr <= (sensor_subchn ==0)? height1_m1: height2_m1; else if (inc_line && (line_cntr == 0)) line_cntr <= (sensor_subchn ==0)? height1_m1: height2_m1;
else if (inc_line) line_cntr <= line_cntr - 1;
end end
...@@ -275,8 +282,8 @@ module sens_gamma #( ...@@ -275,8 +282,8 @@ module sens_gamma #(
.NUM_CYCLES (6), .NUM_CYCLES (6),
.ADDR_WIDTH (2), .ADDR_WIDTH (2),
.DATA_WIDTH (32) .DATA_WIDTH (32)
) cmd_deser_sens_io_i ( ) cmd_deser_sens_gamma_i (
.rst (1'b0), // rst), // input .rst (mrst), // rst), // input
.clk (mclk), // input .clk (mclk), // input
.srst (mrst), // input .srst (mrst), // input
.ad (cmd_ad), // input[7:0] .ad (cmd_ad), // input[7:0]
...@@ -336,7 +343,7 @@ module sens_gamma #( ...@@ -336,7 +343,7 @@ module sens_gamma #(
.REGISTERS (1), // try to delay i2c_byte_start by one more cycle .REGISTERS (1), // try to delay i2c_byte_start by one more cycle
.LOG2WIDTH_WR (4), .LOG2WIDTH_WR (4),
.LOG2WIDTH_RD (4), .LOG2WIDTH_RD (4),
.DUMMY (!((SENS_GAMMA_NUM_CHN > 1) && ((SENS_GAMMA_NUM_CHN > 2) || SENS_GAMMA_BUFFER))) .DUMMY (!((SENS_NUM_SUBCHN > 1) && ((SENS_NUM_SUBCHN > 2) || SENS_GAMMA_BUFFER)))
) gamma_table1_i ( ) gamma_table1_i (
.rclk (pclk), // input .rclk (pclk), // input
.raddr (table_raddr), // input[11:0] .raddr (table_raddr), // input[11:0]
...@@ -354,7 +361,7 @@ module sens_gamma #( ...@@ -354,7 +361,7 @@ module sens_gamma #(
.REGISTERS (1), // try to delay i2c_byte_start by one more cycle .REGISTERS (1), // try to delay i2c_byte_start by one more cycle
.LOG2WIDTH_WR (4), .LOG2WIDTH_WR (4),
.LOG2WIDTH_RD (4), .LOG2WIDTH_RD (4),
.DUMMY (!(SENS_GAMMA_BUFFER && (SENS_GAMMA_NUM_CHN > 2))) .DUMMY (!(SENS_GAMMA_BUFFER && (SENS_NUM_SUBCHN > 2)))
) gamma_table2_i ( ) gamma_table2_i (
.rclk (pclk), // input .rclk (pclk), // input
.raddr (table_raddr), // input[11:0] .raddr (table_raddr), // input[11:0]
...@@ -372,7 +379,7 @@ module sens_gamma #( ...@@ -372,7 +379,7 @@ module sens_gamma #(
.REGISTERS (1), // try to delay i2c_byte_start by one more cycle .REGISTERS (1), // try to delay i2c_byte_start by one more cycle
.LOG2WIDTH_WR (4), .LOG2WIDTH_WR (4),
.LOG2WIDTH_RD (4), .LOG2WIDTH_RD (4),
.DUMMY (!(SENS_GAMMA_BUFFER && (SENS_GAMMA_NUM_CHN > 3))) .DUMMY (!(SENS_GAMMA_BUFFER && (SENS_NUM_SUBCHN > 3)))
) gamma_table3_i ( ) gamma_table3_i (
.rclk (pclk), // input .rclk (pclk), // input
.raddr (table_raddr), // input[11:0] .raddr (table_raddr), // input[11:0]
......
...@@ -44,7 +44,7 @@ module sensor_channel#( ...@@ -44,7 +44,7 @@ module sensor_channel#(
parameter SENSOR_NUM_HISTOGRAM= 3, // number of histogram channels parameter SENSOR_NUM_HISTOGRAM= 3, // number of histogram channels
parameter HISTOGRAM_RAM_MODE = "NOBUF", // valid: "NOBUF" (32-bits, no buffering), "BUF18", "BUF32" parameter HISTOGRAM_RAM_MODE = "NOBUF", // valid: "NOBUF" (32-bits, no buffering), "BUF18", "BUF32"
parameter SENS_GAMMA_NUM_CHN = 3, // number of subchannels for his sensor ports (1..4) parameter SENS_NUM_SUBCHN = 3, // number of subchannels for his sensor ports (1..4)
parameter SENS_GAMMA_BUFFER = 0, // 1 - use "shadow" table for clean switching, 0 - single table per channel parameter SENS_GAMMA_BUFFER = 0, // 1 - use "shadow" table for clean switching, 0 - single table per channel
// parameters defining address map // parameters defining address map
...@@ -91,8 +91,31 @@ module sensor_channel#( ...@@ -91,8 +91,31 @@ module sensor_channel#(
parameter SENS_GAMMA_MODE_EN = 3, parameter SENS_GAMMA_MODE_EN = 3,
parameter SENS_GAMMA_MODE_REPET = 4, parameter SENS_GAMMA_MODE_REPET = 4,
parameter SENS_GAMMA_MODE_TRIG = 5, parameter SENS_GAMMA_MODE_TRIG = 5,
// Vignetting correction / pixel value scaling - controlled via single data word (same as in 252), some of bits [23:16]
parameter SENSIO_RADDR = 8, //'h308 .. 'h30f // are used to select register, bits 25:24 - select sub-frame
parameter SENS_LENS_RADDR = 'h3c,
parameter SENS_LENS_ADDR_MASK = 'h7fc,
parameter SENS_LENS_COEFF = 'h3, // set vignetting/scale coefficients (
parameter SENS_LENS_AX = 'h00, // 00000...
parameter SENS_LENS_AX_MASK = 'hf8,
parameter SENS_LENS_AY = 'h08, // 00001...
parameter SENS_LENS_AY_MASK = 'hf8,
parameter SENS_LENS_C = 'h10, // 00010...
parameter SENS_LENS_C_MASK = 'hf8,
parameter SENS_LENS_BX = 'h20, // 001.....
parameter SENS_LENS_BX_MASK = 'he0,
parameter SENS_LENS_BY = 'h40, // 010.....
parameter SENS_LENS_BY_MASK = 'he0,
parameter SENS_LENS_SCALES = 'h60, // 01100...
parameter SENS_LENS_SCALES_MASK = 'hf8,
parameter SENS_LENS_FAT0_IN = 'h68, // 01101000
parameter SENS_LENS_FAT0_IN_MASK = 'hff,
parameter SENS_LENS_FAT0_OUT = 'h69, // 01101001
parameter SENS_LENS_FAT0_OUT_MASK = 'hff,
parameter SENS_LENS_POST_SCALE = 'h6a, // 01101010
parameter SENS_LENS_POST_SCALE_MASK = 'hff,
parameter SENSIO_RADDR = 8, //'h408 .. 'h40f
parameter SENSIO_ADDR_MASK = 'h7f8, parameter SENSIO_ADDR_MASK = 'h7f8,
// sens_parallel12 registers // sens_parallel12 registers
parameter SENSIO_CTRL = 'h0, parameter SENSIO_CTRL = 'h0,
...@@ -118,8 +141,8 @@ module sensor_channel#( ...@@ -118,8 +141,8 @@ module sensor_channel#(
parameter SENSIO_DELAYS = 'h4, // 'h4..'h7 parameter SENSIO_DELAYS = 'h4, // 'h4..'h7
// 4 of 8-bit delays per register // 4 of 8-bit delays per register
// sensor_i2c_io command/data write registers s (relative to SENSOR_BASE_ADDR) // sensor_i2c_io command/data write registers s (relative to SENSOR_BASE_ADDR)
parameter SENSI2C_ABS_RADDR = 'h10, // 'h310..'h31f parameter SENSI2C_ABS_RADDR = 'h10, // 'h410..'h41f
parameter SENSI2C_REL_RADDR = 'h20, // 'h320..'h32f parameter SENSI2C_REL_RADDR = 'h20, // 'h420..'h42f
parameter SENSI2C_ADDR_MASK = 'h7f0, // both for SENSI2C_ABS_ADDR and SENSI2C_REL_ADDR parameter SENSI2C_ADDR_MASK = 'h7f0, // both for SENSI2C_ABS_ADDR and SENSI2C_REL_ADDR
// sens_hist registers (relative to SENSOR_BASE_ADDR) // sens_hist registers (relative to SENSOR_BASE_ADDR)
...@@ -228,6 +251,7 @@ module sensor_channel#( ...@@ -228,6 +251,7 @@ module sensor_channel#(
localparam SENSI2C_CTRL_ADDR = SENSOR_BASE_ADDR + SENSI2C_CTRL_RADDR; localparam SENSI2C_CTRL_ADDR = SENSOR_BASE_ADDR + SENSI2C_CTRL_RADDR;
localparam SENS_GAMMA_ADDR = SENSOR_BASE_ADDR + SENS_GAMMA_RADDR; localparam SENS_GAMMA_ADDR = SENSOR_BASE_ADDR + SENS_GAMMA_RADDR;
localparam SENSIO_ADDR = SENSOR_BASE_ADDR + SENSIO_RADDR; localparam SENSIO_ADDR = SENSOR_BASE_ADDR + SENSIO_RADDR;
localparam SENS_LENS_ADDR = SENSOR_BASE_ADDR + SENS_LENS_RADDR;
localparam SENSI2C_ABS_ADDR = SENSOR_BASE_ADDR + SENSI2C_ABS_RADDR; localparam SENSI2C_ABS_ADDR = SENSOR_BASE_ADDR + SENSI2C_ABS_RADDR;
localparam SENSI2C_REL_ADDR = SENSOR_BASE_ADDR + SENSI2C_REL_RADDR; localparam SENSI2C_REL_ADDR = SENSOR_BASE_ADDR + SENSI2C_REL_RADDR;
localparam HISTOGRAM_ADDR0 = (SENSOR_NUM_HISTOGRAM > 0)?(SENSOR_BASE_ADDR + HISTOGRAM_RADDR0):-1; // localparam HISTOGRAM_ADDR0 = (SENSOR_NUM_HISTOGRAM > 0)?(SENSOR_BASE_ADDR + HISTOGRAM_RADDR0):-1; //
...@@ -261,11 +285,18 @@ module sensor_channel#( ...@@ -261,11 +285,18 @@ module sensor_channel#(
wire sof_out_sync; // sof filtetred, optionally decimated (for linescan mode) wire sof_out_sync; // sof filtetred, optionally decimated (for linescan mode)
wire [15:0] lens_pxd_in;
wire lens_hact_in;
wire lens_sof_in;
wire lens_eof_in;
wire [15:0] gamma_pxd_in; wire [15:0] gamma_pxd_in;
wire gamma_hact_in; wire gamma_hact_in;
wire gamma_sof_in; wire gamma_sof_in;
wire gamma_eof_in; wire gamma_eof_in;
wire [1:0] gamma_bayer; // gamma module mode register bits -> lens_flat module
wire [7:0] gamma_pxd_out; wire [7:0] gamma_pxd_out;
...@@ -299,10 +330,10 @@ module sensor_channel#( ...@@ -299,10 +330,10 @@ module sensor_channel#(
reg eof_out_r; reg eof_out_r;
// TODO: insert vignetting and/or flat field, pixel defects before gamma_*_in // TODO: insert vignetting and/or flat field, pixel defects before gamma_*_in
assign gamma_pxd_in = {pxd[11:0],4'b0}; assign lens_pxd_in = {pxd[11:0],4'b0};
assign gamma_hact_in = hact; assign lens_hact_in = hact;
assign gamma_sof_in = sof_out_sync; // sof; assign lens_sof_in = sof_out_sync; // sof;
assign gamma_eof_in = eof; assign lens_eof_in = eof;
assign dout = dout_r; assign dout = dout_r;
assign dout_valid = dav_r; assign dout_valid = dav_r;
...@@ -538,8 +569,56 @@ module sensor_channel#( ...@@ -538,8 +569,56 @@ module sensor_channel#(
.cmd_stb (cmd_stb) // input .cmd_stb (cmd_stb) // input
); );
lens_flat393 #(
.SENS_LENS_ADDR (SENS_LENS_ADDR),
.SENS_LENS_ADDR_MASK (SENS_LENS_ADDR_MASK),
.SENS_LENS_COEFF (SENS_LENS_COEFF),
.SENS_LENS_AX (SENS_LENS_AX),
.SENS_LENS_AX_MASK (SENS_LENS_AX_MASK),
.SENS_LENS_AY (SENS_LENS_AY),
.SENS_LENS_AY_MASK (SENS_LENS_AY_MASK),
.SENS_LENS_C (SENS_LENS_C),
.SENS_LENS_C_MASK (SENS_LENS_C_MASK),
.SENS_LENS_BX (SENS_LENS_BX),
.SENS_LENS_BX_MASK (SENS_LENS_BX_MASK),
.SENS_LENS_BY (SENS_LENS_BY),
.SENS_LENS_BY_MASK (SENS_LENS_BY_MASK),
.SENS_LENS_SCALES (SENS_LENS_SCALES),
.SENS_LENS_SCALES_MASK (SENS_LENS_SCALES_MASK),
.SENS_LENS_FAT0_IN (SENS_LENS_FAT0_IN),
.SENS_LENS_FAT0_IN_MASK (SENS_LENS_FAT0_IN_MASK),
.SENS_LENS_FAT0_OUT (SENS_LENS_FAT0_OUT),
.SENS_LENS_FAT0_OUT_MASK (SENS_LENS_FAT0_OUT_MASK),
.SENS_LENS_POST_SCALE (SENS_LENS_POST_SCALE),
.SENS_LENS_POST_SCALE_MASK (SENS_LENS_POST_SCALE_MASK),
.SENS_NUM_SUBCHN (SENS_NUM_SUBCHN),
.SENS_LENS_F_WIDTH (19),
.SENS_LENS_F_SHIFT (22),
.SENS_LENS_B_SHIFT (12),
.SENS_LENS_A_WIDTH (19),
.SENS_LENS_B_WIDTH (21)
) lens_flat393_i (
.prst (prst), // input
.pclk (pclk), // input
.mrst (mrst), // input
.mclk (mclk), // input
.cmd_ad (cmd_ad), // input[7:0]
.cmd_stb (cmd_stb), // input
.pxd_in (lens_pxd_in), // input[15:0]
.hact_in (lens_hact_in), // input
.sof_in (lens_sof_in), // input
.eof_in (lens_eof_in), // input
.pxd_out (gamma_pxd_in), // output[15:0] reg
.hact_out (gamma_hact_in), // output
.sof_out (gamma_sof_in), // output
.eof_out (gamma_eof_in), // output
.bayer (gamma_bayer), // input[1:0] // from gamma module
.subchannel(), // output[1:0] - RFU
.last_in_sub() // output - RFU
);
sens_gamma #( sens_gamma #(
.SENS_GAMMA_NUM_CHN (SENS_GAMMA_NUM_CHN), .SENS_NUM_SUBCHN (SENS_NUM_SUBCHN),
.SENS_GAMMA_BUFFER (SENS_GAMMA_BUFFER), .SENS_GAMMA_BUFFER (SENS_GAMMA_BUFFER),
.SENS_GAMMA_ADDR (SENS_GAMMA_ADDR), .SENS_GAMMA_ADDR (SENS_GAMMA_ADDR),
.SENS_GAMMA_ADDR_MASK (SENS_GAMMA_ADDR_MASK), .SENS_GAMMA_ADDR_MASK (SENS_GAMMA_ADDR_MASK),
...@@ -569,7 +648,8 @@ module sensor_channel#( ...@@ -569,7 +648,8 @@ module sensor_channel#(
.eof_out (gamma_eof_out), // output .eof_out (gamma_eof_out), // output
.mclk (mclk), // input .mclk (mclk), // input
.cmd_ad (cmd_ad), // input[7:0] .cmd_ad (cmd_ad), // input[7:0]
.cmd_stb (cmd_stb) // input .cmd_stb (cmd_stb), // input
.bayer_out (gamma_bayer) // output [1:0]
); );
// TODO: Use generate to generate 1-4 histogram modules // TODO: Use generate to generate 1-4 histogram modules
......
...@@ -36,7 +36,7 @@ module sensors393 #( ...@@ -36,7 +36,7 @@ module sensors393 #(
parameter SENSIO_STATUS_REG_REL = 1, // 4 locations" 'h21, 'h23, 'h25, 'h27 parameter SENSIO_STATUS_REG_REL = 1, // 4 locations" 'h21, 'h23, 'h25, 'h27
parameter SENSOR_NUM_HISTOGRAM= 3, // number of histogram channels parameter SENSOR_NUM_HISTOGRAM= 3, // number of histogram channels
parameter HISTOGRAM_RAM_MODE = "NOBUF", // valid: "NOBUF" (32-bits, no buffering), "BUF18", "BUF32" parameter HISTOGRAM_RAM_MODE = "NOBUF", // valid: "NOBUF" (32-bits, no buffering), "BUF18", "BUF32"
parameter SENS_GAMMA_NUM_CHN = 3, // number of subchannels for his sensor ports (1..4) parameter SENS_NUM_SUBCHN = 3, // number of subchannels for his sensor ports (1..4)
parameter SENS_GAMMA_BUFFER = 0, // 1 - use "shadow" table for clean switching, 0 - single table per channel parameter SENS_GAMMA_BUFFER = 0, // 1 - use "shadow" table for clean switching, 0 - single table per channel
// parameters defining address map // parameters defining address map
...@@ -91,7 +91,31 @@ module sensors393 #( ...@@ -91,7 +91,31 @@ module sensors393 #(
parameter SENS_GAMMA_MODE_REPET = 4, parameter SENS_GAMMA_MODE_REPET = 4,
parameter SENS_GAMMA_MODE_TRIG = 5, parameter SENS_GAMMA_MODE_TRIG = 5,
parameter SENSIO_RADDR = 8, //'h308 .. 'h30c // Vignetting correction / pixel value scaling - controlled via single data word (same as in 252), some of bits [23:16]
// are used to select register, bits 25:24 - select sub-frame
parameter SENS_LENS_RADDR = 'h3c,
parameter SENS_LENS_ADDR_MASK = 'h7fc,
parameter SENS_LENS_COEFF = 'h3, // set vignetting/scale coefficients (
parameter SENS_LENS_AX = 'h00, // 00000...
parameter SENS_LENS_AX_MASK = 'hf8,
parameter SENS_LENS_AY = 'h08, // 00001...
parameter SENS_LENS_AY_MASK = 'hf8,
parameter SENS_LENS_C = 'h10, // 00010...
parameter SENS_LENS_C_MASK = 'hf8,
parameter SENS_LENS_BX = 'h20, // 001.....
parameter SENS_LENS_BX_MASK = 'he0,
parameter SENS_LENS_BY = 'h40, // 010.....
parameter SENS_LENS_BY_MASK = 'he0,
parameter SENS_LENS_SCALES = 'h60, // 01100...
parameter SENS_LENS_SCALES_MASK = 'hf8,
parameter SENS_LENS_FAT0_IN = 'h68, // 01101000
parameter SENS_LENS_FAT0_IN_MASK = 'hff,
parameter SENS_LENS_FAT0_OUT = 'h69, // 01101001
parameter SENS_LENS_FAT0_OUT_MASK = 'hff,
parameter SENS_LENS_POST_SCALE = 'h6a, // 01101010
parameter SENS_LENS_POST_SCALE_MASK = 'hff,
parameter SENSIO_RADDR = 8, //'h408 .. 'h40f
parameter SENSIO_ADDR_MASK = 'h7f8, parameter SENSIO_ADDR_MASK = 'h7f8,
// sens_parallel12 registers // sens_parallel12 registers
parameter SENSIO_CTRL = 'h0, parameter SENSIO_CTRL = 'h0,
...@@ -117,8 +141,8 @@ module sensors393 #( ...@@ -117,8 +141,8 @@ module sensors393 #(
parameter SENSIO_DELAYS = 'h4, // 'h4..'h7 parameter SENSIO_DELAYS = 'h4, // 'h4..'h7
// 4 of 8-bit delays per register // 4 of 8-bit delays per register
// sensor_i2c_io command/data write registers s (relative to SENSOR_GROUP_ADDR) // sensor_i2c_io command/data write registers s (relative to SENSOR_GROUP_ADDR)
parameter SENSI2C_ABS_RADDR = 'h10, // 'h310..'h31f parameter SENSI2C_ABS_RADDR = 'h10, // 'h410..'h41f
parameter SENSI2C_REL_RADDR = 'h20, // 'h320..'h32f parameter SENSI2C_REL_RADDR = 'h20, // 'h420..'h42f
parameter SENSI2C_ADDR_MASK = 'h7f0, // both for SENSI2C_ABS_ADDR and SENSI2C_REL_ADDR parameter SENSI2C_ADDR_MASK = 'h7f0, // both for SENSI2C_ABS_ADDR and SENSI2C_REL_ADDR
// sens_hist registers (relative to SENSOR_GROUP_ADDR) // sens_hist registers (relative to SENSOR_GROUP_ADDR)
...@@ -326,7 +350,7 @@ module sensors393 #( ...@@ -326,7 +350,7 @@ module sensors393 #(
.SENS_SYNC_MINPER (SENS_SYNC_MINPER), .SENS_SYNC_MINPER (SENS_SYNC_MINPER),
.SENSOR_NUM_HISTOGRAM (SENSOR_NUM_HISTOGRAM), .SENSOR_NUM_HISTOGRAM (SENSOR_NUM_HISTOGRAM),
.HISTOGRAM_RAM_MODE (HISTOGRAM_RAM_MODE), .HISTOGRAM_RAM_MODE (HISTOGRAM_RAM_MODE),
.SENS_GAMMA_NUM_CHN (SENS_GAMMA_NUM_CHN), .SENS_NUM_SUBCHN (SENS_NUM_SUBCHN),
.SENS_GAMMA_BUFFER (SENS_GAMMA_BUFFER), .SENS_GAMMA_BUFFER (SENS_GAMMA_BUFFER),
.SENSOR_CTRL_RADDR (SENSOR_CTRL_RADDR), .SENSOR_CTRL_RADDR (SENSOR_CTRL_RADDR),
.SENSOR_CTRL_ADDR_MASK (SENSOR_CTRL_ADDR_MASK), .SENSOR_CTRL_ADDR_MASK (SENSOR_CTRL_ADDR_MASK),
...@@ -349,7 +373,6 @@ module sensors393 #( ...@@ -349,7 +373,6 @@ module sensors393 #(
.SENSI2C_CMD_SCL_WIDTH (SENSI2C_CMD_SCL_WIDTH), .SENSI2C_CMD_SCL_WIDTH (SENSI2C_CMD_SCL_WIDTH),
.SENSI2C_CMD_SDA (SENSI2C_CMD_SDA), .SENSI2C_CMD_SDA (SENSI2C_CMD_SDA),
.SENSI2C_CMD_SDA_WIDTH (SENSI2C_CMD_SDA_WIDTH), .SENSI2C_CMD_SDA_WIDTH (SENSI2C_CMD_SDA_WIDTH),
.SENSI2C_STATUS (SENSI2C_STATUS), .SENSI2C_STATUS (SENSI2C_STATUS),
.SENS_GAMMA_RADDR (SENS_GAMMA_RADDR), .SENS_GAMMA_RADDR (SENS_GAMMA_RADDR),
.SENS_GAMMA_ADDR_MASK (SENS_GAMMA_ADDR_MASK), .SENS_GAMMA_ADDR_MASK (SENS_GAMMA_ADDR_MASK),
...@@ -363,6 +386,27 @@ module sensors393 #( ...@@ -363,6 +386,27 @@ module sensors393 #(
.SENS_GAMMA_MODE_EN (SENS_GAMMA_MODE_EN), .SENS_GAMMA_MODE_EN (SENS_GAMMA_MODE_EN),
.SENS_GAMMA_MODE_REPET (SENS_GAMMA_MODE_REPET), .SENS_GAMMA_MODE_REPET (SENS_GAMMA_MODE_REPET),
.SENS_GAMMA_MODE_TRIG (SENS_GAMMA_MODE_TRIG), .SENS_GAMMA_MODE_TRIG (SENS_GAMMA_MODE_TRIG),
.SENS_LENS_RADDR (SENS_LENS_RADDR),
.SENS_LENS_ADDR_MASK (SENS_LENS_ADDR_MASK),
.SENS_LENS_COEFF (SENS_LENS_COEFF),
.SENS_LENS_AX (SENS_LENS_AX),
.SENS_LENS_AX_MASK (SENS_LENS_AX_MASK),
.SENS_LENS_AY (SENS_LENS_AY),
.SENS_LENS_AY_MASK (SENS_LENS_AY_MASK),
.SENS_LENS_C (SENS_LENS_C),
.SENS_LENS_C_MASK (SENS_LENS_C_MASK),
.SENS_LENS_BX (SENS_LENS_BX),
.SENS_LENS_BX_MASK (SENS_LENS_BX_MASK),
.SENS_LENS_BY (SENS_LENS_BY),
.SENS_LENS_BY_MASK (SENS_LENS_BY_MASK),
.SENS_LENS_SCALES (SENS_LENS_SCALES),
.SENS_LENS_SCALES_MASK (SENS_LENS_SCALES_MASK),
.SENS_LENS_FAT0_IN (SENS_LENS_FAT0_IN),
.SENS_LENS_FAT0_IN_MASK (SENS_LENS_FAT0_IN_MASK),
.SENS_LENS_FAT0_OUT (SENS_LENS_FAT0_OUT),
.SENS_LENS_FAT0_OUT_MASK (SENS_LENS_FAT0_OUT_MASK),
.SENS_LENS_POST_SCALE (SENS_LENS_POST_SCALE),
.SENS_LENS_POST_SCALE_MASK (SENS_LENS_POST_SCALE_MASK),
.SENSIO_RADDR (SENSIO_RADDR), .SENSIO_RADDR (SENSIO_RADDR),
.SENSIO_ADDR_MASK (SENSIO_ADDR_MASK), .SENSIO_ADDR_MASK (SENSIO_ADDR_MASK),
.SENSIO_CTRL (SENSIO_CTRL), .SENSIO_CTRL (SENSIO_CTRL),
......
...@@ -1376,7 +1376,7 @@ assign axi_grst = axi_rst_pre; ...@@ -1376,7 +1376,7 @@ assign axi_grst = axi_rst_pre;
.SENSIO_STATUS_REG_REL (SENSIO_STATUS_REG_REL), .SENSIO_STATUS_REG_REL (SENSIO_STATUS_REG_REL),
.SENSOR_NUM_HISTOGRAM (SENSOR_NUM_HISTOGRAM), .SENSOR_NUM_HISTOGRAM (SENSOR_NUM_HISTOGRAM),
.HISTOGRAM_RAM_MODE (HISTOGRAM_RAM_MODE), .HISTOGRAM_RAM_MODE (HISTOGRAM_RAM_MODE),
.SENS_GAMMA_NUM_CHN (SENS_GAMMA_NUM_CHN), .SENS_NUM_SUBCHN (SENS_NUM_SUBCHN),
.SENS_GAMMA_BUFFER (SENS_GAMMA_BUFFER), .SENS_GAMMA_BUFFER (SENS_GAMMA_BUFFER),
.SENSOR_CTRL_RADDR (SENSOR_CTRL_RADDR), .SENSOR_CTRL_RADDR (SENSOR_CTRL_RADDR),
.SENSOR_CTRL_ADDR_MASK (SENSOR_CTRL_ADDR_MASK), .SENSOR_CTRL_ADDR_MASK (SENSOR_CTRL_ADDR_MASK),
...@@ -1416,6 +1416,26 @@ assign axi_grst = axi_rst_pre; ...@@ -1416,6 +1416,26 @@ assign axi_grst = axi_rst_pre;
.SENS_GAMMA_MODE_EN (SENS_GAMMA_MODE_EN), .SENS_GAMMA_MODE_EN (SENS_GAMMA_MODE_EN),
.SENS_GAMMA_MODE_REPET (SENS_GAMMA_MODE_REPET), .SENS_GAMMA_MODE_REPET (SENS_GAMMA_MODE_REPET),
.SENS_GAMMA_MODE_TRIG (SENS_GAMMA_MODE_TRIG), .SENS_GAMMA_MODE_TRIG (SENS_GAMMA_MODE_TRIG),
.SENS_LENS_RADDR (SENS_LENS_RADDR),
.SENS_LENS_ADDR_MASK (SENS_LENS_ADDR_MASK),
.SENS_LENS_AX (SENS_LENS_AX),
.SENS_LENS_AX_MASK (SENS_LENS_AX_MASK),
.SENS_LENS_AY (SENS_LENS_AY),
.SENS_LENS_AY_MASK (SENS_LENS_AY_MASK),
.SENS_LENS_C (SENS_LENS_C),
.SENS_LENS_C_MASK (SENS_LENS_C_MASK),
.SENS_LENS_BX (SENS_LENS_BX),
.SENS_LENS_BX_MASK (SENS_LENS_BX_MASK),
.SENS_LENS_BY (SENS_LENS_BY),
.SENS_LENS_BY_MASK (SENS_LENS_BY_MASK),
.SENS_LENS_SCALES (SENS_LENS_SCALES),
.SENS_LENS_SCALES_MASK (SENS_LENS_SCALES_MASK),
.SENS_LENS_FAT0_IN (SENS_LENS_FAT0_IN),
.SENS_LENS_FAT0_IN_MASK (SENS_LENS_FAT0_IN_MASK),
.SENS_LENS_FAT0_OUT (SENS_LENS_FAT0_OUT),
.SENS_LENS_FAT0_OUT_MASK (SENS_LENS_FAT0_OUT_MASK),
.SENS_LENS_POST_SCALE (SENS_LENS_POST_SCALE),
.SENS_LENS_POST_SCALE_MASK (SENS_LENS_POST_SCALE_MASK),
.SENSIO_RADDR (SENSIO_RADDR), .SENSIO_RADDR (SENSIO_RADDR),
.SENSIO_ADDR_MASK (SENSIO_ADDR_MASK), .SENSIO_ADDR_MASK (SENSIO_ADDR_MASK),
.SENSIO_CTRL (SENSIO_CTRL), .SENSIO_CTRL (SENSIO_CTRL),
......
...@@ -797,6 +797,9 @@ assign #10 gpio_pins[9] = gpio_pins[8]; ...@@ -797,6 +797,9 @@ assign #10 gpio_pins[9] = gpio_pins[8];
TEST_TITLE = "ALL_DONE"; TEST_TITLE = "ALL_DONE";
$display("===================== TEST_%s =========================",TEST_TITLE); $display("===================== TEST_%s =========================",TEST_TITLE);
#20000; #20000;
TEST_TITLE = "WAITING 30usec more";
$display("===================== TEST_%s =========================",TEST_TITLE);
#30000;
$finish; $finish;
end end
// protect from never end // protect from never end
...@@ -1936,6 +1939,30 @@ task setup_sensor_channel; ...@@ -1936,6 +1939,30 @@ task setup_sensor_channel;
$display("===================== TEST_%s =========================",TEST_TITLE); $display("===================== TEST_%s =========================",TEST_TITLE);
test_i2c_353; // test soft/sequencer i2c test_i2c_353; // test soft/sequencer i2c
TEST_TITLE = "LENS_FLAT_SETUP";
$display("===================== TEST_%s =========================",TEST_TITLE);
set_sensor_lens_flat_heights (
num_sensor, // input [1:0] num_sensor;
'hffff, // input [15:0] height0_m1; // height of the first sub-frame minus 1
0, // input [15:0] height1_m1; // height of the second sub-frame minus 1
0); // input [15:0] height2_m1; // height of the third sub-frame minus 1 (no need for 4-th)
set_sensor_lens_flat_parameters(
num_sensor,
// add mode "DIRECT", "ASAP", "RELATIVE", "ABSOLUTE" and frame number
0, // input [18:0] AX;
0, // input [18:0] AY;
0, // input [20:0] BX;
0, // input [20:0] BY;
'h8000, // input [18:0] C;
32768, // input [16:0] scales0;
32768, // input [16:0] scales1;
32768, // input [16:0] scales2;
32768, // input [16:0] scales3;
0, // input [15:0] fatzero_in;
0, // input [15:0] fatzero_out;
1); // input [ 3:0] post_scale;
TEST_TITLE = "GAMMA_SETUP"; TEST_TITLE = "GAMMA_SETUP";
$display("===================== TEST_%s =========================",TEST_TITLE); $display("===================== TEST_%s =========================",TEST_TITLE);
...@@ -2329,7 +2356,85 @@ task set_sensor_io_width; ...@@ -2329,7 +2356,85 @@ task set_sensor_io_width;
endtask endtask
task set_sensor_lens_flat_heights;
input [1:0] num_sensor;
input [15:0] height0_m1; // height of the first sub-frame minus 1
input [15:0] height1_m1; // height of the second sub-frame minus 1
input [15:0] height2_m1; // height of the third sub-frame minus 1 (no need for 4-th)
reg [29:0] reg_addr;
begin
reg_addr = (SENSOR_GROUP_ADDR + num_sensor * SENSOR_BASE_INC) + SENS_LENS_RADDR;
write_contol_register(reg_addr, {16'b0, height0_m1});
write_contol_register(reg_addr+1, {16'b0, height1_m1});
write_contol_register(reg_addr+2, {16'b0, height2_m1});
end
endtask
task set_sensor_lens_flat_parameters;
input [1:0] num_sensor;
// add mode "DIRECT", "ASAP", "RELATIVE", "ABSOLUTE" and frame number
input [18:0] AX;
input [18:0] AY;
input [20:0] BX;
input [20:0] BY;
input [18:0] C;
input [16:0] scales0;
input [16:0] scales1;
input [16:0] scales2;
input [16:0] scales3;
input [15:0] fatzero_in;
input [15:0] fatzero_out;
input [ 3:0] post_scale;
reg [29:0] reg_addr;
reg [31:0] data;
begin
reg_addr = (SENSOR_GROUP_ADDR + num_sensor * SENSOR_BASE_INC) + SENS_LENS_RADDR + SENS_LENS_COEFF;
data = func_lens_data(num_sensor, SENS_LENS_AX);
data[18:0] = AX;
write_contol_register(reg_addr, data);
data = func_lens_data(num_sensor, SENS_LENS_AY);
data[18:0] = AY;
write_contol_register(reg_addr, data);
data = func_lens_data(num_sensor, SENS_LENS_C);
data[18:0] = C;
write_contol_register(reg_addr, data);
data = func_lens_data(num_sensor, SENS_LENS_BX);
data[20:0] = BX;
write_contol_register(reg_addr, data);
data = func_lens_data(num_sensor, SENS_LENS_BY);
data[20:0] = BY;
write_contol_register(reg_addr, data);
data = func_lens_data(num_sensor, SENS_LENS_SCALES + 0);
data[16:0] = scales0;
write_contol_register(reg_addr, data);
data = func_lens_data(num_sensor, SENS_LENS_SCALES + 2);
data[16:0] = scales1;
write_contol_register(reg_addr, data);
data = func_lens_data(num_sensor, SENS_LENS_SCALES + 4);
data[16:0] = scales2;
write_contol_register(reg_addr, data);
data = func_lens_data(num_sensor, SENS_LENS_SCALES + 6);
data[16:0] = scales3;
write_contol_register(reg_addr, data);
data = func_lens_data(num_sensor, SENS_LENS_FAT0_IN);
data[15:0] = fatzero_in;
write_contol_register(reg_addr, data);
data = func_lens_data(num_sensor, SENS_LENS_FAT0_OUT);
data[15:0] = fatzero_out;
write_contol_register(reg_addr, data);
data = func_lens_data(num_sensor, SENS_LENS_POST_SCALE);
data[3:0] = post_scale;
write_contol_register(reg_addr, data);
end
endtask
function [31:0] func_lens_data;
input [1:0] num_sensor;
input [7:0] addr;
begin
func_lens_data = {6'b0, num_sensor, addr,16'b0};
end
endfunction
task program_curves; task program_curves;
......
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