一个完整的sdi编解码的verilog实现
时间: 2023-08-09 10:10:31 浏览: 221
SDI(Serial Digital Interface)是一种用于数字视频信号传输的标准接口,常用于广播、电视制作和视频监控等领域。SDI包括SD-SDI、HD-SDI、3G-SDI等多种规格,其中最常见的是HD-SDI。
下面是一个简单的SDI编解码的Verilog实现,包括SDI接收端和发送端。该实现仅支持HD-SDI规格,即1.485Gbps的传输速率。
SDI接收端:
```verilog
module sdi_rx (
input clk,
input rst,
input sdi_in,
output reg [9:0] data_out,
output reg [2:0] ctrl_out,
output reg err_out
);
parameter IDLE = 3'd0;
parameter HEADER = 3'd1;
parameter DATA = 3'd2;
parameter PARITY = 3'd3;
reg [2:0] state;
reg [9:0] data_reg;
reg [2:0] ctrl_reg;
reg [9:0] crc_reg;
reg crc_en;
reg [4:0] crc_cnt;
reg crc_err;
always @(posedge clk or posedge rst) begin
if (rst) begin
state <= IDLE;
data_reg <= 0;
ctrl_reg <= 0;
crc_reg <= 0;
crc_en <= 0;
crc_cnt <= 0;
crc_err <= 0;
err_out <= 0;
end else begin
case (state)
IDLE: begin
if (sdi_in == 1'b0) begin
state <= HEADER;
crc_en <= 1;
crc_cnt <= 4;
end
end
HEADER: begin
data_reg <= {data_reg[7:0], sdi_in};
ctrl_reg <= {ctrl_reg[1:0], sdi_in};
if (ctrl_reg == 3'b000) begin
state <= DATA;
crc_en <= 1;
crc_cnt <= 10;
end else if (ctrl_reg == 3'b010) begin
state <= PARITY;
crc_en <= 1;
crc_cnt <= 10;
end else if (ctrl_reg == 3'b101) begin
state <= IDLE;
if (crc_reg == 10'd0 && crc_err == 0) begin
data_out <= data_reg;
ctrl_out <= ctrl_reg;
end else begin
err_out <= 1;
end
end else begin
state <= IDLE;
err_out <= 1;
end
end
DATA: begin
data_reg <= {data_reg[7:0], sdi_in};
ctrl_reg <= {ctrl_reg[1:0], sdi_in};
if (crc_en) begin
crc_reg <= crc_reg ^ {2'b00, sdi_in};
crc_cnt <= crc_cnt - 1;
if (crc_cnt == 0) begin
crc_en <= 0;
crc_cnt <= 4;
end
end
if (ctrl_reg == 3'b101) begin
state <= IDLE;
if (crc_reg == 10'd0 && crc_err == 0) begin
data_out <= data_reg;
ctrl_out <= ctrl_reg;
end else begin
err_out <= 1;
end
end
end
PARITY: begin
if (sdi_in == crc_err) begin
crc_err <= 1;
end
if (crc_en) begin
crc_reg <= crc_reg ^ {2'b00, sdi_in};
crc_cnt <= crc_cnt - 1;
if (crc_cnt == 0) begin
crc_en <= 0;
crc_cnt <= 4;
end
end
if (ctrl_reg == 3'b101) begin
state <= IDLE;
if (crc_reg == 10'd0 && crc_err == 0) begin
data_out <= data_reg;
ctrl_out <= ctrl_reg;
end else begin
err_out <= 1;
end
end
end
endcase
end
end
endmodule
```
SDI发送端:
```verilog
module sdi_tx (
input clk,
input rst,
input [9:0] data_in,
input [2:0] ctrl_in,
output reg sdi_out
);
parameter IDLE = 3'd0;
parameter HEADER = 3'd1;
parameter DATA = 3'd2;
parameter PARITY = 3'd3;
reg [2:0] state;
reg [9:0] data_reg;
reg [2:0] ctrl_reg;
reg [9:0] crc_reg;
reg crc_en;
reg [4:0] crc_cnt;
always @(posedge clk or posedge rst) begin
if (rst) begin
state <= IDLE;
data_reg <= 0;
ctrl_reg <= 0;
crc_reg <= 0;
crc_en <= 0;
crc_cnt <= 0;
end else begin
case (state)
IDLE: begin
sdi_out <= 1'b1;
if (ctrl_in == 3'b000) begin
state <= HEADER;
crc_en <= 1;
crc_cnt <= 4;
end
end
HEADER: begin
sdi_out <= ctrl_reg[2];
data_reg <= {data_reg[7:0], sdi_out};
ctrl_reg <= {ctrl_reg[1:0], sdi_out};
if (ctrl_reg == 3'b000) begin
state <= DATA;
crc_en <= 1;
crc_cnt <= 10;
end else if (ctrl_reg == 3'b010) begin
state <= PARITY;
crc_en <= 1;
crc_cnt <= 10;
end else if (ctrl_reg == 3'b101) begin
state <= IDLE;
end else begin
state <= IDLE;
end
end
DATA: begin
sdi_out <= data_reg[9];
data_reg <= {data_reg[7:0], data_in[0]};
ctrl_reg <= {ctrl_reg[1:0], data_in[1]};
if (crc_en) begin
crc_reg <= crc_reg ^ {2'b00, sdi_out};
crc_cnt <= crc_cnt - 1;
if (crc_cnt == 0) begin
crc_en <= 0;
crc_cnt <= 4;
end
end
if (ctrl_in == 3'b101) begin
state <= HEADER;
crc_en <= 1;
crc_cnt <= 4;
end
end
PARITY: begin
sdi_out <= crc_reg[9];
if (crc_en) begin
crc_reg <= crc_reg ^ {2'b00, sdi_out};
crc_cnt <= crc_cnt - 1;
if (crc_cnt == 0) begin
crc_en <= 0;
crc_cnt <= 4;
end
end
if (ctrl_in == 3'b101) begin
state <= HEADER;
crc_en <= 1;
crc_cnt <= 4;
end
end
endcase
end
end
endmodule
```
以上是一个简单的SDI编解码的Verilog实现,仅供参考。实际应用中,需要考虑更多的细节和特殊情况。
阅读全文