Created
October 12, 2017 09:26
-
-
Save buttercutter/ba541ea1f69c08e53256151343e4b9ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module check_parity(clk, serial_in, received_data, data_is_valid, is_parity_stage, rx_error); // even parity checker | |
input clk, serial_in, data_is_valid, is_parity_stage; | |
input [7:0] received_data; | |
output reg rx_error = 0; | |
reg parity_value; // this is being computed from the received 8-bit data | |
reg parity_bit; // this bit is received directly through UART | |
always @(posedge clk) | |
begin | |
parity_value <= ^(received_data); | |
end | |
always @(posedge clk) | |
begin | |
if (is_parity_stage) | |
parity_bit <= serial_in; | |
end | |
always @(posedge clk) | |
begin | |
if ((data_is_valid) && (parity_bit != parity_value)) | |
rx_error <= 1; | |
end | |
endmodule |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment