diff options
| author | Julian Blake Kongslie | 2022-05-15 15:50:21 -0700 |
|---|---|---|
| committer | Julian Blake Kongslie | 2022-05-15 15:50:21 -0700 |
| commit | c9697a5bc6e315be8441223fbb07d00e57547e2f (patch) | |
| tree | f52f502910f9276101858bd237aec17aca3232ad /hdl/rs232.sv | |
| parent | Change makefile to unconditionally load memory for 16 PDP-8s (diff) | |
| download | multipdp8-c9697a5bc6e315be8441223fbb07d00e57547e2f.tar.xz | |
Consistent RS232 wire names (DCE side names is used everywhere)
Diffstat (limited to '')
| -rw-r--r-- | hdl/rs232.sv | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/hdl/rs232.sv b/hdl/rs232.sv index 2949201..b898a9c 100644 --- a/hdl/rs232.sv +++ b/hdl/rs232.sv | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | module rs232_tx | 3 | module rs232_tx |
| 4 | #( PARITY = 0 | 4 | #( PARITY = 0 |
| 5 | , STOP_BITS = 2 | 5 | , STOP_BITS = 2 |
| 6 | , CTS_BITS = 3 | 6 | , RTS_BITS = 3 |
| 7 | ) | 7 | ) |
| 8 | ( input bit clock | 8 | ( input bit clock |
| 9 | , input bit reset | 9 | , input bit reset |
| @@ -12,8 +12,8 @@ module rs232_tx | |||
| 12 | , input bit out_valid | 12 | , input bit out_valid |
| 13 | , input uart_byte_t out_data | 13 | , input uart_byte_t out_data |
| 14 | 14 | ||
| 15 | , output bit tx | 15 | , output bit rxd |
| 16 | , input bit cts | 16 | , input bit rts |
| 17 | ); | 17 | ); |
| 18 | 18 | ||
| 19 | bit hold_valid; | 19 | bit hold_valid; |
| @@ -30,18 +30,18 @@ module rs232_tx | |||
| 30 | bit [$clog2($bits(uart_byte_t)):0] data_bits; | 30 | bit [$clog2($bits(uart_byte_t)):0] data_bits; |
| 31 | bit [$clog2(STOP_BITS):0] stop_bits; | 31 | bit [$clog2(STOP_BITS):0] stop_bits; |
| 32 | 32 | ||
| 33 | bit [CTS_BITS-1:0] cts_samples; | 33 | bit [RTS_BITS-1:0] rts_samples; |
| 34 | 34 | ||
| 35 | always @(posedge clock, posedge reset) begin | 35 | always @(posedge clock, posedge reset) begin |
| 36 | if (reset) begin | 36 | if (reset) begin |
| 37 | out_ready = 0; | 37 | out_ready = 0; |
| 38 | tx = 1; | 38 | rxd = 1; |
| 39 | hold_valid = 0; | 39 | hold_valid = 0; |
| 40 | parity = PARITY; | 40 | parity = PARITY; |
| 41 | state = state.first; | 41 | state = state.first; |
| 42 | data_bits = 0; | 42 | data_bits = 0; |
| 43 | stop_bits = 0; | 43 | stop_bits = 0; |
| 44 | cts_samples = 0; | 44 | rts_samples = 0; |
| 45 | end else begin | 45 | end else begin |
| 46 | if (out_ready && out_valid) begin | 46 | if (out_ready && out_valid) begin |
| 47 | hold_valid = 1; | 47 | hold_valid = 1; |
| @@ -52,23 +52,23 @@ module rs232_tx | |||
| 52 | stop_bits = 0; | 52 | stop_bits = 0; |
| 53 | end | 53 | end |
| 54 | 54 | ||
| 55 | cts_samples = cts_samples << 1; | 55 | rts_samples = rts_samples << 1; |
| 56 | cts_samples[0] = cts; | 56 | rts_samples[0] = rts; |
| 57 | 57 | ||
| 58 | if (hold_valid) begin | 58 | if (hold_valid) begin |
| 59 | case (state) | 59 | case (state) |
| 60 | 60 | ||
| 61 | START: begin | 61 | START: begin |
| 62 | if (cts_samples == 0) begin | 62 | if (rts_samples == 0) begin |
| 63 | tx = 0; | 63 | rxd = 0; |
| 64 | state = state.next; | 64 | state = state.next; |
| 65 | end | 65 | end |
| 66 | end | 66 | end |
| 67 | 67 | ||
| 68 | DATA: begin | 68 | DATA: begin |
| 69 | tx = hold[0]; | 69 | rxd = hold[0]; |
| 70 | hold = hold >> 1; | 70 | hold = hold >> 1; |
| 71 | parity = parity ^ tx; | 71 | parity = parity ^ rxd; |
| 72 | if (data_bits == `UART_BYTE_BITS-1) | 72 | if (data_bits == `UART_BYTE_BITS-1) |
| 73 | state = state.next; | 73 | state = state.next; |
| 74 | else | 74 | else |
| @@ -76,12 +76,12 @@ module rs232_tx | |||
| 76 | end | 76 | end |
| 77 | 77 | ||
| 78 | PARITY_BIT: begin | 78 | PARITY_BIT: begin |
| 79 | tx = parity; | 79 | rxd = parity; |
| 80 | state = state.next; | 80 | state = state.next; |
| 81 | end | 81 | end |
| 82 | 82 | ||
| 83 | STOP: begin | 83 | STOP: begin |
| 84 | tx = 1; | 84 | rxd = 1; |
| 85 | if (stop_bits == STOP_BITS-1) begin | 85 | if (stop_bits == STOP_BITS-1) begin |
| 86 | hold_valid = 0; | 86 | hold_valid = 0; |
| 87 | state = state.next; | 87 | state = state.next; |
| @@ -92,7 +92,7 @@ module rs232_tx | |||
| 92 | 92 | ||
| 93 | endcase | 93 | endcase |
| 94 | end else begin | 94 | end else begin |
| 95 | tx = 1; | 95 | rxd = 1; |
| 96 | end | 96 | end |
| 97 | 97 | ||
| 98 | out_ready = !hold_valid; | 98 | out_ready = !hold_valid; |
| @@ -114,8 +114,8 @@ module rs232_rx | |||
| 114 | , output bit in_valid | 114 | , output bit in_valid |
| 115 | , output uart_byte_t in_data | 115 | , output uart_byte_t in_data |
| 116 | 116 | ||
| 117 | , input bit rx | 117 | , input bit txd |
| 118 | , output bit rts | 118 | , output bit cts |
| 119 | ); | 119 | ); |
| 120 | 120 | ||
| 121 | (* syn_encoding = "one-hot" *) enum int unsigned | 121 | (* syn_encoding = "one-hot" *) enum int unsigned |
| @@ -138,7 +138,7 @@ module rs232_rx | |||
| 138 | if (reset) begin | 138 | if (reset) begin |
| 139 | clock_out = 0; | 139 | clock_out = 0; |
| 140 | in_valid = 0; | 140 | in_valid = 0; |
| 141 | rts = 1; | 141 | cts = 1; |
| 142 | state = state.first; | 142 | state = state.first; |
| 143 | buffer = 0; | 143 | buffer = 0; |
| 144 | data_bits = 0; | 144 | data_bits = 0; |
| @@ -174,7 +174,7 @@ module rs232_rx | |||
| 174 | case (state) | 174 | case (state) |
| 175 | 175 | ||
| 176 | START: begin | 176 | START: begin |
| 177 | if (rx == 0) begin | 177 | if (txd == 0) begin |
| 178 | state = state.next; | 178 | state = state.next; |
| 179 | if (OVERSAMPLE == 0) | 179 | if (OVERSAMPLE == 0) |
| 180 | state = state.next; | 180 | state = state.next; |
| @@ -189,8 +189,8 @@ module rs232_rx | |||
| 189 | 189 | ||
| 190 | DATA: begin | 190 | DATA: begin |
| 191 | buffer = buffer >> 1; | 191 | buffer = buffer >> 1; |
| 192 | buffer[`UART_BYTE_BITS-1] = rx; | 192 | buffer[`UART_BYTE_BITS-1] = txd; |
| 193 | parity = parity ^ rx; | 193 | parity = parity ^ txd; |
| 194 | if (data_bits == `UART_BYTE_BITS-1) | 194 | if (data_bits == `UART_BYTE_BITS-1) |
| 195 | state = state.next; | 195 | state = state.next; |
| 196 | else | 196 | else |
| @@ -198,33 +198,33 @@ module rs232_rx | |||
| 198 | end | 198 | end |
| 199 | 199 | ||
| 200 | PARITY_BIT: begin | 200 | PARITY_BIT: begin |
| 201 | parity = parity ^ rx; | 201 | parity = parity ^ txd; |
| 202 | state = state.next; | 202 | state = state.next; |
| 203 | end | 203 | end |
| 204 | 204 | ||
| 205 | STOP: begin | 205 | STOP: begin |
| 206 | if (!in_valid && rx == 1 && parity == 0) begin | 206 | if (!in_valid && txd == 1 && parity == 0) begin |
| 207 | in_valid = 1; | 207 | in_valid = 1; |
| 208 | in_data = buffer; | 208 | in_data = buffer; |
| 209 | end | 209 | end |
| 210 | if (rx == 1 && parity == 0) begin | 210 | if (txd == 1 && parity == 0) begin |
| 211 | clock_counter = (OVERSAMPLE+1)/2; | 211 | clock_counter = (OVERSAMPLE+1)/2; |
| 212 | end | 212 | end |
| 213 | if (rx == 1) | 213 | if (txd == 1) |
| 214 | state = state.first; | 214 | state = state.first; |
| 215 | else | 215 | else |
| 216 | state = state.next; | 216 | state = state.next; |
| 217 | end | 217 | end |
| 218 | 218 | ||
| 219 | REALSTOP: begin | 219 | REALSTOP: begin |
| 220 | if (rx == 1) | 220 | if (txd == 1) |
| 221 | state = state.first; | 221 | state = state.first; |
| 222 | end | 222 | end |
| 223 | 223 | ||
| 224 | endcase | 224 | endcase |
| 225 | end | 225 | end |
| 226 | 226 | ||
| 227 | rts = !(state == state.first && !in_valid); | 227 | cts = !(state == state.first && !in_valid); |
| 228 | end | 228 | end |
| 229 | end | 229 | end |
| 230 | 230 | ||
