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

Subversion Repositories nysa_sata

[/] [nysa_sata/] [trunk/] [rtl/] [phy/] [sata_phy_layer.v] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 cospan
//sata_phy_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
 
26
`include "sata_defines.v"
27
 
28
module sata_phy_layer (
29
 
30
input               rst,            //reset
31
input               clk,
32
 
33
input               platform_ready,   //the underlying physical platform is
34 3 cospan
output              platform_error,
35 2 cospan
output              linkup,           //link is finished
36
 
37
output  [31:0]      tx_dout,
38 3 cospan
output              tx_is_k,
39 2 cospan
output              tx_comm_reset,
40
output              tx_comm_wake,
41
output              tx_elec_idle,
42 3 cospan
input               tx_oob_complete,
43 2 cospan
 
44
input   [31:0]      rx_din,
45 3 cospan
input   [3:0]       rx_is_k,
46 2 cospan
input               rx_elec_idle,
47
input               rx_byte_is_aligned,
48 3 cospan
 
49 2 cospan
input               comm_init_detect,
50
input               comm_wake_detect,
51
 
52
output              phy_ready,
53 3 cospan
input               phy_error,
54 2 cospan
output      [3:0]   lax_state
55
);
56
 
57
//Parameters
58
parameter           NOT_READY         = 4'h0;
59
parameter           SEND_FIRST_ALIGN  = 4'h1;
60
parameter           SEND_SECOND_ALIGN = 4'h2;
61
parameter           READY             = 4'h3;
62
 
63
//Registers/Wires
64
reg         [3:0]   state;
65
reg         [7:0]   align_count;
66
 
67
//OOB Control
68
wire        [31:0]  oob_tx_dout;
69 3 cospan
wire                oob_tx_is_k;
70 2 cospan
 
71
//Phy Control
72
wire        [31:0]  phy_tx_dout;
73 3 cospan
wire                phy_tx_is_k;
74
//wire                align_detected;
75
wire                oob_platform_error;
76
reg                 phy_platform_error;
77 2 cospan
 
78
//Submodules
79
oob_controller oob (
80 3 cospan
  .rst                (rst                ),
81
  .clk                (clk                ),
82 2 cospan
 
83
  //OOB controller
84 3 cospan
  .phy_error          (phy_error          ),
85
  .platform_ready     (platform_ready     ),
86
  .platform_error     (oob_platform_error ),
87
  .linkup             (linkup             ),
88 2 cospan
 
89
  //Platform Control
90 3 cospan
  .tx_dout            (oob_tx_dout        ),
91
  .tx_is_k            (oob_tx_is_k        ),
92
  .tx_comm_reset      (tx_comm_reset      ),
93
  .tx_comm_wake       (tx_comm_wake       ),
94
  .tx_set_elec_idle   (tx_elec_idle       ),
95
  .tx_oob_complete    (tx_oob_complete    ),
96 2 cospan
 
97 3 cospan
  .rx_din             (rx_din             ),
98
  .rx_is_k            (rx_is_k            ),
99
  .comm_init_detect   (comm_init_detect   ),
100
  .comm_wake_detect   (comm_wake_detect   ),
101
  .rx_is_elec_idle    (rx_elec_idle       ),
102
  .rx_byte_is_aligned (rx_byte_is_aligned ),
103
  .lax_state          (lax_state          )
104 2 cospan
 
105
);
106
 
107
//Asynchronous Logic
108
assign              tx_dout         = !linkup ? oob_tx_dout : phy_tx_dout;
109 3 cospan
assign              tx_is_k          = !linkup ? oob_tx_is_k  : phy_tx_is_k;
110 2 cospan
 
111
assign              phy_tx_dout     =  `PRIM_ALIGN;
112 3 cospan
assign              phy_tx_is_k      =  1;
113 2 cospan
 
114 3 cospan
//assign              align_detected  = ((rx_is_k > 0) && (rx_din == `PRIM_ALIGN) && !phy_error);
115 2 cospan
//assign              phy_ready       = ((state == READY) && (!align_detected));
116
assign              phy_ready       = (state == READY);
117 3 cospan
assign              platform_error  = oob_platform_error || phy_platform_error;
118 2 cospan
 
119
//Synchronous Logic
120
always @ (posedge clk) begin
121
  if (rst) begin
122
    state             <=  NOT_READY;
123
    align_count       <=  0;
124 3 cospan
    phy_platform_error<=  0;
125 2 cospan
  end
126
  else begin
127
    if (state == READY) begin
128 3 cospan
      align_count       <=  align_count + 8'h01;
129 2 cospan
    end
130
    case (state)
131
      NOT_READY:  begin
132 3 cospan
        align_count         <=  0;
133
        phy_platform_error  <=  0;
134 2 cospan
        if (linkup) begin
135
`ifdef VERBOSE
136
          $display ("sata_phy_layer: linkup! send aligns");
137
`endif
138 3 cospan
          state             <=  SEND_FIRST_ALIGN;
139 2 cospan
        end
140
      end
141
      SEND_FIRST_ALIGN: begin
142 3 cospan
        state               <=  SEND_SECOND_ALIGN;
143 2 cospan
      end
144
      SEND_SECOND_ALIGN: begin
145 3 cospan
        state               <=  READY;
146 2 cospan
      end
147
      READY:      begin
148
        if (align_count ==  255) begin
149 3 cospan
          state             <=  SEND_FIRST_ALIGN;
150 2 cospan
`ifdef VERBOSE
151
          $display ("sata_phy_layer: linkup! send alignment dwords");
152
`endif
153
        end
154 3 cospan
        if (phy_error) begin
155
          phy_platform_error <=  1;
156
        end
157 2 cospan
      end
158
      default:    begin
159
      end
160
    endcase
161
  end
162
end
163
 
164
 
165
 
166
endmodule

powered by: WebSVN 2.1.0

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