📄 usb1_pe.v
字号:
///////////////////////////////////////////////////////////////////////// //////// Protocol Engine //////// Performs automatic protocol functions //////// //////// 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_pe.v,v 1.1.1.1 2002/09/19 12:07:24 rudi Exp $//// $Date: 2002/09/19 12:07:24 $// $Revision: 1.1.1.1 $// $Author: rudi $// $Locker: $// $State: Exp $//// Change History:// $Log: usb1_pe.v,v $// Revision 1.1.1.1 2002/09/19 12:07:24 rudi// Initial Checkin//////////////`include "usb1_defines.v"module usb1_pe( clk, rst, // UTMI Interfaces tx_valid, rx_active,//pe也需要这两个信号的,从外壳引脚上获得 // PID Information pid_OUT, pid_IN, pid_SOF, pid_SETUP, pid_DATA0, pid_DATA1, pid_DATA2, pid_MDATA, pid_ACK, pid_PING, // Token Information token_valid, //来自包拆装模块,说明是令牌包或握手ack包 // Receive Data Output rx_data_done, crc16_err,//均来自包拆装模块 // Packet Assembler Interface send_token, token_pid_sel, data_pid_sel, // IDMA Interface rx_dma_en, tx_dma_en, abort, idma_done, // Register File Interface,目前这个给我的感觉很不熟悉 fsel, ep_sel, match, nse_err, ep_full, ep_empty, int_upid_set, int_crc16_set, int_to_set, int_seqerr_set, csr, send_stall//这可是输入啊 );input clk, rst;input tx_valid, rx_active;//应该都是连在外壳引脚// Packet Disassembler Interface // Decoded PIDs (used when token_valid is asserted)input pid_OUT, pid_IN, pid_SOF, pid_SETUP;input pid_DATA0, pid_DATA1, pid_DATA2, pid_MDATA;input pid_ACK, pid_PING;input token_valid; // Token is valid,零牌包或是握手ack包input rx_data_done; // Indicates end of a transfer,从包拆装获得input crc16_err; // Data packet CRC 16 error// Packet Assembler Interfaceoutput send_token;output [1:0] token_pid_sel;output [1:0] data_pid_sel;// IDMA Interfaceoutput rx_dma_en; // Allows the data to be storedoutput tx_dma_en; // Allows for data to be retrievedoutput abort; // Abort Transfer (time_out, crc_err or rx_error)input idma_done; // DMA is done indicatorinput ep_full; // Indicates the endpoints fifo is fullinput ep_empty; // Indicates the endpoints fifo is empty// Register File interfaceinput fsel; // This function is selected,一位input [3:0] ep_sel; // Endpoint Number Inputinput match; // Endpoint Matched,端点匹配output nse_err; // no such endpoint erroroutput int_upid_set; // Set unsupported PID interruptoutput int_crc16_set; // Set CRC16 error interruptoutput int_to_set; // Set time out interruptoutput int_seqerr_set; // Set PID sequence error interruptinput [13:0] csr; // Internal CSR Output,注意14位input send_stall; // Force sending a STALL during setup,这个信号要注意/////////////////////////////////////////////////////////////////////// Local Wires and Registers//// tx token decoding,这个应该是给token_pid_sel的,全是用来组装握手包的parameter ACK = 0, NACK = 1, STALL = 2, NYET = 3;// State decodingparameter [9:0] // synopsys enum state,一位热码 IDLE = 10'b000000_0001, TOKEN = 10'b000000_0010, IN = 10'b000000_0100, IN2 = 10'b000000_1000, OUT = 10'b000001_0000, OUT2A = 10'b000010_0000, OUT2B = 10'b000100_0000, UPDATEW = 10'b001000_0000, UPDATE = 10'b010000_0000, UPDATE2 = 10'b100000_0000;//这个好象没什么印象reg [1:0] token_pid_sel;reg [1:0] token_pid_sel_d;reg send_token;reg send_token_d;reg rx_dma_en, tx_dma_en;reg int_seqerr_set_d;//是int_seqerr_set的什么东西reg int_seqerr_set;reg int_upid_set;reg match_r;//跟match的关系要注意// Endpoint Decodingwire IN_ep, OUT_ep, CTRL_ep; // Endpoint Types注意是wire型wire txfr_iso, txfr_bulk, txfr_int; // Transfer Typesreg [1:0] uc_dpd;//全然不知这是什么,现在有点感觉了// Buffer checksreg [9:0] /* synopsys enum state */ state, next_state;// synopsys state_vector state// PID next and current decodersreg [1:0] next_dpid;reg [1:0] this_dpid;reg pid_seq_err;//要注意它的用途,跟int_seqerr_set相区别,int_seqerr_set是用来输出的wire [1:0] tr_fr_d;//干什么的?Number of transfers per micro-framewire [13:0] size_next;//14位:好象就没用过?wire buf_smaller;//好象也没用过// After sending Data in response to an IN token from host, the// host must reply with an ack. The host has XXXnS to reply.// "rx_ack_to" indicates when this time has expired.// rx_ack_to_clr, clears the timerreg rx_ack_to_clr;reg rx_ack_to_clr_d;reg rx_ack_to;reg [7:0] rx_ack_to_cnt;//计数空间// After sending a OUT token the host must send a data packet.// The host has XX nS to send the packet. "tx_data_to" indicates// when this time has expired.// tx_data_to_clr, clears the timerwire tx_data_to_clr;reg tx_data_to;reg [7:0] tx_data_to_cnt;wire [7:0] rx_ack_to_val, tx_data_to_val;//注意是wire型wire [1:0] next_bsel;//这是什么,好象也没有用过reg uc_stat_set_d;//指示要不要data0,data1变化的reg uc_dpd_set;//?是允许改变epN_dpid的标志,上面有个uc_dpdreg in_token;//输入令牌reg out_token;//输出令牌reg setup_token;//setup令牌wire in_op, out_op; // Indicate a IN or OUT operation,应该是相对主机说的reg [1:0] allow_pid;reg nse_err;reg abort;wire [1:0] ep_type, txfr_type;//两位可以表达清楚了,txfr_type:txfr_iso,txfr_int,txfr_bulk //ep_type:IN_ep,OUT_ep,CTRL_ep/////////////////////////////////////////////////////////////////////// Misc Logic//// Endpoint/CSR Decodingassign IN_ep = csr[9];//都是wire型,要注意assign OUT_ep = csr[10];assign CTRL_ep = csr[11];assign txfr_iso = csr[12];//wire型assign txfr_bulk = csr[13];assign txfr_int = !csr[12] & !csr[13];//不是同步也不是批量,则是中断传输assign ep_type = csr[10:9];//233行定义,也是wire型,00就是控制端点assign txfr_type = csr[13:12];//与245,246,247呼应了,也是wire型always @(posedge clk) match_r <= #1 match & fsel;//fsel:This function is selected,一定搞清match怎么来的 //match是从外面输入的// No Such Endpoint Indicatoralways @(posedge clk) nse_err <= #1 token_valid & (pid_OUT | pid_IN | pid_SETUP) & !match;//是有效的令牌包,但是不匹配 //则nse_err高always @(posedge clk) send_token <= #1 send_token_d;//意料之中的事always @(posedge clk) token_pid_sel <= #1 token_pid_sel_d;/////////////////////////////////////////////////////////////////////// Data Pid Storage,数据包标识符存储// reg [1:0] ep0_dpid, ep1_dpid, ep2_dpid, ep3_dpid;reg [1:0] ep4_dpid, ep5_dpid, ep6_dpid, ep7_dpid;always @(posedge clk or negedge rst) if(!rst) ep0_dpid <= 2'b00;//复位用data0初始化 else if(uc_dpd_set & (ep_sel == 4'h0)) ep0_dpid <= next_dpid;//uc_dpd_set是允许改变epN_dpid的标志always @(posedge clk or negedge rst) if(!rst) ep1_dpid <= 2'b00; else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -