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

Subversion Repositories nysa_sata

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 cospan
//faux_sata_hd_phy.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
`include "sata_defines.v"
26
 
27
module faux_sata_hd_phy (
28
//Inputs/Outputs
29
input               rst,              //reset
30
input               clk,
31
 
32
//Data Interface
33
output  reg [31:0]  tx_dout,
34 3 cospan
output  reg         tx_is_k,
35 2 cospan
output  reg         tx_set_elec_idle,
36
output  reg         rx_byte_is_aligned,
37
 
38
input       [31:0]  rx_din,
39 3 cospan
input       [3:0]   rx_is_k,
40 2 cospan
input               rx_is_elec_idle,
41
 
42
input               comm_reset_detect,
43
input               comm_wake_detect,
44
 
45
output  reg         tx_comm_reset,
46
output  reg         tx_comm_wake,
47
 
48
output      [3:0]   lax_state,
49
 
50
output  reg         hd_ready,
51
output              phy_ready
52
 
53
 
54
 
55
);
56
 
57
//Parameters
58
parameter           IDLE                  = 4'h0;
59
parameter           WAIT_FOR_NO_RESET     = 4'h1;
60
parameter           SEND_INIT             = 4'h2;
61
parameter           WAIT_FOR_WAKE         = 4'h3;
62
parameter           WAIT_FOR_NO_WAKE      = 4'h4;
63
parameter           SEND_WAKE             = 4'h5;
64
parameter           STOP_SEND_WAKE        = 4'h6;
65
parameter           SEND_CONFIGURE_END    = 4'h7;
66
parameter           WAIT_FOR_DIALTONE     = 4'h8;
67
parameter           SEND_ALIGN            = 4'h9;
68
parameter           WAIT_FOR_ALIGN        = 4'hA;
69
parameter           READY                 = 4'hB;
70
parameter           SEND_FIRST_ALIGNMENT  = 4'hC;
71
parameter           SEND_SECOND_ALIGNMENT = 4'hD;
72
 
73
 
74
parameter           INITIALIZE_TIMEOUT         = 100;
75
 
76
//Registers/Wires
77
reg         [3:0]   state = IDLE;
78
reg         [31:0]  timer;
79
reg         [7:0]   align_count;
80
wire                align_detected;
81
wire                dialtone_detected;
82
wire                timeout;
83
 
84
//Sub Modules
85
 
86
 
87
//Asynchronous Logic
88
 
89
assign              lax_state         = state;
90 3 cospan
assign              align_detected    = ((rx_is_k > 0) && (rx_din == `PRIM_ALIGN));
91
assign              dialtone_detected = ((rx_is_k == 0) && (rx_din == `DIALTONE));
92 2 cospan
assign              timeout           = (timer == 0);
93
assign              phy_ready         = (state == READY);
94
 
95
//Synchronous Logic
96
always @ (posedge clk) begin
97
  if (rst) begin
98
    state                   <=  IDLE;
99
    tx_dout                 <=  0;
100 3 cospan
    tx_is_k                 <=  0;
101 2 cospan
    tx_set_elec_idle        <=  1;
102
    timer                   <=  0;
103
    hd_ready                <=  0;
104
    rx_byte_is_aligned      <=  0;
105
    align_count             <=  0;
106
  end
107
  else begin
108
    tx_comm_reset           <=  0;
109
    tx_comm_wake            <=  0;
110
    rx_byte_is_aligned      <=  0;
111
 
112
    if (state == READY) begin
113
      align_count           <=  align_count + 1;
114
    end
115
    if (timer > 0) begin
116
      timer                 <=  timer - 1;
117
    end
118
 
119
    if ((comm_reset_detect) && (state > WAIT_FOR_NO_RESET)) begin
120
      $display("faux_sata_hd: Asynchronous RESET detected");
121 3 cospan
      align_count           <=  0;
122
      hd_ready              <=  0;
123
      state                 <=  WAIT_FOR_NO_RESET;
124 2 cospan
    end
125
 
126
    case (state)
127
      IDLE: begin
128 3 cospan
        align_count         <=  0;
129 2 cospan
        hd_ready            <=  0;
130
        tx_set_elec_idle    <=  1;
131
        if (comm_reset_detect) begin
132
          //detected a reset from the host
133
          $display("faux_sata_hd: RESET detected");
134
          state             <=  WAIT_FOR_NO_RESET;
135
        end
136
      end
137
      WAIT_FOR_NO_RESET: begin
138
        if (!comm_reset_detect) begin
139
          //host stopped sending reset
140
          $display("faux_sata_hd: RESET deasserted");
141 3 cospan
          hd_ready          <=  0;
142 2 cospan
          state             <=  SEND_INIT;
143
        end
144
      end
145
      SEND_INIT: begin
146
//XXX: I may need to send more than one of these
147
        $display("faux_sata_hd: send INIT");
148
        tx_comm_reset       <=  1;
149
        state               <=  WAIT_FOR_WAKE;
150
      end
151
      WAIT_FOR_WAKE: begin
152
        if (comm_wake_detect) begin
153
          $display ("faux_sata_hd: WAKE detected");
154
          state             <=  WAIT_FOR_NO_WAKE;
155
        end
156
      end
157
      WAIT_FOR_NO_WAKE: begin
158
        if (!comm_wake_detect) begin
159
          $display ("faux_sata_hd: WAKE deasserted");
160
          state             <=  SEND_WAKE;
161
        end
162
      end
163
      SEND_WAKE: begin
164
        $display ("faux_sata_hd: send WAKE");
165
        tx_comm_wake        <=  1;
166
        state               <=  STOP_SEND_WAKE;
167
      end
168
      STOP_SEND_WAKE: begin
169
        $display ("faux_sata_hd: stop sending WAKE");
170
        state               <=  WAIT_FOR_DIALTONE;
171
      end
172
      WAIT_FOR_DIALTONE: begin
173
        if (dialtone_detected) begin
174 3 cospan
          $display ("faux_sata_hd: detected dialtone");
175 2 cospan
          state             <=  SEND_ALIGN;
176
        end
177
      end
178
      SEND_ALIGN: begin
179 3 cospan
        $display ("faux_sata_hd: send aligns");
180 2 cospan
        tx_set_elec_idle    <=  0;
181
        tx_dout             <=  `PRIM_ALIGN;
182 3 cospan
        tx_is_k             <=  1;
183 2 cospan
        state               <=  WAIT_FOR_ALIGN;
184
        timer               <=  32'h`INITIALIZE_TIMEOUT;
185
        rx_byte_is_aligned  <=  1;
186
      end
187
      WAIT_FOR_ALIGN: begin
188 3 cospan
        tx_is_k             <=  1;
189
        tx_dout             <=  `PRIM_ALIGN;
190 2 cospan
        rx_byte_is_aligned  <=  1;
191 3 cospan
        //$display ("faux_sata_hd: waiting for aligns...");
192
        //$display ("rx din: %h, k: %h", rx_din, rx_is_k);
193 2 cospan
        if (align_detected) begin
194
          $display ("faux_sata_hd: detected ALIGN primitive from host");
195
          $display ("faux_sata_hd: Ready");
196
          tx_dout           <=  `PRIM_ALIGN;
197 3 cospan
          tx_is_k           <=  1;
198 2 cospan
          timer             <=  0;
199
          state             <=  READY;
200
        end
201
        else if (timeout) begin
202
          $display ("faux_sata_hd: Timeout while waiting for an alignment from the host");
203
          state             <=  IDLE;
204
        end
205
      end
206
      READY: begin
207
        hd_ready            <=  1;
208
        rx_byte_is_aligned  <=  1;
209 3 cospan
        tx_is_k             <=  1;
210 2 cospan
        tx_dout             <=  `PRIM_SYNC;
211
        if (align_count == 255) begin
212
          tx_dout           <=  `PRIM_ALIGN;
213
          state             <=  SEND_FIRST_ALIGNMENT;
214
        end
215
      end
216
      SEND_FIRST_ALIGNMENT: begin
217
        rx_byte_is_aligned  <=  1;
218 3 cospan
        tx_is_k             <=  1;
219 2 cospan
        tx_dout             <=  `PRIM_ALIGN;
220
        state               <=  SEND_SECOND_ALIGNMENT;
221
      end
222
      SEND_SECOND_ALIGNMENT: begin
223
        rx_byte_is_aligned  <=  1;
224 3 cospan
        tx_is_k             <=  1;
225 2 cospan
        tx_dout             <=  `PRIM_ALIGN;
226
        state               <=  READY;
227
      end
228
      default: begin
229
        $display ("faux_sata_hd: In undefined state!");
230
        state               <=  IDLE;
231
      end
232
    endcase
233
  end
234
end
235
 
236
endmodule

powered by: WebSVN 2.1.0

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