Design Technology | High Level Synthesis | How Does Synthagate work | Funcmi.cpp
#include "Funcmi.h"
void Funcmi::main_proc()
{
if (rst.read() == 1)
{
bitcnt.write(0);
br.write(0);
cnt.write(0);
cnt_elem.write(0);
cnt_m1_m3.write(0);
cnt_m2.write(0);
codcomplete.write(0);
decodcomplete.write(0);
ext_in.write(0);
idle.write(0);
mac1.write(0);
mac2.write(0);
rbyte.write(0);
rd.write(0);
relem.write(0);
rfilelength.write(0);
rlengthd.write(0);
rmask.write(0);
rmax.write(0);
rmin.write(0);
rt1.write(0);
rt2.write(0);
rtemp1.write(0);
rwrite2m2.write(0);
rwrite2m3.write(0);
shcnt.write(0);
for (unsigned int i = 0; i < 65536; ++i)
{
m1[i].write(0);
}
for (unsigned int i = 0; i < 65536; ++i)
{
m2[i].write(0);
}
for (unsigned int i = 0; i < 65536; ++i)
{
m3[i].write(0);
}
currentState = a1;
idle.write(1);
}
else
{
idle.write(0);
proc_Funcmi();
}
}
void Funcmi::proc_Funcmi()
{
sc_uint<8> rbyte_tmp = rbyte.read();
codcomplete.write(0);
decodcomplete.write(0);
ext_in.write(0);
idle.write(0);
rwrite2m2.write(0);
rwrite2m3.write(0);
switch (currentState)
{
case a1:
if (s.read() && dma.read() && ext_rdwr.read())
{
m1_address = ext_adr.read();
currentState = a2;
m1[m1_address].write(ext_out.read());
}
else if (s.read() && dma.read() && !ext_rdwr.read() && m.read())
{
m3_address = ext_adr.read();
currentState = a3;
}
else if (s.read() && dma.read() && !ext_rdwr.read() && !m.read())
{
m2_address = ext_adr.read();
currentState = a4;
}
else if (s.read() && !dma.read() && bit0.read())
{
currentState = a5;
decodcomplete.write(0);
}
else if (s.read() && !dma.read() && !bit0.read())
{
currentState = a6;
relem.write(nelem.read());
codcomplete.write(0);
}
else
{
currentState = a1;
idle.write(1);
}
break;
case a2:
{
currentState = a1;
cnt_m1_m3.write(cnt_m1_m3.read()+1);
idle.write(1);
}
break;
case a3:
{
m3_address = ext_adr.read();
currentState = a1;
ext_in.write(m3[m3_address].read());
idle.write(1);
}
break;
case a4:
{
m2_address = ext_adr.read();
currentState = a1;
ext_in.write(m2[m2_address].read());
idle.write(1);
}
break;
case a5:
{
currentState = a7;
mac2.write(0);
decodcomplete.write(0);
}
break;
case a6:
{
currentState = a8;
mac2.write(0);
br.write(0xff);
cnt.write(0);
cnt_m2.write(0);
}
break;
case a7:
{
m2_address = mac2.read();
currentState = a9;
}
break;
case a8:
{
m2_address = mac2.read();
currentState = a10;
m2[m2_address].write(br.read());
cnt_m2.write(cnt_m2.read()+1);
}
break;
case a9:
{
currentState = a11;
br.write(m2[m2_address].read());
mac2.write(mac2.read()+1);
}
break;
case a10:
{
currentState = a12;
mac2.write(mac2.read()+1);
}
break;
case a11:
if (br.read() == 0xff)
{
m2_address = mac2.read();
currentState = a13;
}
else
{
m2_address = mac2.read();
currentState = a9;
}
break;
case a12:
if (cnt.read() == 0x03)
{
currentState = a14;
rfilelength.write(cnt_m1_m3.read());
}
else
{
currentState = a8;
cnt.write(cnt.read()+1);
}
break;
case a13:
{
currentState = a15;
br.write(m2[m2_address].read());
mac2.write(mac2.read()+1);
}
break;
case a14:
{
currentState = a16;
cnt_elem.write(0);
rtemp1.write(mac1.read());
}
break;
case a15:
if (br.read() == 0xff)
{
m2_address = mac2.read();
currentState = a17;
}
else
{
m2_address = mac2.read();
currentState = a9;
}
break;
case a16:
{
m1_address = mac1.read();
currentState = a18;
}
break;
case a17:
{
currentState = a19;
br.write(m2[m2_address].read());
mac2.write(mac2.read()+1);
}
break;
case a18:
{
currentState = a20;
br.write(m1[m1_address].read());
mac1.write(mac1.read()+1);
}
break;
case a19:
if (br.read() == 0xff)
{
m2_address = mac2.read();
currentState = a21;
}
else
{
m2_address = mac2.read();
currentState = a9;
}
break;
case a20:
{
currentState = a22;
rmax.write(br.read());
rmin.write(br.read());
cnt_elem.write(cnt_elem.read()+1);
}
break;
case a21:
{
currentState = a23;
br.write(m2[m2_address].read());
mac2.write(mac2.read()+1);
}
break;
case a22:
{
m1_address = mac1.read();
currentState = a24;
}
break;
case a23:
if (br.read() == 0xff)
{
currentState = a25;
mac1.write(0);
shcnt.write(0);
}
else
{
m2_address = mac2.read();
currentState = a9;
}
break;
case a24:
{
currentState = a26;
br.write(m1[m1_address].read());
mac1.write(mac1.read()+1);
}
break;
case a25:
{
m2_address = mac2.read();
currentState = a27;
}
break;
case a26:
if (br.read() => rmax.read())
{
currentState = a28;
rmax.write(br.read());
}
else if (!(br.read() => rmax.read()) && br.read() <= rmin.read())
{
currentState = a28;
rmin.write(br.read());
}
else if (!(br.read() => rmax.read()) && !(br.read() <= rmin.read()) && cnt_elem.read() == relem.read()-0x0001)
{
currentState = a29;
br.write(rmin.read());
}
else
{
currentState = a22;
cnt_elem.write(cnt_elem.read()+1);
}
break;
case a27:
{
currentState = a30;
br.write(m2[m2_address].read());
mac2.write(mac2.read()+1);
}
break;
case a28:
if (cnt_elem.read() == relem.read()-0x0001)
{
currentState = a29;
br.write(rmin.read());
}
else
{
currentState = a22;
cnt_elem.write(cnt_elem.read()+1);
}
break;
case a29:
{
m2_address = mac2.read();
currentState = a31;
m2[m2_address].write(br.read());
cnt_m2.write(cnt_m2.read()+1);
}
break;
case a30:
{
currentState = a32;
rmin.write(br.read());
}
break;
case a31:
{
currentState = a33;
mac2.write(mac2.read()+1);
}
break;
case a32:
{
m2_address = mac2.read();
currentState = a34;
}
break;
case a33:
{
currentState = a35;
rd.write(rmax.read()-rmin.read());
}
break;
case a34:
{
currentState = a36;
br.write(m2[m2_address].read());
mac2.write(mac2.read()+1);
}
break;
case a35:
{
currentState = a37;
cnt_elem.write(0);
cnt.write(0);
}
break;
case a36:
{
currentState = a38;
rlengthd.write(br.read());
rmask.write(0x80);
shcnt.write(0);
}
break;
case a37:
if (rd.read() == 0x00)
{
currentState = a39;
br.write(cnt.read());
rlengthd.write(cnt.read());
}
else
{
currentState = a40;
rd.write(rd.read() >> 1);
}
break;
case a38:
{
currentState = a41;
cnt_elem.write(0);
}
break;
case a39:
{
m2_address = mac2.read();
currentState = a42;
m2[m2_address].write(br.read());
cnt_m2.write(cnt_m2.read()+1);
}
break;
case a40:
{
currentState = a37;
cnt.write(cnt.read()+1);
}
break;
case a41:
if (rlengthd.read() == 0x00)
{
currentState = a43;
br.write(rmin.read());
}
else
{
m2_address = mac2.read();
currentState = a44;
}
break;
case a42:
{
currentState = a45;
mac2.write(mac2.read()+1);
}
break;
case a43:
{
m3_address = mac1.read();
currentState = a46;
m3[m3_address].write(br.read());
cnt_m1_m3.write(cnt_m1_m3.read()+1);
}
break;
case a44:
{
currentState = a47;
br.write(m2[m2_address].read());
mac2.write(mac2.read()+1);
}
break;
case a45:
if (rlengthd.read() == 0x00)
{
currentState = a48;
cnt_m1_m3.write(cnt_m1_m3.read()-relem.read());
}
else
{
currentState = a49;
shcnt.write(0);
mac1.write(rtemp1.read());
rmask.write(0x01);
}
break;
case a46:
{
currentState = a50;
mac1.write(mac1.read()+1);
}
break;
case a47:
{
currentState = a51;
rt2.write(br.read());
}
break;
case a48:
if (cnt_m1_m3.read() == 0x0000)
{
currentState = a1;
codcomplete.write(1);
rwrite2m2.write(cnt_m2.read());
idle.write(1);
}
else
{
currentState = a16;
cnt_elem.write(0);
rtemp1.write(mac1.read());
}
break;
case a49:
if (shcnt.read() == rlengthd.read()-0x01)
{
m1_address = mac1.read();
currentState = a52;
}
else
{
currentState = a49;
rmask.write(rmask.read() << 1);
shcnt.write(shcnt.read()+1);
}
break;
case a50:
{
currentState = a53;
cnt_elem.write(cnt_elem.read()+1);
}
break;
case a51:
{
currentState = a54;
bitcnt.write(0);
}
break;
case a52:
{
currentState = a55;
br.write(m1[m1_address].read());
mac1.write(mac1.read()+1);
}
break;
case a53:
if (cnt_elem.read() == relem.read() && cnt_m1_m3.read() == rfilelength.read())
{
currentState = a1;
decodcomplete.write(1);
rwrite2m3.write(cnt_m1_m3.read());
idle.write(1);
}
else if (cnt_elem.read() == relem.read() && !(cnt_m1_m3.read() == rfilelength.read()))
{
m2_address = mac2.read();
currentState = a27;
}
else
{
currentState = a43;
br.write(rmin.read());
}
break;
case a54:
{
currentState = a56;
rt1.write(rmask.read() && rt2.read());
}
break;
case a55:
{
currentState = a57;
rt1.write(br.read());
}
break;
case a56:
{
currentState = a58;
rt2.write(rt2.read() << 1);
}
break;
case a57:
{
currentState = a59;
rt2.write(rt1.read()-rmin.read());
cnt_m1_m3.write(cnt_m1_m3.read()-1);
}
break;
case a58:
{
currentState = a60;
rbyte.write(rbyte.read() << 1);
}
break;
case a59:
{
currentState = a61;
shcnt.write(0);
}
break;
case a60:
if (rt1.read() == 0x00)
{
currentState = a62;
shcnt.write(shcnt.read()+1);
bitcnt.write(bitcnt.read()+1);
}
else
{
currentState = a63;
rbyte_tmp[0] = 1;
rbyte.write(rbyte_tmp);
}
break;
case a61:
{
currentState = a64;
rt1.write(rmask.read() && rt2.read());
}
break;
case a62:
if (shcnt.read() == rlengthd.read())
{
currentState = a65;
br.write(rbyte.read()+rmin.read());
shcnt.write(0);
}
else if (!(shcnt.read() == rlengthd.read()) && bitcnt.read() == 0x8 && cnt_elem.read() == relem.read() && cnt_m1_m3.read() == rfilelength.read())
{
currentState = a1;
decodcomplete.write(1);
rwrite2m3.write(cnt_m1_m3.read());
idle.write(1);
}
else if (!(shcnt.read() == rlengthd.read()) && bitcnt.read() == 0x8 && cnt_elem.read() == relem.read() && !(cnt_m1_m3.read() == rfilelength.read()))
{
m2_address = mac2.read();
currentState = a27;
}
else if (!(shcnt.read() == rlengthd.read()) && bitcnt.read() == 0x8 && !(cnt_elem.read() == relem.read()))
{
m2_address = mac2.read();
currentState = a44;
}
else
{
currentState = a56;
rt1.write(rmask.read() && rt2.read());
}
break;
case a63:
{
currentState = a62;
shcnt.write(shcnt.read()+1);
bitcnt.write(bitcnt.read()+1);
}
break;
case a64:
{
currentState = a66;
rt2.write(rt2.read() << 1);
}
break;
case a65:
{
m3_address = mac1.read();
currentState = a67;
m3[m3_address].write(br.read());
cnt_m1_m3.write(cnt_m1_m3.read()+1);
}
break;
case a66:
{
currentState = a68;
rbyte.write(rbyte.read() << 1);
}
break;
case a67:
{
currentState = a69;
mac1.write(mac1.read()+1);
}
break;
case a68:
if (rt1.read() == 0x00)
{
currentState = a70;
shcnt.write(shcnt.read()+1);
bitcnt.write(bitcnt.read()+1);
}
else
{
currentState = a71;
rbyte_tmp[0] = 1;
rbyte.write(rbyte_tmp);
}
break;
case a69:
{
currentState = a72;
rbyte.write(0x00);
cnt_elem.write(cnt_elem.read()+1);
}
break;
case a70:
if (bitcnt.read() == 0x8)
{
currentState = a73;
br.write(rbyte.read());
}
else if (!(bitcnt.read() == 0x8) && shcnt.read() == rlengthd.read() && cnt_elem.read() == relem.read()-0x0001 && cnt_m1_m3.read() == 0x0000)
{
currentState = a1;
codcomplete.write(1);
rwrite2m2.write(cnt_m2.read());
idle.write(1);
}
else if (!(bitcnt.read() == 0x8) && shcnt.read() == rlengthd.read() && cnt_elem.read() == relem.read()-0x0001 && !(cnt_m1_m3.read() == 0x0000))
{
currentState = a16;
cnt_elem.write(0);
rtemp1.write(mac1.read());
}
else if (!(bitcnt.read() == 0x8) && shcnt.read() == rlengthd.read() && !(cnt_elem.read() == relem.read()-0x0001))
{
currentState = a74;
cnt_elem.write(cnt_elem.read()+1);
}
else
{
currentState = a64;
rt1.write(rmask.read() && rt2.read());
}
break;
case a71:
{
currentState = a70;
shcnt.write(shcnt.read()+1);
bitcnt.write(bitcnt.read()+1);
}
break;
case a72:
if (bitcnt.read() == 0x8 && cnt_elem.read() == relem.read() && cnt_m1_m3.read() == rfilelength.read())
{
currentState = a1;
decodcomplete.write(1);
rwrite2m3.write(cnt_m1_m3.read());
idle.write(1);
}
else if (bitcnt.read() == 0x8 && cnt_elem.read() == relem.read() && !(cnt_m1_m3.read() == rfilelength.read()))
{
m2_address = mac2.read();
currentState = a27;
}
else if (bitcnt.read() == 0x8 && !(cnt_elem.read() == relem.read()))
{
m2_address = mac2.read();
currentState = a44;
}
else
{
currentState = a56;
rt1.write(rmask.read() && rt2.read());
}
break;
case a73:
{
m2_address = mac2.read();
currentState = a75;
m2[m2_address].write(br.read());
cnt_m2.write(cnt_m2.read()+1);
}
break;
case a74:
{
m1_address = mac1.read();
currentState = a52;
}
break;
case a75:
{
currentState = a76;
mac2.write(mac2.read()+1);
}
break;
case a76:
{
currentState = a77;
bitcnt.write(0);
rbyte.write(0x00);
}
break;
case a77:
if (shcnt.read() == rlengthd.read() && cnt_elem.read() == relem.read()-0x0001 && cnt_m1_m3.read() == 0x0000)
{
currentState = a1;
codcomplete.write(1);
rwrite2m2.write(cnt_m2.read());
idle.write(1);
}
else if (shcnt.read() == rlengthd.read() && cnt_elem.read() == relem.read()-0x0001 && !(cnt_m1_m3.read() == 0x0000))
{
currentState = a16;
cnt_elem.write(0);
rtemp1.write(mac1.read());
}
else if (shcnt.read() == rlengthd.read() && !(cnt_elem.read() == relem.read()-0x0001))
{
currentState = a74;
cnt_elem.write(cnt_elem.read()+1);
}
else
{
currentState = a64;
rt1.write(rmask.read() && rt2.read());
}
break;
}
}
#ifdef MTI_SYSTEMC
SC_MODULE_EXPORT(Funcmi);
#endif