⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usb_pe_sie.cpp

📁 USB 1.1 PHY的代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/////////////////////////////////////////////////////////////////////////                                                             ////////  USB Protocol Engine                                        ////////  Performs automatic protocol functions                      ////////                                                             ////////  SystemC Version: usb_pe_sie.cpp                            ////////  Author: Alfredo Luiz Foltran Fialho                        ////////          alfoltran@ig.com.br                                ////////                                                             ////////                                                             /////////////////////////////////////////////////////////////////////////////                                                             //////// Verilog Version: usb1_pe.v                                  //////// 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.                                 ////////                                                             /////////////////////////////////////////////////////////////////////////#include "systemc.h"#include "usb_pe_sie.h"// Endpoint/CSR Decodingvoid usb_pe_sie::csr_decoder(void) {	IN_ep.write(csr.read()[9]);	OUT_ep.write(csr.read()[10]);	CTRL_ep.write(csr.read()[11]);	txfr_iso.write(csr.read()[12]);	txfr_bulk.write(csr.read()[13]);	txfr_int.write(!csr.read()[12] && !csr.read()[13]);	ep_type.write(csr.read().range(10, 9));	txfr_type.write(csr.read().range(13, 12));}void usb_pe_sie::match_up(void) {	match_r.write(match.read() && fsel.read());}// No such endpoint indicatorvoid usb_pe_sie::nse_err_up(void) {	nse_err.write(token_valid.read() && (pid_OUT.read() || pid_IN.read() || pid_SETUP.read()) && !match.read());}void usb_pe_sie::send_token_up(void) {	send_token.write(send_token_d.read());}void usb_pe_sie::token_pid_sel_up(void) {	token_pid_sel.write(token_pid_sel_d.read());}// Data PID storagevoid usb_pe_sie::ep0_dpid_up(void) {	if (!rst.read())		ep0_dpid.write(0);	else if (uc_dpd_set.read() && (ep_sel.read() == 0))		ep0_dpid.write(next_dpid.read());}void usb_pe_sie::ep1_dpid_up(void) {	if (!rst.read())		ep1_dpid.write(0);	else if (uc_dpd_set.read() && (ep_sel.read() == 1))		ep1_dpid.write(next_dpid.read());}void usb_pe_sie::ep2_dpid_up(void) {	if (!rst.read())		ep2_dpid.write(0);	else if (uc_dpd_set.read() && (ep_sel.read() == 2))		ep2_dpid.write(next_dpid.read());}void usb_pe_sie::ep3_dpid_up(void) {	if (!rst.read())		ep3_dpid.write(0);	else if (uc_dpd_set.read() && (ep_sel.read() == 3))		ep3_dpid.write(next_dpid.read());}void usb_pe_sie::ep4_dpid_up(void) {	if (!rst.read())		ep4_dpid.write(0);	else if (uc_dpd_set.read() && (ep_sel.read() == 4))		ep4_dpid.write(next_dpid.read());}void usb_pe_sie::ep5_dpid_up(void) {	if (!rst.read())		ep5_dpid.write(0);	else if (uc_dpd_set.read() && (ep_sel.read() == 5))		ep5_dpid.write(next_dpid.read());}void usb_pe_sie::ep6_dpid_up(void) {	if (!rst.read())		ep6_dpid.write(0);	else if (uc_dpd_set.read() && (ep_sel.read() == 6))		ep6_dpid.write(next_dpid.read());}void usb_pe_sie::ep7_dpid_up(void) {	if (!rst.read())		ep7_dpid.write(0);	else if (uc_dpd_set.read() && (ep_sel.read() == 7))		ep7_dpid.write(next_dpid.read());}void usb_pe_sie::uc_dpd_up(void) {	switch (ep_sel.read()) {		case 0:	uc_dpd.write(ep0_dpid.read()); break;		case 1:	uc_dpd.write(ep1_dpid.read()); break;		case 2:	uc_dpd.write(ep2_dpid.read()); break;		case 3:	uc_dpd.write(ep3_dpid.read()); break;		case 4:	uc_dpd.write(ep4_dpid.read()); break;		case 5:	uc_dpd.write(ep5_dpid.read()); break;		case 6:	uc_dpd.write(ep6_dpid.read()); break;		case 7:	uc_dpd.write(ep7_dpid.read()); break;	}}// Data PID sequencervoid usb_pe_sie::sq_statemachine(void) {	sc_uint<8> sel1;	sc_uint<5> sel2;	sc_uint<2> sel_d1, sel_d2;	// tr/mf:ep/type:tr/type:last dpd	sel1 = ((sc_uint<2>)tr_fr_d.read(), (sc_uint<2>)ep_type.read(), (sc_uint<2>)txfr_type.read(), (sc_uint<2>)uc_dpd.read());	// CTRL Endpoint Selector	sel2 = ((sc_uint<1>)setup_token.read(), (sc_uint<1>)in_op.read(), (sc_uint<1>)out_op.read(), (sc_uint<2>)uc_dpd.read());	// Sync1 Selector	sel_d1 = ((sc_uint<1>)pid_MDATA.read(), (sc_uint<1>)pid_DATA1.read());	// Sync2 Selector	sel_d2 = ((sc_uint<1>)pid_MDATA.read(), (sc_uint<1>)pid_DATA2.read());	switch (sel1) {// synopsys full_case parallel_case		// 0X_01_01_XX -> ISO txfr. IN, 1 tr/mf		case 0x14:		case 0x15:		case 0x16:		case 0x17:		case 0x54:		case 0x55:		case 0x56:		case 0x57:	next_dpid.write(0);					break;		// 10_01_01_X0 -> ISO txfr. IN, 2 tr/mf		case 0x94:		case 0x96:	next_dpid.write(1);					break;		// 10_01_01_X1 -> ISO txfr. IN, 2 tr/mf		case 0x95:		case 0x97:	next_dpid.write(0);					break;		// 11_01_01_00 -> ISO txfr. IN, 3 tr/mf		case 0xd4:	next_dpid.write(1);					break;		// 11_01_01_01 -> ISO txfr. IN, 3 tr/mf		case 0xd5:	next_dpid.write(2);					break;		// 11_01_01_10 -> ISO txfr. IN, 3 tr/mf		case 0xd6:	next_dpid.write(0);					break;		// 0X_10_01_XX -> ISO txfr. OUT, 1 tr/mf		case 0x24:		case 0x25:		case 0x26:		case 0x27:		case 0x64:		case 0x65:		case 0x66:		case 0x67:	next_dpid.write(0);					break;		// 10_10_01_XX -> ISO txfr. OUT, 2 tr/mf		case 0xa4:		case 0xa5:		case 0xa6:	// Resynchronize in case of PID error		case 0xa7:	switch (sel_d1) {// synopsys full_case parallel_case						case 2:	next_dpid.write(1); break;						case 1: next_dpid.write(0); break;					}					break;		// 11_10_01_00 -> ISO txfr. OUT, 3 tr/mf		case 0xe4:	// Resynchronize in case of PID error					switch (sel_d2) {// synopsys full_case parallel_case						case 2:	next_dpid.write(1); break;						case 1: next_dpid.write(0); break;					}					break;		// 11_10_01_01 -> ISO txfr. OUT, 3 tr/mf		case 0xe5:	// Resynchronize in case of PID error					switch (sel_d2) {// synopsys full_case parallel_case						case 2:	next_dpid.write(2); break;						case 1: next_dpid.write(0); break;					}					break;		// 11_10_01_10 -> ISO txfr. OUT, 3 tr/mf		case 0xe6:	// Resynchronize in case of PID error					switch (sel_d2) {// synopsys full_case parallel_case						case 2:	next_dpid.write(1); break;						case 1: next_dpid.write(0); break;					}					break;		// XX_01_00_X0 or XX_10_00_X0 -> IN/OUT endpoint only		case 0x10:		case 0x12:		case 0x50:		case 0x52:		case 0x90:		case 0x92:		case 0xd0:		case 0xd2:		case 0x20:		case 0x22:		case 0x60:		case 0x62:		case 0xa0:		case 0xa2:		case 0xe0:		case 0xe2:	next_dpid.write(1);	// INT transfers					break;		// XX_01_00_X1 or XX_10_00_X1 -> IN/OUT endpoint only		case 0x11:		case 0x13:		case 0x51:		case 0x53:		case 0x91:		case 0x93:		case 0xd1:		case 0xd3:		case 0x21:		case 0x23:		case 0x61:		case 0x63:		case 0xa1:		case 0xa3:		case 0xe1:		case 0xe3:	next_dpid.write(0);	// INT transfers					break;		// XX_01_10_X0 or XX_10_10_X0 -> IN/OUT endpoint only		case 0x18:		case 0x1a:		case 0x58:		case 0x5a:		case 0x98:		case 0x9a:		case 0xd8:		case 0xda:		case 0x28:		case 0x2a:		case 0x68:		case 0x6a:		case 0xa8:		case 0xaa:		case 0xe8:		case 0xea:	next_dpid.write(1);	// BULK transfers					break;		// XX_01_10_X1 or XX_10_10_X1 -> IN/OUT endpoint only		case 0x19:		case 0x1b:		case 0x59:		case 0x5b:		case 0x99:		case 0x9b:		case 0xd9:		case 0xdb:		case 0x29:		case 0x2b:		case 0x69:		case 0x6b:		case 0xa9:		case 0xab:		case 0xe9:		case 0xeb:	next_dpid.write(0);	// BULK transfers					break;		// XX_00_XX_XX -> CTRL Endpoint		case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x06: case 0x07:		case 0x08: case 0x09: case 0x0a: case 0x0b: case 0x0c: case 0x0d: case 0x0e: case 0x0f:		case 0x40: case 0x41: case 0x42: case 0x43: case 0x44: case 0x45: case 0x46: case 0x47:		case 0x48: case 0x49: case 0x4a: case 0x4b: case 0x4c: case 0x4d: case 0x4e: case 0x4f:		case 0x80: case 0x81: case 0x82: case 0x83: case 0x84: case 0x85: case 0x86: case 0x87:		case 0x88: case 0x89: case 0x8a: case 0x8b: case 0x8c: case 0x8d: case 0x8e: case 0x8f:		case 0xc0: case 0xc1: case 0xc2: case 0xc3: case 0xc4: case 0xc5: case 0xc6: case 0xc7:		case 0xc8: case 0xc9: case 0xca: case 0xcb: case 0xcc: case 0xcd: case 0xce: case 0xcf:					switch (sel2) {// synopsys full_case parallel_case						// 1_XX_XX -> SETUP operation						case 0x10:						case 0x11:						case 0x12:						case 0x13:						case 0x14:						case 0x15:						case 0x16:						case 0x17:						case 0x18:						case 0x19:						case 0x1a:						case 0x1b:						case 0x1c:						case 0x1d:						case 0x1e:						case 0x1f:	next_dpid.write(3);									break;						// 0_10_0X -> IN operation						case 0x08:						case 0x09:	next_dpid.write(3);									break;						// 0_10_1X -> IN operation						case 0x0a:						case 0x0b:	next_dpid.write(1);									break;						// 0_01_X0 -> OUT operation						case 0x04:						case 0x06:	next_dpid.write(3);									break;						// 0_01_X1 -> OUT operation						case 0x05:						case 0x07:	next_dpid.write(2);									break;					}					break;	}}// Current PID decoder// Allow any PID for ISO transfers when mode full speed or tr_fr is zerovoid usb_pe_sie::allow_pid_up(void) {	sc_uint<4> sel;	sel = ((sc_uint<1>)pid_DATA0.read(), (sc_uint<1>)pid_DATA1.read(), (sc_uint<1>)pid_DATA2.read(), (sc_uint<1>)pid_MDATA.read());	switch (sel) {// synopsys full_case parallel_case		// 1000		case 8:	allow_pid.write(0); break;		// 0100		case 4:	allow_pid.write(1); break;		// 0010		case 2:	allow_pid.write(2); break;		// 0001		case 1:	allow_pid.write(3); break;	}}void usb_pe_sie::this_dpid_up(void) {	sc_uint<8> sel1;	sc_uint<5> sel2;	// tr/mf:ep/type:tr/type:last dpd	sel1 = ((sc_uint<2>)tr_fr_d.read(), (sc_uint<2>)ep_type.read(), (sc_uint<2>)txfr_type.read(), (sc_uint<2>)uc_dpd.read());	// CTRL Endpoint Selector	sel2 = ((sc_uint<1>)setup_token.read(), (sc_uint<1>)in_op.read(), (sc_uint<1>)out_op.read(), (sc_uint<2>)uc_dpd.read());	switch (sel1) {// synopsys full_case parallel_case		// 0X_01_01_XX -> ISO txfr. IN, 1 tr/mf		case 0x14:		case 0x15:		case 0x16:		case 0x17:		case 0x54:		case 0x55:		case 0x56:		case 0x57:	this_dpid.write(0);					break;		// 10_01_01_X0 -> ISO txfr. IN, 2 tr/mf		case 0x94:		case 0x96:	this_dpid.write(1);					break;		// 10_01_01_X1 -> ISO txfr. IN, 2 tr/mf		case 0x95:		case 0x97:	this_dpid.write(0);					break;		// 11_01_01_00 -> ISO txfr. IN, 3 tr/mf		case 0xd4:	this_dpid.write(2);					break;		// 11_01_01_01 -> ISO txfr. IN, 3 tr/mf		case 0xd5:	this_dpid.write(1);					break;		// 11_01_01_10 -> ISO txfr. IN, 3 tr/mf		case 0xd6:	this_dpid.write(0);					break;		// 00_10_01_XX -> ISO txfr. OUT, 0 tr/mf		case 0x24:		case 0x25:		case 0x26:		case 0x27:	this_dpid.write(allow_pid.read());					break;		// 01_10_01_XX -> ISO txfr. OUT, 1 tr/mf		case 0x64:		case 0x65:		case 0x66:		case 0x67:	this_dpid.write(0);					break;		// 10_10_01_X0 -> ISO txfr. OUT, 2 tr/mf		case 0xa4:		case 0xa6:	this_dpid.write(3);					break;		// 10_10_01_X1 -> ISO txfr. OUT, 2 tr/mf		case 0xa5:		case 0xa7:	this_dpid.write(1);					break;		// 11_10_01_00 -> ISO txfr. OUT, 3 tr/mf		case 0xe4:	this_dpid.write(3);					break;		// 11_10_01_01 -> ISO txfr. OUT, 3 tr/mf		case 0xe5:	this_dpid.write(3);					break;		// 11_10_01_10 -> ISO txfr. OUT, 3 tr/mf		case 0xe6:	this_dpid.write(2);					break;		// XX_01_00_X0 or XX_10_00_X0 -> IN/OUT endpoint only		case 0x10:		case 0x12:		case 0x50:		case 0x52:		case 0x90:		case 0x92:		case 0xd0:		case 0xd2:		case 0x20:		case 0x22:		case 0x60:		case 0x62:		case 0xa0:		case 0xa2:		case 0xe0:		case 0xe2:	this_dpid.write(0);	// INT transfers					break;		// XX_01_00_X1 or XX_10_00_X1 -> IN/OUT endpoint only		case 0x11:		case 0x13:		case 0x51:		case 0x53:		case 0x91:		case 0x93:		case 0xd1:		case 0xd3:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -