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

Subversion Repositories usbhostslave

[/] [usbhostslave/] [tags/] [rel_00_07_alpha/] [RTL/] [slaveController/] [slaveSendpacket.v] - Blame information for rev 43

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

Line No. Rev Author Line
1 5 sfielding
 
2
//////////////////////////////////////////////////////////////////////
3
////                                                              ////
4
//// slaveSendPacket
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
//
46
`timescale 1ns / 1ps
47
`include "usbSerialInterfaceEngine_h.v"
48
`include "usbConstants_h.v"
49
 
50
module slaveSendPacket (clk, fifoData, fifoEmpty, fifoReadEn, PID, rst, SCTxPortCntl, SCTxPortData, SCTxPortGnt, SCTxPortRdy, SCTxPortReq, SCTxPortWEn, sendPacketRdy, sendPacketWEn);
51
input   clk;
52
input   [7:0]fifoData;
53
input   fifoEmpty;
54
input   [3:0]PID;
55
input   rst;
56
input   SCTxPortGnt;
57
input   SCTxPortRdy;
58
input   sendPacketWEn;
59
output  fifoReadEn;
60
output  [7:0]SCTxPortCntl;
61
output  [7:0]SCTxPortData;
62
output  SCTxPortReq;
63
output  SCTxPortWEn;
64
output  sendPacketRdy;
65
 
66
wire    clk;
67
wire    [7:0]fifoData;
68
wire    fifoEmpty;
69
reg     fifoReadEn, next_fifoReadEn;
70
wire    [3:0]PID;
71
wire    rst;
72
reg     [7:0]SCTxPortCntl, next_SCTxPortCntl;
73
reg     [7:0]SCTxPortData, next_SCTxPortData;
74
wire    SCTxPortGnt;
75
wire    SCTxPortRdy;
76
reg     SCTxPortReq, next_SCTxPortReq;
77
reg     SCTxPortWEn, next_SCTxPortWEn;
78
reg     sendPacketRdy, next_sendPacketRdy;
79
wire    sendPacketWEn;
80
 
81
// diagram signals declarations
82
reg  [7:0]PIDNotPID;
83
 
84
// BINARY ENCODED state machine: slvSndPkt
85
// State codes definitions:
86
`define START_SP1 4'b0000
87
`define SP_WAIT_ENABLE 4'b0001
88
`define SP1_WAIT_GNT 4'b0010
89
`define SP_SEND_PID_WAIT_RDY 4'b0011
90
`define SP_SEND_PID_FIN 4'b0100
91
`define FIN_SP1 4'b0101
92
`define SP_D0_D1_READ_FIFO 4'b0110
93
`define SP_D0_D1_WAIT_READ_FIFO 4'b0111
94
`define SP_D0_D1_FIFO_EMPTY 4'b1000
95
`define SP_D0_D1_FIN 4'b1001
96
`define SP_D0_D1_TERM_BYTE 4'b1010
97
`define SP_NOT_DATA 4'b1011
98
`define SP_D0_D1_CLR_WEN 4'b1100
99
`define SP_D0_D1_CLR_REN 4'b1101
100
 
101
reg [3:0]CurrState_slvSndPkt, NextState_slvSndPkt;
102
 
103
// Diagram actions (continuous assignments allowed only: assign ...)
104
always @(PID)
105
begin
106
PIDNotPID <=  { (PID ^ 4'hf), PID };
107
end
108
 
109
 
110
// Machine: slvSndPkt
111
 
112
// NextState logic (combinatorial)
113
always @ (sendPacketWEn or SCTxPortGnt or SCTxPortRdy or PIDNotPID or PID or fifoData or fifoEmpty or sendPacketRdy or fifoReadEn or SCTxPortData or SCTxPortCntl or SCTxPortWEn or SCTxPortReq or CurrState_slvSndPkt)
114
begin
115
  NextState_slvSndPkt <= CurrState_slvSndPkt;
116
  // Set default values for outputs and signals
117
  next_sendPacketRdy <= sendPacketRdy;
118
  next_fifoReadEn <= fifoReadEn;
119
  next_SCTxPortData <= SCTxPortData;
120
  next_SCTxPortCntl <= SCTxPortCntl;
121
  next_SCTxPortWEn <= SCTxPortWEn;
122
  next_SCTxPortReq <= SCTxPortReq;
123
  case (CurrState_slvSndPkt)  // synopsys parallel_case full_case
124
    `START_SP1:
125
    begin
126
      NextState_slvSndPkt <= `SP_WAIT_ENABLE;
127
    end
128
    `SP_WAIT_ENABLE:
129
    begin
130
      if (sendPacketWEn == 1'b1)
131
      begin
132
        NextState_slvSndPkt <= `SP1_WAIT_GNT;
133
        next_sendPacketRdy <= 1'b0;
134
        next_SCTxPortReq <= 1'b1;
135
      end
136
    end
137
    `SP1_WAIT_GNT:
138
    begin
139
      if (SCTxPortGnt == 1'b1)
140
      begin
141
        NextState_slvSndPkt <= `SP_SEND_PID_WAIT_RDY;
142
      end
143
    end
144
    `FIN_SP1:
145
    begin
146
      NextState_slvSndPkt <= `SP_WAIT_ENABLE;
147
      next_sendPacketRdy <= 1'b1;
148
      next_SCTxPortReq <= 1'b0;
149
    end
150
    `SP_NOT_DATA:
151
    begin
152
      NextState_slvSndPkt <= `FIN_SP1;
153
    end
154
    `SP_SEND_PID_WAIT_RDY:
155
    begin
156
      if (SCTxPortRdy == 1'b1)
157
      begin
158
        NextState_slvSndPkt <= `SP_SEND_PID_FIN;
159
        next_SCTxPortWEn <= 1'b1;
160
        next_SCTxPortData <= PIDNotPID;
161
        next_SCTxPortCntl <= `TX_PACKET_START;
162
      end
163
    end
164
    `SP_SEND_PID_FIN:
165
    begin
166
      next_SCTxPortWEn <= 1'b0;
167
      if (PID == `DATA0 || PID == `DATA1)
168
      begin
169
        NextState_slvSndPkt <= `SP_D0_D1_FIFO_EMPTY;
170
      end
171
      else
172
      begin
173
        NextState_slvSndPkt <= `SP_NOT_DATA;
174
      end
175
    end
176
    `SP_D0_D1_READ_FIFO:
177
    begin
178
      next_SCTxPortWEn <= 1'b1;
179
      next_SCTxPortData <= fifoData;
180
      next_SCTxPortCntl <= `TX_PACKET_STREAM;
181
      NextState_slvSndPkt <= `SP_D0_D1_CLR_WEN;
182
    end
183
    `SP_D0_D1_WAIT_READ_FIFO:
184
    begin
185
      if (SCTxPortRdy == 1'b1)
186
      begin
187
        NextState_slvSndPkt <= `SP_D0_D1_CLR_REN;
188
        next_fifoReadEn <= 1'b1;
189
      end
190
    end
191
    `SP_D0_D1_FIFO_EMPTY:
192
    begin
193
      if (fifoEmpty == 1'b0)
194
      begin
195
        NextState_slvSndPkt <= `SP_D0_D1_WAIT_READ_FIFO;
196
      end
197
      else
198
      begin
199
        NextState_slvSndPkt <= `SP_D0_D1_TERM_BYTE;
200
      end
201
    end
202
    `SP_D0_D1_FIN:
203
    begin
204
      next_SCTxPortWEn <= 1'b0;
205
      NextState_slvSndPkt <= `FIN_SP1;
206
    end
207
    `SP_D0_D1_TERM_BYTE:
208
    begin
209
      if (SCTxPortRdy == 1'b1)
210
      begin
211
        NextState_slvSndPkt <= `SP_D0_D1_FIN;
212
        //Last byte is not valid data,
213
        //but the 'TX_PACKET_STOP' flag is required
214
        //by the SIE state machine to detect end of data packet
215
        next_SCTxPortWEn <= 1'b1;
216
        next_SCTxPortData <= 8'h00;
217
        next_SCTxPortCntl <= `TX_PACKET_STOP;
218
      end
219
    end
220
    `SP_D0_D1_CLR_WEN:
221
    begin
222
      next_SCTxPortWEn <= 1'b0;
223
      NextState_slvSndPkt <= `SP_D0_D1_FIFO_EMPTY;
224
    end
225
    `SP_D0_D1_CLR_REN:
226
    begin
227
      next_fifoReadEn <= 1'b0;
228
      NextState_slvSndPkt <= `SP_D0_D1_READ_FIFO;
229
    end
230
  endcase
231
end
232
 
233
// Current State Logic (sequential)
234
always @ (posedge clk)
235
begin
236
  if (rst)
237
    CurrState_slvSndPkt <= `START_SP1;
238
  else
239
    CurrState_slvSndPkt <= NextState_slvSndPkt;
240
end
241
 
242
// Registered outputs logic
243
always @ (posedge clk)
244
begin
245
  if (rst)
246
  begin
247
    sendPacketRdy <= 1'b1;
248
    fifoReadEn <= 1'b0;
249
    SCTxPortData <= 8'h00;
250
    SCTxPortCntl <= 8'h00;
251
    SCTxPortWEn <= 1'b0;
252
    SCTxPortReq <= 1'b0;
253
  end
254
  else
255
  begin
256
    sendPacketRdy <= next_sendPacketRdy;
257
    fifoReadEn <= next_fifoReadEn;
258
    SCTxPortData <= next_SCTxPortData;
259
    SCTxPortCntl <= next_SCTxPortCntl;
260
    SCTxPortWEn <= next_SCTxPortWEn;
261
    SCTxPortReq <= next_SCTxPortReq;
262
  end
263
end
264
 
265 2 sfielding
endmodule

powered by: WebSVN 2.1.0

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