diff options
| author | Julian Blake Kongslie | 2022-02-20 15:27:24 -0800 |
|---|---|---|
| committer | Julian Blake Kongslie | 2022-02-20 15:27:24 -0800 |
| commit | 5d4103339cade951363e2dc8d57e1a3e9ac1b5d7 (patch) | |
| tree | 4e70f7c917f942eae3a96fb0032606be02f5b686 | |
| parent | Correctly reset command parser state after sending commands or invalid input. (diff) | |
| download | simple-memory-controller-5d4103339cade951363e2dc8d57e1a3e9ac1b5d7.tar.xz | |
Fix timing and RWDS handling.
Diffstat (limited to '')
| -rw-r--r-- | hdl/ram_controller.sv | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/hdl/ram_controller.sv b/hdl/ram_controller.sv index d32560d..5ce0478 100644 --- a/hdl/ram_controller.sv +++ b/hdl/ram_controller.sv | |||
| @@ -104,14 +104,13 @@ module ram_controller | |||
| 104 | data = 0; | 104 | data = 0; |
| 105 | slow = 0; | 105 | slow = 0; |
| 106 | state = state.first; | 106 | state = state.first; |
| 107 | half_state = half_state.first; | ||
| 107 | if (!resetn) | 108 | if (!resetn) |
| 108 | reset_counter = 5; // Spec wants >= 100ns of reset | 109 | reset_counter = 5; // Spec wants >= 100ns of reset |
| 109 | else | 110 | else |
| 110 | reset_counter = reset_counter - 1; | 111 | reset_counter = reset_counter - 1; |
| 111 | end else begin | 112 | end else begin |
| 112 | ram_resetn = 1; | 113 | ram_resetn = 1; |
| 113 | ram_rwds_oe = 0; | ||
| 114 | ram_data_oe = 0; | ||
| 115 | 114 | ||
| 116 | if (result_ready) result_valid = 0; | 115 | if (result_ready) result_valid = 0; |
| 117 | if (command_ready && command_valid) begin | 116 | if (command_ready && command_valid) begin |
| @@ -123,11 +122,19 @@ module ram_controller | |||
| 123 | end | 122 | end |
| 124 | 123 | ||
| 125 | if (!valid) begin | 124 | if (!valid) begin |
| 125 | ram_rwds_oe = 0; | ||
| 126 | ram_data_oe = 0; | ||
| 126 | ram_csn = 1; | 127 | ram_csn = 1; |
| 127 | ram_clkp = 0; | 128 | ram_clkp = 0; |
| 128 | end else begin | 129 | end else if (half_state == TOGGLE_CLOCK) begin |
| 130 | half_state = half_state.next; | ||
| 131 | if (state != CHIP_SELECT && state != SEND_COMMAND_1) | ||
| 132 | ram_clkp = !ram_clkp; | ||
| 133 | end else if (half_state == SETUP_OUTPUTS) begin | ||
| 129 | automatic bit stall = 0; | 134 | automatic bit stall = 0; |
| 130 | ram_clkp = !ram_clkp; | 135 | half_state = half_state.next; |
| 136 | ram_rwds_oe = 0; | ||
| 137 | ram_data_oe = 0; | ||
| 131 | case (state) | 138 | case (state) |
| 132 | 139 | ||
| 133 | CHIP_SELECT: begin | 140 | CHIP_SELECT: begin |
| @@ -178,13 +185,13 @@ module ram_controller | |||
| 178 | DATA_1, DATA_2: begin | 185 | DATA_1, DATA_2: begin |
| 179 | if (write) begin | 186 | if (write) begin |
| 180 | ram_rwds_oe = 1; | 187 | ram_rwds_oe = 1; |
| 181 | ram_rwds_out = 1; | 188 | ram_rwds_out = 0; |
| 182 | ram_data_oe = 1; | 189 | ram_data_oe = 1; |
| 183 | ram_data_out = data[7:0]; | 190 | ram_data_out = data[7:0]; |
| 184 | data = data >> 8; | 191 | data = data >> 8; |
| 185 | end else if (ram_rwds_in) begin | 192 | end else if (prev_rwds != ram_rwds_in) begin |
| 186 | data = data << 8; | 193 | data = data >> 8; |
| 187 | data[7:0] = ram_data_in; | 194 | data[15:8] = ram_data_in; |
| 188 | end else begin | 195 | end else begin |
| 189 | stall = 1; | 196 | stall = 1; |
| 190 | end | 197 | end |
| @@ -204,6 +211,7 @@ module ram_controller | |||
| 204 | end | 211 | end |
| 205 | end | 212 | end |
| 206 | 213 | ||
| 214 | prev_rwds = ram_rwds_in; | ||
| 207 | command_ready = !valid && !result_valid; | 215 | command_ready = !valid && !result_valid; |
| 208 | end | 216 | end |
| 209 | end | 217 | end |
