📄 usb1_pd.v
字号:
///////////////////////////////////////////////////////////////////////// //////// Packet Disassembler //////// Disassembles Token and Data USB packets //////// //////// Author: Rudolf Usselmann //////// rudi@asics.ws //////// //////// //////// Downloaded from: http://www.opencores.org/cores/usb1_funct///////// ///////////////////////////////////////////////////////////////////////////// //////// Copyright (C) 2000-2002 Rudolf Usselmann //////// www.asics.ws //////// rudi@asics.ws //////// //////// This source file may be used and distributed without //////// restriction provided that this copyright statement is not //////// removed from the file and that any derivative work contains //////// the original copyright notice and the associated disclaimer.//////// //////// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY //////// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED //////// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS //////// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR //////// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, //////// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES //////// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE //////// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR //////// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF //////// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT //////// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT //////// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE //////// POSSIBILITY OF SUCH DAMAGE. //////// /////////////////////////////////////////////////////////////////////////// CVS Log//// $Id: usb1_pd.v,v 1.2 2002/09/25 06:06:49 rudi Exp $//// $Date: 2002/09/25 06:06:49 $// $Revision: 1.2 $// $Author: rudi $// $Locker: $// $State: Exp $//// Change History:// $Log: usb1_pd.v,v $// Revision 1.2 2002/09/25 06:06:49 rudi// - Added New Top Level// - Remove old top level and associated files// - Moved FIFOs to "Generic FIFOs" project//// Revision 1.1.1.1 2002/09/19 12:07:17 rudi// Initial Checkin////////////////`include "usb1_defines.v"module usb1_pd( clk, rst, // UTMI RX I/F rx_data, rx_valid, rx_active, rx_err, // PID Information pid_OUT, pid_IN, pid_SOF, pid_SETUP, pid_DATA0, pid_DATA1, pid_DATA2, pid_MDATA, pid_ACK, pid_NACK, pid_STALL, pid_NYET, pid_PRE, pid_ERR, pid_SPLIT, pid_PING, pid_cks_err, // Token Information token_fadr, token_endp, token_valid, crc5_err, frame_no, // Receive Data Output rx_data_st, rx_data_valid, rx_data_done, crc16_err, // Misc. seq_err, rx_busy //这是什么?????? );input clk, rst; //好象是全局的信号,但是这里的clk是谁提供的?? //是phy_clk! //UTMI RX Interfaceinput [7:0] rx_data;input rx_valid, rx_active, rx_err; // Decoded PIDs (used when token_valid is asserted)这句注释很重要output pid_OUT, pid_IN, pid_SOF, pid_SETUP;output pid_DATA0, pid_DATA1, pid_DATA2, pid_MDATA;output pid_ACK, pid_NACK, pid_STALL, pid_NYET;output pid_PRE, pid_ERR, pid_SPLIT, pid_PING;output pid_cks_err; // Indicates a PID checksum erroroutput [6:0] token_fadr; // Function address from tokenoutput [3:0] token_endp; // Endpoint number from tokenoutput token_valid; // Token is validoutput crc5_err; // Token crc5 erroroutput [10:0] frame_no; // Frame number for SOF tokensoutput [7:0] rx_data_st; // Data to memory store unitoutput rx_data_valid; // Data on rx_data_st is validoutput rx_data_done; // Indicates end of a transferoutput crc16_err; // Data packet CRC 16 erroroutput seq_err; // State Machine Sequence Erroroutput rx_busy; // Receivig Data Packet/////////////////////////////////////////////////////////////////////// Local Wires and Registers//parameter [3:0] // synopsys enum state,注意这种编码!! IDLE = 4'b0001, ACTIVE = 4'b0010, TOKEN = 4'b0100, DATA = 4'b1000;reg [3:0] /* synopsys enum state */ state, next_state;//状态向量出现!!// synopsys state_vector statereg [7:0] pid; // Packet PDIreg pid_le_sm; // PID Load enable from State Machinewire pid_ld_en; // Enable loading of PID (all conditions)333行使用wire pid_cks_err; // Indicates a pid checksum err // Decoded PID valueswire pid_OUT, pid_IN, pid_SOF, pid_SETUP;wire pid_DATA0, pid_DATA1, pid_DATA2, pid_MDATA;wire pid_ACK, pid_NACK, pid_STALL, pid_NYET;wire pid_PRE, pid_ERR, pid_SPLIT, pid_PING, pid_RES;wire pid_TOKEN; // All TOKEN packet that we recognizewire pid_DATA; // All DATA packets that we recognizereg [7:0] token0, token1; // Token Registers,用来装令牌包后的两个字节reg token_le_1, token_le_2; // Latch enables for token storage registerswire [4:0] token_crc5; //与crc5_err有关reg [7:0] d0, d1, d2; // Data path delay line (used to filter out crcs)reg data_valid_d; // Data Valid output from State Machine 273行336赋值reg data_done; // Data cycle complete output from State Machine 274行reg data_valid0; // Data valid delay line 285reg rxv1; //这是什么?271行使用reg rxv2; //这是什么?reg seq_err; // State machine sequence errorreg pid_ack; //给谁的?后面有用233行,它代表什么?reg token_valid_r1; //不明reg token_valid_str1, token_valid_str2; //不明reg rx_active_r;//wire [4:0] crc5_out;//257行使用wire [4:0] crc5_out2;wire crc16_clr;reg [15:0] crc16_sum;//注意它可是reg型的啊wire [15:0] crc16_out;/////////////////////////////////////////////////////////////////////// Misc Logic//reg rx_busy, rx_busy_d; //需要它们的解释!!rx_busy_d表示接受数据中always @(posedge clk or negedge rst)//对rx_busy_d赋值 if(!rst) rx_busy_d <= #1 1'b0; //复位清零 else if(rx_valid & (state == DATA)) rx_busy_d <= #1 1'b1;//正在接收数据 else if(state != DATA) rx_busy_d <= #1 1'b0;//那如果state==data,但rx_valid //为低怎么办?没变化?!是的 //如果不在传数据,则rx_busy_d清零 always @(posedge clk)//对rx_busy赋值 rx_busy <= #1 rx_busy_d;//一级缓冲,注意不是持续赋值。注意rx_busy是要输出的// PID Decoding Logic,pid_ld_en信号为谁所用??为197所用assign pid_ld_en = pid_le_sm & rx_active & rx_valid;always @(posedge clk or negedge rst)//对包标识符赋值pid if(!rst) pid <= #1 8'hf0;//复位变为默认保留包,不代表任何包 else if(pid_ld_en) pid <= #1 rx_data;//读进接收包的标识符assign pid_cks_err = (pid[3:0] != ~pid[7:4]);assign pid_OUT = pid[3:0] == `USBF_T_PID_OUT;assign pid_IN = pid[3:0] == `USBF_T_PID_IN;assign pid_SOF = pid[3:0] == `USBF_T_PID_SOF;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -