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 2

Go to most recent revision | 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
output  reg         tx_isk,
35
output  reg         tx_set_elec_idle,
36
output  reg         rx_byte_is_aligned,
37
 
38
input       [31:0]  rx_din,
39
input       [3:0]   rx_isk,
40
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
assign              align_detected    = ((rx_isk > 0) && (rx_din == `PRIM_ALIGN));
91
assign              dialtone_detected = ((rx_isk == 0) && (rx_din == `DIALTONE));
92
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
    tx_isk                  <=  0;
101
    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
      state                 <=  IDLE;
122
    end
123
 
124
    case (state)
125
      IDLE: begin
126
        align_count   <=  0;
127
        hd_ready            <=  0;
128
        tx_set_elec_idle    <=  1;
129
        if (comm_reset_detect) begin
130
          //detected a reset from the host
131
          $display("faux_sata_hd: RESET detected");
132
          state             <=  WAIT_FOR_NO_RESET;
133
        end
134
      end
135
      WAIT_FOR_NO_RESET: begin
136
        if (!comm_reset_detect) begin
137
          //host stopped sending reset
138
          $display("faux_sata_hd: RESET deasserted");
139
          hd_ready            <=  0;
140
          tx_set_elec_idle    <=  1;
141
          state             <=  SEND_INIT;
142
        end
143
      end
144
      SEND_INIT: begin
145
//XXX: I may need to send more than one of these
146
        $display("faux_sata_hd: send INIT");
147
        tx_comm_reset       <=  1;
148
        state               <=  WAIT_FOR_WAKE;
149
      end
150
      WAIT_FOR_WAKE: begin
151
        if (comm_wake_detect) begin
152
          $display ("faux_sata_hd: WAKE detected");
153
          state             <=  WAIT_FOR_NO_WAKE;
154
        end
155
      end
156
      WAIT_FOR_NO_WAKE: begin
157
        if (!comm_wake_detect) begin
158
          $display ("faux_sata_hd: WAKE deasserted");
159
          state             <=  SEND_WAKE;
160
        end
161
      end
162
      SEND_WAKE: begin
163
        $display ("faux_sata_hd: send WAKE");
164
        tx_comm_wake        <=  1;
165
        state               <=  STOP_SEND_WAKE;
166
      end
167
      STOP_SEND_WAKE: begin
168
        $display ("faux_sata_hd: stop sending WAKE");
169
        state               <=  WAIT_FOR_DIALTONE;
170
      end
171
      WAIT_FOR_DIALTONE: begin
172
        if (dialtone_detected) begin
173
          $display ("faul_sata_hd: detected dialtone");
174
          state             <=  SEND_ALIGN;
175
        end
176
      end
177
      SEND_ALIGN: begin
178
        $display ("faul_sata_hd: send aligns");
179
        tx_set_elec_idle    <=  0;
180
        tx_dout             <=  `PRIM_ALIGN;
181
        tx_isk              <=  1;
182
        state               <=  WAIT_FOR_ALIGN;
183
        timer               <=  32'h`INITIALIZE_TIMEOUT;
184
        rx_byte_is_aligned  <=  1;
185
      end
186
      WAIT_FOR_ALIGN: begin
187
        rx_byte_is_aligned  <=  1;
188
        if (align_detected) begin
189
          $display ("faux_sata_hd: detected ALIGN primitive from host");
190
          $display ("faux_sata_hd: Ready");
191
          tx_dout           <=  `PRIM_ALIGN;
192
          tx_isk            <=  1;
193
          timer             <=  0;
194
          state             <=  READY;
195
        end
196
        else if (timeout) begin
197
          $display ("faux_sata_hd: Timeout while waiting for an alignment from the host");
198
          state             <=  IDLE;
199
        end
200
      end
201
      READY: begin
202
        hd_ready            <=  1;
203
        rx_byte_is_aligned  <=  1;
204
        tx_isk              <=  1;
205
        tx_dout             <=  `PRIM_SYNC;
206
        if (align_count == 255) begin
207
          tx_dout           <=  `PRIM_ALIGN;
208
          state             <=  SEND_FIRST_ALIGNMENT;
209
        end
210
      end
211
      SEND_FIRST_ALIGNMENT: begin
212
        rx_byte_is_aligned  <=  1;
213
        tx_isk              <=  1;
214
        tx_dout             <=  `PRIM_ALIGN;
215
        state               <=  SEND_SECOND_ALIGNMENT;
216
      end
217
      SEND_SECOND_ALIGNMENT: begin
218
        rx_byte_is_aligned  <=  1;
219
        tx_isk              <=  1;
220
        tx_dout             <=  `PRIM_ALIGN;
221
        state               <=  READY;
222
      end
223
      default: begin
224
        $display ("faux_sata_hd: In undefined state!");
225
        state               <=  IDLE;
226
      end
227
    endcase
228
  end
229
end
230
 
231
endmodule

powered by: WebSVN 2.1.0

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