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

Subversion Repositories usbhostslave

[/] [usbhostslave/] [trunk/] [usbDevice/] [RTL/] [checkLineState.v] - Blame information for rev 43

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 37 sfielding
 
2
//////////////////////////////////////////////////////////////////////
3
////                                                              ////
4
//// checkLineState.v                                 ////
5
////                                                              ////
6
//// This file is part of the usbHostSlave opencores effort.
7
//// <http://www.opencores.org/cores//>                           ////
8
////                                                              ////
9
//// Module Description:                                          ////
10
//// Checks USB line state. When reset state detected
11
//// asserts usbRstDet for one clock tick
12
//// usbRstDet is used to reset most of the logic.
13
//// 
14
////                                                              ////
15
//// To Do:                                                       ////
16
//// 
17
////                                                              ////
18
//// Author(s):                                                   ////
19
//// - Steve Fielding, sfielding@base2designs.com                 ////
20
////                                                              ////
21
//////////////////////////////////////////////////////////////////////
22
////                                                              ////
23
//// Copyright (C) 2008 Steve Fielding and OPENCORES.ORG          ////
24
////                                                              ////
25
//// This source file may be used and distributed without         ////
26
//// restriction provided that this copyright statement is not    ////
27
//// removed from the file and that any derivative work contains  ////
28
//// the original copyright notice and the associated disclaimer. ////
29
////                                                              ////
30
//// This source file is free software; you can redistribute it   ////
31
//// and/or modify it under the terms of the GNU Lesser General   ////
32
//// Public License as published by the Free Software Foundation; ////
33
//// either version 2.1 of the License, or (at your option) any   ////
34
//// later version.                                               ////
35
////                                                              ////
36
//// This source is distributed in the hope that it will be       ////
37
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
38
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
39
//// PURPOSE. See the GNU Lesser General Public License for more  ////
40
//// details.                                                     ////
41
////                                                              ////
42
//// You should have received a copy of the GNU Lesser General    ////
43
//// Public License along with this source; if not, download it   ////
44
//// from <http://www.opencores.org/lgpl.shtml>                   ////
45
////                                                              ////
46
//////////////////////////////////////////////////////////////////////
47
//
48
`include "timescale.v"
49
`include "usbSlaveControl_h.v"
50
`include "usbHostSlaveReg_define.v"
51
`include "usbSerialInterfaceEngine_h.v"
52
`include "usbDevice_define.v"
53
module checkLineState (clk, initComplete, rst, usbRstDet, wb_ack, wb_addr, wb_data_i, wb_stb, wb_we, wbBusGnt, wbBusReq);
54
input   clk;
55
input   initComplete;
56
input   rst;
57
input   wb_ack;
58
input   [7:0]wb_data_i;
59
input   wbBusGnt;
60
output  usbRstDet;
61
output  [7:0]wb_addr;
62
output  wb_stb;
63
output  wb_we;
64
output  wbBusReq;
65
 
66
wire    clk;
67
wire    initComplete;
68
wire    rst;
69
reg     usbRstDet, next_usbRstDet;
70
wire    wb_ack;
71
reg     [7:0]wb_addr, next_wb_addr;
72
wire    [7:0]wb_data_i;
73
reg     wb_stb, next_wb_stb;
74
reg     wb_we, next_wb_we;
75
wire    wbBusGnt;
76
reg     wbBusReq, next_wbBusReq;
77
 
78
// diagram signals declarations
79
reg  [15:0]cnt, next_cnt;
80
reg  [1:0]resetState, next_resetState;
81
 
82
// BINARY ENCODED state machine: chkLSt
83
// State codes definitions:
84
`define START 3'b000
85
`define GET_STAT 3'b001
86
`define WT_GNT 3'b010
87
`define SET_RST_DET 3'b011
88
`define DEL_ONE_MSEC 3'b100
89
 
90
reg [2:0]CurrState_chkLSt, NextState_chkLSt;
91
 
92
// Diagram actions (continuous assignments allowed only: assign ...)
93
// diagram ACTION
94
 
95
 
96
// Machine: chkLSt
97
 
98
// NextState logic (combinatorial)
99
always @ (initComplete or wb_ack or resetState or wbBusGnt or cnt or usbRstDet or wbBusReq or wb_addr or wb_stb or wb_we or CurrState_chkLSt)
100
begin
101
  NextState_chkLSt <= CurrState_chkLSt;
102
  // Set default values for outputs and signals
103
  next_usbRstDet <= usbRstDet;
104
  next_wbBusReq <= wbBusReq;
105
  next_wb_addr <= wb_addr;
106
  next_wb_stb <= wb_stb;
107
  next_wb_we <= wb_we;
108
  next_cnt <= cnt;
109
  next_resetState <= resetState;
110
  case (CurrState_chkLSt)  // synopsys parallel_case full_case
111
    `START:
112
    begin
113
      next_usbRstDet <= 1'b0;
114
      next_wbBusReq <= 1'b0;
115
      next_wb_addr <= 8'h00;
116
      next_wb_stb <= 1'b0;
117
      next_wb_we <= 1'b0;
118
      next_cnt <= 16'h0000;
119
      next_resetState <= 2'b00;
120
      if (initComplete == 1'b1)
121
      begin
122
        NextState_chkLSt <= `WT_GNT;
123
      end
124
    end
125
    `GET_STAT:
126
    begin
127
      next_wb_addr <= `RA_SC_LINE_STATUS_REG;
128
      next_wb_stb <= 1'b1;
129
      next_wb_we <= 1'b1;
130
      if (wb_ack == 1'b1)
131
      begin
132
        NextState_chkLSt <= `SET_RST_DET;
133
        next_wb_stb <= 1'b0;
134
        if ( (wb_data_i[1:0] == `DISCONNECT) || (wb_data_i[`VBUS_PRES_BIT] == 1'b0) )
135
        next_resetState <= {resetState[0], 1'b1};
136
        else
137
        next_resetState <= 2'b00;
138
        next_wbBusReq <= 1'b0;
139
      end
140
    end
141
    `WT_GNT:
142
    begin
143
      next_wbBusReq <= 1'b1;
144
      if (wbBusGnt == 1'b1)
145
      begin
146
        NextState_chkLSt <= `GET_STAT;
147
      end
148
    end
149
    `SET_RST_DET:
150
    begin
151
      NextState_chkLSt <= `DEL_ONE_MSEC;
152
      if (resetState == 2'b11) // if reset condition aserted for 2mS
153
      next_usbRstDet <= 1'b1;
154
      next_cnt <= 16'h0000;
155
    end
156
    `DEL_ONE_MSEC:
157
    begin
158
      next_cnt <= cnt + 1'b1;
159
      next_usbRstDet <= 1'b0;
160
      if (cnt == `ONE_MSEC_DEL)
161
      begin
162
        NextState_chkLSt <= `WT_GNT;
163
      end
164
    end
165
  endcase
166
end
167
 
168
// Current State Logic (sequential)
169
always @ (posedge clk)
170
begin
171
  if (rst == 1'b1)
172
    CurrState_chkLSt <= `START;
173
  else
174
    CurrState_chkLSt <= NextState_chkLSt;
175
end
176
 
177
// Registered outputs logic
178
always @ (posedge clk)
179
begin
180
  if (rst == 1'b1)
181
  begin
182
    usbRstDet <= 1'b0;
183
    wbBusReq <= 1'b0;
184
    wb_addr <= 8'h00;
185
    wb_stb <= 1'b0;
186
    wb_we <= 1'b0;
187
    cnt <= 16'h0000;
188
    resetState <= 2'b00;
189
  end
190
  else
191
  begin
192
    usbRstDet <= next_usbRstDet;
193
    wbBusReq <= next_wbBusReq;
194
    wb_addr <= next_wb_addr;
195
    wb_stb <= next_wb_stb;
196
    wb_we <= next_wb_we;
197
    cnt <= next_cnt;
198
    resetState <= next_resetState;
199
  end
200
end
201
 
202
endmodule

powered by: WebSVN 2.1.0

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