26 changed files with 443 additions and 1151 deletions
-
2led_test.fdc
-
180led_test.pds
-
0source/src/input/src_genlock.v
-
0source/src/input/src_timecode.v
-
0source/src/input/src_ttl_parser.v
-
18source/src/monitor_line.v
-
4source/src/rd_data_router.v
-
16source/src/spi_reg_reader.v
-
76source/src/transmitter.v
-
157source/src/uart_reg_reader.v
-
172source/src/uart_rx.v
-
161source/src/uart_tx.v
-
0source/src/zutils/baud_rate_gen.v
-
8source/src/zutils/zutils_clk_parser.v
-
2source/src/zutils/zutils_debug_led.v
-
24source/src/zutils/zutils_edge_detecter.v
-
4source/src/zutils/zutils_multiplexer_16t1.v
-
4source/src/zutils/zutils_multiplexer_4t1.v
-
6source/src/zutils/zutils_pluse_generator.v
-
8source/src/zutils/zutils_pwm_generator.v
-
7source/src/zutils/zutils_register.v
-
5source/src/zutils/zutils_signal_filter.v
@ -1,18 +0,0 @@ |
|||
/* |
|||
* Hacky baud rate generator to divide a 50MHz clock into a 115200 baud |
|||
* rx/tx pair where the rx clcken oversamples by 16x. |
|||
*/ |
|||
module monitor_line ( |
|||
input wire clk_50m, |
|||
input wire rst_n, |
|||
input wire in, |
|||
output reg out |
|||
); |
|||
|
|||
|
|||
always @(posedge clk_50m or negedge rst_n) begin |
|||
if (!rst_n) out <= 1'b0; |
|||
else out <= in; |
|||
end |
|||
|
|||
endmodule |
@ -1,76 +0,0 @@ |
|||
module transmitter ( |
|||
input wire [7:0] din, |
|||
input wire wr_en, |
|||
input wire clk_50m, |
|||
input wire clken, |
|||
input wire rest_n, |
|||
output reg tx, |
|||
output wire tx_busy, |
|||
output wire [1:0] t_state, |
|||
output wire [2:0] t_bitpos, |
|||
output wire t_worksignal |
|||
); |
|||
parameter STATE_IDLE = 2'b00; |
|||
parameter STATE_START = 2'b01; |
|||
parameter STATE_DATA = 2'b10; |
|||
parameter STATE_STOP = 2'b11; |
|||
initial begin |
|||
tx = 1'b1; |
|||
end |
|||
|
|||
|
|||
reg [7:0] data = 8'h00; |
|||
reg [2:0] bitpos = 3'h0; |
|||
reg [1:0] state = STATE_IDLE; |
|||
reg worksignal = 0; |
|||
|
|||
assign workflag = (state != STATE_IDLE); |
|||
|
|||
always @(posedge clken, posedge wr_en) begin |
|||
if (wr_en) begin |
|||
worksignal <= 1'b1; |
|||
data <= din; |
|||
end else begin |
|||
if (!workflag) worksignal <= 1'b0; |
|||
end |
|||
end |
|||
|
|||
|
|||
always @(posedge clken or negedge rest_n) begin |
|||
if (!rest_n) begin |
|||
state <= STATE_IDLE; |
|||
end else begin |
|||
case (state) |
|||
STATE_IDLE: begin |
|||
tx <= 1'b1; |
|||
if (worksignal) begin |
|||
state <= STATE_START; |
|||
bitpos <= 0; |
|||
end |
|||
end |
|||
STATE_START: begin |
|||
tx <= 1'b0; |
|||
state <= STATE_DATA; |
|||
end |
|||
STATE_DATA: begin |
|||
if (bitpos == 3'h7) state <= STATE_STOP; |
|||
else bitpos <= bitpos + 3'h1; |
|||
tx <= data[bitpos]; |
|||
end |
|||
STATE_STOP: begin |
|||
tx <= 1'b1; |
|||
state <= STATE_IDLE; |
|||
end |
|||
default begin |
|||
tx <= 1'b1; |
|||
state <= STATE_IDLE; |
|||
end |
|||
endcase |
|||
end |
|||
end |
|||
|
|||
assign tx_busy = (state != STATE_IDLE); |
|||
assign t_state = state; |
|||
assign t_bitpos = bitpos; |
|||
assign t_worksignal = worksignal; |
|||
endmodule |
@ -1,157 +0,0 @@ |
|||
module uart_reg_reader #( |
|||
parameter CLK_FRE = 50, //clock frequency(Mhz) |
|||
parameter BAUD_RATE = 115200 //serial baud rate |
|||
) ( |
|||
input clk, //clock input |
|||
input rst_n, //asynchronous reset input, low active |
|||
input wire [31:0] reg_data, //received serial data |
|||
output reg [31:0] reg_add, |
|||
output reg reg_add_valid, |
|||
input wire uart_rx_pin, |
|||
output wire uart_tx_pin |
|||
); |
|||
// |
|||
// overtime |
|||
// |----------------------^ |
|||
// v | |
|||
// IDLE ---------------> READ REG ADD ---------------> READ_REG ---------------> SEND_REG_DATA |
|||
// ^ | |
|||
// |------------------------------------------------------------------------------------v |
|||
// |
|||
// |
|||
// |
|||
// |
|||
parameter STATE_IDLE = 0; |
|||
parameter STATE_READ_REG_ADD = 1; |
|||
parameter STATE_READ_REG = 2; |
|||
parameter STATE_SEND_REG_DATA = 3; |
|||
parameter STATE_WAIT_SEND_END = 4; |
|||
|
|||
wire [7:0] rx_data; |
|||
wire rx_data_valid; |
|||
wire rx_data_ready; |
|||
|
|||
wire tx_data_ready; |
|||
reg [7:0] tx_data = 0; |
|||
reg tx_data_valid = 0; |
|||
|
|||
reg [7:0] state = 0; |
|||
reg [7:0] rxpacket_num = 0; |
|||
reg [7:0] txpacket_num = 0; |
|||
reg [7:0] rxdatacache = 0; //接收数据buffer |
|||
|
|||
uart_rx #( |
|||
.CLK_FRE (CLK_FRE), |
|||
.BAUD_RATE(BAUD_RATE) |
|||
) uart_rx_impl ( |
|||
.clk (clk), // input |
|||
.rst_n (rst_n), // input |
|||
.rx_data (rx_data), // output |
|||
.rx_data_valid(rx_data_valid), // output |
|||
.rx_data_ready(rx_data_ready), // input |
|||
.rx_pin (uart_rx_pin) // input |
|||
); |
|||
|
|||
uart_tx #( |
|||
.CLK_FRE (CLK_FRE), |
|||
.BAUD_RATE(BAUD_RATE) |
|||
) uart_tx_impl ( |
|||
.clk (clk), // input |
|||
.rst_n (rst_n), // input |
|||
.tx_data (tx_data), // input |
|||
.tx_data_valid(tx_data_valid), // input |
|||
.tx_data_ready(tx_data_ready), // output |
|||
.tx_pin (uart_tx_pin) // output |
|||
); |
|||
|
|||
|
|||
assign rx_data_ready = 1'b1; |
|||
reg [ 7:0] substep = 0; |
|||
reg [31:0] reg_data_cache = 0; |
|||
|
|||
|
|||
always @(posedge clk or negedge rst_n) begin |
|||
if (!rst_n) begin |
|||
state <= STATE_IDLE; |
|||
rxpacket_num <= 0; |
|||
txpacket_num <= 0; |
|||
substep <= 0; |
|||
reg_add <= 0; |
|||
reg_add_valid <= 0; |
|||
end else begin |
|||
case (state) |
|||
STATE_IDLE: begin |
|||
rxpacket_num <= 0; |
|||
txpacket_num <= 0; |
|||
substep <= 0; |
|||
state <= STATE_READ_REG_ADD; |
|||
end |
|||
STATE_READ_REG_ADD: begin |
|||
if (rxpacket_num == 1) begin |
|||
state <= STATE_READ_REG; |
|||
end else if (rx_data_valid) begin |
|||
rxdatacache <= rx_data; |
|||
rxpacket_num <= rxpacket_num + 1; |
|||
end |
|||
end |
|||
STATE_READ_REG: begin |
|||
case (substep) |
|||
0: begin |
|||
reg_add_valid <= 1; |
|||
reg_add[7:0] <= rxdatacache; |
|||
substep <= 1; |
|||
end |
|||
1: begin |
|||
tx_data_valid <= 0; |
|||
substep <= 0; |
|||
state <= STATE_SEND_REG_DATA; |
|||
end |
|||
endcase |
|||
end |
|||
STATE_SEND_REG_DATA: begin |
|||
case (substep) |
|||
0: begin |
|||
case (txpacket_num) |
|||
0: begin |
|||
tx_data[7:0] <= reg_data_cache[7:0]; |
|||
end |
|||
1: begin |
|||
tx_data[7:0] <= reg_data_cache[15:8]; |
|||
end |
|||
2: begin |
|||
tx_data[7:0] <= reg_data_cache[23:16]; |
|||
end |
|||
3: begin |
|||
tx_data[7:0] <= reg_data_cache[31:24]; |
|||
end |
|||
default: begin |
|||
tx_data[7:0] <= 0; |
|||
end |
|||
endcase |
|||
tx_data_valid <= 1; |
|||
txpacket_num <= txpacket_num + 1; |
|||
substep <= 1; |
|||
end |
|||
1: begin |
|||
tx_data_valid <= 0; |
|||
substep <= 2; |
|||
end |
|||
2: begin |
|||
if (tx_data_ready) begin |
|||
if (txpacket_num != 4) begin |
|||
substep <= 0; |
|||
end else begin |
|||
substep <= 0; |
|||
state <= STATE_IDLE; |
|||
end |
|||
end |
|||
end |
|||
endcase |
|||
end |
|||
default begin |
|||
state <= STATE_IDLE; |
|||
end |
|||
endcase |
|||
end |
|||
end |
|||
endmodule |
@ -1,172 +0,0 @@ |
|||
////////////////////////////////////////////////////////////////////////////////// |
|||
// // |
|||
// // |
|||
// Author: meisq // |
|||
// msq@qq.com // |
|||
// ALINX(shanghai) Technology Co.,Ltd // |
|||
// heijin // |
|||
// WEB: http://www.alinx.cn/ // |
|||
// BBS: http://www.heijin.org/ // |
|||
// // |
|||
////////////////////////////////////////////////////////////////////////////////// |
|||
// // |
|||
// Copyright (c) 2017,ALINX(shanghai) Technology Co.,Ltd // |
|||
// All rights reserved // |
|||
// // |
|||
// This source file may be used and distributed without restriction provided // |
|||
// that this copyright statement is not removed from the file and that any // |
|||
// derivative work contains the original copyright notice and the associated // |
|||
// disclaimer. // |
|||
// // |
|||
////////////////////////////////////////////////////////////////////////////////// |
|||
|
|||
//================================================================================ |
|||
// Revision History: |
|||
// Date By Revision Change Description |
|||
//-------------------------------------------------------------------------------- |
|||
//2017/8/1 1.0 Original |
|||
//*******************************************************************************/ |
|||
module uart_rx |
|||
#( |
|||
parameter CLK_FRE = 50, //clock frequency(Mhz) |
|||
parameter BAUD_RATE = 115200 //serial baud rate |
|||
) |
|||
( |
|||
input clk, //clock input |
|||
input rst_n, //asynchronous reset input, low active |
|||
output reg[7:0] rx_data, //received serial data |
|||
output reg rx_data_valid, //received serial data is valid |
|||
input rx_data_ready, //data receiver module ready |
|||
input rx_pin //serial data input |
|||
); |
|||
//calculates the clock cycle for baud rate |
|||
localparam CYCLE = CLK_FRE * 1000000 / BAUD_RATE; |
|||
//state machine code |
|||
localparam S_IDLE = 1; |
|||
localparam S_START = 2; //start bit |
|||
localparam S_REC_BYTE = 3; //data bits |
|||
localparam S_STOP = 4; //stop bit |
|||
localparam S_DATA = 5; |
|||
|
|||
reg[2:0] state; |
|||
reg[2:0] next_state; |
|||
reg rx_d0; //delay 1 clock for rx_pin |
|||
reg rx_d1; //delay 1 clock for rx_d0 |
|||
wire rx_negedge; //negedge of rx_pin |
|||
reg[7:0] rx_bits; //temporary storage of received data |
|||
reg[15:0] cycle_cnt; //baud counter |
|||
reg[2:0] bit_cnt; //bit counter |
|||
|
|||
assign |
|||
rx_negedge = rx_d1 && ~rx_d0; |
|||
|
|||
always@(posedge clk or negedge rst_n) |
|||
begin |
|||
if(rst_n == 1'b0) |
|||
begin |
|||
rx_d0 <= 1'b0; |
|||
rx_d1 <= 1'b0; |
|||
end |
|||
else |
|||
begin |
|||
rx_d0 <= rx_pin; |
|||
rx_d1 <= rx_d0; |
|||
end |
|||
end |
|||
|
|||
|
|||
always@(posedge clk or negedge rst_n) |
|||
begin |
|||
if(rst_n == 1'b0) |
|||
state <= S_IDLE; |
|||
else |
|||
state <= next_state; |
|||
end |
|||
|
|||
always@(*) |
|||
begin |
|||
case(state) |
|||
S_IDLE: |
|||
if(rx_negedge) |
|||
next_state <= S_START; |
|||
else |
|||
next_state <= S_IDLE; |
|||
S_START: |
|||
if(cycle_cnt == CYCLE - 1)//one data cycle |
|||
next_state <= S_REC_BYTE; |
|||
else |
|||
next_state <= S_START; |
|||
S_REC_BYTE: |
|||
if(cycle_cnt == CYCLE - 1 && bit_cnt == 3'd7) //receive 8bit data |
|||
next_state <= S_STOP; |
|||
else |
|||
next_state <= S_REC_BYTE; |
|||
S_STOP: |
|||
if(cycle_cnt == CYCLE/2 - 1)//half bit cycle,to avoid missing the next byte receiver |
|||
next_state <= S_DATA; |
|||
else |
|||
next_state <= S_STOP; |
|||
S_DATA: |
|||
if(rx_data_ready) //data receive complete |
|||
next_state <= S_IDLE; |
|||
else |
|||
next_state <= S_DATA; |
|||
default: |
|||
next_state <= S_IDLE; |
|||
endcase |
|||
end |
|||
|
|||
always@(posedge clk or negedge rst_n) |
|||
begin |
|||
if(rst_n == 1'b0) |
|||
rx_data_valid <= 1'b0; |
|||
else if(state == S_STOP && next_state != state) |
|||
rx_data_valid <= 1'b1; |
|||
else if(state == S_DATA && rx_data_ready) |
|||
rx_data_valid <= 1'b0; |
|||
end |
|||
|
|||
always@(posedge clk or negedge rst_n) |
|||
begin |
|||
if(rst_n == 1'b0) |
|||
rx_data <= 8'd0; |
|||
else if(state == S_STOP && next_state != state) |
|||
rx_data <= rx_bits;//latch received data |
|||
end |
|||
|
|||
always@(posedge clk or negedge rst_n) |
|||
begin |
|||
if(rst_n == 1'b0) |
|||
begin |
|||
bit_cnt <= 3'd0; |
|||
end |
|||
else if(state == S_REC_BYTE) |
|||
if(cycle_cnt == CYCLE - 1) |
|||
bit_cnt <= bit_cnt + 3'd1; |
|||
else |
|||
bit_cnt <= bit_cnt; |
|||
else |
|||
bit_cnt <= 3'd0; |
|||
end |
|||
|
|||
|
|||
always@(posedge clk or negedge rst_n) |
|||
begin |
|||
if(rst_n == 1'b0) |
|||
cycle_cnt <= 16'd0; |
|||
else if((state == S_REC_BYTE && cycle_cnt == CYCLE - 1) || next_state != state) |
|||
cycle_cnt <= 16'd0; |
|||
else |
|||
cycle_cnt <= cycle_cnt + 16'd1; |
|||
end |
|||
//receive serial data bit data |
|||
always@(posedge clk or negedge rst_n) |
|||
begin |
|||
if(rst_n == 1'b0) |
|||
rx_bits <= 8'd0; |
|||
else if(state == S_REC_BYTE && cycle_cnt == CYCLE/2 - 1) |
|||
rx_bits[bit_cnt] <= rx_pin; |
|||
else |
|||
rx_bits <= rx_bits; |
|||
end |
|||
endmodule |
@ -1,161 +0,0 @@ |
|||
////////////////////////////////////////////////////////////////////////////////// |
|||
// // |
|||
// // |
|||
// Author: meisq // |
|||
// msq@qq.com // |
|||
// ALINX(shanghai) Technology Co.,Ltd // |
|||
// heijin // |
|||
// WEB: http://www.alinx.cn/ // |
|||
// BBS: http://www.heijin.org/ // |
|||
// // |
|||
////////////////////////////////////////////////////////////////////////////////// |
|||
// // |
|||
// Copyright (c) 2017,ALINX(shanghai) Technology Co.,Ltd // |
|||
// All rights reserved // |
|||
// // |
|||
// This source file may be used and distributed without restriction provided // |
|||
// that this copyright statement is not removed from the file and that any // |
|||
// derivative work contains the original copyright notice and the associated // |
|||
// disclaimer. // |
|||
// // |
|||
////////////////////////////////////////////////////////////////////////////////// |
|||
|
|||
//================================================================================ |
|||
// Revision History: |
|||
// Date By Revision Change Description |
|||
//-------------------------------------------------------------------------------- |
|||
//2017/8/1 1.0 Original |
|||
//*******************************************************************************/ |
|||
module uart_tx |
|||
#( |
|||
parameter CLK_FRE = 50, //clock frequency(Mhz) |
|||
parameter BAUD_RATE = 115200 //serial baud rate |
|||
) |
|||
( |
|||
input clk, //clock input |
|||
input rst_n, //asynchronous reset input, low active |
|||
input[7:0] tx_data, //data to send |
|||
input tx_data_valid, //data to be sent is valid |
|||
output reg tx_data_ready, //send ready |
|||
output tx_pin //serial data output |
|||
); |
|||
//calculates the clock cycle for baud rate |
|||
localparam CYCLE = CLK_FRE * 1000000 / BAUD_RATE; |
|||
//state machine code |
|||
localparam S_IDLE = 1; |
|||
localparam S_START = 2;//start bit |
|||
localparam S_SEND_BYTE = 3;//data bits |
|||
localparam S_STOP = 4;//stop bit |
|||
reg[2:0] state; |
|||
reg[2:0] next_state; |
|||
reg[15:0] cycle_cnt; //baud counter |
|||
reg[2:0] bit_cnt;//bit counter |
|||
reg[7:0] tx_data_latch; //latch data to send |
|||
reg tx_reg; //serial data output |
|||
assign tx_pin = tx_reg; |
|||
always@(posedge clk or negedge rst_n) |
|||
begin |
|||
if(rst_n == 1'b0) |
|||
state <= S_IDLE; |
|||
else |
|||
state <= next_state; |
|||
end |
|||
|
|||
always@(*) |
|||
begin |
|||
case(state) |
|||
S_IDLE: |
|||
if(tx_data_valid == 1'b1) |
|||
next_state <= S_START; |
|||
else |
|||
next_state <= S_IDLE; |
|||
S_START: |
|||
if(cycle_cnt == CYCLE - 1) |
|||
next_state <= S_SEND_BYTE; |
|||
else |
|||
next_state <= S_START; |
|||
S_SEND_BYTE: |
|||
if(cycle_cnt == CYCLE - 1 && bit_cnt == 3'd7) |
|||
next_state <= S_STOP; |
|||
else |
|||
next_state <= S_SEND_BYTE; |
|||
S_STOP: |
|||
if(cycle_cnt == CYCLE - 1) |
|||
next_state <= S_IDLE; |
|||
else |
|||
next_state <= S_STOP; |
|||
default: |
|||
next_state <= S_IDLE; |
|||
endcase |
|||
end |
|||
always@(posedge clk or negedge rst_n) |
|||
begin |
|||
if(rst_n == 1'b0) |
|||
begin |
|||
tx_data_ready <= 1'b0; |
|||
end |
|||
else if(state == S_IDLE) |
|||
if(tx_data_valid == 1'b1) |
|||
tx_data_ready <= 1'b0; |
|||
else |
|||
tx_data_ready <= 1'b1; |
|||
else if(state == S_STOP && cycle_cnt == CYCLE - 1) |
|||
tx_data_ready <= 1'b1; |
|||
end |
|||
|
|||
|
|||
always@(posedge clk or negedge rst_n) |
|||
begin |
|||
if(rst_n == 1'b0) |
|||
begin |
|||
tx_data_latch <= 8'd0; |
|||
end |
|||
else if(state == S_IDLE && tx_data_valid == 1'b1) |
|||
tx_data_latch <= tx_data; |
|||
|
|||
end |
|||
|
|||
always@(posedge clk or negedge rst_n) |
|||
begin |
|||
if(rst_n == 1'b0) |
|||
begin |
|||
bit_cnt <= 3'd0; |
|||
end |
|||
else if(state == S_SEND_BYTE) |
|||
if(cycle_cnt == CYCLE - 1) |
|||
bit_cnt <= bit_cnt + 3'd1; |
|||
else |
|||
bit_cnt <= bit_cnt; |
|||
else |
|||
bit_cnt <= 3'd0; |
|||
end |
|||
|
|||
|
|||
always@(posedge clk or negedge rst_n) |
|||
begin |
|||
if(rst_n == 1'b0) |
|||
cycle_cnt <= 16'd0; |
|||
else if((state == S_SEND_BYTE && cycle_cnt == CYCLE - 1) || next_state != state) |
|||
cycle_cnt <= 16'd0; |
|||
else |
|||
cycle_cnt <= cycle_cnt + 16'd1; |
|||
end |
|||
|
|||
always@(posedge clk or negedge rst_n) |
|||
begin |
|||
if(rst_n == 1'b0) |
|||
tx_reg <= 1'b1; |
|||
else |
|||
case(state) |
|||
S_IDLE,S_STOP: |
|||
tx_reg <= 1'b1; |
|||
S_START: |
|||
tx_reg <= 1'b0; |
|||
S_SEND_BYTE: |
|||
tx_reg <= tx_data_latch[bit_cnt]; |
|||
default: |
|||
tx_reg <= 1'b1; |
|||
endcase |
|||
end |
|||
|
|||
endmodule |
Write
Preview
Loading…
Cancel
Save
Reference in new issue