| 1 | 408 | julius |  
 | 
      
         | 2 |  |  | // File        : ../RTL/hostController/softransmit.v
 | 
      
         | 3 |  |  | // Generated   : 11/10/06 05:37:21
 | 
      
         | 4 |  |  | // From        : ../RTL/hostController/softransmit.asf
 | 
      
         | 5 |  |  | // By          : FSM2VHDL ver. 5.0.0.9
 | 
      
         | 6 |  |  |  
 | 
      
         | 7 |  |  | //////////////////////////////////////////////////////////////////////
 | 
      
         | 8 |  |  | ////                                                              ////
 | 
      
         | 9 |  |  | //// softransmit
 | 
      
         | 10 |  |  | ////                                                              ////
 | 
      
         | 11 |  |  | //// This file is part of the usbhostslave opencores effort.
 | 
      
         | 12 |  |  | //// http://www.opencores.org/cores/usbhostslave/                 ////
 | 
      
         | 13 |  |  | ////                                                              ////
 | 
      
         | 14 |  |  | //// Module Description:                                          ////
 | 
      
         | 15 |  |  | //// 
 | 
      
         | 16 |  |  | ////                                                              ////
 | 
      
         | 17 |  |  | //// To Do:                                                       ////
 | 
      
         | 18 |  |  | //// 
 | 
      
         | 19 |  |  | ////                                                              ////
 | 
      
         | 20 |  |  | //// Author(s):                                                   ////
 | 
      
         | 21 |  |  | //// - Steve Fielding, sfielding@base2designs.com                 ////
 | 
      
         | 22 |  |  | ////                                                              ////
 | 
      
         | 23 |  |  | //////////////////////////////////////////////////////////////////////
 | 
      
         | 24 |  |  | ////                                                              ////
 | 
      
         | 25 |  |  | //// Copyright (C) 2004 Steve Fielding and OPENCORES.ORG          ////
 | 
      
         | 26 |  |  | ////                                                              ////
 | 
      
         | 27 |  |  | //// This source file may be used and distributed without         ////
 | 
      
         | 28 |  |  | //// restriction provided that this copyright statement is not    ////
 | 
      
         | 29 |  |  | //// removed from the file and that any derivative work contains  ////
 | 
      
         | 30 |  |  | //// the original copyright notice and the associated disclaimer. ////
 | 
      
         | 31 |  |  | ////                                                              ////
 | 
      
         | 32 |  |  | //// This source file is free software; you can redistribute it   ////
 | 
      
         | 33 |  |  | //// and/or modify it under the terms of the GNU Lesser General   ////
 | 
      
         | 34 |  |  | //// Public License as published by the Free Software Foundation; ////
 | 
      
         | 35 |  |  | //// either version 2.1 of the License, or (at your option) any   ////
 | 
      
         | 36 |  |  | //// later version.                                               ////
 | 
      
         | 37 |  |  | ////                                                              ////
 | 
      
         | 38 |  |  | //// This source is distributed in the hope that it will be       ////
 | 
      
         | 39 |  |  | //// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
 | 
      
         | 40 |  |  | //// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
 | 
      
         | 41 |  |  | //// PURPOSE. See the GNU Lesser General Public License for more  ////
 | 
      
         | 42 |  |  | //// details.                                                     ////
 | 
      
         | 43 |  |  | ////                                                              ////
 | 
      
         | 44 |  |  | //// You should have received a copy of the GNU Lesser General    ////
 | 
      
         | 45 |  |  | //// Public License along with this source; if not, download it   ////
 | 
      
         | 46 |  |  | //// from http://www.opencores.org/lgpl.shtml                     ////
 | 
      
         | 47 |  |  | ////                                                              ////
 | 
      
         | 48 |  |  | //////////////////////////////////////////////////////////////////////
 | 
      
         | 49 |  |  | //
 | 
      
         | 50 |  |  | `include "timescale.v"
 | 
      
         | 51 |  |  | `include "usbhostslave_hostcontrol_h.v"
 | 
      
         | 52 |  |  |  
 | 
      
         | 53 |  |  |  
 | 
      
         | 54 |  |  | module SOFTransmit (SOFEnable, SOFSent, SOFSyncEn, SOFTimerClr, SOFTimer, clk, rst, sendPacketArbiterGnt, sendPacketArbiterReq, sendPacketRdy, sendPacketWEn);
 | 
      
         | 55 |  |  | input   SOFEnable;              // After host software asserts SOFEnable, must wait TBD time before asserting SOFSyncEn
 | 
      
         | 56 |  |  | input   SOFSyncEn;
 | 
      
         | 57 |  |  | input   [15:0] SOFTimer;
 | 
      
         | 58 |  |  | input   clk;
 | 
      
         | 59 |  |  | input   rst;
 | 
      
         | 60 |  |  | input   sendPacketArbiterGnt;
 | 
      
         | 61 |  |  | input   sendPacketRdy;
 | 
      
         | 62 |  |  | output  SOFSent;                // single cycle pulse
 | 
      
         | 63 |  |  | output  SOFTimerClr;            // Single cycle pulse
 | 
      
         | 64 |  |  | output  sendPacketArbiterReq;
 | 
      
         | 65 |  |  | output  sendPacketWEn;
 | 
      
         | 66 |  |  |  
 | 
      
         | 67 |  |  | wire    SOFEnable;
 | 
      
         | 68 |  |  | reg     SOFSent, next_SOFSent;
 | 
      
         | 69 |  |  | wire    SOFSyncEn;
 | 
      
         | 70 |  |  | reg     SOFTimerClr, next_SOFTimerClr;
 | 
      
         | 71 |  |  | wire    [15:0] SOFTimer;
 | 
      
         | 72 |  |  | wire    clk;
 | 
      
         | 73 |  |  | wire    rst;
 | 
      
         | 74 |  |  | wire    sendPacketArbiterGnt;
 | 
      
         | 75 |  |  | reg     sendPacketArbiterReq, next_sendPacketArbiterReq;
 | 
      
         | 76 |  |  | wire    sendPacketRdy;
 | 
      
         | 77 |  |  | reg     sendPacketWEn, next_sendPacketWEn;
 | 
      
         | 78 |  |  |  
 | 
      
         | 79 |  |  | // diagram signals declarations
 | 
      
         | 80 |  |  | reg  [7:0]i, next_i;
 | 
      
         | 81 |  |  |  
 | 
      
         | 82 |  |  | // BINARY ENCODED state machine: SOFTx
 | 
      
         | 83 |  |  | // State codes definitions:
 | 
      
         | 84 |  |  | `define START_STX 3'b000
 | 
      
         | 85 |  |  | `define WAIT_SOF_NEAR 3'b001
 | 
      
         | 86 |  |  | `define WAIT_SP_GNT 3'b010
 | 
      
         | 87 |  |  | `define WAIT_SOF_NOW 3'b011
 | 
      
         | 88 |  |  | `define SOF_FIN 3'b100
 | 
      
         | 89 |  |  | `define DLY_SOF_CHK1 3'b101
 | 
      
         | 90 |  |  | `define DLY_SOF_CHK2 3'b110
 | 
      
         | 91 |  |  |  
 | 
      
         | 92 |  |  | reg [2:0] CurrState_SOFTx;
 | 
      
         | 93 |  |  | reg [2:0] NextState_SOFTx;
 | 
      
         | 94 |  |  |  
 | 
      
         | 95 |  |  |  
 | 
      
         | 96 |  |  | //--------------------------------------------------------------------
 | 
      
         | 97 |  |  | // Machine: SOFTx
 | 
      
         | 98 |  |  | //--------------------------------------------------------------------
 | 
      
         | 99 |  |  | //----------------------------------
 | 
      
         | 100 |  |  | // Next State Logic (combinatorial)
 | 
      
         | 101 |  |  | //----------------------------------
 | 
      
         | 102 |  |  | always @ (i or SOFTimer or SOFSyncEn or SOFEnable or sendPacketArbiterGnt or sendPacketRdy or sendPacketArbiterReq or sendPacketWEn or SOFTimerClr or SOFSent or CurrState_SOFTx)
 | 
      
         | 103 |  |  | begin : SOFTx_NextState
 | 
      
         | 104 |  |  |   NextState_SOFTx <= CurrState_SOFTx;
 | 
      
         | 105 |  |  |   // Set default values for outputs and signals
 | 
      
         | 106 |  |  |   next_sendPacketArbiterReq <= sendPacketArbiterReq;
 | 
      
         | 107 |  |  |   next_sendPacketWEn <= sendPacketWEn;
 | 
      
         | 108 |  |  |   next_SOFTimerClr <= SOFTimerClr;
 | 
      
         | 109 |  |  |   next_SOFSent <= SOFSent;
 | 
      
         | 110 |  |  |   next_i <= i;
 | 
      
         | 111 |  |  |   case (CurrState_SOFTx)
 | 
      
         | 112 |  |  |     `START_STX:
 | 
      
         | 113 |  |  |       NextState_SOFTx <= `WAIT_SOF_NEAR;
 | 
      
         | 114 |  |  |     `WAIT_SOF_NEAR:
 | 
      
         | 115 |  |  |       if (SOFTimer >= `SOF_TX_TIME - `SOF_TX_MARGIN ||
 | 
      
         | 116 |  |  |         (SOFSyncEn == 1'b1 &&
 | 
      
         | 117 |  |  |         SOFEnable == 1'b1))
 | 
      
         | 118 |  |  |       begin
 | 
      
         | 119 |  |  |         NextState_SOFTx <= `WAIT_SP_GNT;
 | 
      
         | 120 |  |  |         next_sendPacketArbiterReq <= 1'b1;
 | 
      
         | 121 |  |  |       end
 | 
      
         | 122 |  |  |     `WAIT_SP_GNT:
 | 
      
         | 123 |  |  |       if (sendPacketArbiterGnt == 1'b1 && sendPacketRdy == 1'b1)
 | 
      
         | 124 |  |  |         NextState_SOFTx <= `WAIT_SOF_NOW;
 | 
      
         | 125 |  |  |     `WAIT_SOF_NOW:
 | 
      
         | 126 |  |  |       if (SOFTimer >= `SOF_TX_TIME)
 | 
      
         | 127 |  |  |       begin
 | 
      
         | 128 |  |  |         NextState_SOFTx <= `SOF_FIN;
 | 
      
         | 129 |  |  |         next_sendPacketWEn <= 1'b1;
 | 
      
         | 130 |  |  |         next_SOFTimerClr <= 1'b1;
 | 
      
         | 131 |  |  |         next_SOFSent <= 1'b1;
 | 
      
         | 132 |  |  |       end
 | 
      
         | 133 |  |  |       else if (SOFEnable == 1'b0)
 | 
      
         | 134 |  |  |       begin
 | 
      
         | 135 |  |  |         NextState_SOFTx <= `SOF_FIN;
 | 
      
         | 136 |  |  |         next_SOFTimerClr <= 1'b1;
 | 
      
         | 137 |  |  |       end
 | 
      
         | 138 |  |  |     `SOF_FIN:
 | 
      
         | 139 |  |  |     begin
 | 
      
         | 140 |  |  |       next_sendPacketWEn <= 1'b0;
 | 
      
         | 141 |  |  |       next_SOFTimerClr <= 1'b0;
 | 
      
         | 142 |  |  |       next_SOFSent <= 1'b0;
 | 
      
         | 143 |  |  |       if (sendPacketRdy == 1'b1)
 | 
      
         | 144 |  |  |       begin
 | 
      
         | 145 |  |  |         NextState_SOFTx <= `DLY_SOF_CHK1;
 | 
      
         | 146 |  |  |         next_i <= 8'h00;
 | 
      
         | 147 |  |  |       end
 | 
      
         | 148 |  |  |     end
 | 
      
         | 149 |  |  |     `DLY_SOF_CHK1:
 | 
      
         | 150 |  |  |     begin
 | 
      
         | 151 |  |  |       next_i <= i + 1'b1;
 | 
      
         | 152 |  |  |       if (i==8'hff)
 | 
      
         | 153 |  |  |       begin
 | 
      
         | 154 |  |  |         NextState_SOFTx <= `DLY_SOF_CHK2;
 | 
      
         | 155 |  |  |         next_sendPacketArbiterReq <= 1'b0;
 | 
      
         | 156 |  |  |         next_i <= 8'h00;
 | 
      
         | 157 |  |  |       end
 | 
      
         | 158 |  |  |     end
 | 
      
         | 159 |  |  |     `DLY_SOF_CHK2:
 | 
      
         | 160 |  |  |     begin
 | 
      
         | 161 |  |  |       next_i <= i + 1'b1;
 | 
      
         | 162 |  |  |       if (i==8'hff)
 | 
      
         | 163 |  |  |         NextState_SOFTx <= `WAIT_SOF_NEAR;
 | 
      
         | 164 |  |  |     end
 | 
      
         | 165 |  |  |   endcase
 | 
      
         | 166 |  |  | end
 | 
      
         | 167 |  |  |  
 | 
      
         | 168 |  |  | //----------------------------------
 | 
      
         | 169 |  |  | // Current State Logic (sequential)
 | 
      
         | 170 |  |  | //----------------------------------
 | 
      
         | 171 |  |  | always @ (posedge clk)
 | 
      
         | 172 |  |  | begin : SOFTx_CurrentState
 | 
      
         | 173 |  |  |   if (rst)
 | 
      
         | 174 |  |  |     CurrState_SOFTx <= `START_STX;
 | 
      
         | 175 |  |  |   else
 | 
      
         | 176 |  |  |     CurrState_SOFTx <= NextState_SOFTx;
 | 
      
         | 177 |  |  | end
 | 
      
         | 178 |  |  |  
 | 
      
         | 179 |  |  | //----------------------------------
 | 
      
         | 180 |  |  | // Registered outputs logic
 | 
      
         | 181 |  |  | //----------------------------------
 | 
      
         | 182 |  |  | always @ (posedge clk)
 | 
      
         | 183 |  |  | begin : SOFTx_RegOutput
 | 
      
         | 184 |  |  |   if (rst)
 | 
      
         | 185 |  |  |   begin
 | 
      
         | 186 |  |  |     i <= 8'h00;
 | 
      
         | 187 |  |  |     SOFSent <= 1'b0;
 | 
      
         | 188 |  |  |     SOFTimerClr <= 1'b0;
 | 
      
         | 189 |  |  |     sendPacketArbiterReq <= 1'b0;
 | 
      
         | 190 |  |  |     sendPacketWEn <= 1'b0;
 | 
      
         | 191 |  |  |   end
 | 
      
         | 192 |  |  |   else
 | 
      
         | 193 |  |  |   begin
 | 
      
         | 194 |  |  |     i <= next_i;
 | 
      
         | 195 |  |  |     SOFSent <= next_SOFSent;
 | 
      
         | 196 |  |  |     SOFTimerClr <= next_SOFTimerClr;
 | 
      
         | 197 |  |  |     sendPacketArbiterReq <= next_sendPacketArbiterReq;
 | 
      
         | 198 |  |  |     sendPacketWEn <= next_sendPacketWEn;
 | 
      
         | 199 |  |  |   end
 | 
      
         | 200 |  |  | end
 | 
      
         | 201 |  |  |  
 | 
      
         | 202 |  |  | endmodule
 |