From e95933ab449f20d78ef79b634d02472908e03f75 Mon Sep 17 00:00:00 2001 From: Ushakov Michael Date: Sat, 22 Jul 2023 12:38:53 +0500 Subject: [PATCH] cleanup --- quick_rs232.v | 12 +++++------- quick_rs232_tb.v | 6 +++--- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/quick_rs232.v b/quick_rs232.v index b8b3477..e43910a 100644 --- a/quick_rs232.v +++ b/quick_rs232.v @@ -29,16 +29,14 @@ // Flow controls `define NO_FLOW_CONTROL 0 `define CTS_RTS_FLOW_CONTROL 1 -// Baud Rate -// todo(UMV) add consts ... +// Baud = Bit/s, supported values: 2400, 4800, 9600, 19200, 38400, 57600, or 115200 (RS232 ) module quick_rs232 #( - parameter CLK_FREQ = 50000000, // clk input Frequency (Hz) + parameter CLK_TICKS_PER_RS232_BIT = 434, // ticks of clock per rs232 bit (i.e 434 is a value for 50MHz at clk && 115200 bit/s RS232 speed), = clk freq / rs232 speed parameter DEFAULT_BYTE_LEN = 8, // RS232 byte length, available values are - 5, 6, 7, 8, 9 parameter DEFAULT_PARITY = `EVEN_PARITY, // Parity: No, Even, Odd, Mark or Space - parameter DEFAULT_STOP_BITS = `ONE_STOP_BIT, // Stop bits number: 0, 1.5 or 2 - parameter DEFAULT_BAUD_RATE = 115200, // Baud = Bit/s, supported values: 2400, 4800, 9600, 19200, 38400, 57600, or 115200 + parameter DEFAULT_STOP_BITS = `ONE_STOP_BIT, // Stop bits number: 0, 1.5 or 2 parameter DEFAULT_RECV_BUFFER_LEN = 16, // Input (Rx) buffer size parameter DEFAULT_FLOW_CONTROL = `NO_FLOW_CONTROL // Flow control type: NO, HARDWARE ) @@ -120,8 +118,8 @@ begin rx_data_bit_counter <= 0; rx_data_parity <= 1'b0; rx_err <= 1'b0; - TICKS_PER_UART_BIT <= CLK_FREQ / DEFAULT_BAUD_RATE; - HALF_TICKS_PER_UART_BIT <= TICKS_PER_UART_BIT / 2; + TICKS_PER_UART_BIT <= CLK_TICKS_PER_RS232_BIT; + HALF_TICKS_PER_UART_BIT <= CLK_TICKS_PER_RS232_BIT / 2; j <= 0; end else diff --git a/quick_rs232_tb.v b/quick_rs232_tb.v index 9a46265..4cf19dd 100644 --- a/quick_rs232_tb.v +++ b/quick_rs232_tb.v @@ -48,10 +48,10 @@ wire tx_busy; reg [31:0] counter; -localparam reg[31:0] RS232_BIT_TICKS = 50000000 / 115200; // == 434 +localparam reg[31:0] RS232_BIT_TICKS = 434; // 115200 bit/s at 50 MHz -quick_rs232 #(.CLK_FREQ(50000000), .DEFAULT_BYTE_LEN(8), .DEFAULT_PARITY(1), .DEFAULT_STOP_BITS(0), - .DEFAULT_BAUD_RATE(115200), .DEFAULT_RECV_BUFFER_LEN(16), .DEFAULT_FLOW_CONTROL(0)) +quick_rs232 #(.CLK_TICKS_PER_RS232_BIT(RS232_BIT_TICKS), .DEFAULT_BYTE_LEN(8), .DEFAULT_PARITY(1), .DEFAULT_STOP_BITS(0), + .DEFAULT_RECV_BUFFER_LEN(16), .DEFAULT_FLOW_CONTROL(0)) serial_dev (.clk(clk), .rst(rst), .rx(rx), .tx(tx), .rts(rts), .cts(cts), .rx_read(rx_read), .rx_err(rx_err), .rx_data(rx_data), .rx_byte_received(rx_byte_received), .tx_transaction(tx_transaction), .tx_data(tx_data), .tx_data_ready(tx_data_ready),