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 2

Go to most recent revision | 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
//Registers/Wires
108
reg         [3:0]   state               = SLEEP_START;
109
wire                idle;
110
 
111
reg         [8:0]   byte_count          = 0;
112
reg         [15:0]  sector_count        = 0;
113
reg         [15:0]  sector_size         = 16'h0000;
114
 
115
reg         [15:0]  sleep_count         = 0;
116
reg         [15:0]  sleep_size          = 1000;
117
 
118
 
119
wire                soft_reset;
120
 
121
//Asynchronous Logic
122
assign              idle                = (state == IDLE);
123
assign              command_layer_busy  = !idle;
124
assign              command_layer_ready = idle;
125
 
126
//Short circuit the ping pong fifos
127
assign              hd_read_from_host   = cl_of_strobe;
128
assign              hd_data_from_host   = cl_of_data;
129
assign              cl_of_ready         = 1;
130
assign              cl_of_size          = 2048;
131
 
132
assign              hd_write_to_host    = cl_if_strobe;
133
assign              cl_if_data          = hd_data_to_host;
134
assign              cl_if_ready         = 1;
135
assign              cl_if_size          = 24'h0100;
136
 
137
assign              soft_reset          = h2d_control[`CONTROL_SRST_BIT];
138
assign              cl_state            = state;
139
 
140
//Synchronous Logic
141
always @ (posedge clk) begin
142
  if (rst) begin
143
    state                               <=  SLEEP_START;
144
 
145
    send_reg_stb                        <=  0;
146
    send_dma_act_stb                    <=  0;
147
    send_data_stb                       <=  0;
148
    send_pio_stb                        <=  0;
149
    send_dev_bits_stb                   <=  0;
150
 
151
    sector_count                        <=  0;
152
    sector_size                         <=  1000;
153
 
154
    sleep_count                         <=  0;
155
    sleep_size                          <=  1000;
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
      state                             <=  SLEEP_START;
185
      sleep_count                       <=  0;
186
      sleep_size                        <=  1000;
187
    end
188
 
189
    case (state)
190
      SLEEP_START: begin
191
        if (sleep_count  < sleep_size) begin
192
          sleep_count                   <=  sleep_count + 1;
193
        end
194
        else begin
195
          state                         <=  SEND_DIAGNOSTICS;
196
        end
197
      end
198
      SEND_DIAGNOSTICS: begin
199
        send_reg_stb                    <=  1;
200
        state                           <=  IDLE;
201
      end
202
      IDLE: begin
203
        if (h2d_reg_stb) begin
204
          if (h2d_cmd_bit) begin
205
            d2h_lba                     <=  h2d_lba;
206
            d2h_sector_count            <=  h2d_sector_count;
207
 
208
            sector_size                 <=  h2d_sector_count;
209
 
210
            case (h2d_command)
211
              `COMMAND_DMA_READ_EX: begin
212
                //send_data_stb           <=  1;
213
                sector_count            <=  0;
214
                sector_size             <=  h2d_sector_count;
215
                state                   <=  SEND_DATA;
216
              end
217
              `COMMAND_DMA_WRITE_EX: begin
218
                send_dma_act_stb        <=  1;
219
                sector_count            <=  0;
220
                sector_size             <=  h2d_sector_count;
221
                state                   <=  DMA_READY;
222
              end
223
              default: begin
224
                //unrecognized command
225
                $display ("fcl: Unrecognized command from host");
226
              end
227
            endcase
228
          end
229
        end
230
      end
231
      DMA_READY: begin
232
        if (transport_layer_ready) begin
233
          send_dma_act_stb          <=  1;
234
          byte_count                <=  0;
235
          state                     <=  READ_DATA;
236
        end
237
      end
238
      READ_DATA: begin
239
        if (cl_of_activate && cl_of_strobe) begin
240
          byte_count                <=  byte_count + 4;
241
        end
242
        if(byte_count == 508) begin
243
          sector_count              <=  sector_count + 1;
244
        end
245
        if (h2d_data_stb) begin
246
          if (sector_count  <  sector_size) begin
247
            state                   <=  DMA_READY;
248
          end
249
          else begin
250
            state                   <=  SEND_STATUS;
251
          end
252
        end
253
      end
254
      SEND_DATA: begin
255
        if (transport_layer_ready) begin
256
          sector_count              <=  sector_count + 1;
257
          send_data_stb             <=  1;
258
          state                     <=  READ_IN_PROGRESS;
259
          //state                     <=  SEND_STATUS;
260
        end
261
      end
262
      READ_IN_PROGRESS: begin
263
        if (!transport_layer_ready) begin
264
            state                   <= SEND_STATUS;
265
        end
266
        //if (sector_count < sector_size) begin
267
        //  state                     <=  SEND_DATA;
268
        //end
269
        //else begin
270
        //  if (transport_layer_ready) begin
271
        //    send_reg_stb            <=  1;
272
        //    //Send a done register
273
        //    state                   <=  SEND_STATUS;
274
        //  end
275
        //end
276
      end
277
      SEND_STATUS: begin
278
        if (transport_layer_ready) begin
279
          send_reg_stb            <=  1;
280
          //Send a done register
281
          state                   <=  IDLE;
282
        end
283
      end
284
      default: begin
285
        $display ("fcl: Entered illegal state, restart");
286
        state                       <=  SLEEP_START;
287
        sleep_count                 <=  0;
288
        sleep_size                  <=  1000;
289
      end
290
    endcase
291
  end
292
end
293
 
294
 
295
 
296
 
297
endmodule

powered by: WebSVN 2.1.0

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