-
Notifications
You must be signed in to change notification settings - Fork 292
add parity to uart verification component #1181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
99fe60d
03c183d
7940e58
2fc01ff
ac0952b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,12 +18,14 @@ package uart_pkg is | |
| type uart_master_t is record | ||
| p_actor : actor_t; | ||
| p_baud_rate : natural; | ||
| p_parity : natural; | ||
| p_idle_state : std_logic; | ||
| end record; | ||
| end record uart_master_t; | ||
|
|
||
| type uart_slave_t is record | ||
| p_actor : actor_t; | ||
| p_baud_rate : natural; | ||
| p_parity : natural; | ||
| p_idle_state : std_logic; | ||
| p_data_length : positive; | ||
| end record; | ||
|
|
@@ -37,12 +39,25 @@ package uart_pkg is | |
| uart_slave : uart_slave_t; | ||
| baud_rate : natural); | ||
|
|
||
| -- 0 = no parity, 1 = odd parity, 2 = even parity | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are suitable names for the values of |
||
| procedure set_parity(signal net : inout network_t; | ||
| uart_master : uart_master_t; | ||
| parity : natural); | ||
|
|
||
| procedure set_parity(signal net : inout network_t; | ||
| uart_slave : uart_slave_t; | ||
| parity : natural); | ||
|
|
||
| constant default_baud_rate : natural := 115200; | ||
| constant default_idle_state : std_logic := '1'; | ||
| constant default_data_length : positive := 8; | ||
| constant default_parity : natural := 0; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better to use the |
||
|
|
||
| impure function new_uart_master(initial_baud_rate : natural := default_baud_rate; | ||
| initial_parity : natural := default_parity; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add new parameters to the end to avoid breaking existing implementations. |
||
| idle_state : std_logic := default_idle_state) return uart_master_t; | ||
| impure function new_uart_slave(initial_baud_rate : natural := default_baud_rate; | ||
| initial_parity : natural := default_parity; | ||
| idle_state : std_logic := default_idle_state; | ||
| data_length : positive := default_data_length) return uart_slave_t; | ||
|
|
||
|
|
@@ -52,24 +67,37 @@ package uart_pkg is | |
| impure function as_sync(uart_slave : uart_slave_t) return sync_handle_t; | ||
|
|
||
| constant uart_set_baud_rate_msg : msg_type_t := new_msg_type("uart set baud rate"); | ||
|
|
||
| constant uart_set_parity_msg : msg_type_t := new_msg_type("uart set parity rate"); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No "rate" in the message name. |
||
|
|
||
| function even_parity(data : std_logic_vector) return std_logic; | ||
| function odd_parity (data : std_logic_vector) return std_logic; | ||
|
|
||
| end package; | ||
|
|
||
| package body uart_pkg is | ||
|
|
||
| impure function new_uart_master(initial_baud_rate : natural := default_baud_rate; | ||
| initial_parity : natural := default_parity; | ||
| idle_state : std_logic := default_idle_state) return uart_master_t is | ||
| begin | ||
| return (p_actor => new_actor, | ||
| p_baud_rate => initial_baud_rate, | ||
| p_parity => initial_parity, | ||
| p_idle_state => idle_state); | ||
| end; | ||
|
|
||
| impure function new_uart_slave(initial_baud_rate : natural := default_baud_rate; | ||
| impure function new_uart_slave( | ||
| initial_baud_rate : natural := default_baud_rate; | ||
| initial_parity : natural := default_parity; | ||
| idle_state : std_logic := default_idle_state; | ||
| data_length : positive := default_data_length) return uart_slave_t is | ||
| data_length : positive := default_data_length | ||
| ) return uart_slave_t is | ||
|
|
||
| begin | ||
| return (p_actor => new_actor, | ||
| p_baud_rate => initial_baud_rate, | ||
| p_parity => initial_parity, | ||
| p_idle_state => idle_state, | ||
| p_data_length => data_length); | ||
| end; | ||
|
|
@@ -116,4 +144,44 @@ package body uart_pkg is | |
| begin | ||
| set_baud_rate(net, uart_slave.p_actor, baud_rate); | ||
| end; | ||
|
|
||
| procedure set_parity(signal net : inout network_t; | ||
| actor : actor_t; | ||
| parity : natural) is | ||
| variable msg : msg_t := new_msg(uart_set_parity_msg); | ||
| begin | ||
| if parity > 2 then | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for this check with an enumerated type |
||
| report "Invalid parity value: " & to_string(parity) | ||
| severity error; | ||
| end if; | ||
|
|
||
| push(msg, parity); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Push |
||
| send(net, actor, msg); | ||
| end; | ||
|
|
||
| procedure set_parity(signal net : inout network_t; | ||
| uart_master : uart_master_t; | ||
| parity : natural) is | ||
| begin | ||
| set_parity(net, uart_master.p_actor, parity); | ||
| end; | ||
|
|
||
| procedure set_parity(signal net : inout network_t; | ||
| uart_slave : uart_slave_t; | ||
| parity : natural) is | ||
| begin | ||
| set_parity(net, uart_slave.p_actor, parity); | ||
| end; | ||
|
|
||
| function even_parity (data : std_logic_vector) return std_logic is | ||
| begin | ||
| return xor data; | ||
|
|
||
| end function even_parity; | ||
|
|
||
| function odd_parity (data : std_logic_vector) return std_logic is | ||
| begin | ||
|
|
||
| return xnor data; | ||
| end function odd_parity; | ||
| end package body; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create an enumerated type
parity_tfor this.