1 |
2 |
alfoltran |
/////////////////////////////////////////////////////////////////////
|
2 |
|
|
//// ////
|
3 |
|
|
//// USB SIE ////
|
4 |
|
|
//// ////
|
5 |
|
|
//// SystemC Version: usb_sie.cpp ////
|
6 |
|
|
//// Author: Alfredo Luiz Foltran Fialho ////
|
7 |
|
|
//// alfoltran@ig.com.br ////
|
8 |
|
|
//// ////
|
9 |
|
|
//// ////
|
10 |
|
|
/////////////////////////////////////////////////////////////////////
|
11 |
|
|
//// ////
|
12 |
|
|
//// Verilog Version: usb1_utmi_if.v + usb1_pl.v ////
|
13 |
|
|
//// Copyright (C) 2000-2002 Rudolf Usselmann ////
|
14 |
|
|
//// www.asics.ws ////
|
15 |
|
|
//// rudi@asics.ws ////
|
16 |
|
|
//// ////
|
17 |
|
|
//// This source file may be used and distributed without ////
|
18 |
|
|
//// restriction provided that this copyright statement is not ////
|
19 |
|
|
//// removed from the file and that any derivative work contains ////
|
20 |
|
|
//// the original copyright notice and the associated disclaimer.////
|
21 |
|
|
//// ////
|
22 |
|
|
//// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY ////
|
23 |
|
|
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED ////
|
24 |
|
|
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS ////
|
25 |
|
|
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR ////
|
26 |
|
|
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, ////
|
27 |
|
|
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ////
|
28 |
|
|
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ////
|
29 |
|
|
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR ////
|
30 |
|
|
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF ////
|
31 |
|
|
//// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ////
|
32 |
|
|
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ////
|
33 |
|
|
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ////
|
34 |
|
|
//// POSSIBILITY OF SUCH DAMAGE. ////
|
35 |
|
|
//// ////
|
36 |
|
|
/////////////////////////////////////////////////////////////////////
|
37 |
|
|
|
38 |
|
|
#include "systemc.h"
|
39 |
|
|
#include "usb_sie.h"
|
40 |
|
|
|
41 |
|
|
void usb_sie::tx_interface1(void) {
|
42 |
|
|
if (!rst.read())
|
43 |
|
|
TxValid_s.write(false);
|
44 |
|
|
else
|
45 |
|
|
TxValid_s.write(tx_valid.read() || tx_valid_last.read() ||
|
46 |
|
|
(TxValid_s.read() && !TxReady.read()));
|
47 |
|
|
}
|
48 |
|
|
|
49 |
|
|
void usb_sie::tx_interface2(void) {
|
50 |
|
|
tx_ready.write(TxReady.read());
|
51 |
|
|
|
52 |
|
|
if (TxReady.read() || tx_first.read())
|
53 |
|
|
DataOut.write(tx_data.read());
|
54 |
|
|
}
|
55 |
|
|
|
56 |
|
|
void usb_sie::tx_interface3(void) {
|
57 |
|
|
TxValid.write(TxValid_s.read());
|
58 |
|
|
}
|
59 |
|
|
|
60 |
|
|
void usb_sie::rx_interface1(void) {
|
61 |
|
|
if (!rst.read()) {
|
62 |
|
|
rx_valid.write(false);
|
63 |
|
|
rx_active.write(false);
|
64 |
|
|
rx_err.write(false);
|
65 |
|
|
} else {
|
66 |
|
|
rx_valid.write(RxValid.read());
|
67 |
|
|
rx_active.write(RxActive.read());
|
68 |
|
|
rx_err.write(RxError.read());
|
69 |
|
|
}
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
void usb_sie::rx_interface2(void) {
|
73 |
|
|
rx_data.write(DataIn.read());
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
void usb_sie::csr9_up(void) {
|
77 |
|
|
csr9.write(csr.read().range(8, 0));
|
78 |
|
|
}
|
79 |
|
|
|
80 |
|
|
void usb_sie::x_busy_up(void) {
|
81 |
|
|
x_busy.write(tx_busy.read() || rx_busy.read());
|
82 |
|
|
}
|
83 |
|
|
|
84 |
|
|
// PIDs we should never receive
|
85 |
|
|
void usb_sie::pid_bad_up(void) {
|
86 |
|
|
pid_bad.write(pid_ACK.read() || pid_NACK.read() ||
|
87 |
|
|
pid_STALL.read() || pid_NYET.read() ||
|
88 |
|
|
pid_PRE.read() || pid_ERR.read() ||
|
89 |
|
|
pid_SPLIT.read() || pid_PING.read());
|
90 |
|
|
}
|
91 |
|
|
|
92 |
|
|
void usb_sie::match_o_up(void) {
|
93 |
|
|
match_o.write(!pid_bad.read() && token_valid.read() && !crc5_err.read());
|
94 |
|
|
}
|
95 |
|
|
|
96 |
|
|
void usb_sie::rx_data_st_up(void) {
|
97 |
|
|
rx_data_st.write(rx_data_st_d.read());
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
void usb_sie::decoder_pk(void) {
|
101 |
|
|
ctrl_setup.write(token_valid.read() && pid_SETUP.read() && (ep_sel.read() == 0));
|
102 |
|
|
ctrl_in.write(token_valid.read() && pid_IN.read() && (ep_sel.read() == 0));
|
103 |
|
|
ctrl_out.write(token_valid.read() && pid_OUT.read() && (ep_sel.read() == 0));
|
104 |
|
|
}
|
105 |
|
|
|
106 |
|
|
// Frame Number (from SOF token)
|
107 |
|
|
void usb_sie::frame_no_up1(void) {
|
108 |
|
|
frame_no_we.write(token_valid.read() && !crc5_err.read() && pid_SOF.read());
|
109 |
|
|
}
|
110 |
|
|
|
111 |
|
|
void usb_sie::frame_no_up2(void) {
|
112 |
|
|
frame_no_we_r.write(frame_no_we.read());
|
113 |
|
|
}
|
114 |
|
|
|
115 |
|
|
void usb_sie::frame_no_up3(void) {
|
116 |
|
|
if (!rst.read())
|
117 |
|
|
frame_no_r.write(0);
|
118 |
|
|
else if (frame_no_we_r.read())
|
119 |
|
|
frame_no_r.write(frame_no.read());
|
120 |
|
|
}
|
121 |
|
|
|
122 |
|
|
void usb_sie::frm_nat_up1(void) {
|
123 |
|
|
clr_sof_time.write(frame_no_we.read());
|
124 |
|
|
}
|
125 |
|
|
|
126 |
|
|
void usb_sie::frm_nat_up2(void) {
|
127 |
|
|
if (clr_sof_time.read())
|
128 |
|
|
sof_time.write(0);
|
129 |
|
|
else if (hms_clk.read())
|
130 |
|
|
sof_time.write(sof_time.read() + 1);
|
131 |
|
|
}
|
132 |
|
|
|
133 |
|
|
void usb_sie::frm_nat_up3(void) {
|
134 |
|
|
frm_nat.write(((sc_uint<5>)0, (sc_uint<11>)frame_no_r.read(), (sc_uint<4>)0, (sc_uint<12>)sof_time.read()));
|
135 |
|
|
}
|
136 |
|
|
|
137 |
|
|
void usb_sie::hms_clk_up1(void) {
|
138 |
|
|
if (!rst.read())
|
139 |
|
|
hms_cnt.write(0);
|
140 |
|
|
else if (hms_clk.read() || frame_no_we_r.read())
|
141 |
|
|
hms_cnt.write(0);
|
142 |
|
|
else
|
143 |
|
|
hms_cnt.write(hms_cnt.read() + 1);
|
144 |
|
|
}
|
145 |
|
|
|
146 |
|
|
void usb_sie::hms_clk_up2(void) {
|
147 |
|
|
hms_clk.write((hms_cnt.read() == USBF_HMS_DEL));
|
148 |
|
|
}
|
149 |
|
|
|
150 |
|
|
// This function is addressed
|
151 |
|
|
void usb_sie::fsel_up(void) {
|
152 |
|
|
fsel.write((token_fadr.read() == fa.read()));
|
153 |
|
|
}
|
154 |
|
|
|
155 |
|
|
// Only write when we are addressed
|
156 |
|
|
void usb_sie::idma_we_up(void) {
|
157 |
|
|
idma_we.write(idma_we_d.read() && fsel.read()); // moved full check to idma... && !ep_full.read());
|
158 |
|
|
}
|
159 |
|
|
/*
|
160 |
|
|
usb_sie::~usb_sie(void) {
|
161 |
|
|
if (i_pa_sie)
|
162 |
|
|
delete i_pa_sie;
|
163 |
|
|
if (i_pd_sie)
|
164 |
|
|
delete i_pd_sie;
|
165 |
|
|
if (i_pe_sie)
|
166 |
|
|
delete i_pe_sie;
|
167 |
|
|
if (i_dma)
|
168 |
|
|
delete i_dma;
|
169 |
|
|
}
|
170 |
|
|
*/
|