OpenCores
URL https://opencores.org/ocsvn/nysa_sata/nysa_sata/trunk

Subversion Repositories nysa_sata

[/] [nysa_sata/] [trunk/] [sim/] [faux_sata_hd_command_layer.v] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 cospan
//faux_hd_command_layer.v
2
/*
3
Distributed under the MIT license.
4
Copyright (c) 2011 Dave McCoy (dave.mccoy@cospandesign.com)
5
 
6
Permission is hereby granted, free of charge, to any person obtaining a copy of
7
this software and associated documentation files (the "Software"), to deal in
8
the Software without restriction, including without limitation the rights to
9
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10
of the Software, and to permit persons to whom the Software is furnished to do
11
so, subject to the following conditions:
12
 
13
The above copyright notice and this permission notice shall be included in all
14
copies or substantial portions of the Software.
15
 
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
SOFTWARE.
23
*/
24
 
25
module faux_hd_command_layer (
26
input               rst,            //reset
27
input               clk,
28
 
29
 
30
 
31
output              command_layer_ready,
32
output              command_layer_busy,
33
 
34
output              hd_read_from_host,
35
output      [31:0]  hd_data_from_host,
36
 
37
output              hd_write_to_host,
38
input       [31:0]  hd_data_to_host,
39
 
40
 
41
input               transport_layer_ready,
42
output  reg         send_reg_stb,
43
output  reg         send_dma_act_stb,
44
output  reg         send_data_stb,
45
output  reg         send_pio_stb,
46
output  reg         send_dev_bits_stb,
47
 
48
input               remote_abort,
49
input               xmit_error,
50
input               read_crc_fail,
51
 
52
input               h2d_reg_stb,
53
input               h2d_data_stb,
54
 
55
input               pio_request,
56
output reg   [15:0] pio_transfer_count,
57
output reg          pio_direction,
58
output reg   [7:0]  pio_e_status,
59
 
60
//FIS Structure
61
input        [7:0]  h2d_command,
62
input        [15:0] h2d_features,
63
input               h2d_cmd_bit,
64
input        [3:0]  h2d_port_mult,
65
input        [7:0]  h2d_control,
66
input        [7:0]  h2d_device,
67
input        [47:0] h2d_lba,
68
input        [15:0] h2d_sector_count,
69
 
70
output  reg         d2h_interrupt,
71
output  reg         d2h_notification,
72
output  reg  [7:0]  d2h_status,
73
output  reg  [7:0]  d2h_error,
74
output  reg  [3:0]  d2h_port_mult,
75
output  reg  [7:0]  d2h_device,
76
output  reg  [47:0] d2h_lba,
77
output  reg  [15:0] d2h_sector_count,
78
 
79
//command layer data interface
80
input               cl_if_strobe,
81
output      [31:0]  cl_if_data,
82
output              cl_if_ready,
83
input               cl_if_activate,
84
output      [23:0]  cl_if_size,
85
 
86
input               cl_of_strobe,
87
input       [31:0]  cl_of_data,
88
output      [1:0]   cl_of_ready,
89
input       [1:0]   cl_of_activate,
90
output      [23:0]  cl_of_size,
91
 
92
output      [3:0]   cl_state
93
 
94
 
95
);
96
 
97
//Parameters
98
parameter SLEEP_START       = 4'h0;
99
parameter SEND_DIAGNOSTICS  = 4'h1;
100
parameter IDLE              = 4'h2;
101
parameter DMA_READY         = 4'h3;
102
parameter READ_DATA         = 4'h4;
103
parameter SEND_DATA         = 4'h5;
104
parameter READ_IN_PROGRESS  = 4'h6;
105
parameter SEND_STATUS       = 4'h7;
106
 
107 3 cospan
parameter SLEEP_LENGTH      = 100;
108
 
109 2 cospan
//Registers/Wires
110
reg         [3:0]   state               = SLEEP_START;
111
wire                idle;
112
 
113
reg         [8:0]   byte_count          = 0;
114 3 cospan
reg         [16:0]  sector_count        = 0;
115
reg         [16:0]  sector_size         = 16'h0000;
116 2 cospan
 
117
reg         [15:0]  sleep_count         = 0;
118
 
119
 
120
wire                soft_reset;
121
 
122
//Asynchronous Logic
123
assign              idle                = (state == IDLE);
124
assign              command_layer_busy  = !idle;
125
assign              command_layer_ready = idle;
126
 
127
//Short circuit the ping pong fifos
128
assign              hd_read_from_host   = cl_of_strobe;
129
assign              hd_data_from_host   = cl_of_data;
130
assign              cl_of_ready         = 1;
131
assign              cl_of_size          = 2048;
132
 
133
assign              hd_write_to_host    = cl_if_strobe;
134
assign              cl_if_data          = hd_data_to_host;
135
assign              cl_if_ready         = 1;
136
assign              cl_if_size          = 24'h0100;
137
 
138
assign              soft_reset          = h2d_control[`CONTROL_SRST_BIT];
139
assign              cl_state            = state;
140
 
141
//Synchronous Logic
142
always @ (posedge clk) begin
143
  if (rst) begin
144
    state                               <=  SLEEP_START;
145
 
146
    send_reg_stb                        <=  0;
147
    send_dma_act_stb                    <=  0;
148
    send_data_stb                       <=  0;
149
    send_pio_stb                        <=  0;
150
    send_dev_bits_stb                   <=  0;
151
 
152
    sector_count                        <=  0;
153
    sector_size                         <=  1000;
154
 
155
    sleep_count                         <=  0;
156
 
157
 
158
 
159
    pio_transfer_count                  <=  0;
160
    pio_direction                       <=  0;
161
    pio_e_status                        <=  0;
162
 
163
    d2h_interrupt                       <=  0;
164
    d2h_notification                    <=  0;
165
    d2h_status                          <=  8'h50;
166
    d2h_error                           <=  1;
167
    d2h_port_mult                       <=  0;
168
    d2h_lba                             <=  1;
169
    d2h_sector_count                    <=  1;
170
    d2h_device                          <=  0;
171
 
172
    byte_count                          <=  0;
173
 
174
  end
175
  else begin
176
    //Strobe Lines
177
    send_reg_stb                        <=  0;
178
    send_dma_act_stb                    <=  0;
179
    send_data_stb                       <=  0;
180
    send_pio_stb                        <=  0;
181
    send_dev_bits_stb                   <=  0;
182
 
183
    if (soft_reset) begin
184 3 cospan
      if (soft_reset) begin
185
        $display ("Reset from soft reset");
186
      end
187 2 cospan
      state                             <=  SLEEP_START;
188
      sleep_count                       <=  0;
189
    end
190
 
191
    case (state)
192
      SLEEP_START: begin
193 3 cospan
        if (sleep_count  < SLEEP_LENGTH) begin
194 2 cospan
          sleep_count                   <=  sleep_count + 1;
195
        end
196
        else begin
197
          state                         <=  SEND_DIAGNOSTICS;
198
        end
199
      end
200
      SEND_DIAGNOSTICS: begin
201 3 cospan
        $display ("Send Diagnostics");
202 2 cospan
        send_reg_stb                    <=  1;
203
        state                           <=  IDLE;
204
      end
205
      IDLE: begin
206
        if (h2d_reg_stb) begin
207
          if (h2d_cmd_bit) begin
208
            d2h_lba                     <=  h2d_lba;
209
            d2h_sector_count            <=  h2d_sector_count;
210
 
211 3 cospan
            if (h2d_sector_count == 0) begin
212
                sector_size             <= 17'h10000;
213
            end
214
            else begin
215
                sector_size             <=  h2d_sector_count;
216
            end
217 2 cospan
 
218
            case (h2d_command)
219
              `COMMAND_DMA_READ_EX: begin
220
                //send_data_stb           <=  1;
221
                sector_count            <=  0;
222
                state                   <=  SEND_DATA;
223
              end
224
              `COMMAND_DMA_WRITE_EX: begin
225
                send_dma_act_stb        <=  1;
226
                sector_count            <=  0;
227
                state                   <=  DMA_READY;
228
              end
229
              default: begin
230
                //unrecognized command
231
                $display ("fcl: Unrecognized command from host");
232
              end
233
            endcase
234
          end
235
        end
236
      end
237
      DMA_READY: begin
238
        if (transport_layer_ready) begin
239
          send_dma_act_stb          <=  1;
240
          byte_count                <=  0;
241
          state                     <=  READ_DATA;
242
        end
243
      end
244
      READ_DATA: begin
245
        if (cl_of_activate && cl_of_strobe) begin
246
          byte_count                <=  byte_count + 4;
247
        end
248
        if(byte_count == 508) begin
249
          sector_count              <=  sector_count + 1;
250
        end
251
        if (h2d_data_stb) begin
252
          if (sector_count  <  sector_size) begin
253
            state                   <=  DMA_READY;
254
          end
255
          else begin
256
            state                   <=  SEND_STATUS;
257
          end
258
        end
259
      end
260
      SEND_DATA: begin
261
        if (transport_layer_ready) begin
262
          sector_count              <=  sector_count + 1;
263
          send_data_stb             <=  1;
264
          state                     <=  READ_IN_PROGRESS;
265
          //state                     <=  SEND_STATUS;
266
        end
267
      end
268
      READ_IN_PROGRESS: begin
269
        if (!transport_layer_ready) begin
270
            state                   <= SEND_STATUS;
271
        end
272
        //if (sector_count < sector_size) begin
273
        //  state                     <=  SEND_DATA;
274
        //end
275
        //else begin
276
        //  if (transport_layer_ready) begin
277
        //    send_reg_stb            <=  1;
278
        //    //Send a done register
279
        //    state                   <=  SEND_STATUS;
280
        //  end
281
        //end
282
      end
283
      SEND_STATUS: begin
284
        if (transport_layer_ready) begin
285
          send_reg_stb            <=  1;
286
          //Send a done register
287
          state                   <=  IDLE;
288
        end
289
      end
290
      default: begin
291
        $display ("fcl: Entered illegal state, restart");
292
        state                       <=  SLEEP_START;
293
        sleep_count                 <=  0;
294
      end
295
    endcase
296
  end
297
end
298
 
299
 
300
 
301
 
302
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.