📄 udevctl.v
字号:
// This file is made for M/C interface
// This performs vender cmd decoding and generates the signal of commands reg.
// This block is modified for set_descriptor for Vendor ID Setting
module Udevctl
(
// inputs from sie
usbclock, // 12 MHz clock
usbreset, // usb reset signal
turnaround,
rcvdatabyte,
rcvdatabytevalid,
rcvaddress,
rcvaddressvalid,
rcvendpoint,
rcvendpointvalid,
rcvdatatogglebit,
rcvack,
rcvdata,
rcvdatain,
rcvdataout,
rcvsetup,
rcvpacketok,
rcvpacketnotok,
nextxmitbyte,
acksent,
datasent,
naksent,
stallsent,
syncreset,
// outputs to sie
xmitlastbyte,
xmitdatatogglebit,
xmitdatabyte,
senddata,
sendnak,
sendack,
sendstall,
// connections to all endpoints
devromsetupaddr,
endpwrdata,
datapacketok,
datapacketnotok,
// connections to endpoint 0
romdevsetupdata,
devromdescriptorindex,
romen,
endp0internaltogglebit,
setupcycle,
setupbyteaddr,
setupdata,
`include "Uvendorcmdios.v"
`include "Udevios.v"
);
input usbclock; // 12 MHz clock
input usbreset; // synopsys sync_set_reset "usbreset"
input turnaround;
input [7:0] rcvdatabyte;
input rcvdatabytevalid;
input [6:0] rcvaddress;
input rcvaddressvalid;
input [3:0] rcvendpoint;
input rcvendpointvalid;
input rcvdatatogglebit;
input rcvack;
input rcvdata;
input rcvdatain;
input rcvdataout;
input rcvsetup;
input rcvpacketok;
input rcvpacketnotok;
input nextxmitbyte;
input acksent;
input datasent;
input naksent;
input stallsent;
input syncreset;
// outputs to sie
output xmitlastbyte;
output xmitdatatogglebit;
output [7:0] xmitdatabyte;
output senddata;
output sendnak;
output sendack;
output sendstall;
// connection to all endpoints
output [7:0] devromsetupaddr; // allow 255
output [7:0] endpwrdata;
output datapacketok;
output datapacketnotok;
// This next session describes our endpoints and is specific
// to each implementation
// and includes the continuation of the input/output declarations and the
// register declarations
// connections to endpoint0
input [7:0] romdevsetupdata;
output [6:0] devromdescriptorindex;
output romen;
output endp0internaltogglebit;
output setupcycle;
input [2:0] setupbyteaddr; // select one of 8 bytes
output [7:0] setupdata; // setup byte output
`include "Udevinouts.v"
`include "Udevendpoints.v"
`include "Uvendorcmdinouts.v"
// decoded state machine definitions for ctl states
// 4'b0111 is unused
parameter [3:0]
CTLIDLE = 4'b0000,
CTLSETUP = 4'b0001,
CTLDIN = 4'b0010,
CTLDOUT = 4'b0011,
CTLWAIT4DATA = 4'b0100,
CTLWAIT4ACK = 4'b0101,
CTLWAIT4SETUP = 4'b0110,
CTLIGNOREDATA = 4'b1000,
CTLOVERFLOW = 4'b1001,
CTLGRABDATA = 4'b1010,
CTLGRABSETUP = 4'b1011,
CTLSENDDATA = 4'b1100,
CTLSENDACK = 4'b1101,
CTLSENDNAK = 4'b1110,
CTLSENDSTALL = 4'b1111;
// standard Descriptor Types from spec p. 175
parameter [2:0]
TYPEDEVICE = 3'h1,
TYPECONFIG = 3'h2,
TYPESTRING = 3'h3,
TYPEINTF = 3'h4,
TYPEENDP = 3'h5;
// bmRequestType from spec p183
parameter [1:0]
TYPESTD = 2'b00,
TYPECLASS = 2'b01,
TYPEVENDOR = 2'b10;
// standard Request Types from spec p. 172
parameter [1:0]
REQDEVICE = 2'b00,
REQINTERFACE = 2'b01,
REQENDPOINT = 2'b10,
REQOTHER = 2'b11;
// standard Request Codes from spec p. 175
parameter [3:0]
GETSTATUS = 4'h0,
CLEARFEATURE = 4'h1,
SETFEATURE = 4'h3,
SETADDRESS = 4'h5,
GETDESCRIPTOR = 4'h6,
SETDESCRIPTOR = 4'h7,
GETCONFIGURATION = 4'h8,
SETCONFIGURATION = 4'h9,
GETINTERFACE = 4'ha,
SETINTERFACE = 4'hb,
SYNCHFRAME = 4'hc;
// vendor Request Codes from jake
parameter [3:0]
SETCMD = 4'h0,
GETSTATUSV = 4'h1,
GETDATA = 4'h2,
GPIORD = 4'h3,
GPIOWR = 4'h4,
GETBUSY = 4'h5,
CLOCKRATE = 4'h6,
SETCMDRD = 4'h7,
SETCMDWR = 4'h8,
SETVID = 4'h9,
SETMODE = 4'ha,
GETSTATUSCHECK = 4'hb;
reg [MAXENDPOINTS:1] endpointintogglebits;
reg [MAXENDPOINTS:1] endpointouttogglebits;
reg endpointzerotogglebit;
reg [7:0] setupdata; // setup byte output
wire endp0internaltogglebit = endpointzerotogglebit;
reg [7:0] xmitdatabyte;
reg senddata;
reg sendack;
reg sendstall;
reg sendnak;
reg xmitlastbyted;
reg xmitlastbyte; // this will cause the sie-pkt to send CRC16 data
reg datapacketok;
reg datapacketnotok;
reg [3:0] ctlst, nextctlst; // state machine flops
reg [7:0] firstbyte, secondbyte; // keep two bytes which end up being crc
reg firstbytevalid, secondbytevalid;
reg [6:0] ouraddress; // holds our address based on setaddress setup command
reg ourconfiguration; // holds our current config, 1 is configured, 0 is not
reg [6:0] currentaddr; // address of current operation, might not need this
reg [3:0] currentendp; // endpoint of current operation
reg endpointrdready;
reg endpointwrready;
reg endpointrdstall;
reg endpointwrstall;
reg setupcycle;
reg setupinfovalid;
reg firsttimethrough;
reg [15:0] bytecountd, bytecount; // allow 256
reg [15:0] totalbytecount, totalbytecountd, prevtotalbytecount;
wire [7:0] devromsetupaddr = totalbytecount;
reg [7:0] currentalternatesetting; // gets set by SETINTERFACE command
reg [1:0] gettype; // 2-bit field that specifies type of get
reg romen; // this may not be used all the time the anchor core is used
// but it is a nice signal denoting when we are reading ctl info
assign endpwrdata = secondbyte;
wire endpoint0active = (currentendp == 4'h0);
wire configured = (ourconfiguration != 0); // configured if non-zero configuration
wire grabdata = ((ctlst == CTLGRABDATA) && rcvdatabytevalid);
wire grabsetup = ((ctlst == CTLGRABSETUP) && rcvdatabytevalid);
wire nextdata = ((ctlst == CTLSENDDATA) && nextxmitbyte);
// can only match address at ouraddress or default pipe (addr 0, endp 0)
wire isoendpoint = ISOENDPOINTS[currentendp];
wire xmitdatatogglebit = (endpoint0active) ? endpointzerotogglebit :
// endpointintogglebits[currentendp];
endpointintogglebits[currentendp[1:0]];
reg addressmatch;
reg endpointrdmatch;
reg endpointwrmatch;
reg clearfeature;
reg endp1wrstall;
reg endp2rdstall;
reg endp3rdstall;
// For VENDOR CMD
reg[2:0] setmode;
reg setcmdrd;
reg setcmdwr;
reg getstatus;
reg getstatuscheck;
reg getdata;
reg gpiopin3,gpiopin4, gpiopin5,gpiopin6,gpiopin7;
reg getbusy;
reg[2:0] clockrate;
reg gpiord;
reg wpb;
parameter HOSTTODEV = 1'b0, DEVTOHOST = 1'b1;
// here is all the setup stuff, may want to move this
// someday
reg setupdirection;
reg [1:0] setuptype;
reg [1:0] setuprecipient;
reg [7:0] setuprequest;
reg [7:0] setupvalue0;
reg [7:0] setupvalue1;
reg [7:0] setupwindexlo;
reg [7:0] setupwindexhi;
wire [15:0] setupwindex = {setupwindexhi,setupwindexlo};
reg [7:0] setuplengthlo, setuplengthhi;
wire [15:0] setuplength = {setuplengthhi,setuplengthlo};
reg [6:0] devromdescriptorindex; // 7 bits - 3 for type and 4 for index, could be sparse
reg sendzerolengthpkt;
reg [7:0] cfgdesclengthlo, cfgdesclengthhi;
wire [15:0] cfgdesclength = {cfgdesclengthhi,cfgdesclengthlo};
reg getcfgdesccycleflag;
reg getnoncfgdesccycleflag;
wire corecommand ;
always @(posedge usbclock)
begin
addressmatch <= (currentaddr == ouraddress);
endpointrdmatch <= ((VALIDRDENDPOINTS[currentendp] && configured) || endpoint0active);
endpointwrmatch <= ((VALIDWRENDPOINTS[currentendp] && configured) || endpoint0active);
xmitlastbyte <= xmitlastbyted;
end
// determine if the data packet all got here ok or not
always @(posedge usbclock)
begin
if (usbreset)
datapacketnotok <= 1'b0;
else if (((ctlst == CTLGRABDATA) && rcvpacketnotok) || ( (ctlst == CTLGRABSETUP) && rcvpacketnotok) ||
((ctlst == CTLOVERFLOW) && (rcvpacketnotok || rcvpacketok)) ||
((ctlst == CTLWAIT4ACK) && turnaround) ||
((ctlst == CTLWAIT4ACK) && rcvpacketnotok) ||
((ctlst == CTLWAIT4ACK) && rcvdata) ||
((ctlst == CTLWAIT4ACK) && rcvdatain) ||
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -