2015-06-26 09:04:19 +00:00
|
|
|
// ***************************************************************************
|
|
|
|
// ***************************************************************************
|
2017-05-17 08:44:52 +00:00
|
|
|
// Copyright 2014 - 2017 (c) Analog Devices, Inc. All rights reserved.
|
|
|
|
//
|
2017-05-31 15:15:24 +00:00
|
|
|
// In this HDL repository, there are many different and unique modules, consisting
|
|
|
|
// of various HDL (Verilog or VHDL) components. The individual modules are
|
|
|
|
// developed independently, and may be accompanied by separate and unique license
|
|
|
|
// terms.
|
|
|
|
//
|
|
|
|
// The user should read each of these license terms, and understand the
|
2018-03-14 14:45:47 +00:00
|
|
|
// freedoms and responsibilities that he or she has by using this source/core.
|
2017-05-31 15:15:24 +00:00
|
|
|
//
|
|
|
|
// This core is distributed in the hope that it will be useful, but WITHOUT ANY
|
2017-05-29 06:55:41 +00:00
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE.
|
2017-05-17 08:44:52 +00:00
|
|
|
//
|
2017-05-29 06:55:41 +00:00
|
|
|
// Redistribution and use of source or resulting binaries, with or without modification
|
|
|
|
// of this file, are permitted under one of the following two license terms:
|
2017-05-17 08:44:52 +00:00
|
|
|
//
|
|
|
|
// 1. The GNU General Public License version 2 as published by the
|
2017-05-31 15:15:24 +00:00
|
|
|
// Free Software Foundation, which can be found in the top level directory
|
|
|
|
// of this repository (LICENSE_GPL2), and also online at:
|
|
|
|
// <https://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
|
2017-05-17 08:44:52 +00:00
|
|
|
//
|
|
|
|
// OR
|
|
|
|
//
|
2017-05-31 15:15:24 +00:00
|
|
|
// 2. An ADI specific BSD license, which can be found in the top level directory
|
|
|
|
// of this repository (LICENSE_ADIBSD), and also on-line at:
|
2017-05-29 06:55:41 +00:00
|
|
|
// https://github.com/analogdevicesinc/hdl/blob/master/LICENSE_ADIBSD
|
|
|
|
// This will allow to generate bit files and not release the source code,
|
|
|
|
// as long as it attaches to an ADI device.
|
2015-06-26 09:04:19 +00:00
|
|
|
//
|
|
|
|
// ***************************************************************************
|
|
|
|
// ***************************************************************************
|
|
|
|
// csc = c1*d[23:16] + c2*d[15:8] + c3*d[7:0] + c4;
|
|
|
|
|
2018-08-27 07:14:54 +00:00
|
|
|
`timescale 1ns/100ps
|
|
|
|
|
2018-09-13 13:26:51 +00:00
|
|
|
module ad_csc #(
|
2017-04-13 08:45:54 +00:00
|
|
|
|
2018-09-18 13:30:50 +00:00
|
|
|
parameter DELAY_DW = 16,
|
|
|
|
parameter MUL_COEF_DW = 17,
|
|
|
|
parameter SUM_COEF_DW = 24,
|
2022-04-08 10:21:52 +00:00
|
|
|
parameter YCbCr_2_RGB = 0
|
|
|
|
) (
|
2015-06-26 09:04:19 +00:00
|
|
|
|
|
|
|
// data
|
|
|
|
|
2018-09-18 13:30:50 +00:00
|
|
|
input clk,
|
|
|
|
input [ DELAY_DW-1:0] sync,
|
|
|
|
input [ 23:0] data,
|
2015-06-26 09:04:19 +00:00
|
|
|
|
|
|
|
// constants
|
|
|
|
|
2018-09-18 13:30:50 +00:00
|
|
|
input signed [MUL_COEF_DW-1:0] C1,
|
|
|
|
input signed [MUL_COEF_DW-1:0] C2,
|
|
|
|
input signed [MUL_COEF_DW-1:0] C3,
|
|
|
|
input signed [SUM_COEF_DW-1:0] C4,
|
2015-06-26 09:04:19 +00:00
|
|
|
|
|
|
|
// sync is delay matched
|
|
|
|
|
2018-09-18 13:24:58 +00:00
|
|
|
output [ DELAY_DW-1:0] csc_sync,
|
2022-04-08 10:21:52 +00:00
|
|
|
output [ 7:0] csc_data
|
|
|
|
);
|
2015-06-26 09:04:19 +00:00
|
|
|
|
2018-09-18 13:24:58 +00:00
|
|
|
localparam PIXEL_WD = 9; // sign extended
|
|
|
|
localparam MUL_DW = MUL_COEF_DW + PIXEL_WD -1;
|
2015-06-26 09:04:19 +00:00
|
|
|
|
2018-09-18 13:24:58 +00:00
|
|
|
// internal wires
|
2018-09-13 13:26:51 +00:00
|
|
|
|
2018-09-18 13:24:58 +00:00
|
|
|
reg signed [ 23:0] data_d1;
|
|
|
|
reg signed [ 23:0] data_d2;
|
|
|
|
reg signed [ MUL_DW:0] data_1;
|
|
|
|
reg signed [ MUL_DW:0] data_2;
|
|
|
|
reg signed [ MUL_DW:0] data_3;
|
|
|
|
reg signed [ MUL_DW:0] s_data_1;
|
|
|
|
reg signed [ MUL_DW:0] s_data_2;
|
|
|
|
reg signed [ MUL_DW:0] s_data_3;
|
|
|
|
reg [DELAY_DW-1:0] sync_1_m;
|
|
|
|
reg [DELAY_DW-1:0] sync_2_m;
|
|
|
|
reg [DELAY_DW-1:0] sync_3_m;
|
|
|
|
reg [DELAY_DW-1:0] sync_4_m;
|
|
|
|
reg [ 7:0] csc_data_d;
|
2018-09-13 13:26:51 +00:00
|
|
|
|
2018-09-18 13:24:58 +00:00
|
|
|
wire signed [8:0] color1;
|
|
|
|
wire signed [8:0] color2;
|
|
|
|
wire signed [8:0] color3;
|
2018-09-13 13:26:51 +00:00
|
|
|
|
2018-09-18 13:24:58 +00:00
|
|
|
// delay signals
|
2018-09-13 13:26:51 +00:00
|
|
|
|
|
|
|
always @(posedge clk) begin
|
|
|
|
data_d1 <= data;
|
|
|
|
data_d2 <= data_d1;
|
|
|
|
sync_1_m <= sync;
|
2018-09-18 13:24:58 +00:00
|
|
|
sync_2_m <= sync_1_m;
|
|
|
|
sync_3_m <= sync_2_m;
|
|
|
|
sync_4_m <= sync_3_m;
|
2018-09-13 13:26:51 +00:00
|
|
|
end
|
|
|
|
|
2018-09-18 13:24:58 +00:00
|
|
|
assign color1 = {1'd0, data[23:16]};
|
|
|
|
assign color2 = {1'd0, data_d1[15: 8]};
|
|
|
|
assign color3 = {1'd0, data_d2[ 7: 0]};
|
|
|
|
|
|
|
|
// pipeline DSPs for multiplications and additions
|
2018-09-13 13:26:51 +00:00
|
|
|
|
|
|
|
always @(posedge clk) begin
|
2018-09-18 13:24:58 +00:00
|
|
|
data_1 <= color1 * C1;
|
|
|
|
data_2 <= color2 * C2;
|
|
|
|
data_3 <= color3 * C3;
|
|
|
|
end
|
|
|
|
|
|
|
|
always @(posedge clk) begin
|
|
|
|
s_data_1 <= data_1 + C4;
|
|
|
|
s_data_2 <= s_data_1 + data_2;
|
|
|
|
s_data_3 <= s_data_2 + data_3;
|
2018-09-13 13:26:51 +00:00
|
|
|
end
|
|
|
|
|
2018-09-18 13:30:50 +00:00
|
|
|
generate
|
|
|
|
// in RGB to YCbCr there are no overflows or underflows
|
|
|
|
if (YCbCr_2_RGB) begin
|
2020-09-10 06:47:22 +00:00
|
|
|
reg [DELAY_DW-1:0] sync_5_m;
|
2018-09-18 13:30:50 +00:00
|
|
|
// output registers, output is unsigned (0 if sum is < 0) and saturated.
|
|
|
|
// the inputs are expected to be 1.4.20 format (output is 8bits).
|
|
|
|
|
|
|
|
always @(posedge clk) begin
|
|
|
|
if (s_data_3[27] == 1'b1) begin
|
|
|
|
csc_data_d <= 8'h0;
|
|
|
|
end else if (s_data_3[26:24] != 3'b0) begin
|
|
|
|
csc_data_d <= 8'hff;
|
|
|
|
end else begin
|
|
|
|
csc_data_d <= s_data_3[22:15];
|
|
|
|
end
|
2020-09-10 06:47:22 +00:00
|
|
|
sync_5_m <= sync_4_m;
|
2018-09-18 13:30:50 +00:00
|
|
|
end
|
|
|
|
assign csc_data = csc_data_d;
|
|
|
|
assign csc_sync = sync_5_m;
|
|
|
|
end else begin
|
|
|
|
assign csc_data = s_data_3[23:16];
|
|
|
|
assign csc_sync = sync_4_m;
|
|
|
|
end
|
|
|
|
endgenerate
|
2015-06-26 09:04:19 +00:00
|
|
|
|
|
|
|
endmodule
|