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

Subversion Repositories usbhostslave

[/] [usbhostslave/] [trunk/] [RTL/] [hostController/] [sendpacket.v] - Blame information for rev 5

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

Line No. Rev Author Line
1 5 sfielding
 
2
//////////////////////////////////////////////////////////////////////
3
////                                                              ////
4
//// sendPacket
5
////                                                              ////
6
//// This file is part of the usbhostslave opencores effort.
7
//// http://www.opencores.org/cores/usbhostslave/                 ////
8
////                                                              ////
9
//// Module Description:                                          ////
10
//// 
11
////                                                              ////
12
//// To Do:                                                       ////
13
//// 
14
////                                                              ////
15
//// Author(s):                                                   ////
16
//// - Steve Fielding, sfielding@base2designs.com                 ////
17
////                                                              ////
18
//////////////////////////////////////////////////////////////////////
19
////                                                              ////
20
//// Copyright (C) 2004 Steve Fielding and OPENCORES.ORG          ////
21
////                                                              ////
22
//// This source file may be used and distributed without         ////
23
//// restriction provided that this copyright statement is not    ////
24
//// removed from the file and that any derivative work contains  ////
25
//// the original copyright notice and the associated disclaimer. ////
26
////                                                              ////
27
//// This source file is free software; you can redistribute it   ////
28
//// and/or modify it under the terms of the GNU Lesser General   ////
29
//// Public License as published by the Free Software Foundation; ////
30
//// either version 2.1 of the License, or (at your option) any   ////
31
//// later version.                                               ////
32
////                                                              ////
33
//// This source is distributed in the hope that it will be       ////
34
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
35
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
36
//// PURPOSE. See the GNU Lesser General Public License for more  ////
37
//// details.                                                     ////
38
////                                                              ////
39
//// You should have received a copy of the GNU Lesser General    ////
40
//// Public License along with this source; if not, download it   ////
41
//// from http://www.opencores.org/lgpl.shtml                     ////
42
////                                                              ////
43
//////////////////////////////////////////////////////////////////////
44
//
45
// $Id: sendpacket.v,v 1.2 2004-12-18 14:36:10 sfielding Exp $
46
//
47
// CVS Revision History
48
//
49
// $Log: not supported by cvs2svn $
50
//
51
`timescale 1ns / 1ps
52
`include "usbSerialInterfaceEngine_h.v"
53
`include "usbConstants_h.v"
54
 
55
 
56
 
57
module sendPacket (clk, fifoData, fifoEmpty, fifoReadEn, frameNum, HCTxPortCntl, HCTxPortData, HCTxPortGnt, HCTxPortRdy, HCTxPortReq, HCTxPortWEn, PID, rst, sendPacketRdy, sendPacketWEn, TxAddr, TxEndP);
58
input   clk;
59
input   [7:0]fifoData;
60
input   fifoEmpty;
61
input   HCTxPortGnt;
62
input   HCTxPortRdy;
63
input   [3:0]PID;
64
input   rst;
65
input   sendPacketWEn;
66
input   [6:0]TxAddr;
67
input   [3:0]TxEndP;
68
output  fifoReadEn;
69
output  [10:0]frameNum;
70
output  [7:0]HCTxPortCntl;
71
output  [7:0]HCTxPortData;
72
output  HCTxPortReq;
73
output  HCTxPortWEn;
74
output  sendPacketRdy;
75
 
76
wire    clk;
77
wire    [7:0]fifoData;
78
wire    fifoEmpty;
79
reg     fifoReadEn, next_fifoReadEn;
80
reg     [10:0]frameNum, next_frameNum;
81
reg     [7:0]HCTxPortCntl, next_HCTxPortCntl;
82
reg     [7:0]HCTxPortData, next_HCTxPortData;
83
wire    HCTxPortGnt;
84
wire    HCTxPortRdy;
85
reg     HCTxPortReq, next_HCTxPortReq;
86
reg     HCTxPortWEn, next_HCTxPortWEn;
87
wire    [3:0]PID;
88
wire    rst;
89
reg     sendPacketRdy, next_sendPacketRdy;
90
wire    sendPacketWEn;
91
wire    [6:0]TxAddr;
92
wire    [3:0]TxEndP;
93
 
94
// diagram signals declarations
95
reg  [7:0]PIDNotPID;
96
 
97
// BINARY ENCODED state machine: sndPkt
98
// State codes definitions:
99
`define START_SP 5'b00000
100
`define WAIT_ENABLE 5'b00001
101
`define SP_WAIT_GNT 5'b00010
102
`define SEND_PID_WAIT_RDY 5'b00011
103
`define SEND_PID_FIN 5'b00100
104
`define FIN_SP 5'b00101
105
`define OUT_IN_SETUP_WAIT_RDY1 5'b00110
106
`define OUT_IN_SETUP_WAIT_RDY2 5'b00111
107
`define OUT_IN_SETUP_FIN 5'b01000
108
`define SEND_SOF_FIN1 5'b01001
109
`define SEND_SOF_WAIT_RDY3 5'b01010
110
`define SEND_SOF_WAIT_RDY4 5'b01011
111
`define DATA0_DATA1_READ_FIFO 5'b01100
112
`define DATA0_DATA1_WAIT_READ_FIFO 5'b01101
113
`define DATA0_DATA1_FIFO_EMPTY 5'b01110
114
`define DATA0_DATA1_FIN 5'b01111
115
`define DATA0_DATA1_TERM_BYTE 5'b10000
116
`define OUT_IN_SETUP_CLR_WEN1 5'b10001
117
`define SEND_SOF_CLR_WEN1 5'b10010
118
`define DATA0_DATA1_CLR_WEN 5'b10011
119
`define DATA0_DATA1_CLR_REN 5'b10100
120
 
121
reg [4:0]CurrState_sndPkt, NextState_sndPkt;
122
 
123
// Diagram actions (continuous assignments allowed only: assign ...)
124
always @(PID)
125
begin
126
PIDNotPID <=  { (PID ^ 4'hf), PID };
127
end
128
 
129
 
130
// Machine: sndPkt
131
 
132
// NextState logic (combinatorial)
133
always @ (sendPacketWEn or HCTxPortGnt or HCTxPortRdy or PIDNotPID or PID or TxEndP or TxAddr or frameNum or fifoData or fifoEmpty or sendPacketRdy or fifoReadEn or HCTxPortData or HCTxPortCntl or HCTxPortWEn or HCTxPortReq or CurrState_sndPkt)
134
begin
135
  NextState_sndPkt <= CurrState_sndPkt;
136
  // Set default values for outputs and signals
137
  next_sendPacketRdy <= sendPacketRdy;
138
  next_fifoReadEn <= fifoReadEn;
139
  next_HCTxPortData <= HCTxPortData;
140
  next_HCTxPortCntl <= HCTxPortCntl;
141
  next_HCTxPortWEn <= HCTxPortWEn;
142
  next_HCTxPortReq <= HCTxPortReq;
143
  next_frameNum <= frameNum;
144
  case (CurrState_sndPkt)  // synopsys parallel_case full_case
145
    `START_SP:
146
    begin
147
      NextState_sndPkt <= `WAIT_ENABLE;
148
    end
149
    `WAIT_ENABLE:
150
    begin
151
      if (sendPacketWEn == 1'b1)
152
      begin
153
        NextState_sndPkt <= `SP_WAIT_GNT;
154
        next_sendPacketRdy <= 1'b0;
155
        next_HCTxPortReq <= 1'b1;
156
      end
157
    end
158
    `SP_WAIT_GNT:
159
    begin
160
      if (HCTxPortGnt == 1'b1)
161
      begin
162
        NextState_sndPkt <= `SEND_PID_WAIT_RDY;
163
      end
164
    end
165
    `FIN_SP:
166
    begin
167
      NextState_sndPkt <= `WAIT_ENABLE;
168
      next_sendPacketRdy <= 1'b1;
169
      next_HCTxPortReq <= 1'b0;
170
    end
171
    `SEND_PID_WAIT_RDY:
172
    begin
173
      if (HCTxPortRdy == 1'b1)
174
      begin
175
        NextState_sndPkt <= `SEND_PID_FIN;
176
        next_HCTxPortWEn <= 1'b1;
177
        next_HCTxPortData <= PIDNotPID;
178
        next_HCTxPortCntl <= `TX_PACKET_START;
179
      end
180
    end
181
    `SEND_PID_FIN:
182
    begin
183
      next_HCTxPortWEn <= 1'b0;
184
      if (PID == `DATA0 || PID == `DATA1)
185
      begin
186
        NextState_sndPkt <= `DATA0_DATA1_FIFO_EMPTY;
187
      end
188
      else if (PID == `SOF)
189
      begin
190
        NextState_sndPkt <= `SEND_SOF_WAIT_RDY3;
191
      end
192
      else if (PID == `OUT ||
193
        PID == `IN ||
194
        PID == `SETUP)
195
      begin
196
        NextState_sndPkt <= `OUT_IN_SETUP_WAIT_RDY1;
197
      end
198
      else
199
      begin
200
        NextState_sndPkt <= `FIN_SP;
201
      end
202
    end
203
    `OUT_IN_SETUP_WAIT_RDY1:
204
    begin
205
      if (HCTxPortRdy == 1'b1)
206
      begin
207
        NextState_sndPkt <= `OUT_IN_SETUP_CLR_WEN1;
208
        next_HCTxPortWEn <= 1'b1;
209
        next_HCTxPortData <= {TxEndP[0], TxAddr[6:0]};
210
        next_HCTxPortCntl <= `TX_PACKET_STREAM;
211
      end
212
    end
213
    `OUT_IN_SETUP_WAIT_RDY2:
214
    begin
215
      if (HCTxPortRdy == 1'b1)
216
      begin
217
        NextState_sndPkt <= `OUT_IN_SETUP_FIN;
218
        next_HCTxPortWEn <= 1'b1;
219
        next_HCTxPortData <= {5'b00000, TxEndP[3:1]};
220
        next_HCTxPortCntl <= `TX_PACKET_STREAM;
221
      end
222
    end
223
    `OUT_IN_SETUP_FIN:
224
    begin
225
      next_HCTxPortWEn <= 1'b0;
226
      NextState_sndPkt <= `FIN_SP;
227
    end
228
    `OUT_IN_SETUP_CLR_WEN1:
229
    begin
230
      next_HCTxPortWEn <= 1'b0;
231
      NextState_sndPkt <= `OUT_IN_SETUP_WAIT_RDY2;
232
    end
233
    `SEND_SOF_FIN1:
234
    begin
235
      next_HCTxPortWEn <= 1'b0;
236
      next_frameNum <= frameNum + 1'b1;
237
      NextState_sndPkt <= `FIN_SP;
238
    end
239
    `SEND_SOF_WAIT_RDY3:
240
    begin
241
      if (HCTxPortRdy == 1'b1)
242
      begin
243
        NextState_sndPkt <= `SEND_SOF_CLR_WEN1;
244
        next_HCTxPortWEn <= 1'b1;
245
        next_HCTxPortData <= frameNum[7:0];
246
        next_HCTxPortCntl <= `TX_PACKET_STREAM;
247
      end
248
    end
249
    `SEND_SOF_WAIT_RDY4:
250
    begin
251
      if (HCTxPortRdy == 1'b1)
252
      begin
253
        NextState_sndPkt <= `SEND_SOF_FIN1;
254
        next_HCTxPortWEn <= 1'b1;
255
        next_HCTxPortData <= {5'b00000, frameNum[10:8]};
256
        next_HCTxPortCntl <= `TX_PACKET_STREAM;
257
      end
258
    end
259
    `SEND_SOF_CLR_WEN1:
260
    begin
261
      next_HCTxPortWEn <= 1'b0;
262
      NextState_sndPkt <= `SEND_SOF_WAIT_RDY4;
263
    end
264
    `DATA0_DATA1_READ_FIFO:
265
    begin
266
      next_HCTxPortWEn <= 1'b1;
267
      next_HCTxPortData <= fifoData;
268
      next_HCTxPortCntl <= `TX_PACKET_STREAM;
269
      NextState_sndPkt <= `DATA0_DATA1_CLR_WEN;
270
    end
271
    `DATA0_DATA1_WAIT_READ_FIFO:
272
    begin
273
      if (HCTxPortRdy == 1'b1)
274
      begin
275
        NextState_sndPkt <= `DATA0_DATA1_CLR_REN;
276
        next_fifoReadEn <= 1'b1;
277
      end
278
    end
279
    `DATA0_DATA1_FIFO_EMPTY:
280
    begin
281
      if (fifoEmpty == 1'b0)
282
      begin
283
        NextState_sndPkt <= `DATA0_DATA1_WAIT_READ_FIFO;
284
      end
285
      else
286
      begin
287
        NextState_sndPkt <= `DATA0_DATA1_TERM_BYTE;
288
      end
289
    end
290
    `DATA0_DATA1_FIN:
291
    begin
292
      next_HCTxPortWEn <= 1'b0;
293
      NextState_sndPkt <= `FIN_SP;
294
    end
295
    `DATA0_DATA1_TERM_BYTE:
296
    begin
297
      if (HCTxPortRdy == 1'b1)
298
      begin
299
        NextState_sndPkt <= `DATA0_DATA1_FIN;
300
        //Last byte is not valid data,
301
        //but the 'TX_PACKET_STOP' flag is required
302
        //by the SIE state machine to detect end of data packet
303
        next_HCTxPortWEn <= 1'b1;
304
        next_HCTxPortData <= 8'h00;
305
        next_HCTxPortCntl <= `TX_PACKET_STOP;
306
      end
307
    end
308
    `DATA0_DATA1_CLR_WEN:
309
    begin
310
      next_HCTxPortWEn <= 1'b0;
311
      NextState_sndPkt <= `DATA0_DATA1_FIFO_EMPTY;
312
    end
313
    `DATA0_DATA1_CLR_REN:
314
    begin
315
      next_fifoReadEn <= 1'b0;
316
      NextState_sndPkt <= `DATA0_DATA1_READ_FIFO;
317
    end
318
  endcase
319
end
320
 
321
// Current State Logic (sequential)
322
always @ (posedge clk)
323
begin
324
  if (rst)
325
    CurrState_sndPkt <= `START_SP;
326
  else
327
    CurrState_sndPkt <= NextState_sndPkt;
328
end
329
 
330
// Registered outputs logic
331
always @ (posedge clk)
332
begin
333
  if (rst)
334
  begin
335
    sendPacketRdy <= 1'b1;
336
    fifoReadEn <= 1'b0;
337
    HCTxPortData <= 8'h00;
338
    HCTxPortCntl <= 8'h00;
339
    HCTxPortWEn <= 1'b0;
340
    HCTxPortReq <= 1'b0;
341
    frameNum <= 11'h000;
342
  end
343
  else
344
  begin
345
    sendPacketRdy <= next_sendPacketRdy;
346
    fifoReadEn <= next_fifoReadEn;
347
    HCTxPortData <= next_HCTxPortData;
348
    HCTxPortCntl <= next_HCTxPortCntl;
349
    HCTxPortWEn <= next_HCTxPortWEn;
350
    HCTxPortReq <= next_HCTxPortReq;
351
    frameNum <= next_frameNum;
352
  end
353
end
354
 
355 2 sfielding
endmodule

powered by: WebSVN 2.1.0

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