// =============================================================================
// Generated by efx_ipmgr
// Version: 2025.2.288.2.10
// IP Version: 7.1
// =============================================================================

////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2013-2025 Efinix Inc. All rights reserved.              
//
// This   document  contains  proprietary information  which   is        
// protected by  copyright. All rights  are reserved.  This notice       
// refers to original work by Efinix, Inc. which may be derivitive       
// of other work distributed under license of the authors.  In the       
// case of derivative work, nothing in this notice overrides the         
// original author's license agreement.  Where applicable, the           
// original license agreement is included in it's original               
// unmodified form immediately below this header.                        
//                                                                       
// WARRANTY DISCLAIMER.                                                  
//     THE  DESIGN, CODE, OR INFORMATION ARE PROVIDED “AS IS” AND        
//     EFINIX MAKES NO WARRANTIES, EXPRESS OR IMPLIED WITH               
//     RESPECT THERETO, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES,  
//     INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF          
//     MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR    
//     PURPOSE.  SOME STATES DO NOT ALLOW EXCLUSIONS OF AN IMPLIED       
//     WARRANTY, SO THIS DISCLAIMER MAY NOT APPLY TO LICENSEE.           
//                                                                       
// LIMITATION OF LIABILITY.                                              
//     NOTWITHSTANDING ANYTHING TO THE CONTRARY, EXCEPT FOR BODILY       
//     INJURY, EFINIX SHALL NOT BE LIABLE WITH RESPECT TO ANY SUBJECT    
//     MATTER OF THIS AGREEMENT UNDER TORT, CONTRACT, STRICT LIABILITY   
//     OR ANY OTHER LEGAL OR EQUITABLE THEORY (I) FOR ANY INDIRECT,      
//     SPECIAL, INCIDENTAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES OF ANY    
//     CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF      
//     GOODWILL, DATA OR PROFIT, WORK STOPPAGE, OR COMPUTER FAILURE OR   
//     MALFUNCTION, OR IN ANY EVENT (II) FOR ANY AMOUNT IN EXCESS, IN    
//     THE AGGREGATE, OF THE FEE PAID BY LICENSEE TO EFINIX HEREUNDER    
//     (OR, IF THE FEE HAS BEEN WAIVED, $100), EVEN IF EFINIX SHALL HAVE 
//     BEEN INFORMED OF THE POSSIBILITY OF SUCH DAMAGES.  SOME STATES DO 
//     NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL OR            
//     CONSEQUENTIAL DAMAGES, SO THIS LIMITATION AND EXCLUSION MAY NOT   
//     APPLY TO LICENSEE.                                                
//
////////////////////////////////////////////////////////////////////////////////

`define IP_UUID _4c19f37180ff465ca20760e199a0613f
`define IP_NAME_CONCAT(a,b) a``b
`define IP_MODULE_NAME(name) `IP_NAME_CONCAT(name,`IP_UUID)
module gTSE
(
    input mac_reset,
    input proto_reset,
    output rx_mac_aclk,
    input tx_mac_aclk,
    output [2:0] eth_speed,
    input rx_axis_clk,
    output rx_axis_mac_tuser,
    output rx_axis_mac_tlast,
    output rx_axis_mac_tvalid,
    input rx_axis_mac_tready,
    input tx_axis_clk,
    input tx_axis_mac_tvalid,
    input tx_axis_mac_tlast,
    input tx_axis_mac_tuser,
    output tx_axis_mac_tready,
    output [3:0] rgmii_txd_HI,
    output [3:0] rgmii_txd_LO,
    output rgmii_tx_ctl_HI,
    output rgmii_tx_ctl_LO,
    output rgmii_txc_HI,
    output rgmii_txc_LO,
    input [3:0] rgmii_rxd_HI,
    input [3:0] rgmii_rxd_LO,
    input rgmii_rx_ctl_HI,
    input rgmii_rx_ctl_LO,
    input rgmii_rxc,
    input s_axi_aclk,
    output [7:0] rx_axis_mac_tdata,
    input [7:0] tx_axis_mac_tdata,
    input [0:0] tx_axis_mac_tstrb,
    output [0:0] rx_axis_mac_tstrb,
    output MdoEn,
    output Mdo,
    input Mdi,
    output Mdc,
    input [9:0] s_axi_araddr,
    output s_axi_arready,
    input s_axi_arvalid,
    input [9:0] s_axi_awaddr,
    output s_axi_awready,
    input s_axi_awvalid,
    input s_axi_bready,
    output [1:0] s_axi_bresp,
    output s_axi_bvalid,
    output [31:0] s_axi_rdata,
    input s_axi_rready,
    output [1:0] s_axi_rresp,
    output s_axi_rvalid,
    input [31:0] s_axi_wdata,
    output s_axi_wready,
    input s_axi_wvalid
);
`IP_MODULE_NAME(efx_mac1gbe)
#(
    .VERSION (16),
    .TXFIFO_EN (1'b1),
    .RXFIFO_EN (1'b1),
    .TXFIFO_DTH (4096),
    .RXFIFO_DTH (4096),
    .PHY_INTF_MODE (0),
    .AXIS_DW (8),
    .RGMII_RXC_EDGE (1'b1),
    .RGMII_TXC_DLY (1'b1),
    .INTER_PACKET_GAP (6'd12),
    .MTU_FRAME_LENGTH (16'd1518),
    .MAC_SOURCE_ADDRESS (48'd0),
    .ENABLE_BROADCAST_FILTERING (1'b1),
    .LOOPBACK_EN (1'b1),
    .APBIF (1'b0),
    .FAMILY ("TITANIUM")
)
u_efx_mac1gbe
(
    .mac_reset ( mac_reset ),
    .proto_reset ( proto_reset ),
    .rx_mac_aclk ( rx_mac_aclk ),
    .tx_mac_aclk ( tx_mac_aclk ),
    .eth_speed ( eth_speed ),
    .rx_axis_clk ( rx_axis_clk ),
    .rx_axis_mac_tuser ( rx_axis_mac_tuser ),
    .rx_axis_mac_tlast ( rx_axis_mac_tlast ),
    .rx_axis_mac_tvalid ( rx_axis_mac_tvalid ),
    .rx_axis_mac_tready ( rx_axis_mac_tready ),
    .tx_axis_clk ( tx_axis_clk ),
    .tx_axis_mac_tvalid ( tx_axis_mac_tvalid ),
    .tx_axis_mac_tlast ( tx_axis_mac_tlast ),
    .tx_axis_mac_tuser ( tx_axis_mac_tuser ),
    .tx_axis_mac_tready ( tx_axis_mac_tready ),
    .rgmii_txd_HI ( rgmii_txd_HI ),
    .rgmii_txd_LO ( rgmii_txd_LO ),
    .rgmii_tx_ctl_HI ( rgmii_tx_ctl_HI ),
    .rgmii_tx_ctl_LO ( rgmii_tx_ctl_LO ),
    .rgmii_txc_HI ( rgmii_txc_HI ),
    .rgmii_txc_LO ( rgmii_txc_LO ),
    .rgmii_rxd_HI ( rgmii_rxd_HI ),
    .rgmii_rxd_LO ( rgmii_rxd_LO ),
    .rgmii_rx_ctl_HI ( rgmii_rx_ctl_HI ),
    .rgmii_rx_ctl_LO ( rgmii_rx_ctl_LO ),
    .rgmii_rxc ( rgmii_rxc ),
    .s_axi_aclk ( s_axi_aclk ),
    .rx_axis_mac_tdata ( rx_axis_mac_tdata ),
    .tx_axis_mac_tdata ( tx_axis_mac_tdata ),
    .tx_axis_mac_tstrb ( tx_axis_mac_tstrb ),
    .rx_axis_mac_tstrb ( rx_axis_mac_tstrb ),
    .MdoEn ( MdoEn ),
    .Mdo ( Mdo ),
    .Mdi ( Mdi ),
    .Mdc ( Mdc ),
    .s_axi_araddr ( s_axi_araddr ),
    .s_axi_arready ( s_axi_arready ),
    .s_axi_arvalid ( s_axi_arvalid ),
    .s_axi_awaddr ( s_axi_awaddr ),
    .s_axi_awready ( s_axi_awready ),
    .s_axi_awvalid ( s_axi_awvalid ),
    .s_axi_bready ( s_axi_bready ),
    .s_axi_bresp ( s_axi_bresp ),
    .s_axi_bvalid ( s_axi_bvalid ),
    .s_axi_rdata ( s_axi_rdata ),
    .s_axi_rready ( s_axi_rready ),
    .s_axi_rresp ( s_axi_rresp ),
    .s_axi_rvalid ( s_axi_rvalid ),
    .s_axi_wdata ( s_axi_wdata ),
    .s_axi_wready ( s_axi_wready ),
    .s_axi_wvalid ( s_axi_wvalid )
);
endmodule

//pragma protect
//pragma protect begin

/* Encryption Envelope */

`pragma protect begin_protected
`pragma protect version = 1
`pragma protect encrypt_agent = "QuestaSim" , encrypt_agent_info = "2023.4"
`pragma protect key_keyowner = "Aldec" , key_keyname = "ALDEC15_001"
`pragma protect key_method = "rsa"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 256 )
`pragma protect key_block
MKHWLtljMm7kaIKwqUK8B5EM2QxPAoxLfX2cJIpcD8uU6akTM8tOaCCq3fMfRLOr
SMgTjMO8gkEDhuWpeeY3zc0UfPumTQ7/0MePhALxq2YkHeE6xpzjoV214ddWs2SZ
ngn3y/T3JwvOLSP8v3chWxTaLfsv781pmyiWaW2ANcnxLKss63esqdwxjuAKGa1E
t4Pkivr+Y4WTlOFhRJLNNWs96MemiTmFKpo0yfpF8JoeM118sL8OZxdN3uFAYRGY
JjRQnM2MKtMN/trj8aMlCDTmFBKh76B5x+WVJ6FpZzMTtC43cHm6IFdKP5cbozNi
q6qjblAU3CRV8RZn8/HoCg==
`pragma protect data_method = "aes256-cbc"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 8512 )
`pragma protect data_block
[encoded data, 11505 characters]
efI5V6Qput3fH857O6KfcA==
`pragma protect end_protected

//pragma protect end


//pragma protect
//pragma protect begin

/* Encryption Envelope */

`pragma protect begin_protected
`pragma protect version = 1
`pragma protect encrypt_agent = "QuestaSim" , encrypt_agent_info = "2023.4"
`pragma protect key_keyowner = "Aldec" , key_keyname = "ALDEC15_001"
`pragma protect key_method = "rsa"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 256 )
`pragma protect key_block
sJoun9hXsaBjoXd5vq4p0WrRiBOmYRz7dLZcqHre9vcVYQPlTOAqH0akQ6/PLAvo
b9EUQM/9bTYotLNHFDMfXIxqXF7xhnq3mOzPkpjLwLd10+G18u3FajkaV7bI0IAW
oAt4VExdspy9hXF3QLCwQvl+uXjg6B9tfkQ9lRE9Lt8c2s17Xx07Kvbp1zl7vyZg
jIzh1M8YJu5XWmIzLuCFgslf9Kr91eatrzMfWF2L1/8ZSvGiwK0dx68laecFUI5B
EnV0j0+orVdTEn15qN5+MomveXhwUi6euoryiKOhEuwxQPwJgWJdLJFjc2PGdHKK
NsgFLAx5GqkU+UrV2n2SXQ==
`pragma protect data_method = "aes256-cbc"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 448 )
`pragma protect data_block
VQEpSYyrqyMy0d6e5MIzq762bzEojUES6yynx1aA5YDeKe6T5+dbMqPYRoy2ZpgY
1pDSzeqP4kI9eLLRgGkBdiK45om6VD11yNVwjrQMTGqbPqFazzhwUBUoSB7JwcAD
uC1FXbWkLYXBlKP+jolNB7dno1fTrg9L/nOmBI1I8OVyjmP4bvnXN45GNXRtvVMX
y0zkEfl9r7gQWPbQ4ywNu1WiReEE9uKWaSlhmunbfKrHkR+WQoexuhfV8DZ0hZyQ
MVmGaG4hL0IiKUoIKKwz/5nkAFBSQg9XQgwniu/4pwNJbvB2ps4oRE+CkkabddOd
REXQ3xbluJgS/j9unThBmb1sg08axrYBcQT5C9BQTNxLnKH3jAJtkhB32EUR7K8Y
VFSV9qT4ZiPutIB+jlDZKcQXzDvwTKs2/UovSgdwdL0fDYh8N6iTXamqVKfKR41O
IrzRJLOlQ7Zb4WUDyft5RB/ZA77Gaeeo8xXAfHgbLIe4KM8m05Mx3dOixwdPKOf4
Iivkxru9/M6xHtIkk7Sb3gYK6gcWfW5av9qpewcpb9BqBDlFGVg8BqlxkhxKymHd
rzVfVgBqmYYmXoH399QOsQ==
`pragma protect end_protected

//pragma protect end


//pragma protect
//pragma protect begin

/* Encryption Envelope */

`pragma protect begin_protected
`pragma protect version = 1
`pragma protect encrypt_agent = "QuestaSim" , encrypt_agent_info = "2023.4"
`pragma protect key_keyowner = "Aldec" , key_keyname = "ALDEC15_001"
`pragma protect key_method = "rsa"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 256 )
`pragma protect key_block
h07AONsTLlxUVOuPlT8XRZHZulcIPjI5IlCVE57voQcoylYjcYlec6S5UHg4gef0
KagslBKEtX4SBcosPVrVrw3xKbkRoW2OrahVzxsru597XKu7PRdb8MZ96PsJavzN
tdgLf54Xf5Ya8oqvlMrbmHSj+vVnFC+AqKvIp7XrFpYla22SC4RENMPZltjegEZu
vLTTClkxA4XzNVJjS+RNXjMnUscfzBmMKXRWZ9QFgA4yEJ5BZidIbatzYW3aLyXs
+jIeuJjAO35ZhJozFu/FkqDptxBpy8zvkLY3GpiwNCnetBHMPm5/Yyc5c1525c/g
ako3dDZN6Kobgs5dVRe0xQ==
`pragma protect data_method = "aes256-cbc"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 6192 )
`pragma protect data_block
[encoded data, 8385 characters]
`pragma protect end_protected

//pragma protect end


//pragma protect
//pragma protect begin

/* Encryption Envelope */

`pragma protect begin_protected
`pragma protect version = 1
`pragma protect encrypt_agent = "QuestaSim" , encrypt_agent_info = "2023.4"
`pragma protect key_keyowner = "Aldec" , key_keyname = "ALDEC15_001"
`pragma protect key_method = "rsa"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 256 )
`pragma protect key_block
SF6jRX5MbN1KbFm1wuYk5J3Ovoq4vxkJqESI6Lrz2iEvnMS6GgkGXQXWjHgiisJ7
yeAGiWNDQuLR6MWZCgtUohyFVU5eVKvERRAf9nVBSJBjfh09WftAIdSadBWiV5fx
fxFuUL6SPamPNpCdkO2W2FOSvEEMSqyOalaIk65mCV4mOJyRYzm96tMhjOizDFlt
4AxCGA0kys+jln4Q5Dpo2Zsu5AbVIIDlHF6kqtCRkH4DLpbo2ByxXzHHXZvTdpbT
X92OXbfcUawSFeXO6LqrcEOuVN+X8nzaArA+w+nL5rWhNDZN/nCqvwPNE7I5nukd
Ei2KoM+M5Wo95QuqKU74Aw==
`pragma protect data_method = "aes256-cbc"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 1152 )
`pragma protect data_block
FVnbUs5RJWbO4aJIvIqCuSa9rRE3WgP2KsRWQvunl5MVjQ6us8TfajzoDBQQlXOr
UrzPRf8jcH5Ge3JHkIIQFf7+TuupWW/oi338I4wB5u+kxkF7Cv2BQf3+5J5xF3xj
ZKlAxC2BLIojcgSliK+kpNl/TFnhg2A4dVB2uq+Me1YS11Py8fPTSxEAOgl05QoB
cjIH5OJO9lr25DDpttC0lhvM8AKmBiGT23mG63iyQfhgEfIrL06z4zjw2unfA5sJ
kkj0TbaZy78ZtXVm6yTZdfRPbph+eEJUOCZLMR11MSTTJlGV1VfOpIPYD7sRCt3T
7HmU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ZIRmEAoluwwpn
MvcESNGKGoB+gFwd1SdsreIwTo6uPiT4QlgdbbQ6RwYYeSZIWOZBo9NkhK6ebLSU
il0NYDxK8g2uEMRnQefBxfshN9xuIiy1eKgef0JCKvvnWdU50dLd3y2HcMzCcfUl
`pragma protect end_protected

//pragma protect end


//pragma protect
//pragma protect begin

/* Encryption Envelope */

`pragma protect begin_protected
`pragma protect version = 1
`pragma protect encrypt_agent = "QuestaSim" , encrypt_agent_info = "2023.4"
`pragma protect key_keyowner = "Aldec" , key_keyname = "ALDEC15_001"
`pragma protect key_method = "rsa"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 256 )
`pragma protect key_block
aolNkchrHQdmf62Vo9Z1dgP0MtOYoRaBWW72TEEQ6JVJYPWBBRjaO8khH/Z8oasr
nAt/W+xy88PFXSJezzJXyWx65EvvU8/+aXYHwr5KugLXmFdBQoWoFUb+DwN8muhK
Ikytq2rL9li9q4mNyW32tSsKIPcqi0v4Zf9+wgrklH/XUtBmycjvls+noGdRVa+G
t06I+WZ4Rmdx6Bl74XCV29VQUj8i1xc4Q6zBymcQrCQOhc9uP0gYGbk4pyEHO7OJ
FBfq42AexS2wgmTmdEX64M3Tw0ILbqaLd3YHTgwKlUyDsmfaEbaK1UqBS9/f3XWP
pRjsuHm1RjnY5XhVBsZyFQ==
`pragma protect data_method = "aes256-cbc"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 8208 )
`pragma protect data_block
[encoded data, 11115 characters]
`pragma protect end_protected

//pragma protect end


//pragma protect
//pragma protect begin

/* Encryption Envelope */

`pragma protect begin_protected
`pragma protect version = 1
`pragma protect encrypt_agent = "QuestaSim" , encrypt_agent_info = "2023.4"
`pragma protect key_keyowner = "Aldec" , key_keyname = "ALDEC15_001"
`pragma protect key_method = "rsa"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 256 )
`pragma protect key_block
YE2kAOrL4lpJYzbOGvwVsCIUVQOUtbCEDF8bhBb6qm5AayzRmcPL25FFvnq7UAQ1
uB3C658d0USynAoyfE1U4QQb1oURV6Hntl4FB7UVcquRD04cnlV2TxvDYdS0JbcR
7vCuwcLQ4Qte69nkRwXoGW47I8lU9Xm4LMbqKbIO/H3kwcGjabId4a9VWNoR9NUd
PqnLp9omCj724zHA/CeFacgIJ5WhxXKQvnlZsQiVyvLnVMe4kfyh3xvKd6+yFOFv
VarMWNpp0pgGSfBec1WQY1kFJu4x4xVdGdW+rciXNMqIap22sQQ5VR6o674a1ze9
ohiUaQrLxx8AEBjSHL5u5Q==
`pragma protect data_method = "aes256-cbc"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 1680 )
`pragma protect data_block
26ATNUwJBh0ERNEcYuEZLNE2VR9F6dwubFMZn6V94RpIq6yn+q6LS2FXjj2KJGzD
JS3I3g/f2ZRWtySljkRc1KscNbsRLollG3vzaxGk3AU9rhiwcR59Tlek/gi1zf+a
vnB5tGGsg/c4cWAMVJbV8PKUWDGiLi3FajdMtoeQ2/2ujxLHGwEFdRxz09sXoYCg
hiNsoVdheY4BAOvOLN7agW1NGEwfKvGK6YnR7MfJjD8SCKZtfWK96BiVdMe4jEBk
IxiAIvyt7SZzIWNyt7jgB9BTja5HfYz5PATIZLxTsR1vzC7haJVEB65PkGjQUR3/
U2Zldx0O/LqWBkWZ2dgAqOiWXE5Lmg5pDcEXj6SMQhqLHFr4O22HhF+qZY9TzKAD
k+/2hq55JUUgaFg2fLL9gsLQ79QxMYZXBOV4PJvxozL/ZyOUNyJKljT/cAnQjuAx
/A/wFPZS2U7hr1eV7gSw2UkOJS8B2bKGEWjoSCXP+t/3q70eNQOsyHFoqe3yFYas
omQFQ26FhNOR4U+bTsWem4PMJtaCxNoeTmQdA+0xt2conseTJQvKJvIe/TC8Fwjv
GrJaqE9OJt3DgLbraKI7YuWqCKQeCFgX9xxu53qHShYH4o4/yz8YQwQ8aAes+i04
vrOggaK7jZeVqvXF/w/DU1qKW3fLOFsJNx6Yk7RWzUws4Xb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dCiDfOAL8bzK8EdvVuOHQ
s6X0dURl2g9zx0HrmCMTy9Gp0zPr0ncz0quyrmLLa5mGXZz603vwg5kMLoTE1zgT
d/bO2AZTchrwVIw7IU26KSxopJ5NEk9fl28c6yqemCaohURa0mpF9m+lFna2l0PO
VszF83++mGHZxD/B3SpAMEnYv0d6uV560E5j32UdE5d5VkUEpMUNtSZJNgyq6RN0
5vNg8srxsy2rG3nDhpc8Ir4nYm73n6rl0rUBkUwQGb/s3D5QzE3lTpnbzznjA9oW
vm7qHy3ZV79Ty/hn4UBNC7xRiJeHarTxe3aQX7KeZhZKGXdCo4TBFGWZ/iKI4lUx
ofx1MCriuWy7ZKVAPqU5qIrbn3GMC1aiY3tsUIsv6dK4NkiZrovlOdhPIT01B52H
YULlKeHm04FtXfb3Z96XBsyV46X+1rCkv30JpKquKlNnp6c6hfpXKK0WWVeiczzo
`pragma protect end_protected

//pragma protect end


//pragma protect
//pragma protect begin

/* Encryption Envelope */

`pragma protect begin_protected
`pragma protect version = 1
`pragma protect encrypt_agent = "QuestaSim" , encrypt_agent_info = "2023.4"
`pragma protect key_keyowner = "Aldec" , key_keyname = "ALDEC15_001"
`pragma protect key_method = "rsa"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 256 )
`pragma protect key_block
Clh2+96y2UaAIMsOT1iQd0b4LgP6cUyq8ikdSaopI2xdvmHpy4MCZw5eH+3bsiRS
sIEJcXd7mTNOXDmXhErDaFesKLkcq6yObhPVwNralwLNFz2QMabsWP3pK2FVtkYI
fj4egCCAY9GcswHvNDiOf7clwh4nxs+SsNQqWgn4+e03w80+KoCR7ntVbJvNn7Ru
R4Awd91Y3QAh4vNgZAPy9FhwFh529f3cC1dTuK4Ub0ZWgGquypgjleCIisw4zCvg
FHeGKwJ0ypkTUqj3xiglECEaa4kDPmUqRioVyK8ierOu3UdHSjUZ9hAN96tvKAZs
H0Frv1cvk6PU6a5SMhm8lQ==
`pragma protect data_method = "aes256-cbc"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 1872 )
`pragma protect data_block
+FF2ryBPFKhElPRjRPlL94Ht1qyO12X9daQ9C99SM0WbaOTEIqV0p/mmSwo7XdNq
gPyOyDn2mYFJ5Ilb72QyTCdI0y5pnAVoN2wYyhlvtVZhEDTMkVvgmFCmkgSwP7cM
yzGP5HP9OuOS40nO2pFs5iKDvfcKXWtExe42+mtlYGf48INkKp2bHVRIts9uGh+G
nnqPIZuE3py6Ju23I2d35DdwqO/3AV2MOkjFqiWii4B4uT/uInhNTufGLrA8+P0N
WeYJFyIjPX5JPjpYxIAZw+aVuR6pfD0QqPCCxm2jr49DAKsaZtMnBAbQIz38PHaZ
jEToXCuCiAtkLBHcn9PN5PS8HsplbfguTJ0CY/sOvBS6VqCbdoT8Y4lrQpcWvohd
+BhXiJFEMCQ98F1KgLzrdUNmfroOuVwUuzzkkA0bIuJHqUx1f3+vw42RSNBr4zAS
ASwtMbvKbyIN3n4QQeB+rppOS3yrp8NrNcK2xyOSxnsGX+GKsphHbn+8Tz5XKgrJ
WLMi/AmfYiXmv2NXchFp8ELBERHtEo2/4z389iThqwkcqUVrDUlSH4GkhovsGylj
3heghHehw9Ibfys9ZUMpakpZla7LyLbzekJxuXRGAODLu+qiebcZa/idcTV0tcOq
AdE798kou3CdCIdfyeiY9oC35S0rfA07uOA/zvVceoCNZw8oR+iJLBM4zj1LR/qH
0p/7vd81jwDlBOxKYNt2+hmSGzqwgZGkd+49sthGCZtUt5RXR2KPuj1vIwfq32TF
55ow2akOzG5ObW4f6YNNC3f8poq1/O3Vo0SqAx3ccwarGTJ+dZiiM0ucl6YxEtSz
ND9Ez9tWI3BHdSQmjlgOEnsEsoD1B1Jirh/BIClIyB2osigAPCvyqp1xD0IahWeg
cAOWdCrj2WKZpsd7CdZuDie87OWnWiXGR5zfZWVXpqT3qW8M244zcoOZAggHGuXh
ffjFd71jo44drv7OOZ95yMXltL2IXNfkpt6Sv/vP80P5wOv3A4q8bj7KYD7MG47w
dN+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2YY8eZ/aVWwv6uMWf9BbNMl
NcMjxnEBx9RgP5ZXCq2sa+EG/z0GxkpS0jBulYgz1Rq8G5PlaPHIUuUElokeamHV
wI2lJwG7FA91UrGxOUEE76PabAZEBdtbFBmWGnYtzTAsKFHmtr6Jg+yq5A05rEru
OXxmJVsUJyWuzeSwtLtjeYcYIi5HrYHdzhojcj6inmmxk8UdKEQqr+o/93+YDEH9
ac1c7TvoyANVJBmnsyGUJ94zoCf1z9YPBf0sZF24QetIjrNIaI4skW5CN8jVZrzP
ca6D6QlzaU7MR6KZavqsEOX1M/D0wbA+CxtkhRtcEMc4hkwcpFL3AyUgu2c9YIp3
PbijWvq+kgGNPaahydqMP7PhZeaOIyKzogXmzbLXaUhJ/G+gczS6YdqBMqHXYlmt
`pragma protect end_protected

//pragma protect end


//pragma protect
//pragma protect begin

/* Encryption Envelope */

`pragma protect begin_protected
`pragma protect version = 1
`pragma protect encrypt_agent = "QuestaSim" , encrypt_agent_info = "2023.4"
`pragma protect key_keyowner = "Aldec" , key_keyname = "ALDEC15_001"
`pragma protect key_method = "rsa"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 256 )
`pragma protect key_block
LE2+LFfgwm6au8Qed7luh0VjcDc+B3kA1Ir8num5KBRVTiIzuKhCP9/7nz6ao596
bhXmMC4XEva1VPhmJ8sO5e6zRy0FI9xAkDssejY7vLm8R5tJ7VZpvpLFCSx/5wKw
3wWXcxoZR1+PJk4dJ+QV4eKQ7AyeGiwI8DtallapnaG3wjj6w0efefqk8LCOmJI8
behEHZOLQ/5Qpbyxwm0fdcGc0iZ6RspvMpZvEAL+ao2MBxITzF6OuflDziN9nI+3
y4ixJYyFEAT5NSelcIU7gXzJ+0KaGrTGh1cAqPoimqI4gIC3zaVWjwCU16v7PFTz
rz/Vvf25iwmBk7v5U7qx1g==
`pragma protect data_method = "aes256-cbc"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 2656 )
`pragma protect data_block
QhqXslTzgnkGE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1MZRubiHhA1b83nQtn4
u54EmCw/DLG/SdAnEMK6/jQ1F8BM7OWjpNHu3hv7SZPrBAaLXd6JiuE+9+qxl7hW
eereg8KEx/wKv529cnv+i+nzsjSBg0eym/O9ZnkIA5a1xooIdJe8izoEig1leAst
Ao8zJqa0mHX2GXOEad62TSzzDkiqjr7AkFpMLxRqmrp411FDoUfLqqYXWgLNHsEJ
T2M8fB3gDH7WFYjT8S5qJQi55K+AxI07KOW6zZxH1EeWgfuWx1P6qMXD93EQEpPN
qUH4WLO59a5T4QVO3/3l1M4o4v08iF9pcPJlrBX2IT03wgeyFOko+k00CHq+r3Px
xRFznbHeMXrJzICpc1qpNg==
`pragma protect end_protected

//pragma protect end


//pragma protect
//pragma protect begin

/* Encryption Envelope */

`pragma protect begin_protected
`pragma protect version = 1
`pragma protect encrypt_agent = "QuestaSim" , encrypt_agent_info = "2023.4"
`pragma protect key_keyowner = "Aldec" , key_keyname = "ALDEC15_001"
`pragma protect key_method = "rsa"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 256 )
`pragma protect key_block
a9hy4rxBrnfw+wxP50p3JnUR+YJ9+SQjya3L9r3erHPvT0IB1/j6iUYV2UN0bWvo
slhWQdYOx1GoBstYG2navdEMBM1ksTWHFLFWZPJ8ttxrSSiPvCG+xsAf4fHUEoxf
FnAG65tM4DRbdjUOKOcqR+OZW/S1VHDt11jO4HIVRc25PAbPViCji5Os5GNVet3J
G7F8KtMTbVJHqamQ0NPuY6ndxvsW8w9g3nuLQjWI+H7MLiJKtUnjJArfK0/wKAY4
nFsxLy0eSD+CLtVbao9QAWtOqZlWzD0FwO4PqQDtVYngsrhjYpzk6mTCzIwBlMZT
fr+ElYHlgyghsDTuN+QRtg==
`pragma protect data_method = "aes256-cbc"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 16720 )
`pragma protect data_block
[encoded data, 22620 characters]
Pk+CU9d4Pl3z24mJTJ8TpA==
`pragma protect end_protected

//pragma protect end


//pragma protect
//pragma protect begin

/* Encryption Envelope */

`pragma protect begin_protected
`pragma protect version = 1
`pragma protect encrypt_agent = "QuestaSim" , encrypt_agent_info = "2023.4"
`pragma protect key_keyowner = "Aldec" , key_keyname = "ALDEC15_001"
`pragma protect key_method = "rsa"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 256 )
`pragma protect key_block
n9rncH1gli54i44OkRckXrPS5/bYes/awIWcV3RmnEBDP3AcPLSKHOEOZge8ZOyN
wVltadJ2zhaR1pxa1g+6VALvUtvzm+YTBZ3pwQi49ZgPt5/wPep+O/POaCQYq+Ah
x7LGg4e/LzfBv0lRKkcuaea6bHM6A7u0nmr63ytA86LQEL7lABH27sO8NaE0/M5j
DqKGhEYFJSP2Yxpfcc1/3ht3x4Fqhlo+joo6gt+mQm+VUsy5T+U2YN+NQtNZ5J1K
XlAJoqKUJUxgRRd9KJhaVDOBzstJxb66ts5wP2FMr84GZrdw/QQJb8Z+K7VB/H7q
o/xuf13FxxHZIa1S404mhg==
`pragma protect data_method = "aes256-cbc"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 19056 )
`pragma protect data_block
[encoded data, 25805 characters]
`pragma protect end_protected

//pragma protect end


//pragma protect
//pragma protect begin

/* Encryption Envelope */

`pragma protect begin_protected
`pragma protect version = 1
`pragma protect encrypt_agent = "QuestaSim" , encrypt_agent_info = "2023.4"
`pragma protect key_keyowner = "Aldec" , key_keyname = "ALDEC15_001"
`pragma protect key_method = "rsa"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 256 )
`pragma protect key_block
J7BOv0C5jXIeRnLfMOyapOQhyKpFxofs/IUotfm22gu2bHDwrkOZuNyLq83WUu2r
xh4uVd6vqtCoovwzd7WfItOCJ+X3O/rPN+iOMyUD4wUX35A1JlV+R91hVXXEJeJK
O80EKuSi1cjkL94t77Y+BP7umEmcNvaWc2GsIw/yQc6S7Haa3qdT5InDmDim3BIS
8ianCpIbGR5tK2EK3Dd1jXhcsqg63wXWm9ytRW/sXcbLdFEA4q4bAwtsavM1I4gY
2p9fZ2Lqm2N2rOQGPJV4YFUkwXWXjQGKOsaBYkwTWJIkJC4XggjFYhfOPFQhinMU
JpYvRNjOSlo9yPiIiUT90Q==
`pragma protect data_method = "aes256-cbc"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 36512 )
`pragma protect data_block
[encoded data, 49400 characters]
pFJX+dGybQJg3GER4k3t+GvAaYSX/CAIDixMGHLN6tk=
`pragma protect end_protected

//pragma protect end


//pragma protect
//pragma protect begin

/* Encryption Envelope */

`pragma protect begin_protected
`pragma protect version = 1
`pragma protect encrypt_agent = "QuestaSim" , encrypt_agent_info = "2023.4"
`pragma protect key_keyowner = "Aldec" , key_keyname = "ALDEC15_001"
`pragma protect key_method = "rsa"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 256 )
`pragma protect key_block
KOhIlvaBdXECsKrbEVJUzh/U26bIKVYacE93lWLn0xKG9BPuUScZRg86anjHyYc3
BakNe+PgnuJEVToYQFkSSg7dilv1sC1y3A1esk/m/agSm1sZPAp9NXn71CeNtLyq
eXW4+sYrPhCz9ARfu35HctyMw0hohs0d9BUvwOVui0XQVxf6T5Lo83B5XREJlGet
fRnVqNWfzxTOM12vqIQowKKuvxhX1eIWMAY5THDVP0MYXaPzVt/tPmSCOAoMK+x3
fVIwwzPHHpF0DPmvj8JSmJmlaTew2n5hkYU31ogV1dVyjnJqPSvggbb2bB4YHnWr
Ej/zH846G4MmCJDO+yZDLw==
`pragma protect data_method = "aes256-cbc"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 6832 )
`pragma protect data_block
[encoded data, 9230 characters]
hSop+iugpeLj8cyBhVf+qQ==
`pragma protect end_protected

//pragma protect end


//pragma protect
//pragma protect begin

/* Encryption Envelope */

`pragma protect begin_protected
`pragma protect version = 1
`pragma protect encrypt_agent = "QuestaSim" , encrypt_agent_info = "2023.4"
`pragma protect key_keyowner = "Aldec" , key_keyname = "ALDEC15_001"
`pragma protect key_method = "rsa"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 256 )
`pragma protect key_block
EeWN16FcGe9oBJ5oEU+ohgRhhPUxTnyYnwj6pG7yWCXXIFJ/c/Z2IFC6YMj5VV6P
BLyZALNjwaoSRWibW3QAq5qvNT7j0LDbK5BiD3kYMK2NM1ttc5RJe8nvvjIGZf/4
QOgUPzxqMONvaitGcZqFkFRF4F2r32UTAF83wa/GXK2EVl27GpYipuMHfblqQc1T
0P1I+cdkyrOYVdn1Qa81Iz3uywJPy936keWhYnoBKnsgr368YKmcgYSRTKkT/tBw
MxLMmX96CeZt3TRFQHv4gfRxBPY8acA1UBgUTmeIGRMIn6vrYpV8wxIugIJFqVcC
hrVjUIFq33bxM4i1U0TwRQ==
`pragma protect data_method = "aes256-cbc"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 29968 )
`pragma protect data_block
[encoded data, 40560 characters]
YEGEJPC3s9MpByV9Pt6KFA==
`pragma protect end_protected

//pragma protect end


//pragma protect
//pragma protect begin

/* Encryption Envelope */

`pragma protect begin_protected
`pragma protect version = 1
`pragma protect encrypt_agent = "QuestaSim" , encrypt_agent_info = "2023.4"
`pragma protect key_keyowner = "Aldec" , key_keyname = "ALDEC15_001"
`pragma protect key_method = "rsa"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 256 )
`pragma protect key_block
jKKARVQzpBjsnhGaDRXS2of402Denlp/BDQ9Ty1CjdBDB11vyj07ShZzg/yf0s46
4i5BSgiNZFP60ULPBKuj9srpwLgZ+4wnvjoUZO7miHerzd4i2Se96DGrDU1ASNJ1
2zoboipgmNHRUSy6NhrrTjto32IJYxYYdkc+zABhsGGglKjcw3DhZbYM0P21JD9N
6bHb47pm6JAl2t0zF7TNEzG2xZO30CBLIrxT3iqWtJ+UMI7oP+zOgzEa2Hz9dQfu
T/OoYZ+a8/GBNciE6fy3/VsrK3sm4wMF9rlkKl9YLLHSilEdRHKlmFypuvhVMvfB
eHN3u9By19hM6nPHSv0Rfw==
`pragma protect data_method = "aes256-cbc"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 50592 )
`pragma protect data_block
[encoded data, 68510 characters]
`pragma protect end_protected

//pragma protect end


//pragma protect
//pragma protect begin

/* Encryption Envelope */

`pragma protect begin_protected
`pragma protect version = 1
`pragma protect encrypt_agent = "QuestaSim" , encrypt_agent_info = "2023.4"
`pragma protect key_keyowner = "Aldec" , key_keyname = "ALDEC15_001"
`pragma protect key_method = "rsa"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 256 )
`pragma protect key_block
IzMcge2JRDduYI2DRh0KHkEJU4gz02MPgjc2RDBL8iz3Dq4D9psMK+fMS6s9Hjoj
5ZInOPXpv4JtjohyVclxBgY+dsuotOPanGH2Cb+sLKLPGTEeosYSIfKzGmKBYmx9
vQe21qVnWRRwWBudqVwVSVSAWLxLEV0O50OxgYF/kieN+2hl6xZ49mh2t6tcpr/9
crcndWhYLWAyZdPl/f4agVcbX/g1TN2rDAAgR9DVuOJEC/u2OdTqvN85DqlD100O
ftD/3iDyjNM0Xn17m0UW4rxBJ1qzAt6uQ9Ccpl+HXf3Yhc4vxe8A7xtgM/PFZpmN
+MHciuZ8iljRLcc9QByyCg==
`pragma protect data_method = "aes256-cbc"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 5088 )
`pragma protect data_block
[encoded data, 6890 characters]
`pragma protect end_protected

//pragma protect end


//pragma protect
//pragma protect begin

/* Encryption Envelope */

`pragma protect begin_protected
`pragma protect version = 1
`pragma protect encrypt_agent = "QuestaSim" , encrypt_agent_info = "2023.4"
`pragma protect key_keyowner = "Aldec" , key_keyname = "ALDEC15_001"
`pragma protect key_method = "rsa"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 256 )
`pragma protect key_block
dOPtwFtLMcPenaEyGyZsI+s2xj0m2PnKI0HIO0J37nXu9s/URaK6vVkiRIlFAGEc
jCfFmEwDYWhHhdcMMJEeZ4UbEKbS5VAoryHReu51Guj5uwrM85BA53UcCyiAZeLI
EdS3yjfRYJaaq8xYdFrHJ1KpIomCt44AcjX5LRkSbA5prRgzbc/21AHDJHFTEfKd
39Ax/IAlqD3WzO6qUtrvrSaM6Hg+cHV63JSv0MOKYpKgTCPKKoIOvv4+PRaqitlV
FIMIGL5XFDxZWTuv+pweh4TnT7/cGMYXUnBczH1SdsfG1UB9U2S01SifaQbG1Q2v
OupVr/2wpDbCfxGqLmdxhw==
`pragma protect data_method = "aes256-cbc"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 5664 )
`pragma protect data_block
[encoded data, 7670 characters]
`pragma protect end_protected

//pragma protect end


//pragma protect
//pragma protect begin

/* Encryption Envelope */

`pragma protect begin_protected
`pragma protect version = 1
`pragma protect encrypt_agent = "QuestaSim" , encrypt_agent_info = "2023.4"
`pragma protect key_keyowner = "Aldec" , key_keyname = "ALDEC15_001"
`pragma protect key_method = "rsa"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 256 )
`pragma protect key_block
0EdYk8u9EcHvk5jqhjgohDTjVAeJT375Ef59f7yUuToa5zLARg+3ZhYxjn+3f2+f
GHrkhwUVyhyqbT8WjkrsEkbFOY+QQi4ZdA1Xj4Z//wG+fcEvjjatYv48Sz3YtuOH
QUP817ART1osb2GtW/StscEKBvMutLk+Snqv3QkHb4ev4y2y3KJtwzYaBBCh4HP3
fctt1g52yiTQCFtcd+8R7WACRO21cZs0IoR+ctw1Kbk6yZBnnIAQYsMlvYYUNJFr
csfS25mNE9ui/mTPN9AcyuaJ2FfdK4erHR1Fdbr+BAa0sKHxg93I8QWo9O3iRy+5
kVk8iGT9nN7Mv+IhhkiGAg==
`pragma protect data_method = "aes256-cbc"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 3504 )
`pragma protect data_block
[encoded data, 4745 characters]
`pragma protect end_protected

//pragma protect end


//pragma protect
//pragma protect begin

/* Encryption Envelope */

`pragma protect begin_protected
`pragma protect version = 1
`pragma protect encrypt_agent = "QuestaSim" , encrypt_agent_info = "2023.4"
`pragma protect key_keyowner = "Aldec" , key_keyname = "ALDEC15_001"
`pragma protect key_method = "rsa"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 256 )
`pragma protect key_block
M8byHsCbrDGyP62CFo8IvTM3Ae5RZL5oFDkkznIjOqNMKx3MfffncMeFuVCbvra+
Kz6I+7iwc1Fcj6DtkGGvxA4S/1nZs7iGAAvORqAF7HrKRZSfaVC5VZcuRSJzAH0i
Aewvp5YeFpmGEMBrIU4gGOOXU3vOpMTgE7Dg5mf6LqRWI784AXRaAJUNUlNSUHeI
IVbnj9YkS60Jui0wZjzP8PZtP4/xXmKdwe+gXbB/RrDoDgMx04/CnJYEJI/w+bEw
++9yzzLQxLrmwBIQWs2Zht7Nsmy21fpn0sEMQ1KcT+8EVhINv9qF4JLHeDQESCHJ
gODTw8hroSy9hCWlIflMfw==
`pragma protect data_method = "aes256-cbc"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 31840 )
`pragma protect data_block
[encoded data, 43095 characters]
odGVCw643lAXsgmg0EE4bw==
`pragma protect end_protected

//pragma protect end


/////////////////////////////////////////////////////////////////////////////
//           _____       
//          / _______    Copyright (C) 2013-2021 Efinix Inc. All rights reserved.
//         / /       \   
//        / /  ..    /   simple_dual_port_ram_fifo.v
//       / / .'     /    
//    __/ /.'      /     Description:
//   __   \       /      EFX FIFO
//  /_/ /\ \_____/ /     
// ____/  \_______/      
//
// *******************************
// Revisions:
//
// *******************************

module `IP_MODULE_NAME(efx_fifo_top) # (
    parameter FAMILY             = "TRION",       // New Param
    parameter SYNC_CLK           = 0,
    parameter BYPASS_RESET_SYNC  = 0,             // New Param
    parameter SYNC_STAGE         = 2,             // New Param
    parameter MODE               = "STANDARD",
    parameter DEPTH              = 512,           // Reverted (Equivalent to WDATA_DEPTH) 
    parameter DATA_WIDTH         = 32,            // Reverted (Equivalent to WDATA_WIDTH)
    parameter PIPELINE_REG       = 1,             // Reverted (By default is ON)
    parameter OPTIONAL_FLAGS     = 1,             // Reverted
    parameter OUTPUT_REG         = 0,
    parameter PROGRAMMABLE_FULL  = "STATIC_DUAL", // Set to "NONE" if not require this feature
    parameter PROG_FULL_ASSERT   = 27,
    parameter PROG_FULL_NEGATE   = 23,
    parameter PROGRAMMABLE_EMPTY = "STATIC_DUAL", // Set to "NONE" if not require this feature
    parameter PROG_EMPTY_ASSERT  = 5,
    parameter PROG_EMPTY_NEGATE  = 7,
    parameter ALMOST_FLAG        = OPTIONAL_FLAGS,
    parameter HANDSHAKE_FLAG     = OPTIONAL_FLAGS,
    parameter ASYM_WIDTH_RATIO   = 4,
    parameter WADDR_WIDTH        = depth2width(DEPTH),
    parameter RDATA_WIDTH        = rdwidthcompute(ASYM_WIDTH_RATIO,DATA_WIDTH),
    parameter RD_DEPTH           = rddepthcompute(DEPTH,DATA_WIDTH,RDATA_WIDTH),
    parameter RADDR_WIDTH        = depth2width(RD_DEPTH),
    parameter ENDIANESS		      = 0,
    parameter OVERFLOW_PROTECT   = 1,
    parameter UNDERFLOW_PROTECT  = 1,
    parameter RAM_STYLE          = "block_ram"

)(
    input  wire                   a_rst_i,
    input  wire                   a_wr_rst_i,
    input  wire                   a_rd_rst_i,
    input  wire                   clk_i,
    input  wire                   wr_clk_i,
    input  wire                   rd_clk_i,
    input  wire                   wr_en_i,
    input  wire                   rd_en_i,
    input  wire [DATA_WIDTH-1:0]  wdata,
    output wire                   almost_full_o,
    output wire                   prog_full_o,
    output wire                   full_o,
    output wire                   overflow_o,
    output wire                   wr_ack_o,
    output wire [WADDR_WIDTH :0]  datacount_o,
    output wire [WADDR_WIDTH :0]  wr_datacount_o,
    output wire                   empty_o,
    output wire                   almost_empty_o,
    output wire                   prog_empty_o,
    output wire                   underflow_o,
    output wire                   rd_valid_o,
    output wire [RDATA_WIDTH-1:0] rdata,
    output wire [RADDR_WIDTH :0]  rd_datacount_o,
    output wire                   rst_busy
); 

localparam WR_DEPTH      = DEPTH;
localparam WDATA_WIDTH   = DATA_WIDTH;
localparam RAM_MUX_RATIO = (RDATA_WIDTH <= WDATA_WIDTH/32) ? 32 :
                           (RDATA_WIDTH <= WDATA_WIDTH/16) ? 16 :
                           (RDATA_WIDTH <= WDATA_WIDTH/8)  ? 8  :
                           (RDATA_WIDTH <= WDATA_WIDTH/4)  ? 4  :
                           (RDATA_WIDTH <= WDATA_WIDTH/2)  ? 2  :
                           (RDATA_WIDTH <= WDATA_WIDTH)    ? 1  :
                           (RDATA_WIDTH <= WDATA_WIDTH*2)  ? 2  :
                           (RDATA_WIDTH <= WDATA_WIDTH*4)  ? 4  :
                           (RDATA_WIDTH <= WDATA_WIDTH*8)  ? 8  :
                           (RDATA_WIDTH <= WDATA_WIDTH*16) ? 16 : 32;           

wire                   wr_rst_int;
wire                   rd_rst_int;
wire                   wr_en_int;
wire                   rd_en_int;
wire [WADDR_WIDTH-1:0] waddr;
wire [RADDR_WIDTH-1:0] raddr;
wire                   wr_clk_int;
wire                   rd_clk_int;
wire [WADDR_WIDTH :0]  wr_datacount_int;
wire [RADDR_WIDTH :0]  rd_datacount_int;

generate
    if (ASYM_WIDTH_RATIO == 4) begin
        if (SYNC_CLK) begin
            assign wr_clk_int     = clk_i;    
            assign rd_clk_int     = clk_i;
            assign datacount_o    = wr_datacount_int;
            assign wr_datacount_o = {(WADDR_WIDTH+1){1'b0}};
            assign rd_datacount_o = {(RADDR_WIDTH+1){1'b0}};
        end
        else begin
            assign wr_clk_int     = wr_clk_i;    
            assign rd_clk_int     = rd_clk_i;
            assign datacount_o    = {(WADDR_WIDTH+1){1'b0}};
            assign wr_datacount_o = wr_datacount_int;
            assign rd_datacount_o = rd_datacount_int;
        end
    end
    else begin
        assign datacount_o    = {(WADDR_WIDTH+1){1'b0}};
        assign wr_datacount_o = wr_datacount_int;
        assign rd_datacount_o = rd_datacount_int;
        if (SYNC_CLK) begin
            assign wr_clk_int     = clk_i;    
            assign rd_clk_int     = clk_i;
        end
        else begin
            assign wr_clk_int     = wr_clk_i;    
            assign rd_clk_int     = rd_clk_i;
        end
    end    

    if (!SYNC_CLK) begin
        //(* async_reg = "true" *) reg [1:0] wr_rst;
        //(* async_reg = "true" *) reg [1:0] rd_rst;
        //
        //always @ (posedge wr_clk_int or posedge a_rst_i) begin
        //    if (a_rst_i) 
        //        wr_rst <= 2'b11;
        //    else 
        //        wr_rst <= {wr_rst[0],1'b0};            
        //end
        //
        //always @ (posedge rd_clk_int or posedge a_rst_i) begin
        //    if (a_rst_i) 
        //        rd_rst <= 2'b11;
        //    else 
        //        rd_rst <= {rd_rst[0],1'b0};            
        //end
        

        if (BYPASS_RESET_SYNC) begin
            assign wr_rst_int = a_wr_rst_i;
            assign rd_rst_int = a_rd_rst_i; 
            assign rst_busy   = 1'b0;
        end 
        else begin
            `IP_MODULE_NAME(efx_resetsync) #(
               .ACTIVE_LOW (0)
            ) efx_resetsync_wr_rst (
               .clk   (wr_clk_int),
               .reset (a_rst_i),
               .d_o   (wr_rst_int)
            );

            `IP_MODULE_NAME(efx_resetsync) #(
               .ACTIVE_LOW (0)
            ) efx_resetsync_rd_rst (
               .clk   (rd_clk_int),
               .reset (a_rst_i),
               .d_o   (rd_rst_int)
            );
            assign rst_busy   = wr_rst_int | rd_rst_int;
        end

    end
    else begin
        //(* async_reg = "true" *) reg [1:0] a_rst;
        //
        //always @ (posedge clk_i or posedge a_rst_i) begin
        //    if (a_rst_i) 
        //        a_rst <= 2'b11;
        //    else 
        //        a_rst <= {a_rst[0],1'b0};            
        //end
        wire   a_rst;

        `IP_MODULE_NAME(efx_resetsync) #(
           .ACTIVE_LOW (0)
        ) efx_resetsync_a_rst (
           .clk   (clk_i),
           .reset (a_rst_i),
           .d_o   (a_rst)
        );

        if (BYPASS_RESET_SYNC) begin
            assign wr_rst_int = a_rst_i;
            assign rd_rst_int = a_rst_i;
            assign rst_busy   = 1'b0;
        end
        else begin
            assign wr_rst_int = a_rst;
            assign rd_rst_int = a_rst;   
            assign rst_busy   = wr_rst_int | rd_rst_int;
        end
    end 
endgenerate

`IP_MODULE_NAME(efx_fifo_ram) # (
    .FAMILY        (FAMILY),
    .WR_DEPTH      (WR_DEPTH),
    .RD_DEPTH      (RD_DEPTH),
    .WDATA_WIDTH   (WDATA_WIDTH),
    .RDATA_WIDTH   (RDATA_WIDTH),
    .WADDR_WIDTH   (WADDR_WIDTH),
    .RADDR_WIDTH   (RADDR_WIDTH),
    .OUTPUT_REG    (OUTPUT_REG),
    .RAM_MUX_RATIO (RAM_MUX_RATIO),
    .ENDIANESS	    (ENDIANESS),
    .RAM_STYLE     (RAM_STYLE)
) xefx_fifo_ram (
    .wdata (wdata), 
    .waddr (waddr),
    .raddr (raddr), 
    .we    (wr_en_int), 
    .re    (rd_en_int),
    .wclk  (wr_clk_int),
    .rclk  (rd_clk_int),
    .rdata (rdata)
);

`IP_MODULE_NAME(efx_fifo_ctl) # (
    .SYNC_CLK           (SYNC_CLK),
    .SYNC_STAGE         (SYNC_STAGE),
    .MODE               (MODE),
    .WR_DEPTH           (WR_DEPTH),
    .WADDR_WIDTH        (WADDR_WIDTH),
    .RADDR_WIDTH        (RADDR_WIDTH),
    .ASYM_WIDTH_RATIO   (ASYM_WIDTH_RATIO),
    .RAM_MUX_RATIO      (RAM_MUX_RATIO),
    .PIPELINE_REG       (PIPELINE_REG),
    .ALMOST_FLAG        (ALMOST_FLAG),
    .PROGRAMMABLE_FULL  (PROGRAMMABLE_FULL),
    .PROG_FULL_ASSERT   (PROG_FULL_ASSERT),
    .PROG_FULL_NEGATE   (PROG_FULL_NEGATE),
    .PROGRAMMABLE_EMPTY (PROGRAMMABLE_EMPTY),
    .PROG_EMPTY_ASSERT  (PROG_EMPTY_ASSERT),
    .PROG_EMPTY_NEGATE  (PROG_EMPTY_NEGATE),
    .OUTPUT_REG         (OUTPUT_REG),
    .HANDSHAKE_FLAG     (HANDSHAKE_FLAG),
    .OVERFLOW_PROTECT   (OVERFLOW_PROTECT),
    .UNDERFLOW_PROTECT  (UNDERFLOW_PROTECT)
) xefx_fifo_ctl (
    .wr_rst          (wr_rst_int),
    .rd_rst          (rd_rst_int),
    .wclk            (wr_clk_int),
    .rclk            (rd_clk_int),
    .we              (wr_en_i),
    .re              (rd_en_i),
    .wr_full         (full_o),
    .wr_ack          (wr_ack_o),
    .rd_empty        (empty_o),
    .wr_almost_full  (almost_full_o),
    .rd_almost_empty (almost_empty_o),
    .wr_prog_full    (prog_full_o),
    .rd_prog_empty   (prog_empty_o),
    .wr_en_int       (wr_en_int),
    .rd_en_int       (rd_en_int),
    .waddr           (waddr),
    .raddr           (raddr),
    .wr_datacount    (wr_datacount_int),
    .rd_datacount    (rd_datacount_int),
    .rd_vld          (rd_valid_o),
    .wr_overflow     (overflow_o),
    .rd_underflow    (underflow_o)
);

function integer depth2width;
input [31:0] depth;
begin : fnDepth2Width
    if (depth > 1) begin
        depth = depth - 1;
        for (depth2width=0; depth>0; depth2width = depth2width + 1)
            depth = depth>>1;
        end
    else
       depth2width = 0;
end
endfunction 

function integer width2depth;
input [31:0] width;
begin : fnWidth2Depth
    width2depth = width**2;
end
endfunction

function integer rdwidthcompute;
input [31:0] asym_option;
input [31:0] wr_width;
begin : RdWidthCompute
    rdwidthcompute = (asym_option==0)? wr_width/16 :
                     (asym_option==1)? wr_width/8  :
                     (asym_option==2)? wr_width/4  :
                     (asym_option==3)? wr_width/2  :
                     (asym_option==4)? wr_width/1  :
                     (asym_option==5)? wr_width*2  :
                     (asym_option==6)? wr_width*4  :
                     (asym_option==7)? wr_width*8  :
                     (asym_option==8)? wr_width*16 : wr_width/1;
end
endfunction

function integer rddepthcompute;
input [31:0] wr_depth;
input [31:0] wr_width;
input [31:0] rd_width;
begin : RdDepthCompute
    rddepthcompute = (wr_depth * wr_width) / rd_width;
end
endfunction

endmodule


/////////////////////////////////////////////////////////////////////////////
//           _____       
//          / _______    Copyright (C) 2013-2021 Efinix Inc. All rights reserved.
//         / /       \   
//        / /  ..    /   simple_dual_port_ram_fifo.v
//       / / .'     /    
//    __/ /.'      /     Description:
//   __   \       /      EFX FIFO
//  /_/ /\ \_____/ /     
// ____/  \_______/      
//
// *******************************
// Revisions:
//
// *******************************

module `IP_MODULE_NAME(efx_fifo_ram) #(
    parameter FAMILY        = "TRION",
    parameter WR_DEPTH      = 512,
    parameter RD_DEPTH      = 512,
    parameter WDATA_WIDTH   = 8,
    parameter RDATA_WIDTH   = 8,
    parameter WADDR_WIDTH   = 9,
    parameter RADDR_WIDTH   = 9,
    parameter OUTPUT_REG    = 1,
    parameter RAM_MUX_RATIO = 4,
    parameter ENDIANESS 	 = 0, //0: Big endian (default)   1: Little endian 
    parameter RAM_STYLE     = "block_ram"
) (
    input  wire                     wclk,
    input  wire                     rclk,
    input  wire                     we,
    input  wire                     re,
    input  wire [(WDATA_WIDTH-1):0] wdata,
    input  wire [(WADDR_WIDTH-1):0] waddr,
    input  wire [(RADDR_WIDTH-1):0] raddr,
    output wire [(RDATA_WIDTH-1):0] rdata
);

localparam MEM_DEPTH         = (WR_DEPTH > RD_DEPTH) ? WR_DEPTH : RD_DEPTH;
localparam MEM_DATA_WIDTH    = (WDATA_WIDTH > RDATA_WIDTH) ? RDATA_WIDTH : WDATA_WIDTH;   
localparam LSB_WIDTH         = (WADDR_WIDTH > RADDR_WIDTH) ? (WADDR_WIDTH - RADDR_WIDTH) : (RADDR_WIDTH - WADDR_WIDTH);
localparam RDATA_WDATA_RATIO = (RDATA_WIDTH <= WDATA_WIDTH/32) ? "ONE_THIRTYTWO" :
                               (RDATA_WIDTH <= WDATA_WIDTH/16) ? "ONE_SIXTEENTH" :
                               (RDATA_WIDTH <= WDATA_WIDTH/8)  ? "ONE_EIGHTH"    :
                               (RDATA_WIDTH <= WDATA_WIDTH/4)  ? "ONE_FOURTH"    :
                               (RDATA_WIDTH <= WDATA_WIDTH/2)  ? "ONE_HALF"      :
                               (RDATA_WIDTH <= WDATA_WIDTH)    ? "ONE"           :
                               (RDATA_WIDTH <= WDATA_WIDTH*2)  ? "TWO_TIMES"     :
                               (RDATA_WIDTH <= WDATA_WIDTH*4)  ? "FOUR_TIMES"    :
                               (RDATA_WIDTH <= WDATA_WIDTH*4)  ? "EIGHT_TIMES"   :
                               (RDATA_WIDTH <= WDATA_WIDTH*4)  ? "SIXTEEN_TIMES" : "THIRTYTWO_TIMES";

(* syn_ramstyle = RAM_STYLE *) reg [MEM_DATA_WIDTH-1:0] ram[MEM_DEPTH-1:0];
reg [RDATA_WIDTH-1:0]    r_rdata_1P;
reg [RDATA_WIDTH-1:0]    r_rdata_2P;

wire                     re_int;

generate
    if (FAMILY == "TRION") begin
        if (RDATA_WDATA_RATIO == "ONE") begin
            always @ (posedge wclk) begin
                if (we)
                    ram[waddr] <= wdata;
            end
    
            always @ (posedge rclk) begin
                if (re_int) begin
                    r_rdata_1P <= ram[raddr];
                end
                r_rdata_2P <= r_rdata_1P;
            end
        end
        
        else if (RDATA_WDATA_RATIO == "ONE_THIRTYTWO" || RDATA_WDATA_RATIO == "ONE_SIXTEENTH" || RDATA_WDATA_RATIO == "ONE_EIGHTH" || RDATA_WDATA_RATIO == "ONE_FOURTH"  || RDATA_WDATA_RATIO == "ONE_HALF" ) begin
            if (ENDIANESS == 0) begin 
            	integer i;
            	always @ (posedge wclk) begin
                	for (i=0; i<RAM_MUX_RATIO; i=i+1) begin
                    	if (we) begin
                            ram[{waddr,LSB_WIDTH'(RAM_MUX_RATIO-1-i)}] <= wdata[((WDATA_WIDTH/RAM_MUX_RATIO)*i) +: WDATA_WIDTH/RAM_MUX_RATIO];
                        end
                    end
                end
                always @ (posedge rclk) begin 
                	if (re_int) begin
                		r_rdata_1P <= ram[raddr];
                    end
                		r_rdata_2P <= r_rdata_1P;
                end
            end
            else begin //endianess == 1
            	integer i;
            	always @ (posedge wclk) begin
            		for (i=0; i<RAM_MUX_RATIO; i=i+1) begin
                    	if (we) begin
                            ram[{waddr,LSB_WIDTH'(i)}] <= wdata[((WDATA_WIDTH/RAM_MUX_RATIO)*i) +: WDATA_WIDTH/RAM_MUX_RATIO];
                        end
                    end
                end
                always @ (posedge rclk) begin 
                	if (re_int) begin
                		r_rdata_1P <= ram[raddr];
                	end
                		r_rdata_2P <= r_rdata_1P;
                end
            end
        end
        
        else if (RDATA_WDATA_RATIO == "TWO_TIMES" || RDATA_WDATA_RATIO == "FOUR_TIMES"  || RDATA_WDATA_RATIO == "EIGHT_TIMES"  || RDATA_WDATA_RATIO == "SIXTEEN_TIMES"  ||RDATA_WDATA_RATIO == "THIRTYTWO_TIMES" ) begin
            //integer i;
        	if (ENDIANESS == 0) begin
        		always @ (posedge wclk) begin
        			if (we)
        				ram[waddr] <= wdata;
        		end
        		integer i;
        		always @ (posedge rclk) begin
        			for (i=0; i<RAM_MUX_RATIO; i=i+1) begin
                    	if (re_int) begin
                    		r_rdata_1P[((RDATA_WIDTH/RAM_MUX_RATIO)*i) +: RDATA_WIDTH/RAM_MUX_RATIO] <= ram[{raddr,LSB_WIDTH'(RAM_MUX_RATIO-1-i)}];
                    	end
                        	r_rdata_2P <= r_rdata_1P;
                    end
                end 
            end
            else begin //endianess == 1
            	always @ (posedge wclk) begin
        			if (we)
        				ram[waddr] <= wdata;
        		end
        		integer i;
        		always @ (posedge rclk) begin
        			for (i=0; i<RAM_MUX_RATIO; i=i+1) begin
                    	if (re_int) begin
                    		r_rdata_1P[((RDATA_WIDTH/RAM_MUX_RATIO)*i) +: RDATA_WIDTH/RAM_MUX_RATIO] <= ram[{raddr,LSB_WIDTH'(i)}];
                    	end
                        	r_rdata_2P <= r_rdata_1P;
                    end
                end
            end
        end
        if (OUTPUT_REG) begin
            assign re_int = re;
            assign rdata  = r_rdata_2P;            
        end
        else begin
            assign re_int = re;
            assign rdata  = r_rdata_1P;
        end
    end
    else begin
        if (RDATA_WDATA_RATIO == "ONE") begin
            always @ (posedge wclk) begin
                if (we)
                    ram[waddr] <= wdata;
            end
    
            always @ (posedge rclk) begin
                if (re_int) begin
                    r_rdata_1P <= ram[raddr];
                    r_rdata_2P <= r_rdata_1P;
                end
            end
        end 
        else if (RDATA_WDATA_RATIO == "ONE_THIRTYTWO" || RDATA_WDATA_RATIO == "ONE_SIXTEENTH" || RDATA_WDATA_RATIO == "ONE_EIGHTH" || RDATA_WDATA_RATIO == "ONE_FOURTH"  || RDATA_WDATA_RATIO == "ONE_HALF" ) begin
            //integer i;
            if (ENDIANESS == 0) begin
            	integer i;
            	always @ (posedge wclk) begin
            		for (i=0; i<RAM_MUX_RATIO; i=i+1) begin
                    	if (we) begin
                            	ram[{waddr,LSB_WIDTH'(RAM_MUX_RATIO-1-i)}] <= wdata[((WDATA_WIDTH/RAM_MUX_RATIO)*i) +: WDATA_WIDTH/RAM_MUX_RATIO];
                        end
                    end
                 end
               	always @ (posedge rclk) begin 
               		if (re_int) begin
               			r_rdata_1P <= ram[raddr];
               			r_rdata_2P <= r_rdata_1P;
               		end
               	end
            end
            
            else begin //endianess == 1
            	integer i;
            	always @ (posedge wclk) begin
            		for (i=0; i<RAM_MUX_RATIO; i=i+1) begin
                    	if (we) begin
                            	ram[{waddr,LSB_WIDTH'(i)}] <= wdata[((WDATA_WIDTH/RAM_MUX_RATIO)*i) +: WDATA_WIDTH/RAM_MUX_RATIO];
                        end
                    end
                 end
               	always @ (posedge rclk) begin 
               		if (re_int) begin
               			r_rdata_1P <= ram[raddr];
               			r_rdata_2P <= r_rdata_1P;
               		end
               	end
            end
        end
        else if (RDATA_WDATA_RATIO == "TWO_TIMES" || RDATA_WDATA_RATIO == "FOUR_TIMES"  || RDATA_WDATA_RATIO == "EIGHT_TIMES"  || RDATA_WDATA_RATIO == "SIXTEEN_TIMES"  || RDATA_WDATA_RATIO == "THIRTYTWO_TIMES" ) begin
        	//integer i;
        	if (ENDIANESS == 0) begin
        		always @ (posedge wclk) begin
        			if (we)
        				ram[waddr] <= wdata;
        		end
        		integer i;
            	always @ (posedge rclk) begin
            		for (i=0; i<RAM_MUX_RATIO; i=i+1) begin
                    	if (re_int) begin
                    		r_rdata_1P[((RDATA_WIDTH/RAM_MUX_RATIO)*i) +: RDATA_WIDTH/RAM_MUX_RATIO] <= ram[{raddr,LSB_WIDTH'(RAM_MUX_RATIO-1-i)}];
                    		r_rdata_2P                                                               <= r_rdata_1P;
                    	end
                    end
                end 
            end
            
            else begin //endianess ==1
        		always @ (posedge wclk) begin
        			if (we)
        				ram[waddr] <= wdata;
        		end
        		integer i;
            	always @ (posedge rclk) begin
            		for (i=0; i<RAM_MUX_RATIO; i=i+1) begin
                    	if (re_int) begin
                    		r_rdata_1P[((RDATA_WIDTH/RAM_MUX_RATIO)*i) +: RDATA_WIDTH/RAM_MUX_RATIO] <= ram[{raddr,LSB_WIDTH'(i)}];
                    		r_rdata_2P                                                               <= r_rdata_1P;
                    	end
                    end
                end 
            end
        end
        // NIC
        //if (MODE == "STANDARD") begin     
        //    if (OUTPUT_REG) begin
        //        reg re_r;
        //        always @ (posedge rclk) begin
        //            re_r <= re;
        //        end
        //        assign re_int = re | re_r;        
        //        assign rdata  = r_rdata_2P;            
        //    end
        //    else begin
        //        assign re_int = re;
        //        assign rdata  = r_rdata_1P;
        //    end
        //end
        //else begin
        //    assign re_int = re;
        //    assign rdata  = r_rdata_1P;
        //end    
        if (OUTPUT_REG) begin
            reg re_r;
            always @ (posedge rclk) begin
                re_r <= re;
            end
            assign re_int = re | re_r;        
            assign rdata  = r_rdata_2P;            
        end
        else begin
            assign re_int = re;
            assign rdata  = r_rdata_1P;
        end    
    end
endgenerate

endmodule

////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2013-2021 Efinix Inc. All rights reserved.              
//
// This   document  contains  proprietary information  which   is        
// protected by  copyright. All rights  are reserved.  This notice       
// refers to original work by Efinix, Inc. which may be derivitive       
// of other work distributed under license of the authors.  In the       
// case of derivative work, nothing in this notice overrides the         
// original author's license agreement.  Where applicable, the           
// original license agreement is included in it's original               
// unmodified form immediately below this header.                        
//
// WARRANTY DISCLAIMER.                                                  
//     THE  DESIGN, CODE, OR INFORMATION ARE PROVIDED “AS IS” AND        
//     EFINIX MAKES NO WARRANTIES, EXPRESS OR IMPLIED WITH               
//     RESPECT THERETO, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES,  
//     INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF          
//     MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR    
//     PURPOSE.  SOME STATES DO NOT ALLOW EXCLUSIONS OF AN IMPLIED       
//     WARRANTY, SO THIS DISCLAIMER MAY NOT APPLY TO LICENSEE.           
//
// LIMITATION OF LIABILITY.                                              
//     NOTWITHSTANDING ANYTHING TO THE CONTRARY, EXCEPT FOR BODILY       
//     INJURY, EFINIX SHALL NOT BE LIABLE WITH RESPECT TO ANY SUBJECT    
//     MATTER OF THIS AGREEMENT UNDER TORT, CONTRACT, STRICT LIABILITY   
//     OR ANY OTHER LEGAL OR EQUITABLE THEORY (I) FOR ANY INDIRECT,      
//     SPECIAL, INCIDENTAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES OF ANY    
//     CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF      
//     GOODWILL, DATA OR PROFIT, WORK STOPPAGE, OR COMPUTER FAILURE OR   
//     MALFUNCTION, OR IN ANY EVENT (II) FOR ANY AMOUNT IN EXCESS, IN    
//     THE AGGREGATE, OF THE FEE PAID BY LICENSEE TO EFINIX HEREUNDER    
//     (OR, IF THE FEE HAS BEEN WAIVED, $100), EVEN IF EFINIX SHALL HAVE 
//     BEEN INFORMED OF THE POSSIBILITY OF SUCH DAMAGES.  SOME STATES DO 
//     NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL OR            
//     CONSEQUENTIAL DAMAGES, SO THIS LIMITATION AND EXCLUSION MAY NOT   
//     APPLY TO LICENSEE.
//
////////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////////
//           _____       
//          / _______    Copyright (C) 2013-2020 Efinix Inc. All rights reserved.
//         / /       \   
//        / /  ..    /   gray2bin.v
//       / / .'     /    
//    __/ /.'      /     Description:
//   __   \       /      Gray to Binary Encoding Convertor
//  /_/ /\ \_____/ /     
// ____/  \_______/      
//
// *******************************
// Revisions:
// 1.0 Initial rev
//
// *******************************

`resetall
`timescale 1ns/1ps

module `IP_MODULE_NAME(efx_fifo_gray2bin)
#(parameter WIDTH=5)
(// outputs
 output wire [WIDTH-1:0] bin_o,
 // input
 input [WIDTH-1:0] gray_i);

//---------------------------------------------------------------------
// Recursive Module
// Description: reduction xor
generate
   if (WIDTH > 1) begin
      wire [1:0] bin_1;
      assign bin_1 = {gray_i[WIDTH-1], gray_i[WIDTH-1]^gray_i[WIDTH-2]};
      if (WIDTH == 2) begin
	 assign bin_o = bin_1;
      end
      else begin
	 assign bin_o[WIDTH-1] = bin_1[1];
	 `IP_MODULE_NAME(efx_fifo_gray2bin) #(.WIDTH(WIDTH-1)) u_gray2bin (.bin_o(bin_o[WIDTH-2:0]), .gray_i({bin_1[0], gray_i[WIDTH-3:0]}));
      end
   end
   else /* if (WIDTH == 1) */
     assign bin_o = gray_i;
endgenerate
   
endmodule 

////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2013-2020 Efinix Inc. All rights reserved.              
//
// This   document  contains  proprietary information  which   is        
// protected by  copyright. All rights  are reserved.  This notice       
// refers to original work by Efinix, Inc. which may be derivitive       
// of other work distributed under license of the authors.  In the       
// case of derivative work, nothing in this notice overrides the         
// original author's license agreement.  Where applicable, the           
// original license agreement is included in it's original               
// unmodified form immediately below this header.                        
//
// WARRANTY DISCLAIMER.                                                  
//     THE  DESIGN, CODE, OR INFORMATION ARE PROVIDED “AS IS” AND        
//     EFINIX MAKES NO WARRANTIES, EXPRESS OR IMPLIED WITH               
//     RESPECT THERETO, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES,  
//     INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF          
//     MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR    
//     PURPOSE.  SOME STATES DO NOT ALLOW EXCLUSIONS OF AN IMPLIED       
//     WARRANTY, SO THIS DISCLAIMER MAY NOT APPLY TO LICENSEE.           
//
// LIMITATION OF LIABILITY.                                              
//     NOTWITHSTANDING ANYTHING TO THE CONTRARY, EXCEPT FOR BODILY       
//     INJURY, EFINIX SHALL NOT BE LIABLE WITH RESPECT TO ANY SUBJECT    
//     MATTER OF THIS AGREEMENT UNDER TORT, CONTRACT, STRICT LIABILITY   
//     OR ANY OTHER LEGAL OR EQUITABLE THEORY (I) FOR ANY INDIRECT,      
//     SPECIAL, INCIDENTAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES OF ANY    
//     CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF      
//     GOODWILL, DATA OR PROFIT, WORK STOPPAGE, OR COMPUTER FAILURE OR   
//     MALFUNCTION, OR IN ANY EVENT (II) FOR ANY AMOUNT IN EXCESS, IN    
//     THE AGGREGATE, OF THE FEE PAID BY LICENSEE TO EFINIX HEREUNDER    
//     (OR, IF THE FEE HAS BEEN WAIVED, $100), EVEN IF EFINIX SHALL HAVE 
//     BEEN INFORMED OF THE POSSIBILITY OF SUCH DAMAGES.  SOME STATES DO 
//     NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL OR            
//     CONSEQUENTIAL DAMAGES, SO THIS LIMITATION AND EXCLUSION MAY NOT   
//     APPLY TO LICENSEE.
//
////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////
//           _____       
//          / _______    Copyright (C) 2013-2020 Efinix Inc. All rights reserved.
//         / /       \   
//        / /  ..    /   pipe_reg.v
//       / / .'     /    
//    __/ /.'      /     Description:
//   __   \       /      Parallel Pipelining Shift Register
//  /_/ /\ \_____/ /     
// ____/  \_______/      
//
// *******************************
// Revisions:
// 1.0 Initial rev
//
// *******************************

module `IP_MODULE_NAME(efx_fifo_datasync) #(
    parameter STAGE = 32,
    parameter WIDTH = 4
) (
 input  wire             clk_i,
 input  wire [WIDTH-1:0] d_i,
 output wire [WIDTH-1:0] d_o
);

(* async_reg = "true" *) reg [WIDTH-1:0] pipe_reg [STAGE-1:0];
integer i;

always @(posedge clk_i) begin
  for (i=STAGE-1; i>0; i = i - 1) begin
    pipe_reg[i] <= pipe_reg[i-1];
  end
  pipe_reg[0] <= d_i;
end
assign d_o = pipe_reg[STAGE-1];
   

endmodule

////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2013-2020 Efinix Inc. All rights reserved.              
//
// This   document  contains  proprietary information  which   is        
// protected by  copyright. All rights  are reserved.  This notice       
// refers to original work by Efinix, Inc. which may be derivitive       
// of other work distributed under license of the authors.  In the       
// case of derivative work, nothing in this notice overrides the         
// original author's license agreement.  Where applicable, the           
// original license agreement is included in it's original               
// unmodified form immediately below this header.                        
//
// WARRANTY DISCLAIMER.                                                  
//     THE  DESIGN, CODE, OR INFORMATION ARE PROVIDED “AS IS” AND        
//     EFINIX MAKES NO WARRANTIES, EXPRESS OR IMPLIED WITH               
//     RESPECT THERETO, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES,  
//     INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF          
//     MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR    
//     PURPOSE.  SOME STATES DO NOT ALLOW EXCLUSIONS OF AN IMPLIED       
//     WARRANTY, SO THIS DISCLAIMER MAY NOT APPLY TO LICENSEE.           
//
// LIMITATION OF LIABILITY.                                              
//     NOTWITHSTANDING ANYTHING TO THE CONTRARY, EXCEPT FOR BODILY       
//     INJURY, EFINIX SHALL NOT BE LIABLE WITH RESPECT TO ANY SUBJECT    
//     MATTER OF THIS AGREEMENT UNDER TORT, CONTRACT, STRICT LIABILITY   
//     OR ANY OTHER LEGAL OR EQUITABLE THEORY (I) FOR ANY INDIRECT,      
//     SPECIAL, INCIDENTAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES OF ANY    
//     CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF      
//     GOODWILL, DATA OR PROFIT, WORK STOPPAGE, OR COMPUTER FAILURE OR   
//     MALFUNCTION, OR IN ANY EVENT (II) FOR ANY AMOUNT IN EXCESS, IN    
//     THE AGGREGATE, OF THE FEE PAID BY LICENSEE TO EFINIX HEREUNDER    
//     (OR, IF THE FEE HAS BEEN WAIVED, $100), EVEN IF EFINIX SHALL HAVE 
//     BEEN INFORMED OF THE POSSIBILITY OF SUCH DAMAGES.  SOME STATES DO 
//     NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL OR            
//     CONSEQUENTIAL DAMAGES, SO THIS LIMITATION AND EXCLUSION MAY NOT   
//     APPLY TO LICENSEE.
//
////////////////////////////////////////////////////////////////////////////////



// synopsys translate_off
`timescale 1 ns / 1 ps													
// synopsys translate_on

module `IP_MODULE_NAME(efx_resetsync) #(
    parameter ASYNC_STAGE = 2,
    parameter ACTIVE_LOW = 1
) (
    input  wire             clk,
    input  wire             reset,
    output wire             d_o
);


generate
   if (ACTIVE_LOW == 1) begin: active_low
      `IP_MODULE_NAME(efx_asyncreg) #(
         .WIDTH      (1),
         .ACTIVE_LOW (1),
         .RST_VALUE  (0)
      ) efx_resetsync_active_low (
         .clk     (clk),
         .reset_n (reset),
         .d_i     (1'b1),
         .d_o     (d_o)
      );
   end
   else begin: active_high
      `IP_MODULE_NAME(efx_asyncreg) #(
         .WIDTH      (1),
         .ACTIVE_LOW (0),
         .RST_VALUE  (1)
      ) efx_resetsync_active_high (
         .clk     (clk),
         .reset_n (reset),
         .d_i     (1'b0),
         .d_o     (d_o)
      );
   end
endgenerate

endmodule



// synopsys translate_off
`timescale 1 ns / 1 ps													
// synopsys translate_on

module `IP_MODULE_NAME(efx_asyncreg) #(
    parameter ASYNC_STAGE = 2,
    parameter WIDTH = 4,
    parameter ACTIVE_LOW = 1, // 0 - Active high reset, 1 - Active low reset
    parameter RST_VALUE = 0,
    parameter OFF_ASSERTION = 0 // 1 = Turn off PULSE_WIDTH_CHK assertion for a particular instance 
) (
    input  wire             clk,
    input  wire             reset_n,
    input  wire [WIDTH-1:0] d_i,
    output wire [WIDTH-1:0] d_o
);










`pragma protect begin_protected
`pragma protect version = 1
`pragma protect author = "author-a" , author_info = "author-a-details"
`pragma protect encrypt_agent = "QuestaSim" , encrypt_agent_info = "2023.4"
`pragma protect key_keyowner = "Efinix Inc." , key_keyname = "EFX_K01"
`pragma protect key_method = "rsa"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 256 )
`pragma protect key_block
IjzmeF2ACtI8q/MHPcSQakfCyuQSUgg747Z3U+BWZdCStFbqF/Rhg0VPl8JT+91V
o/8Ohsiw6GnpSIX69XazqGYmhEjb+W7W2ngBYentEXdSyzUYvEbr8i71cL04f1fE
El78uYgSvjFwoDyocXOVYk8JA0v7y6WnabkL02lAqASKGQK55nzfKeUVbJHKHjAY
kIT3Nf7JWK2NVVymI1Zs5QttwrNgKBSqoiPvmy4+16bTQMx4R205Bb4rT1MqSqIc
/5U5/Z1e1tZzOqoEyhfcMMKW0emdBIdByNvteK05ZATt11Uzj2M/Vn1r9KmYd0h1
uYJaS5tuGEuFInBHa7oO8g==
`pragma protect key_keyowner = "Cadence Design Systems." , key_keyname = "CDS_RSA_KEY_VER_2"
`pragma protect key_method = "rsa"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 256 )
`pragma protect key_block
ABJo/BvEH9XbZrt+xPOQ2C7yeLcnebDlRELbHyCdXeeNkZRVZ9m0ie+1HufS/I+3
fC63lnVTenVdf9s4tm1RLd5VBkmFb37ikgaESy2aRKWsdLG6x2OyuODoMDRCjYUa
rxhnwLWh5E55yR3XVZgM2k7/NPP2cTL7iOSCjH4No38siNjs4Fapyc4FFq0TOsQq
PMqsZ5jgmM+ZT8cil0wMt5tpdEOwvchbe1GcZLIhcIFLD/Gb2XtP0Q0QkOlNzuiL
DNyobLTjDkV5si+/23Ng2E7tDq+SX+vJP4ciI63kXtsmQdn1ff2Y64ibNXJtpu/w
K3OoKmk3zFeArSsql8B4/Q==
`pragma protect key_keyowner = "Synopsys" , key_keyname = "SNPS-VCS-RSA-2"
`pragma protect key_method = "rsa"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 128 )
`pragma protect key_block
RAoMYYsrw2j05cvQ8NR0lCh+Ia/OGVfdwZqq0pwIkgDzO3Z7ol96oQmQzFfIQY/M
GzEOFdYJTfjnxPvhSPxT1tpq2Fgx6PbC2FMWFtN6/TrG/s01ifIWIZ9Wrfo8Q01l
6XTAESHR1htrOOx6AiDHAQLOlBb0zgfZjayGJBRX7FI=
`pragma protect key_keyowner = "Aldec" , key_keyname = "ALDEC15_001"
`pragma protect key_method = "rsa"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 256 )
`pragma protect key_block
YclPuIbYLW/ftZYybucr9ooblGFkJDcdUWf6kCJBGKpIRjItUB3LdSwcREekRWqf
RGiSRFoyrOTiScT06zZ4fkm+PEKj8O3RU1VMMzDjuEUqkAEELJHNOH71tCSC6MWk
1dop7MZy8BSXhzg3W3RXIA8IGSJRDibliv+SjkbUzg/WceDI176fJmUwGUji93Tw
Zu2vRjA/RTi3ZMzS/2Z9YE156hpipJ/Cu6ca8V3y5Kt6DX4fcCS09xESr6soT5Oz
eKRExN7wu8dvYMUuu1YgCVVR47BBDQi3wdZHqlq1PLaycnNOwBPLOAzA19Hefh/0
2HflB1HYKxojQCcZU7qUgQ==
`pragma protect key_keyowner = "Siemens" , key_keyname = "SIEMENS-VERIF-SIM-RSA-2"
`pragma protect key_method = "rsa"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 256 )
`pragma protect key_block
fMvC6d2jTMqMqGFzPCPWt6pV9wRUCG4/taH3Nfn7RcekdiLyXQEQgm1SN+X+hkbx
Pu7552vaw2ez4j3zrTk2vRPnDAsxY8GidEnkJcULi8kiia9Xy/ePFLxOJHHigkiB
rU7uwrFblcYYBRwQjhMhJDowyR9HVAonxhOWVIlYagtABxLYlNdDEn+N4yPLVCsr
XUWy1E2L5GUFFNQffENN0iyUaKdWAKGIqgIZK1sB3tVOPVsULetSoyzRErWPNZQD
e5jbBBNZGyQQWgOJkOfy280ekoUUEZajqtB1jDvE3k8kbo4rzvr7yTkhSzLqjGod
B2Zpo2FQ//YDRSAaEa9ksQ==
`pragma protect key_keyowner = "Mentor Graphics Corporation" , key_keyname = "MGC-VERIF-SIM-RSA-2"
`pragma protect key_method = "rsa"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 256 )
`pragma protect key_block
TcmE9lQROafuvxGWP3fMVxDoeaiMX6ALoT3detg/qWZ36+yPTc/t8N7/DtSx17Ze
vr6iBb+ge3aAzWAq2QHyVfgVV15dvW/HsOXXTh7UqExiO7Dxa6nHXuAhYMON6NP2
ihfIRSvdnrL2ufvg7A2rCHGAqnr6cVnRLfhNJxtA1lloQbJEtlf/CWNblDxEfyw2
06l3l8pp1rS0E4tMqagmOr+yhNSpcS9vQswFltqroh6kNIE64zKri96HKkRFLNlP
fpsN7plEpLS54SxIMmh8Op+w0a/jXVOxxD+FLepsZWfGiNksENgu2Xo6TvZIQUUN
ZoPzFCMjGk5ZmMyIlytNCw==
`pragma protect data_method = "aes256-cbc"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 4288 )
`pragma protect data_block
[encoded data, 5785 characters]
Ei7EaFpheCmlTJyxUg8TdA==
`pragma protect end_protected


/////////////////////////////////////////////////////////////////////////////
//           _____       
//          / _______    Copyright (C) 2013-2021 Efinix Inc. All rights reserved.
//         / /       \   
//        / /  ..    /   simple_dual_port_ram_fifo.v
//       / / .'     /    
//    __/ /.'      /     Description:
//   __   \       /      EFX FIFO
//  /_/ /\ \_____/ /     
// ____/  \_______/      
//
// *******************************
// Revisions:
//
// *******************************

module `IP_MODULE_NAME(efx_fifo_ctl) # (
    parameter SYNC_CLK           = 1,
    parameter SYNC_STAGE         = 2,
    parameter MODE               = "STANDARD",
    parameter WR_DEPTH           = 512,
    parameter WADDR_WIDTH        = 9,
    parameter RADDR_WIDTH        = 9,
    parameter ASYM_WIDTH_RATIO   = 4,
    parameter RAM_MUX_RATIO      = 1,
    parameter PIPELINE_REG       = 1,
    parameter ALMOST_FLAG        = 1,
    parameter PROGRAMMABLE_FULL  = "NONE",
    parameter PROG_FULL_ASSERT   = 0,
    parameter PROG_FULL_NEGATE   = 0,
    parameter PROGRAMMABLE_EMPTY = "NONE",
    parameter PROG_EMPTY_ASSERT  = 0,
    parameter PROG_EMPTY_NEGATE  = 0,
    parameter OUTPUT_REG         = 0,
    parameter HANDSHAKE_FLAG     = 1, 
    parameter OVERFLOW_PROTECT   = 0,
    parameter UNDERFLOW_PROTECT  = 0
)(
    input   wire                   wr_rst,
    input   wire                   rd_rst,
    input   wire                   wclk,
    input   wire                   rclk,
    input   wire                   we,
    input   wire                   re,
    output  wire                   wr_full,
    output  reg                    wr_ack,
    output  wire                   wr_almost_full,
    output  wire                   rd_empty,
    output  wire                   rd_almost_empty,
    output  wire                   wr_prog_full,
    output  wire                   rd_prog_empty,
    output  wire                   wr_en_int,
    output  wire                   rd_en_int,
    output  wire [WADDR_WIDTH-1:0] waddr,
    output  wire [RADDR_WIDTH-1:0] raddr,
    output  wire [WADDR_WIDTH:0]   wr_datacount,
    output  wire [RADDR_WIDTH:0]   rd_datacount,
    output  wire                   rd_vld,
    output  reg                    wr_overflow,
    output  reg                    rd_underflow
);

reg  [WADDR_WIDTH:0] waddr_cntr;
reg  [WADDR_WIDTH:0] waddr_cntr_r;
reg  [RADDR_WIDTH:0] raddr_cntr;
reg                  rd_valid;

wire [WADDR_WIDTH:0] waddr_int;
wire [RADDR_WIDTH:0] raddr_int;
wire                 rd_empty_int;
wire [WADDR_WIDTH:0] wr_datacount_int;
wire [RADDR_WIDTH:0] rd_datacount_int;

assign waddr     = waddr_cntr[WADDR_WIDTH-1:0];
// NIC
wire [RADDR_WIDTH:0] ram_raddr;
assign raddr     = (MODE == "FWFT") ? ram_raddr[RADDR_WIDTH-1:0] : raddr_cntr[RADDR_WIDTH-1:0];
//assign raddr     = raddr_cntr[RADDR_WIDTH-1:0];
//assign wr_en_int = we & ~wr_full;
assign wr_en_int = OVERFLOW_PROTECT ? we & ~wr_full : we;

assign wr_datacount  = wr_datacount_int;
assign rd_datacount  = ASYM_WIDTH_RATIO == 4 && SYNC_CLK ? wr_datacount_int : rd_datacount_int;


generate
    if (MODE == "FWFT") begin    
        // NIC
        //assign rd_en_int     = (~rd_empty_int & rd_empty) | (re & ~rd_empty_int);
        //assign rd_empty      = rd_empty_fwft;

        assign rd_en_int     = 1'b1;
        //assign rd_empty      = rd_empty_int;
        
        //always @ (posedge rclk or posedge rd_rst) begin
        //    if (rd_rst) begin
        //        init_set <= 1'b1;
        //    end
        //    else if (~init_set & rd_empty) begin
        //        init_set <= 1'b1;            
        //    end
        //    else if (~rd_empty_int) begin
        //        init_set <= 1'b0;            
        //    end
        //    else if (rd_empty) begin
        //        init_set <= 1'b1;            
        //    end
        //end
        // NIC 
        //always @ (posedge rclk or posedge rd_rst) begin
        //    if (rd_rst) begin
        //        rd_empty_fwft <= 1'b1;
        //    end
        //    else if (rd_en_int) begin
        //        rd_empty_fwft <= 1'b0;            
        //    end
        //    else if (re) begin
        //        rd_empty_fwft <= 1'b1;            
        //    end
        //end          
        
        //if (FAMILY == "TRION") begin
        if (OUTPUT_REG) begin
            always @ (posedge rclk or posedge rd_rst) begin
                if (rd_rst) begin
                    rd_valid <= 1'b0;
                end
                else begin
                    rd_valid <= ~rd_empty;
                end
            end
            assign rd_vld = rd_valid;                
        end    
        else begin
            assign rd_vld = ~rd_empty;                
        end
        
        assign rd_empty = rd_empty_int;
    end
    else begin
        assign rd_en_int     = UNDERFLOW_PROTECT ? re & ~rd_empty_int : re;
        assign rd_empty      = rd_empty_int;
        
        if (OUTPUT_REG) begin
            reg rd_valid_r;
            always @ (posedge rclk or posedge rd_rst) begin
                if (rd_rst) begin
                    rd_valid_r <= 'h0;
                    rd_valid   <= 'h0;
                end
                else begin
                    {rd_valid,rd_valid_r} <= {rd_valid_r,rd_en_int};
                end
            end
            assign rd_vld = rd_valid;            
        end
        else begin
            always @ (posedge rclk or posedge rd_rst) begin
                if (rd_rst) begin
                    rd_valid  <= 'h0;
                end
                else begin
                    rd_valid <= rd_en_int;
                end
            end
            assign rd_vld = rd_valid;
        end
    end
    
    if (ALMOST_FLAG) begin
        assign wr_almost_full   = wr_datacount >= WR_DEPTH-1;
        assign rd_almost_empty  = rd_datacount <= 'd1;
    end
    else begin
        assign wr_almost_full   = 1'b0;
        assign rd_almost_empty  = 1'b0;        
    end
    
    if (PROGRAMMABLE_FULL == "STATIC_SINGLE") begin
        reg    wr_prog_full_int;
        assign wr_prog_full  = wr_datacount >= PROG_FULL_ASSERT;
        
        always @ (posedge wclk or posedge wr_rst) begin
            if (wr_rst) begin
                wr_prog_full_int  <= 1'b0;
            end
            else begin
                wr_prog_full_int  <= wr_prog_full;
            end
        end  
    end
    else if (PROGRAMMABLE_FULL == "STATIC_DUAL") begin
        reg    wr_prog_full_int;
        assign wr_prog_full  = wr_prog_full_int ? wr_datacount >= PROG_FULL_NEGATE : wr_datacount >= PROG_FULL_ASSERT;   

        always @ (posedge wclk or posedge wr_rst) begin
            if (wr_rst) begin
                wr_prog_full_int  <= 1'b0;
            end
            else begin
                wr_prog_full_int  <= wr_prog_full;
            end
        end              
    end
    else begin
        assign wr_prog_full  = 1'b0; 
    end
        
    if (PROGRAMMABLE_EMPTY == "STATIC_SINGLE") begin
        reg    rd_prog_empty_int;
        assign rd_prog_empty  = rd_datacount <= PROG_EMPTY_ASSERT;
            
        always @ (posedge rclk or posedge rd_rst) begin
            if (rd_rst) begin
                rd_prog_empty_int <= 1'b1;
            end
            else begin
                rd_prog_empty_int <= rd_prog_empty;
            end
        end
    end
    else if (PROGRAMMABLE_EMPTY == "STATIC_DUAL") begin
        reg    rd_prog_empty_int;
        assign rd_prog_empty = rd_prog_empty_int ? (rd_datacount <= PROG_EMPTY_NEGATE) : (rd_datacount <= PROG_EMPTY_ASSERT);
            
        always @ (posedge rclk or posedge rd_rst) begin
            if (rd_rst) begin
                rd_prog_empty_int <= 1'b1;
            end
            else begin
                rd_prog_empty_int <= rd_prog_empty;
            end
        end  
    end
    else begin
        assign rd_prog_empty  = 1'b0; 
    end
    
    if (HANDSHAKE_FLAG) begin
        always @ (posedge wclk or posedge wr_rst) begin
            if (wr_rst) begin
                wr_ack <= 1'b0;
            end
            else begin
                // NIC
                //wr_ack <= wr_en_int & ~wr_overflow;
                wr_ack <= OVERFLOW_PROTECT ? wr_en_int & ~wr_overflow : wr_en_int;
            end
        end
    end

    if (OVERFLOW_PROTECT) begin
        always @ (posedge wclk or posedge wr_rst) begin
            if (wr_rst) begin
                wr_overflow <= 1'b0;
            end
            else if (we && wr_full) begin
                wr_overflow <= 1'b1;
            end
            else begin
                wr_overflow <= 1'b0;            
            end
        end
    end
    else if (HANDSHAKE_FLAG) begin
        always @ (posedge wclk or posedge wr_rst) begin
            if (wr_rst) begin
                wr_overflow <= 1'b0;
            end
            else begin
                wr_overflow <= we && wr_full ? 1'b1 : wr_overflow;
            end
        end
    end

    if (UNDERFLOW_PROTECT) begin     
        always @ (posedge rclk or posedge rd_rst) begin
            if (rd_rst) begin
                rd_underflow <= 1'b0;
            end
            else if (re && rd_empty) begin
                rd_underflow <= 1'b1;
            end
            else begin
                rd_underflow <= 1'b0;            
            end
        end
    end
    else if (HANDSHAKE_FLAG) begin
        always @ (posedge rclk or posedge rd_rst) begin
            if (rd_rst) begin
                rd_underflow <= 1'b0;
            end
            else begin
                rd_underflow <= re && rd_empty ? 1'b1 : rd_underflow;
            end
        end
    end
    
    localparam RATIO_WIDTH = (RADDR_WIDTH >= WADDR_WIDTH)? RADDR_WIDTH - WADDR_WIDTH : WADDR_WIDTH - RADDR_WIDTH;
    
    if (ASYM_WIDTH_RATIO < 4) begin
        assign wr_full          = (waddr_cntr[WADDR_WIDTH]^raddr_int[RADDR_WIDTH]) & (waddr_cntr[WADDR_WIDTH-1:0] == raddr_int[RADDR_WIDTH-1:RATIO_WIDTH]);
        assign rd_empty_int     = waddr_int[WADDR_WIDTH:0] == raddr_cntr[RADDR_WIDTH:RATIO_WIDTH];
        assign wr_datacount_int = waddr_cntr - (raddr_int/RAM_MUX_RATIO);
        assign rd_datacount_int = (waddr_int*RAM_MUX_RATIO)-raddr_cntr;
    end
    // NIC
    else if (ASYM_WIDTH_RATIO == 4) begin
        assign wr_full          = (waddr_cntr[WADDR_WIDTH]^raddr_int[RADDR_WIDTH]) & (waddr_cntr[WADDR_WIDTH-1:0] == raddr_int[RADDR_WIDTH-1:0]);
        assign rd_empty_int     = waddr_int[WADDR_WIDTH:0] == raddr_cntr[RADDR_WIDTH:0];
        assign wr_datacount_int = waddr_cntr - raddr_int;
        assign rd_datacount_int = waddr_int - raddr_cntr;
    end
    else begin
        assign wr_full          = (waddr_cntr[WADDR_WIDTH]^raddr_int[RADDR_WIDTH]) & (waddr_cntr[WADDR_WIDTH-1:RATIO_WIDTH] == raddr_int[RADDR_WIDTH-1:0]);
        // NIC
        //assign rd_empty_int     = (waddr_int- raddr_cntr*RAM_MUX_RATIO) < RAM_MUX_RATIO;
        assign rd_empty_int     = waddr_int[WADDR_WIDTH:RATIO_WIDTH] == raddr_cntr[RADDR_WIDTH:0];
        assign wr_datacount_int = waddr_cntr - (raddr_int*RAM_MUX_RATIO);
        assign rd_datacount_int = (waddr_int/RAM_MUX_RATIO)-raddr_cntr;
    end
endgenerate

always @ (posedge wclk or posedge wr_rst) begin
    if (wr_rst) begin
        waddr_cntr   <= 'h0;
    end
    else if (wr_en_int) begin
        waddr_cntr   <= waddr_cntr + 1'b1;
    end
end

always @ (posedge wclk or posedge wr_rst) begin
    if (wr_rst) begin
        waddr_cntr_r  <= 'h0;
    end
    else begin
        waddr_cntr_r  <= waddr_cntr;
    end
end

always @ (posedge rclk or posedge rd_rst) begin
    if (rd_rst) begin
        raddr_cntr   <= 'h0;
    end
    // NIC
    //else if (rd_en_int) begin
    else begin
        //raddr_cntr   <= raddr_cntr + 1'b1;
        //raddr_cntr   <= raddr_cntr + (re & ~rd_empty_int);
        raddr_cntr   <= ram_raddr;
    end
end
// NIC
assign ram_raddr = raddr_cntr + (UNDERFLOW_PROTECT ? re & ~rd_empty_int : re);


generate
    if (SYNC_CLK) begin : sync_clk
       if (MODE == "FWFT") begin
          assign waddr_int = waddr_cntr_r;
          assign raddr_int        = raddr_cntr;
       end
       else begin
          assign waddr_int        = waddr_cntr;
          assign raddr_int        = raddr_cntr;
       end
    end
    else begin : async_clk
        reg  [RADDR_WIDTH:0] raddr_cntr_gry_r;
        reg  [WADDR_WIDTH:0] waddr_cntr_gry_r;
        
        wire [RADDR_WIDTH:0] raddr_cntr_gry;
        wire [RADDR_WIDTH:0] raddr_cntr_gry_sync;
        wire [RADDR_WIDTH:0] raddr_cntr_sync_g2b;
        wire [WADDR_WIDTH:0] waddr_cntr_gry;
        wire [WADDR_WIDTH:0] waddr_cntr_gry_sync;
        wire [WADDR_WIDTH:0] waddr_cntr_sync_g2b;

        if (PIPELINE_REG) begin
            reg  [RADDR_WIDTH:0] raddr_cntr_sync_g2b_r;    
            reg  [WADDR_WIDTH:0] waddr_cntr_sync_g2b_r;        
        
            assign waddr_int        = waddr_cntr_sync_g2b_r;
            assign raddr_int        = raddr_cntr_sync_g2b_r;
            
            always @ (posedge wclk or posedge wr_rst) begin
                if (wr_rst) begin
                    raddr_cntr_sync_g2b_r <= 'h0;
                end
                else begin
                    raddr_cntr_sync_g2b_r <= raddr_cntr_sync_g2b;
                end
            end
            
            always @ (posedge rclk or posedge rd_rst) begin
                if (rd_rst) begin
                    waddr_cntr_sync_g2b_r <= 'h0;
                end
                else begin
                    waddr_cntr_sync_g2b_r <= waddr_cntr_sync_g2b;
                end
            end
        end
        else begin
            assign waddr_int        = waddr_cntr_sync_g2b;
            assign raddr_int        = raddr_cntr_sync_g2b;        
        end
      
        always @ (posedge rclk or posedge rd_rst) begin
            if (rd_rst) begin
                raddr_cntr_gry_r <= 'h0;
            end
            else begin
                raddr_cntr_gry_r <= raddr_cntr_gry;
            end
        end
        `IP_MODULE_NAME(efx_fifo_bin2gray) # (.WIDTH(RADDR_WIDTH+1)                                                               ) xrd2wr_bin2gray    (.bin_i(raddr_cntr), .gray_o(raddr_cntr_gry));
        `IP_MODULE_NAME(efx_asyncreg)      # (.ASYNC_STAGE(SYNC_STAGE), .WIDTH (RADDR_WIDTH+1), .ACTIVE_LOW(0), .OFF_ASSERTION (1)) xrd2wr_addr_sync   (.clk(wclk), .reset_n(wr_rst), .d_i(raddr_cntr_gry_r), .d_o(raddr_cntr_gry_sync));
        `IP_MODULE_NAME(efx_fifo_gray2bin) # (.WIDTH(RADDR_WIDTH+1)                                                               ) xrd2wr_gray2bin    (.gray_i(raddr_cntr_gry_sync), .bin_o(raddr_cntr_sync_g2b));
        
        always @ (posedge wclk or posedge wr_rst) begin
            if (wr_rst) begin
                waddr_cntr_gry_r <= 'h0;
            end
            else begin
                waddr_cntr_gry_r <= waddr_cntr_gry;
            end
        end        
        `IP_MODULE_NAME(efx_fifo_bin2gray) # (.WIDTH(WADDR_WIDTH+1)                                                               ) wr2rd_bin2gray  (.bin_i(waddr_cntr), .gray_o(waddr_cntr_gry));
        `IP_MODULE_NAME(efx_asyncreg)      # (.ASYNC_STAGE(SYNC_STAGE), .WIDTH (WADDR_WIDTH+1), .ACTIVE_LOW(0), .OFF_ASSERTION (1)) wr2rd_addr_sync (.clk(rclk), .reset_n(rd_rst), .d_i(waddr_cntr_gry_r), .d_o(waddr_cntr_gry_sync));
        `IP_MODULE_NAME(efx_fifo_gray2bin) # (.WIDTH(WADDR_WIDTH+1)                                                               ) wr2rd_gray2bin  (.gray_i(waddr_cntr_gry_sync), .bin_o(waddr_cntr_sync_g2b));        

    end
endgenerate
endmodule


////////////////////////////////////////////////////////////////////////////
//           _____       
//          / _______    Copyright (C) 2013-2020 Efinix Inc. All rights reserved.
//         / /       \   
//        / /  ..    /   bin2gray.v
//       / / .'     /    
//    __/ /.'      /     Description:
//   __   \       /      Binary to Gray Encoding Convertor
//  /_/ /\ \_____/ /     
// ____/  \_______/      
//
// *******************************
// Revisions:
// 1.0 Initial rev
//
// *******************************

`resetall
`timescale 1ns/1ps

module `IP_MODULE_NAME(efx_fifo_bin2gray)
#(parameter WIDTH=5)
(// outputs
 output wire [WIDTH-1:0] gray_o,
 // input
 input [WIDTH-1:0] bin_i
 );

//---------------------------------------------------------------------
// Function :   bit_xor
// Description: reduction xor
function bit_xor (
  input [31:0] nex_bit,
  input [31:0] curr_bit,
  input [WIDTH-1:0] xor_in);
  begin : fn_bit_xor
    bit_xor = xor_in[nex_bit] ^ xor_in[curr_bit];
  end
endfunction

// Convert Binary to Gray, bit by bit
generate 
begin
  genvar bit_idx;
  for(bit_idx=0; bit_idx<WIDTH-1; bit_idx=bit_idx+1) begin : gBinBits
    assign gray_o[bit_idx] = bit_xor(bit_idx+1, bit_idx, bin_i);
  end
  assign   gray_o[WIDTH-1] = bin_i[WIDTH-1];
end
endgenerate

endmodule 

////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2013-2020 Efinix Inc. All rights reserved.              
//
// This   document  contains  proprietary information  which   is        
// protected by  copyright. All rights  are reserved.  This notice       
// refers to original work by Efinix, Inc. which may be derivitive       
// of other work distributed under license of the authors.  In the       
// case of derivative work, nothing in this notice overrides the         
// original author's license agreement.  Where applicable, the           
// original license agreement is included in it's original               
// unmodified form immediately below this header.                        
//
// WARRANTY DISCLAIMER.                                                  
//     THE  DESIGN, CODE, OR INFORMATION ARE PROVIDED “AS IS” AND        
//     EFINIX MAKES NO WARRANTIES, EXPRESS OR IMPLIED WITH               
//     RESPECT THERETO, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES,  
//     INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF          
//     MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR    
//     PURPOSE.  SOME STATES DO NOT ALLOW EXCLUSIONS OF AN IMPLIED       
//     WARRANTY, SO THIS DISCLAIMER MAY NOT APPLY TO LICENSEE.           
//
// LIMITATION OF LIABILITY.                                              
//     NOTWITHSTANDING ANYTHING TO THE CONTRARY, EXCEPT FOR BODILY       
//     INJURY, EFINIX SHALL NOT BE LIABLE WITH RESPECT TO ANY SUBJECT    
//     MATTER OF THIS AGREEMENT UNDER TORT, CONTRACT, STRICT LIABILITY   
//     OR ANY OTHER LEGAL OR EQUITABLE THEORY (I) FOR ANY INDIRECT,      
//     SPECIAL, INCIDENTAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES OF ANY    
//     CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF      
//     GOODWILL, DATA OR PROFIT, WORK STOPPAGE, OR COMPUTER FAILURE OR   
//     MALFUNCTION, OR IN ANY EVENT (II) FOR ANY AMOUNT IN EXCESS, IN    
//     THE AGGREGATE, OF THE FEE PAID BY LICENSEE TO EFINIX HEREUNDER    
//     (OR, IF THE FEE HAS BEEN WAIVED, $100), EVEN IF EFINIX SHALL HAVE 
//     BEEN INFORMED OF THE POSSIBILITY OF SUCH DAMAGES.  SOME STATES DO 
//     NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL OR            
//     CONSEQUENTIAL DAMAGES, SO THIS LIMITATION AND EXCLUSION MAY NOT   
//     APPLY TO LICENSEE.
//
////////////////////////////////////////////////////////////////////////////////


module `IP_MODULE_NAME(mii_if) #(
   parameter NO_PREAMBLE = 0
) (
//Globle Signals
input                           tx_mac_aclk,
output  reg                     tx_mac_aclk_en,
input                           tx_reset,
output  wire                    rx_mac_aclk,
output  reg                     rx_mac_aclk_en,
input                           rx_reset,
//Configuration Signals
input           [2:0]           eth_speed,
//GMII Interface
output  reg     [7:0]           gm_rx_d,
output  reg                     gm_rx_dv,
output  reg                     gm_rx_err,
input           [7:0]           gm_tx_d,
input                           gm_tx_en,
input                           gm_tx_err,
//MII Interface
input                           mii_txc,
output  reg     [3:0]           mii_txd,
output  reg                     mii_tx_dv,
output  reg                     mii_tx_err,

input                           mii_rxc,
input           [3:0]           mii_rxd,
input                           mii_rx_dv,
input                           mii_rx_err

//Status and  Error Signals
);
// Parameter Define 
//localparam                      SPEED_100M_DIV = (TX_REFCLK == 125) ? 10 : 2;
//localparam                      SPEED_10M_DIV  = SPEED_100M_DIV*10;
//localparam                      SPEED_CLK_DIV = (TX_REFCLK == 125) ? SPEED_100M_DIV/2 + 1 : 0 ;
// Register Define 
reg     [6:0]                   aclk_en_cnt;
reg     [3:0]                   txd;
reg                             tx_en;
reg                             tx_er;
reg                             rx_dv_pre;
reg                             rx_dv_dl1;
reg     [3:0]                   rxd_pre;
reg     [3:0]                   rxd_dl1;
reg                             rx_odd_data_ptr;
reg     [3:0]                   rxd;
reg                             rx_dv;
reg                             rx_er;
reg     [3:0]                   gm_tx_d_h;
reg     [7:0]                   gm_tx_d_r;
reg                             gm_tx_en_r;
reg                             gm_tx_err_r;
reg                             preamble_flg;
reg     [1:0]                   cur_st;
reg     [1:0]                   nxt_st;
reg                             add_preamble;


// Wire Define
wire                            add_preamble_w;

assign add_preamble_w = mii_rxd == 4'hd && mii_rx_dv && !mii_rx_err && cur_st == 2'b01 && preamble_flg;

/*----------------------------------------------------------------------------------*\
                                 The main code
\*----------------------------------------------------------------------------------*/

/*----------------------- Tx Region ----------------------------*/

always @ (posedge tx_mac_aclk or posedge tx_reset) begin
   if (tx_reset == 1'b1)
      tx_mac_aclk_en <= 1'b0;
   else
      tx_mac_aclk_en <= ~tx_mac_aclk_en;
end

always @ (posedge tx_mac_aclk or posedge tx_reset) begin
   if (tx_reset == 1'b1)
      gm_tx_d_r <= 8'h0;
   else if ((gm_tx_en == 1'b1) && (tx_mac_aclk_en == 1'b1))
      gm_tx_d_r <= gm_tx_d;
end

always @ (posedge tx_mac_aclk or posedge tx_reset) begin
   if (tx_reset == 1'b1)
      gm_tx_en_r <= 1'b0;
   else if (tx_mac_aclk_en == 1'b1)
      gm_tx_en_r <= gm_tx_en;
end

always @ (posedge tx_mac_aclk or posedge tx_reset) begin
   if (tx_reset == 1'b1)
      gm_tx_err_r <= 1'b0;
   else if (tx_mac_aclk_en == 1'b1)
      gm_tx_err_r <= gm_tx_err;
end

always @ (posedge tx_mac_aclk or posedge tx_reset) begin
   if (tx_reset == 1'b1)
      txd <= 4'h0;
   else if (gm_tx_en_r == 1'b1) begin
      if (tx_mac_aclk_en == 1'b0)
          txd <= gm_tx_d_r[3:0];
      else
          txd <= gm_tx_d_r[7:4];
   end
   else;    
end

always @ (posedge tx_mac_aclk or posedge tx_reset) begin
   if (tx_reset == 1'b1)
       tx_en <= 1'b0;
   else 
       tx_en <= gm_tx_en_r;
end

always @ (posedge tx_mac_aclk or posedge tx_reset) begin
   if (tx_reset == 1'b1)
       tx_er <= 1'b0;
   else 
       tx_er <= gm_tx_err_r;
end

always @ (posedge mii_txc or posedge tx_reset) begin 
   if (tx_reset == 1'b1) begin
      mii_tx_dv  <= 1'b0;
      mii_txd    <= 4'h0;
      mii_tx_err <= 1'b0;
   end
   else begin
      mii_tx_dv  <= tx_en;
      mii_txd    <= txd[3:0];
      mii_tx_err <= tx_er;
   end
end
/*----------------------- Rx Region ----------------------------*/
always @ (posedge mii_rxc or posedge rx_reset) begin
   if (rx_reset == 1'b1) begin
      rxd   <= 4'h0;
      rx_dv <= 1'b0;
      rx_er <= 1'b0;
   end
   else if (add_preamble_w && NO_PREAMBLE != 1) begin
      rxd   <= 4'h5;
      rx_dv <= 1'b1;
      rx_er <= rx_er;
   end
   else if (add_preamble && NO_PREAMBLE != 1) begin
      rxd   <= rxd_pre;
      rx_dv <= rx_dv_pre;
      rx_er <= rx_er;
   end
   else begin
      rxd   <= mii_rxd;
      rx_dv <= mii_rx_dv;
      rx_er <= mii_rx_err;
   end
end

assign rx_mac_aclk = mii_rxc;

always @ (posedge rx_mac_aclk or posedge rx_reset) begin
   if (rx_reset == 1'b1) begin
      rxd_pre <= 4'h0;
      rx_dv_pre <= 1'b0;
   end
   else if (add_preamble_w || add_preamble) begin
      rxd_pre <= mii_rxd;
      rx_dv_pre <= mii_rx_dv;
   end
end

always @ (posedge rx_mac_aclk or posedge rx_reset) begin
    if (rx_reset == 1'b1)
       add_preamble <= 1'b0;
    else if (add_preamble_w)
       add_preamble <= 1'b1;
    else if (!mii_rx_dv)
       add_preamble <= 1'b0;
end

always @ (posedge rx_mac_aclk or posedge rx_reset) begin
   if (rx_reset == 1'b1)
      rx_mac_aclk_en <= 1'b0;
   else
      rx_mac_aclk_en <= ~rx_mac_aclk_en;
end

always @ (posedge rx_mac_aclk or posedge rx_reset) begin
   if (rx_reset == 1'b1) begin
      cur_st <= 2'b00;
   end
   else begin
      cur_st <= nxt_st;
   end
end

always @ (*) begin
   case (cur_st)
      2'b00: begin
         if (mii_rxd == 4'h5 && mii_rx_dv && !mii_rx_err)
            nxt_st = 2'b01;
         else
            nxt_st = 2'b00;
      end
      2'b01: begin
         if (mii_rxd == 4'hd && mii_rx_dv && !mii_rx_err)
            nxt_st = 2'b10;
         else if (mii_rxd == 4'h5 && mii_rx_dv && !mii_rx_err)
            nxt_st = 2'b01;
         else 
            nxt_st = 2'b00;
      end
      2'b10: begin
         if (mii_rx_dv) 
            nxt_st = 2'b10;
         else
            nxt_st = 2'b00;
         end
      default: nxt_st = 2'b00;
   endcase
end

always @ (posedge rx_mac_aclk or posedge rx_reset) begin
   if (rx_reset == 1'b1) begin
      preamble_flg <= 1'b0;
   end
   else if (mii_rxd == 4'h5 && mii_rx_dv && !mii_rx_err && cur_st == 2'b01) begin
      preamble_flg <= ~preamble_flg;
   end
   else begin
      preamble_flg <= 1'b0;
   end
end

always @ (posedge rx_mac_aclk or posedge rx_reset) begin
   if (rx_reset == 1'b1) begin
      rx_dv_dl1 <= 1'b0;
      rxd_dl1   <= 4'h0;
   end
   else begin
      rx_dv_dl1 <= rx_dv;
      rxd_dl1   <= rxd;
   end
end

always @ (posedge rx_mac_aclk or posedge rx_reset) begin
   if (rx_reset == 1'b1)
      gm_rx_dv <= 1'b0;
   else
      gm_rx_dv <= rx_dv_dl1;
end

always @ (posedge rx_mac_aclk or posedge rx_reset) begin
   if (rx_reset == 1'b1)
      rx_odd_data_ptr <= 1'b0;
   else if (rx_dv == 1'b0)
      rx_odd_data_ptr <= 1'b0;
   else
      rx_odd_data_ptr <= ~rx_odd_data_ptr;
end

always @ (posedge rx_mac_aclk or posedge rx_reset) begin
   if (rx_reset == 1'b1)
      gm_rx_d <= 8'h0;
   else if ((rx_dv == 1'b1) && (rx_odd_data_ptr == 1'b1))
      gm_rx_d <= {rxd[3:0], rxd_dl1[3:0]};
   else;
end

always @ (posedge rx_mac_aclk or posedge rx_reset) begin
   if (rx_reset == 1'b1)
       gm_rx_err <= 1'b0;
   else begin
      if (rx_er == 1'b1)               gm_rx_err <= 1'b1;
      else if (rx_mac_aclk_en == 1'b1) gm_rx_err <= 1'b0;
   end
end


endmodule



/////////////////////////////////////////////////////////////////////////////
//           _____       
//          / _______    Copyright (C) 2013-2020 Efinix Inc. All rights reserved.
//         / /       \   
//        / /  ..    /   
//       / / .'     /    
//    __/ /.'      /     
//   __   \       /      
//  /_/ /\ \_____/ /     
// ____/  \_______/      
//
// *******************************
// Revisions:
// 1.0 Initial rev
//
// *******************************

module `IP_MODULE_NAME(rgmii_if)#(
    parameter                       RGMII_SYNC_EN = 1
) (
   //Globle Signals
   input                           tx_mac_aclk,
   output  reg                     tx_mac_aclk_en,
   input                           tx_reset,
   output  wire                    rx_mac_aclk,
   output  reg                     rx_mac_aclk_en,
   input                           rx_reset,
   //Configuration Signals
   input           [2:0]           eth_speed,
   input                           rgmii_rxc_edge,//0:DDIO Rising Edge; 1:DDIO Falling Edge; 
   input                           rgmii_txc_dly,//0:rgmii tx clock delay disable; 1:rgmii tx clock delay enable;
   //GMII Interface
   output  reg     [7:0]           gm_rx_d,
   output  reg                     gm_rx_dv,
   output  reg                     gm_rx_err,
   input           [7:0]           gm_tx_d,
   input                           gm_tx_en,
   input                           gm_tx_err,
   //RGMII Interface
   output  wire    [3:0]           rgmii_txd_HI,
   output  wire    [3:0]           rgmii_txd_LO,
   output  wire                    rgmii_tx_ctl_HI,
   output  wire                    rgmii_tx_ctl_LO,
   output  wire                    rgmii_txc_HI,//if rgmii_txc_dly set 0, used clk_125m clock. if rgmii_txc_dly set 1, used clk_125m_90deg clock.
   output  wire                    rgmii_txc_LO,
   input           [3:0]           rgmii_rxd_HI,
   input           [3:0]           rgmii_rxd_LO,
   input                           rgmii_rx_ctl_HI,
   input                           rgmii_rx_ctl_LO,
   input                           rgmii_rxc
   //Status and  Error Signals
);

// Parameter Define 

// Register Define 
reg     [6:0]                   aclk_en_cnt;
reg     [7:0]                   txd;
reg                             tx_en;
reg                             tx_er;
reg     [1:0]                   txc;
reg                             rx_dv_dl1;
reg     [7:0]                   rxd_dl1;
reg                             rx_odd_data_ptr;

// Wire Define
wire                            rx_dv;
wire    [7:0]                   rxd;
wire                            rx_er;

/*----------------------------------------------------------------------------------*\
                                 The main code
\*----------------------------------------------------------------------------------*/
/*----------------------- Tx Region ----------------------------*/
always @ (posedge tx_mac_aclk or posedge tx_reset) begin
   if (tx_reset == 1'b1)
      aclk_en_cnt <= 7'd0;
   else if ((eth_speed == 3'h4) ||
           ((eth_speed == 3'h2) && (aclk_en_cnt == 7'd9)) ||
           ((eth_speed == 3'h1) && (aclk_en_cnt == 7'd99)))
      aclk_en_cnt <= 7'd0;
   else
      aclk_en_cnt <= aclk_en_cnt + 1'b1;
end

always @ (posedge tx_mac_aclk or posedge tx_reset) begin
   if (tx_reset == 1'b1)
      tx_mac_aclk_en <= 1'b0;
   else if (aclk_en_cnt == 7'd0)
      tx_mac_aclk_en <= 1'b1;
   else
      tx_mac_aclk_en <= 1'b0;
end

always @ (posedge tx_mac_aclk or posedge tx_reset) begin
   if (tx_reset == 1'b1)
      txd[7:4] <= 4'h0;
   else if((gm_tx_en == 1'b1) && (tx_mac_aclk_en == 1'b1))
      txd[7:4] <= gm_tx_d[7:4];
end

always @ (posedge tx_mac_aclk or posedge tx_reset) begin
   if (tx_reset == 1'b1)
      txd[3:0] <= 4'h0;
   else if ((gm_tx_en == 1'b1) && (tx_mac_aclk_en == 1'b1))
      txd[3:0] <= gm_tx_d[3:0];
   else if (((eth_speed == 3'h2) && (aclk_en_cnt == 7'd6)) ||
            ((eth_speed == 3'h1) && (aclk_en_cnt == 7'd51)))
      txd[3:0] <= txd[7:4];
end

always @ (posedge tx_mac_aclk or posedge tx_reset) begin
   if (tx_reset == 1'b1)
      tx_en <= 1'b0;
   else if (tx_mac_aclk_en == 1'b1)
      tx_en <= gm_tx_en;
end

always @ (posedge tx_mac_aclk or posedge tx_reset) begin
   if (tx_reset == 1'b1)
      tx_er <= 1'b0;
   else if (tx_mac_aclk_en == 1'b1)
      tx_er <= gm_tx_err;
end
/*
always @(posedge tx_mac_aclk or posedge tx_reset)
begin
    if(tx_reset == 1'b1)
        txc <= 2'b0;
    else
        case(eth_speed)
        3'h4 :
            txc <= 2'b01;
        3'h2 :
            case(rgmii_txc_dly)
            1'b0 ://rgmii tx clock delay disable.
                if((aclk_en_cnt == 7'd0) || (aclk_en_cnt == 7'd5))
                    txc <= 2'b11;
                else if((aclk_en_cnt == 7'd3) || (aclk_en_cnt == 7'd8))
                    txc <= 2'b00;
            1'b1 ://rgmii tx clock delay enable.
                if((aclk_en_cnt == 7'd2) || (aclk_en_cnt == 7'd7))
                    txc <= 2'b11;
                else if((aclk_en_cnt == 7'd0) || (aclk_en_cnt == 7'd5))
                    txc <= 2'b00;
            endcase
        3'h1 :
            case(rgmii_txc_dly)
            1'b0 ://rgmii tx clock delay disable.
                if((aclk_en_cnt == 7'd0) || (aclk_en_cnt == 7'd50))
                    txc <= 2'b11;
                else if((aclk_en_cnt == 7'd25) || (aclk_en_cnt == 7'd75))
                    txc <= 2'b00;
            1'b1 ://rgmii tx clock delay enable.
                if((aclk_en_cnt == 7'd13) || (aclk_en_cnt == 7'd63))
                    txc <= 2'b11;
                else if((aclk_en_cnt == 7'd38) || (aclk_en_cnt == 7'd88))
                    txc <= 2'b00;
            endcase
        default :
            txc <= 2'b0;
        endcase
end

*/
reg [1:0]    txc_100m_r;
reg [1:0]    txc_10m_r;

always @ (posedge tx_mac_aclk or posedge tx_reset) begin
   if (tx_reset == 1'b1)
       txc_100m_r <= 2'b0;
   else begin
       case(rgmii_txc_dly)
          1'b0 : //rgmii tx clock delay disable.
             if ((aclk_en_cnt == 7'd0) || (aclk_en_cnt == 7'd5))
                txc_100m_r <= 2'b11;
             else if ((aclk_en_cnt == 7'd3) || (aclk_en_cnt == 7'd8))
                txc_100m_r <= 2'b00;
          1'b1 ://rgmii tx clock delay enable.
             if ((aclk_en_cnt == 7'd2) || (aclk_en_cnt == 7'd7))
                txc_100m_r <= 2'b11;
             else if ((aclk_en_cnt == 7'd0) || (aclk_en_cnt == 7'd5))
                txc_100m_r <= 2'b00;
       endcase
   end
end

always @ (posedge tx_mac_aclk or posedge tx_reset) begin
   if (tx_reset == 1'b1)
       txc_10m_r <= 2'b0;
   else begin
       case(rgmii_txc_dly)
       1'b0 ://rgmii tx clock delay disable.
           if((aclk_en_cnt == 7'd0) || (aclk_en_cnt == 7'd50))
               txc_10m_r <= 2'b11;
           else if((aclk_en_cnt == 7'd25) || (aclk_en_cnt == 7'd75))
               txc_10m_r <= 2'b00;
       1'b1 ://rgmii tx clock delay enable.
           if((aclk_en_cnt == 7'd13) || (aclk_en_cnt == 7'd63))
               txc_10m_r <= 2'b11;
           else if((aclk_en_cnt == 7'd38) || (aclk_en_cnt == 7'd88))
               txc_10m_r <= 2'b00;
       endcase
   end
end

always @(posedge tx_mac_aclk or posedge tx_reset)
begin
    if(tx_reset == 1'b1)
        txc <= 2'b0;
    else
        case(eth_speed)
            3'h4 :
                txc <= 2'b01;
            3'h2 :
                txc <= txc_100m_r;
            3'h1 :
                txc <= txc_10m_r;
            default :
                txc <= 2'b0;
        endcase
end

/*----------------------- Rx Region ----------------------------*/
assign rx_mac_aclk = rgmii_rxc;

always @(posedge rx_mac_aclk or posedge rx_reset)
begin
    if(rx_reset == 1'b1)
        rx_mac_aclk_en <= 1'b0;
    else if(eth_speed[2] == 1'b1)
        rx_mac_aclk_en <= 1'b1;
    else
        rx_mac_aclk_en <= ~rx_mac_aclk_en;
end

always @(posedge rx_mac_aclk or posedge rx_reset)
begin
    if(rx_reset == 1'b1)
        begin
            rx_dv_dl1 <= 1'b0;
            rxd_dl1 <= 8'h0;
        end
    else
        begin
            rx_dv_dl1 <= rx_dv;
            rxd_dl1 <= rxd;
        end
end

always @(posedge rx_mac_aclk or posedge rx_reset)
begin
    if(rx_reset == 1'b1)
        gm_rx_dv <= 1'b0;
    else
        gm_rx_dv <= rx_dv_dl1;
end

always @(posedge rx_mac_aclk or posedge rx_reset)
begin
    if(rx_reset == 1'b1)
        rx_odd_data_ptr <= 1'b0;
    else if(rx_dv == 1'b0)
        rx_odd_data_ptr <= 1'b0;
    else
        rx_odd_data_ptr <= ~rx_odd_data_ptr;
end

always @(posedge rx_mac_aclk or posedge rx_reset)
begin
    if(rx_reset == 1'b1)
        gm_rx_d <= 8'h0;
    else
        begin
            if((eth_speed[2] == 1'b1) && (rx_dv_dl1 == 1'b1))
                gm_rx_d <= rxd_dl1;
            else if((rx_dv == 1'b1) && (rx_odd_data_ptr == 1'b1))
                gm_rx_d <= {rxd[3:0],rxd_dl1[3:0]};
        end
end

always @(posedge rx_mac_aclk or posedge rx_reset)
begin
    if(rx_reset == 1'b1)
        gm_rx_err <= 1'b0;
    else
        begin
            if(rx_er == 1'b1)
                gm_rx_err <= 1'b1;
            else if(rx_mac_aclk_en == 1'b1)
                gm_rx_err <= 1'b0;
        end
end

/*----------------------- PHY Interface ----------------------------*/
`IP_MODULE_NAME(rgmii) #(
    .RGMII_SYNC_EN                      (RGMII_SYNC_EN                      )
)
u_rgmii
(
//Globle Signals
    .tx_mac_aclk                        (tx_mac_aclk                        ),
    .tx_reset                           (tx_reset                           ),
    .rx_reset                           (rx_reset                           ),
//Configuration Signals
    .eth_speed                          (eth_speed                          ),
    .rgmii_rxc_edge                     (rgmii_rxc_edge                     ),
//Phy Interface
    .txd                                (txd                                ),
    .tx_en                              (tx_en                              ),
    .tx_er                              (tx_er                              ),
    .txc                                (txc                                ),
    .rxd                                (rxd                                ),
    .rx_dv                              (rx_dv                              ),
    .rx_er                              (rx_er                              ),
//RGMII Interface
    .rgmii_txd_HI                       (rgmii_txd_HI                       ),
    .rgmii_txd_LO                       (rgmii_txd_LO                       ),
    .rgmii_tx_ctl_HI                    (rgmii_tx_ctl_HI                    ),
    .rgmii_tx_ctl_LO                    (rgmii_tx_ctl_LO                    ),
    .rgmii_txc_HI                       (rgmii_txc_HI                       ),
    .rgmii_txc_LO                       (rgmii_txc_LO                       ),
    .rgmii_rxd_HI                       (rgmii_rxd_HI                       ),
    .rgmii_rxd_LO                       (rgmii_rxd_LO                       ),
    .rgmii_rx_ctl_HI                    (rgmii_rx_ctl_HI                    ),
    .rgmii_rx_ctl_LO                    (rgmii_rx_ctl_LO                    ),
    .rgmii_rxc                          (rgmii_rxc                          )
);

endmodule


/////////////////////////////////////////////////////////////////////////////
//           _____       
//          / _______    Copyright (C) 2013-2020 Efinix Inc. All rights reserved.
//         / /       \   
//        / /  ..    /   
//       / / .'     /    
//    __/ /.'      /     
//   __   \       /      
//  /_/ /\ \_____/ /     
// ____/  \_______/      
//
// *******************************
// Revisions:
// 1.0 Initial rev
//
// *******************************
module `IP_MODULE_NAME(rgmii_sync)
(
//Globle Signals
input                           rgmii_rxc,
input                           rx_reset,
input           [2:0]           eth_speed,
//RGMII Rx Interface Input
input           [3:0]           rgmii_rxd_HI_i,
input           [3:0]           rgmii_rxd_LO_i,
input                           rgmii_rx_ctl_HI_i,
input                           rgmii_rx_ctl_LO_i,
//RGMII Rx Interface Output
output  reg     [3:0]           rgmii_rxd_HI_o,
output  reg     [3:0]           rgmii_rxd_LO_o,
output  reg                     rgmii_rx_ctl_HI_o,
output  reg                     rgmii_rx_ctl_LO_o
);


// Parameter Define 
parameter State_idle     = 2'd0;
parameter State_preamble = 2'd1;
parameter State_data_dl1 = 2'd2;
parameter State_data_dl2 = 2'd3;


// Register Define 
reg     [1:0]                   cur_state;
reg     [1:0]                   next_state;
reg                             preamble_odd;
reg     [3:0]                   rx_d_dl1;
reg                             rx_dv_dl1;
reg     [3:0]                   rx_d_dl2;
reg                             rx_dv_dl2;

// Wire Define

/*----------------------------------------------------------------------------------*\
                                 The main code
\*----------------------------------------------------------------------------------*/

always @ (posedge rgmii_rxc or posedge rx_reset) begin
   if (rx_reset) begin
      rx_d_dl1      <= 4'h0;
      rx_dv_dl1     <= 1'b0;
      rx_d_dl2      <= 4'h0;
      rx_dv_dl2     <= 1'b0;
   end
   else begin
      rx_d_dl1      <= rgmii_rxd_LO_i;
      rx_dv_dl1     <= rgmii_rx_ctl_HI_i;
      rx_d_dl2      <= rx_d_dl1;
      rx_dv_dl2     <= rx_dv_dl1;
   end
end

/*----------------------- FSM Region ----------------------------*/
always @ (posedge rgmii_rxc or posedge rx_reset) begin
   if (rx_reset) cur_state <= State_idle;
	else          cur_state <= next_state;
end

always @ (*) begin
	case (cur_state)
      State_idle :
         if ((rx_dv_dl1 == 1'b1) && (rx_d_dl1 == 4'h5))
             next_state = State_preamble;
         else
             next_state = State_idle;

      State_preamble : 
         if (rx_dv_dl1 == 1'b0)
            next_state = State_idle;
         else if ((rx_d_dl1 == 4'hd) && (preamble_odd == 1'b0))
            next_state = State_data_dl1;
         else if ((rx_d_dl1 == 4'hd) && (preamble_odd == 1'b1))
            next_state = State_data_dl2;
         else if (rx_d_dl1 != 4'h5)
            next_state = State_idle;
         else
            next_state = State_preamble;
          
      State_data_dl1 :
         if (rx_dv_dl1 == 1'b0)
            next_state = State_idle;
         else
            next_state = State_data_dl1;

      State_data_dl2 :
         if (rx_dv_dl2 == 1'b0)
            next_state = State_idle;
         else
            next_state = State_data_dl2;

      default :
         next_state = State_idle;
    endcase
end

always @ (posedge rgmii_rxc or posedge rx_reset) begin
    if (rx_reset) 
       preamble_odd <= 1'b0;
    else if (cur_state == State_preamble)
       preamble_odd <= ~preamble_odd;
    else
       preamble_odd <= 1'b0;
end

/*----------------------- Sync Output Region ----------------------------*/

always @ (posedge rgmii_rxc or posedge rx_reset) begin
   if (rx_reset)
      rgmii_rxd_LO_o <= 4'h0;
   else if (eth_speed[2] == 1'b1)
      rgmii_rxd_LO_o <= rgmii_rxd_LO_i;
   else if ((cur_state == State_preamble) && (rx_d_dl1 == 4'hd) && (preamble_odd == 1'b1))
      rgmii_rxd_LO_o <= 4'h5;
   else if (cur_state == State_data_dl2)
      rgmii_rxd_LO_o <= rx_d_dl2;
   else
      rgmii_rxd_LO_o <= rx_d_dl1;
end

always @ (posedge rgmii_rxc or posedge rx_reset) begin
   if (rx_reset) 
      rgmii_rxd_HI_o <= 4'h0;
   else if (eth_speed[2] == 1'b1)
      rgmii_rxd_HI_o <= rgmii_rxd_HI_i;
   else
      rgmii_rxd_HI_o <= 4'h0;
end

always @ (posedge rgmii_rxc or posedge rx_reset) begin
   if (rx_reset)
      rgmii_rx_ctl_HI_o <= 1'b0;
   else if (eth_speed[2] == 1'b1)
      rgmii_rx_ctl_HI_o <= rgmii_rx_ctl_HI_i;
   else if ((cur_state == State_preamble) && (rx_d_dl1 == 4'hd) && (preamble_odd == 1'b1))
      rgmii_rx_ctl_HI_o <= 1'b1;
   else if (cur_state == State_data_dl2)
      rgmii_rx_ctl_HI_o <= rx_dv_dl2;
   else
      rgmii_rx_ctl_HI_o <= rx_dv_dl1;
end

always @(posedge rgmii_rxc or posedge rx_reset) begin
   if (rx_reset)
      rgmii_rx_ctl_LO_o <= 1'b0;
   else if (eth_speed[2] == 1'b1)
      rgmii_rx_ctl_LO_o <= rgmii_rx_ctl_LO_i;
   else if ((cur_state == State_preamble) && (rx_d_dl1 == 4'hd) && (preamble_odd == 1'b1))
      rgmii_rx_ctl_LO_o <= 1'b1;
   else if (cur_state == State_data_dl2)
      rgmii_rx_ctl_LO_o <= rx_dv_dl2;
   else
      rgmii_rx_ctl_LO_o <= rx_dv_dl1;
end

endmodule


/////////////////////////////////////////////////////////////////////////////
//           _____       
//          / _______    Copyright (C) 2013-2020 Efinix Inc. All rights reserved.
//         / /       \   
//        / /  ..    /   
//       / / .'     /    
//    __/ /.'      /     
//   __   \       /      
//  /_/ /\ \_____/ /     
// ____/  \_______/      
//
// *******************************
// Revisions:
// 1.0 Initial rev
//
// *******************************

module `IP_MODULE_NAME(rgmii) #(
    parameter                   RGMII_SYNC_EN = 1
) (
   //Globle Signals
   input                        tx_mac_aclk,
   input                        tx_reset,
   input                        rx_reset,
   //Configuration Signals
   input           [2:0]        eth_speed,
   input                        rgmii_rxc_edge, //0:DDIO Rising Edge; 1:DDIO Falling Edge; 
   //Phy Interface
   input           [7:0]        txd,
   input                        tx_en,
   input                        tx_er,
   input           [1:0]        txc, //if rgmii_txc_dly set 0, used clk_125m clock. if rgmii_txc_dly set 1, used clk_125m_90deg clock.
   output  reg     [7:0]        rxd,
   output  reg                  rx_dv,
   output  reg                  rx_er,
   //RGMII Interface
   output  reg     [3:0]        rgmii_txd_HI,
   output  reg     [3:0]        rgmii_txd_LO,
   output  reg                  rgmii_tx_ctl_HI,
   output  reg                  rgmii_tx_ctl_LO,
   output  reg                  rgmii_txc_HI,
   output  reg                  rgmii_txc_LO,
   input           [3:0]        rgmii_rxd_HI,
   input           [3:0]        rgmii_rxd_LO,
   input                        rgmii_rx_ctl_HI,
   input                        rgmii_rx_ctl_LO,
   input                        rgmii_rxc
   //Status and  Error Signals
);
// Parameter Define 

// Register Define 
reg     [3:0]                   rgmii_rxd_HI_d1;
reg                             rgmii_rx_ctl_HI_d1;
reg     [3:0]                   rgmii_txd_HI_r;
reg     [3:0]                   rgmii_txd_LO_r;
reg                             rgmii_tx_ctl_HI_r;
reg                             rgmii_tx_ctl_LO_r;
reg                             rgmii_txc_HI_r;
reg                             rgmii_txc_LO_r;
// Wire Define
wire                            tx_en_to_ddr;
wire                            rgmii_tx_ctl_int;
wire    [3:0]                   txd_falling;
/*----------------------------------------------------------------------------------*\
                                 The main code
\*----------------------------------------------------------------------------------*/

/*----------------------- RGMII Tx Region ----------------------------*/
assign tx_en_to_ddr = (eth_speed[2] == 1'b1) ? tx_en : tx_en && (!tx_er);
assign rgmii_tx_ctl_int = tx_en ^ tx_er;

assign txd_falling = (eth_speed[2] == 1'b1) ? txd[7:4] : txd[3:0];

always @ (posedge tx_mac_aclk or posedge tx_reset) begin
   if (tx_reset) begin
      rgmii_txc_HI_r    <= 1'b0;
      rgmii_txc_LO_r    <= 1'b0;
      rgmii_tx_ctl_HI_r <= 1'b0;
      rgmii_tx_ctl_LO_r <= 1'b0;
      rgmii_txd_HI_r    <= 4'b0;
      rgmii_txd_LO_r    <= 4'b0;
   end 
   else begin
      rgmii_txc_HI_r    <= txc[0];
      rgmii_txc_LO_r    <= txc[1];     
      rgmii_tx_ctl_HI_r <= tx_en_to_ddr;
      rgmii_tx_ctl_LO_r <= rgmii_tx_ctl_int;
      rgmii_txd_HI_r    <= txd[3:0];
      rgmii_txd_LO_r    <= txd_falling;
   end
end


always @ (posedge tx_mac_aclk or posedge tx_reset) begin
   if (tx_reset) begin
      rgmii_txc_HI    <= 1'b0;
      rgmii_txc_LO    <= 1'b0;
      rgmii_tx_ctl_HI <= 1'b0;
      rgmii_tx_ctl_LO <= 1'b0;
      rgmii_txd_HI    <= 4'b0;
      rgmii_txd_LO    <= 4'b0;
   end
   else begin
      rgmii_txc_HI    <= rgmii_txc_HI_r;
      rgmii_txc_LO    <= rgmii_txc_LO_r;
      rgmii_tx_ctl_HI <= rgmii_tx_ctl_HI_r;
      rgmii_tx_ctl_LO <= rgmii_tx_ctl_LO_r;
      rgmii_txd_HI    <= rgmii_txd_HI_r;
      rgmii_txd_LO    <= rgmii_txd_LO_r;
   end
end

/*----------------------- RGMII Rx Region ----------------------------*/
//rgmii_rxd & rgmii_rx_ctl
always @ (posedge rgmii_rxc or posedge rx_reset) begin
   if (rx_reset) begin
      rgmii_rxd_HI_d1    <= 4'h0;
      rgmii_rx_ctl_HI_d1 <= 1'b0;
   end 
   else begin
      rgmii_rxd_HI_d1    <= rgmii_rxd_HI;
      rgmii_rx_ctl_HI_d1 <= rgmii_rx_ctl_HI;
   end
end

generate
   if (RGMII_SYNC_EN == 0) begin
      always @ (posedge rgmii_rxc or posedge rx_reset) begin
         if (rx_reset) begin
            rxd[7:4] <= 4'h0;
            rxd[3:0] <= 4'h0;
            rx_dv    <= 1'b0;
            rx_er    <= 1'b0;
         end
         else if (eth_speed[2] == 1'b1) begin //1000M
            if (rgmii_rxc_edge == 1'b0) begin //0:DDIO Rising Edge
               rxd[7:4] <= rgmii_rxd_LO;
               rxd[3:0] <= rgmii_rxd_HI_d1;
               rx_dv    <= rgmii_rx_ctl_HI_d1;
               rx_er    <= rgmii_rx_ctl_HI_d1^rgmii_rx_ctl_LO;
            end
            else begin//1:DDIO Falling Edge
               rxd[7:4] <= rgmii_rxd_HI;
               rxd[3:0] <= rgmii_rxd_LO;
               rx_dv    <= rgmii_rx_ctl_LO;
               rx_er    <= rgmii_rx_ctl_LO^rgmii_rx_ctl_HI;
            end
        end
        else begin //100M or 10M
           rxd[7:4] <= 4'b0;
           rxd[3:0] <= rgmii_rxd_LO;
           rx_dv    <= rgmii_rx_ctl_LO;
           rx_er    <= rgmii_rx_ctl_LO^rgmii_rx_ctl_HI_d1;
        end
     end
   end
   else begin
      reg  [3:0]  rgmii_rxd_HI_i;
      reg  [3:0]  rgmii_rxd_LO_i;
      reg         rgmii_rx_ctl_HI_i;
      reg         rgmii_rx_ctl_LO_i;
      wire [3:0]  rgmii_rxd_HI_sync;
      wire [3:0]  rgmii_rxd_LO_sync;
      wire        rgmii_rx_ctl_HI_sync;
      wire        rgmii_rx_ctl_LO_sync;

      always @ (posedge rgmii_rxc or posedge rx_reset) begin
         if (rx_reset) begin
            rgmii_rxd_HI_i    <= 4'h0;
            rgmii_rxd_LO_i    <= 4'h0;
            rgmii_rx_ctl_HI_i <= 1'b0;
            rgmii_rx_ctl_LO_i <= 1'b0;
         end
         else if (eth_speed[2] == 1'b1) begin //1000M
            if (rgmii_rxc_edge == 1'b0) begin //0:DDIO Rising Edge
               rgmii_rxd_HI_i    <= rgmii_rxd_LO;
               rgmii_rxd_LO_i    <= rgmii_rxd_HI_d1;
               rgmii_rx_ctl_HI_i <= rgmii_rx_ctl_HI_d1;
               rgmii_rx_ctl_LO_i <= rgmii_rx_ctl_LO;
            end
            else begin //1:DDIO Falling Edge
               rgmii_rxd_HI_i    <= rgmii_rxd_HI;
               rgmii_rxd_LO_i    <= rgmii_rxd_LO;
               rgmii_rx_ctl_HI_i <= rgmii_rx_ctl_HI;
               rgmii_rx_ctl_LO_i <= rgmii_rx_ctl_LO;
            end
         end        
         else begin//100M or 10M
            rgmii_rxd_HI_i    <= rgmii_rxd_HI_d1;
            rgmii_rxd_LO_i    <= rgmii_rxd_LO;
            rgmii_rx_ctl_HI_i <= rgmii_rx_ctl_LO;
            rgmii_rx_ctl_LO_i <= rgmii_rx_ctl_HI_d1;
         end
      end

      always @ (posedge rgmii_rxc or posedge rx_reset) begin
         if (rx_reset) begin
            rxd[7:4] <= 4'h0;
            rxd[3:0] <= 4'h0;
            rx_dv    <= 1'b0;
            rx_er    <= 1'b0;
         end
         else begin
            rxd[7:4] <= rgmii_rxd_HI_sync;
            rxd[3:0] <= rgmii_rxd_LO_sync;
            rx_dv    <= rgmii_rx_ctl_HI_sync;
            rx_er    <= rgmii_rx_ctl_HI_sync^rgmii_rx_ctl_LO_sync;
         end
      end
      
      /*----------------------- RGMII Rx Sync Module -----------------------*/
      `IP_MODULE_NAME(rgmii_sync) u_rgmii_sync
      (
      //Globle Signals
          .rgmii_rxc                  (rgmii_rxc                  ),
          .rx_reset                   (rx_reset                   ),
          .eth_speed                  (eth_speed                  ),
      //RGMII Rx Interface Input
          .rgmii_rxd_HI_i             (rgmii_rxd_HI_i             ),
          .rgmii_rxd_LO_i             (rgmii_rxd_LO_i             ),
          .rgmii_rx_ctl_HI_i          (rgmii_rx_ctl_HI_i          ),
          .rgmii_rx_ctl_LO_i          (rgmii_rx_ctl_LO_i          ),
      //RGMII Rx Interface Output
          .rgmii_rxd_HI_o             (rgmii_rxd_HI_sync          ),
          .rgmii_rxd_LO_o             (rgmii_rxd_LO_sync          ),
          .rgmii_rx_ctl_HI_o          (rgmii_rx_ctl_HI_sync       ),
          .rgmii_rx_ctl_LO_o          (rgmii_rx_ctl_LO_sync       )
      );
   end
endgenerate


endmodule


module `IP_MODULE_NAME(rmii_if)
(
//Globle Signals
input                           tx_mac_aclk,
output  reg                     tx_mac_aclk_en,
input                           tx_reset,
output  wire                    rx_mac_aclk,
output  reg                     rx_mac_aclk_en,
input                           rx_reset,
//Configuration Signals
input           [2:0]           eth_speed,
//GMII Interface
output  reg     [7:0]           gm_rx_d,
output  reg                     gm_rx_dv,
output  reg                     gm_rx_err,
input           [7:0]           gm_tx_d,
input                           gm_tx_en,
input                           gm_tx_err,
//RGMII Interface
input                           rmii_clk_ref,
output  reg     [1:0]           rmii_txd,
output  reg                     rmii_tx_en,

input           [1:0]           rmii_rxd,
input                           rmii_crs_dv,
input                           rmii_rx_err

//Status and  Error Signals
);
// Parameter Define 

// Register Define 
reg     [6:0]                   aclk_en_cnt;
reg     [6:0]                   rx_aclk_en_cnt;
reg     [1:0]                   txd;
reg                             tx_en;
reg                             tx_er;
reg                             rx_err_dl1;
reg                             rx_dv_dl1;
reg     [7:0]                   rxd_dl1;
reg     [6:0]                   rx_odd_data_ptr;
reg     [1:0]                   rxd;
reg                             rx_dv;
reg                             rx_er;
reg     [7:0]                   gm_tx_d_temp;
reg                             tx_en_temp;
reg     [6:0]                   txbit_cnt;
reg                             rx_dv_compensate;
reg                             rx_err_compensate;
reg                             rx_err_latch;
reg     [7:0]                   rx_d_compensate;
reg     [6:0]                   rx_compensate_cnt;
// Wire Define

/*----------------------------------------------------------------------------------*\
                                 The main code
\*----------------------------------------------------------------------------------*/

/*----------------------- Tx Region ----------------------------*/
always @ (posedge tx_mac_aclk or posedge tx_reset) begin
   if (tx_reset == 1'b1)
      aclk_en_cnt <= 7'd0;
   else if (((eth_speed == 3'h2) && (aclk_en_cnt == 7'd3)) ||
           ((eth_speed == 3'h1) && (aclk_en_cnt == 7'd39)))
      aclk_en_cnt <= 7'd0;
   else
      aclk_en_cnt <= aclk_en_cnt + 1'b1;
end

always @ (posedge tx_mac_aclk or posedge tx_reset) begin
   if (tx_reset == 1'b1)
      tx_mac_aclk_en <= 1'b0;
   else if (aclk_en_cnt == 7'd0)
      tx_mac_aclk_en <= 1'b1;
   else
      tx_mac_aclk_en <= 1'b0;
end

always @ (posedge tx_mac_aclk or posedge tx_reset) begin
   if (tx_reset == 1'b1)
      gm_tx_d_temp <= 8'h0;
   else if ((gm_tx_en == 1'b1) && (tx_mac_aclk_en == 1'b1))
      gm_tx_d_temp <= gm_tx_d;
end

always @ (posedge tx_mac_aclk or posedge tx_reset) begin
   if (tx_reset == 1'b1)
      tx_en_temp <= 1'b0;
   else if(tx_mac_aclk_en == 1'b1)
      tx_en_temp <= gm_tx_en;
end

always @ (posedge tx_mac_aclk or posedge tx_reset) begin
   if (tx_reset == 1'b1)
      txbit_cnt <= 7'd0;
   else if (((eth_speed == 3'h2) && (txbit_cnt == 7'd3)) ||
           ((eth_speed == 3'h1) && (txbit_cnt == 7'd39)))
      txbit_cnt <= 7'd0;
   else if (tx_en_temp == 1'b1)
      txbit_cnt <= txbit_cnt + 1'b1;
   else
      txbit_cnt <= 7'd0; 
end

always @ (posedge tx_mac_aclk or posedge tx_reset) begin
   if (tx_reset == 1'b1)
       txd <= 2'h0;
   else if (eth_speed == 3'h2) begin
      case(txbit_cnt[1:0])
         2'b00: txd <= gm_tx_d_temp[1:0];
         2'b01: txd <= gm_tx_d_temp[3:2];
         2'b10: txd <= gm_tx_d_temp[5:4];
         2'b11: txd <= gm_tx_d_temp[7:6];
         default; 
      endcase 
   end 
   else if (eth_speed == 3'h1) begin
      case(txbit_cnt[5:0])
         6'd00: txd <= gm_tx_d_temp[1:0];
         6'd10: txd <= gm_tx_d_temp[3:2];
         6'd20: txd <= gm_tx_d_temp[5:4];
         6'd30: txd <= gm_tx_d_temp[7:6];
         default; 
      endcase 
   end
   else;    
end

always @ (posedge tx_mac_aclk or posedge tx_reset) begin
   if (tx_reset == 1'b1)
      tx_en <= 1'b0;
   else 
      tx_en <= tx_en_temp;
end

always @ (posedge tx_mac_aclk or posedge tx_reset) begin
   if (tx_reset == 1'b1)
       tx_er <= 1'b0;
   else if (tx_mac_aclk_en == 1'b1)
       tx_er <= gm_tx_err;
end

always @ (posedge rmii_clk_ref or posedge tx_reset) begin 
   if (tx_reset == 1'b1) begin
      rmii_tx_en <= 1'b0;
      rmii_txd   <= 2'b0;
   end
   else begin
      rmii_tx_en  <= tx_en;
      rmii_txd    <= txd[1:0];
   end
end

/*----------------------- Rx Region ----------------------------*/
always @(posedge rmii_clk_ref or posedge rx_reset) begin
   if (rx_reset == 1'b1) begin
      rxd   <= 2'b00;
      rx_dv <= 1'b0;
      rx_er <= 1'b0;
   end
   else begin
      rxd   <= rmii_rxd;
      rx_dv <= rmii_crs_dv;
      rx_er <= rmii_rx_err;
   end
end

assign rx_mac_aclk = rmii_clk_ref;

always @ (posedge rx_mac_aclk or posedge rx_reset) begin
   if (rx_reset == 1'b1)
      rx_aclk_en_cnt <= 7'd0;
   else if (((eth_speed == 3'h2) && (rx_aclk_en_cnt == 7'd3)) ||
           ((eth_speed == 3'h1) && (rx_aclk_en_cnt == 7'd39)))
      rx_aclk_en_cnt <= 7'd0;
   else
      rx_aclk_en_cnt <= rx_aclk_en_cnt + 1'b1;
end

always @ (posedge rx_mac_aclk or posedge rx_reset) begin
   if (rx_reset == 1'b1)
      rx_mac_aclk_en <= 1'b0;
   else if (rx_aclk_en_cnt == 7'd0)
      rx_mac_aclk_en <= 1'b1;
   else
      rx_mac_aclk_en <= 1'b0;
end

always @ (posedge rx_mac_aclk or posedge rx_reset) begin
   if (rx_reset == 1'b1)
      rx_odd_data_ptr <= 7'd0;
   else if (((eth_speed == 3'h2) && (rx_odd_data_ptr == 7'd3)) ||
           ((eth_speed == 3'h1) && (rx_odd_data_ptr == 7'd39)) || (rx_dv == 1'b0))
      rx_odd_data_ptr <= 7'd0;
   else 
      rx_odd_data_ptr <= rx_odd_data_ptr + 1'b1;
end

always @ (posedge rx_mac_aclk or posedge rx_reset) begin
   if (rx_reset == 1'b1)
      rx_dv_dl1 <= 1'b0;
   else 
      rx_dv_dl1 <= rx_dv; 
end

always @ (posedge rx_mac_aclk or posedge rx_reset) begin
   if (rx_reset == 1'b1)
       rx_err_dl1 <= 1'b0;
   else 
       rx_err_dl1 <= rx_er; 
end

always @ (posedge rx_mac_aclk or posedge rx_reset) begin
   if (rx_reset == 1'b1)
      rxd_dl1 <= 8'h0;
   else if (eth_speed == 3'h2) begin
      case (rx_odd_data_ptr[1:0])
         2'b00: rxd_dl1[1:0] <= rxd;
         2'b01: rxd_dl1[3:2] <= rxd;
         2'b10: rxd_dl1[5:4] <= rxd;
         2'b11: rxd_dl1[7:6] <= rxd;
         default; 
      endcase 
   end 
   else if (eth_speed == 3'h1) begin
      case (rx_odd_data_ptr[5:0])
         6'd00: rxd_dl1[1:0] <= rxd;
         6'd10: rxd_dl1[3:2] <= rxd;
         6'd20: rxd_dl1[5:4] <= rxd;
         6'd30: rxd_dl1[7:6] <= rxd;
         default; 
      endcase 
   end
   else;    
end

always @ (posedge rx_mac_aclk or posedge rx_reset) begin
   if (rx_reset == 1'b1)
      rx_compensate_cnt <= 7'b0;
   else if (rx_dv_dl1 == 1'b1)
      rx_compensate_cnt <= 7'b0;
   else if (((eth_speed == 3'h2) && (rx_compensate_cnt == 7'd3)) ||
           ((eth_speed == 3'h1) && (rx_compensate_cnt == 7'd39)))
      rx_compensate_cnt <= rx_compensate_cnt;
   else
      rx_compensate_cnt <= rx_compensate_cnt + 1;
end

always @ (posedge rx_mac_aclk or posedge rx_reset) begin
   if (rx_reset == 1'b1)
      rx_dv_compensate <= 1'b0;
   else if (((eth_speed == 3'h2) && (rx_compensate_cnt == 7'd3)) ||
           ((eth_speed == 3'h1) && (rx_compensate_cnt == 7'd39)))
      rx_dv_compensate <= 1'b0;
   else if ((rx_dv_dl1 == 1'b1) && rx_odd_data_ptr == 7'd0)
      rx_dv_compensate <= 1'b1;
end

always @ (posedge rx_mac_aclk or posedge rx_reset) begin
   if (rx_reset == 1'b1)
       rx_err_latch <= 1'b0;
   else begin
      if (rx_dv & rx_er)                rx_err_latch <= 1'b1;
      else if (rx_odd_data_ptr == 7'd0) rx_err_latch <= 1'b0; 
      else                              rx_err_latch <= rx_err_latch;
   end
end

always @ (posedge rx_mac_aclk or posedge rx_reset) begin
   if (rx_reset == 1'b1)
      rx_err_compensate <= 1'b0;
   else if (((eth_speed == 3'h2) && (rx_compensate_cnt == 7'd3)) ||
           ((eth_speed == 3'h1) && (rx_compensate_cnt == 7'd39)))
      rx_err_compensate <= 1'b0;
   else if (rx_odd_data_ptr == 7'd0)
      rx_err_compensate <= rx_err_latch;
end

always @ (posedge rx_mac_aclk or posedge rx_reset) begin
   if (rx_reset == 1'b1)
      rx_d_compensate <= 8'h0;
   else if ((rx_dv_dl1 == 1'b1) && rx_odd_data_ptr == 7'd0)
      rx_d_compensate <= rxd_dl1;
   else;
end

always @ (posedge rx_mac_aclk or posedge rx_reset) begin
   if (rx_reset == 1'b1)
      gm_rx_dv <= 1'b0;
   else if (rx_mac_aclk_en == 1'b1)
      gm_rx_dv <= rx_dv_compensate;
end


always @ (posedge rx_mac_aclk or posedge rx_reset) begin
   if (rx_reset == 1'b1)
      gm_rx_d <= 8'h0;
   else if (rx_mac_aclk_en == 1'b1)
      gm_rx_d <= rx_d_compensate;
   else;
end

always @ (posedge rx_mac_aclk or posedge rx_reset) begin
   if (rx_reset == 1'b1)
      gm_rx_err <= 1'b0;
   else if (rx_mac_aclk_en == 1'b1)
      gm_rx_err <= rx_err_compensate;
end

endmodule



//pragma protect
//pragma protect begin

/* Encryption Envelope */

`pragma protect begin_protected
`pragma protect version = 1
`pragma protect encrypt_agent = "QuestaSim" , encrypt_agent_info = "2023.4"
`pragma protect key_keyowner = "Aldec" , key_keyname = "ALDEC15_001"
`pragma protect key_method = "rsa"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 256 )
`pragma protect key_block
dABJR6nTPJBsIf2DbWNrWr6xEUbX9iZqL/tsYopG8TRP5JnwKiouuNQWHCofchjo
JrIjbKh783Vou/LeTKnX5lIfH++Hxrf50neaYocgR2CoRcx532EI4eOIqxVL8Gwz
bIbmhJJdPjGyqZGConsb2ZdMFVVgDNQFHBtKXfY8yqkEZ3jFgQg7EKR4ibUgZ+p4
GHKlbHgCM4MuDzMJlv2JOECPB/JtnhPWjjtchWKPpSSOYKPrW0wwbTe81cdg5lSx
Ac2nkur+ca/xEy1wLtBSTUx1I/T9Nw60ZDY9alDuBM17BZzZB5qGa+KWerPpsbhX
KzQLdksuClO3/dxQuUGrDw==
`pragma protect data_method = "aes256-cbc"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 22080 )
`pragma protect data_block
[encoded data, 29900 characters]
`pragma protect end_protected

//pragma protect end


//pragma protect
//pragma protect begin

/* Encryption Envelope */

`pragma protect begin_protected
`pragma protect version = 1
`pragma protect encrypt_agent = "QuestaSim" , encrypt_agent_info = "2023.4"
`pragma protect key_keyowner = "Aldec" , key_keyname = "ALDEC15_001"
`pragma protect key_method = "rsa"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 256 )
`pragma protect key_block
w8wsxRggKwG2UBbiaE22KuPFYILiJ3FWu5kzxn+dWN8TwltSIrgCwUUGcCIO5tpx
cK5hRcvvCsIu8Zk3kJif55lpW+A4Oum/oeD6OCOvWCfGmgLNs9R2ipiJ2gZXEysk
12/KIpmXBmxM+ZD8wwJciF+nD5vzI85Mtx8cW5r5hLT3aM0JACjD0W/aGU3DOffO
SFsH6D1HTwJqKzqlWOvHeXbe8HFceBGpNgZnhzrrX5KzNS3L/XeHpneEfpgtU/wj
CNqcZCsxA+UtikVaHuwUKSxrJJCzKSHC0xqKZWn2cX21nGrYDKw8Z2GINaHQnuYv
P7ke4O2bpaUfdMGoOBKivw==
`pragma protect data_method = "aes256-cbc"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 4800 )
`pragma protect data_block
[encoded data, 6500 characters]
`pragma protect end_protected

//pragma protect end


//pragma protect
//pragma protect begin

/* Encryption Envelope */

`pragma protect begin_protected
`pragma protect version = 1
`pragma protect encrypt_agent = "QuestaSim" , encrypt_agent_info = "2023.4"
`pragma protect key_keyowner = "Aldec" , key_keyname = "ALDEC15_001"
`pragma protect key_method = "rsa"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 256 )
`pragma protect key_block
LMqP8CHrAE95Rufp4o4gXU95nNyw8el+6/wbDtLq8Lmq7AjMtlGeDX/fgwFZTPJl
v4GXEQMWDhEBYxcL4+N3cDHH2yF/T0bi5C110k43Ypqt9nuVFETzuXQy2EiKNlBL
wnx8SwN0EoLRxFOYAPVm9xEM8BzT8JbsJxxsYSwL1Q2HYAZYjDGT0YUIdo/87GPE
WLI5Y568FsDovDvhS2gLtJIIPxWm044r2wPKA1+GKDsoO2eP1qR8uupMhEjioJtg
Z/hxWDFLFhaCy1Lxu8Mk25eSzheTch45ka0JPG8h8agoAI18N2V7Dp6oS8MjUk5S
OkpOrjlLHSboIOsUEFoQig==
`pragma protect data_method = "aes256-cbc"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 2992 )
`pragma protect data_block
SOYXP+6WflsGjtNPv/4RiEbA7gaWuVVCfOP8G8Ic9MUBL/3Dcr9M8feD5+D8XmWT
DxivZRipT+B8tOlDAt4PaamAstcXsjVKeafiIqWXSdpdWoHudNi377R8LttDI8f7
Gh1oBCgsfjLW0A9yqOKjdqDcUe6u0RMHl3A3HoLLCansN1Dl/wnXlk37nEVLwiSd
o7YnX4Ezd/lHnk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H+5OlungODo1Mmq
wO2G5lyT3niOAUV5cbLxhNplNKo8FMyRgMrDvkgLfUFn9R6iW0KOSgVybzrDqtw7
p6jUCAT7o6Ugs3eZpLCNixTExt/tUg1k4H8FVAorFDV3PCoC0vwkVdgtSuQ80wZw
rukOoIbe3BSzHfpmjWYJ2o+HUaWrM4jq0hA7yoWuuAkOeIyGxhsMOuANq3RxEPft
dMKTT9wctvRQHabmbxkSFvi0/3ZAVUfaLNwQmrxvyrfN6NjCFbKblP64K3EsiFn+
2cXfqAQ6ubvkdvdEIxFgn/oBKTFZGd35Goal9zzmhZdbANCMQ5/mBxbSMRi+unYX
nL7V3aEXhUJETUp2/l3C54rGL2eiCI6zItb59iqF8LOQODZb6XOLkbkSnb/Ue+tv
/fV6rknF0jtoaRHcGg4mRbtNDXu2bcr+Wmm7G6hc/rbUbrtNCYd4OUkbN6xN92fy
cfN4YPtUsjE6B0QySva2vuTJLxHVKYxodOnOncaxi5LPZpsMe3w5LC7ZSbXeziDO
2Hc/QCc8UKaAgDCtKlvsKyrKmre4BqHMCyClAGHGlkT4m1d5LAozqSRhic9fOSTN
0p4EXNjc3ZWw9yXGV+uQPQ==
`pragma protect end_protected

//pragma protect end


//pragma protect
//pragma protect begin

/* Encryption Envelope */

`pragma protect begin_protected
`pragma protect version = 1
`pragma protect encrypt_agent = "QuestaSim" , encrypt_agent_info = "2023.4"
`pragma protect key_keyowner = "Aldec" , key_keyname = "ALDEC15_001"
`pragma protect key_method = "rsa"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 256 )
`pragma protect key_block
bUW3tiOGrB5RBqBMn4LzF8upTzpMfEp6RnaMyjgirtvFzcyWXB/4o0xJaVmZAjcE
3uib7pMZdVbHlNmhwh/UVgQEzn2kzVQocHzitKHy7gs2felAM9VZ4RriJdu6EGFc
VTf8Br5e/B7dV32U5zQIGeywxoIp65G/PrzP9rN2sMBWi1tC1sbIszZLhK0mTdJA
6aZXr4AX+zDyr46myeukdiDj+zyO2u9lldhRTtPSrUaadNI/JAqJ77o2M2m/Bh4Y
dDcsX09nAZ3R7BrEnZnaXz6DcQzYvOeex75TT/VCyv5Dvke//Ae7cttLeRTPRFIN
M2AIK90M7kZ3QuQ+5S61bw==
`pragma protect data_method = "aes256-cbc"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 4640 )
`pragma protect data_block
[encoded data, 6240 characters]
EQj+m0SDNpeTQsd1VIc3XS3bBGYxTz5Z5N9a+ZkmKJM=
`pragma protect end_protected

//pragma protect end


//pragma protect
//pragma protect begin

/* Encryption Envelope */

`pragma protect begin_protected
`pragma protect version = 1
`pragma protect encrypt_agent = "QuestaSim" , encrypt_agent_info = "2023.4"
`pragma protect key_keyowner = "Aldec" , key_keyname = "ALDEC15_001"
`pragma protect key_method = "rsa"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 256 )
`pragma protect key_block
BoSc/MyCq2/O6cLwueINDSFZce7iknw5eK3SXQOXSsg3z/qKtgz89bT7+niWDsX9
LhuX8lHfMdSLm2sGao896bXhahPN/YJEkR2DxANqo6+gDKPJN7eQtmonVhrnkKg6
NzDlGZk9BBdKjuTxPMcOARy489PUI1PSsEMgx8Tjj5a7FG7d4jVsLvCXh3Wa0Tvl
bDJ8vtXssiN3lcMTg1iAwaaTYEApYMUgR5On0XaE8DZ5ISgCfT63SrinLfQturvM
A0VGRE7Zrw77stJRXQEPivHWVYUylSikZtJ3ZKDSsZo26sH0uTYEjenbUNLEQxJ9
bw9rXP8LUr5+qsPRMZiugw==
`pragma protect data_method = "aes256-cbc"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 3936 )
`pragma protect data_block
[encoded data, 5330 characters]
`pragma protect end_protected

//pragma protect end


module `IP_MODULE_NAME(efx_mac1gbe) #(
   parameter FAMILY = "TRION",
   parameter VERSION = 32'h20,
   parameter RXFIFO_EN = 1,
   parameter RXFIFO_DTH = 2048,
   parameter TXFIFO_EN = 1,
   parameter TXFIFO_DTH = 2048,
   parameter PHY_INTF_MODE = 0,  
   parameter LOOPBACK_EN = 1'b0,
   parameter GMII_DW = PHY_INTF_MODE == 4 ? 16 : 8,
   parameter AXIS_DW = 8,  
   parameter APBIF = 0,
   parameter NO_PREAMBLE = 0,
   parameter INTER_PACKET_GAP = 6'd12,
   parameter MTU_FRAME_LENGTH = 16'd1518,
   parameter MAC_SOURCE_ADDRESS = 48'h0,
   parameter ENABLE_BROADCAST_FILTERING = 1'b1,
   parameter RGMII_RXC_EDGE = 1'b1,
   parameter RGMII_TXC_DLY = 1'b1,
   parameter PKT_CNT_MAX = 256, 
   parameter SIP600 = 0 
) (
   input                  tx_mac_aclk,
   output                 rx_mac_aclk,
   input                  mac_reset,   
   input                  proto_reset, 
   input                  tx_axis_clk,
   input [AXIS_DW-1:0]    tx_axis_mac_tdata,
   input                  tx_axis_mac_tvalid,
   input                  tx_axis_mac_tlast,
   input [AXIS_DW/8-1:0]  tx_axis_mac_tstrb,
   input                  tx_axis_mac_tuser,
   output                 tx_axis_mac_tready,
   input                  rx_axis_clk,
   output [AXIS_DW-1:0]   rx_axis_mac_tdata,
   output                 rx_axis_mac_tvalid,
   output                 rx_axis_mac_tlast,
   output [AXIS_DW/8-1:0] rx_axis_mac_tstrb,
   output                 rx_axis_mac_tuser,
   input                  rx_axis_mac_tready,
   input                  gm_rx_c,
   input  [GMII_DW-1:0]   gm_rx_d,
   input  [GMII_DW/8-1:0] gm_rx_dv,
   input  [GMII_DW/8-1:0] gm_rx_err,
   output                 gm_tx_c,
   output [GMII_DW-1:0]   gm_tx_d,
   output [GMII_DW/8-1:0] gm_tx_en,
   output [GMII_DW/8-1:0] gm_tx_err,
   output [3:0]           rgmii_txd_HI,
   output [3:0]           rgmii_txd_LO,
   output                 rgmii_tx_ctl_HI,
   output                 rgmii_tx_ctl_LO,
   output                 rgmii_txc_HI,
   output                 rgmii_txc_LO,
   input  [3:0]           rgmii_rxd_HI,
   input  [3:0]           rgmii_rxd_LO,
   input                  rgmii_rx_ctl_HI,
   input                  rgmii_rx_ctl_LO,
   input                  rgmii_rxc,
   input                  mii_txc,
   output [3:0]           mii_txd,
   output                 mii_tx_dv,
   output                 mii_tx_err,
   input                  mii_rxc,
   input  [3:0]           mii_rxd,
   input                  mii_rx_dv,
   input                  mii_rx_err,
   input                  rmii_clk_ref,
   output [1:0]           rmii_txd,
   output                 rmii_tx_en,
   input  [1:0]           rmii_rxd,
   input                  rmii_crs_dv,
   input                  rmii_rx_err,
   input  [9:0]           s_paddr,
   input  [31:0]          s_pwdata,
   input                  s_pwrite,
   input                  s_penable,
   input                  s_psel,
   output [31:0]          s_prdata,
   output                 s_pready,
   output                 s_perr,
   input                  s_axi_aclk,    
   input  [9:0]           s_axi_awaddr,  
   input                  s_axi_awvalid, 
   output                 s_axi_awready, 
   input  [31:0]          s_axi_wdata,   
   input                  s_axi_wvalid,  
   output                 s_axi_wready,  
   output [1:0]           s_axi_bresp,   
   output                 s_axi_bvalid,  
   input                  s_axi_bready,  
   input  [9:0]           s_axi_araddr,  
   input                  s_axi_arvalid, 
   output                 s_axi_arready, 
   output [1:0]           s_axi_rresp,   
   output [31:0]          s_axi_rdata,   
   output                 s_axi_rvalid,  
   input                  s_axi_rready,  
`ifdef ONCHIP_PHY
   input  logic           init_clk,
   input  logic           init_rst_n,
   input  logic           PMA_CMN_READY,
   input  logic           PMA_XCVR_PLLCLK_EN_ACK,
   input  logic [3:0]     PMA_XCVR_POWER_STATE_ACK,
   input  logic           PMA_RX_SIGNAL_DETECT,
   output logic           PMA_XCVR_PLLCLK_EN,
   output logic [3:0]     PMA_XCVR_POWER_STATE_REQ,
   output logic           phy_init_done,
`else
   output                 Mdo,   
   output                 MdoEn, 
   input                  Mdi,   
   output                 Mdc,   
`endif
   output [2:0]           eth_speed
);
`ifdef ONCHIP_PHY
//pragma protect
//pragma protect begin

/* Encryption Envelope */

`pragma protect begin_protected
`pragma protect version = 1
`pragma protect encrypt_agent = "QuestaSim" , encrypt_agent_info = "2023.4"
`pragma protect key_keyowner = "Aldec" , key_keyname = "ALDEC15_001"
`pragma protect key_method = "rsa"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 256 )
`pragma protect key_block
jKLMvRQhD67Zscw+i/8M3H+4Tun7q0GAfhEQdOeECCB2L+b2dUg2DZnfMubnucKw
OOfkYmXzPfNddr77Czpbmqs2vSXOuCNqtCbpmrhvGhycE6bj25TTYD4L+QHWr1hT
M6QKdHtiSEGQT3r/k6HnrRnunb2sgGCZAA8WIJWTjOmbG2Y2GSSDXsmreYtsBXBp
1f6CwMKJHxPV6B8oIofXnWW0r5ucOAqWyx2DyWdnZmkZAXxmVdGJz3MC5mcX0lKn
D2DAtu2a+qiy3l8paX2/X7aywJXvKQDcaxmIBs+7paWSZmJL4p//Hsb86cq8zcUG
4+VUog/OG/qI5HLddDP5FA==
`pragma protect data_method = "aes256-cbc"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 4864 )
`pragma protect data_block
[encoded data, 6565 characters]
HC79CWIzctckNIu4dgG5kg==
`pragma protect end_protected

//pragma protect end


// Module: efx_pulse_sync
// Description:
//   Safely transfers a single-cycle pulse from a source clock domain to a
//   destination clock domain using a toggle-based synchronization scheme.
//
// ==========================================================================

module `IP_MODULE_NAME(efx_pulse_sync) #(
   parameter ACTIVE_LOW = 1, // 0 - Active high reset, 1 - Active low reset
   parameter OFF_ASSERTION = 0
) (
   input  src_clk,      // Source clock (e.g., tx_axis_clk)
   input  src_reset,    // Reset for source domain
   input  pulse_in,     // Single-cycle pulse in src_clk domain

   input  dst_clk,      // Destination clock (e.g., tx_clk)
   input  dst_reset,    // Reset for destination domain
   output pulse_out     // Single-cycle pulse in dst_clk domain
);

// Toggle generation in source clock domain
reg toggle_src;

// Synchronizer flops in destination clock domain
wire toggle_sync;
reg  toggle_sync_r;

generate
   if (ACTIVE_LOW == 1) begin
      always @ (posedge src_clk or negedge src_reset) begin
         if (!src_reset)
            toggle_src <= 1'b0;
         else if (pulse_in)
            toggle_src <= ~toggle_src;
         else
            toggle_src <= toggle_src;
      end

     `IP_MODULE_NAME(efx_asyncreg) #(
        .WIDTH         (1),
        .OFF_ASSERTION (OFF_ASSERTION)
     ) efx_asyncreg_toggle_src (
        .clk     (dst_clk),
        .reset_n (dst_reset),
        .d_i     (toggle_src),
        .d_o     (toggle_sync)
     );
      
      always @ (posedge dst_clk or negedge dst_reset) begin
         if (!dst_reset) begin
            toggle_sync_r <= 1'b0;
         end 
         else begin
            toggle_sync_r <= toggle_sync;  // Delay for edge detect
         end
      end
   end
   else begin
      always @ (posedge src_clk or posedge src_reset) begin
         if (src_reset)
            toggle_src <= 1'b0;
         else if (pulse_in)
            toggle_src <= ~toggle_src;
         else
            toggle_src <= toggle_src;
      end

      `IP_MODULE_NAME(efx_asyncreg) #(
         .WIDTH         (1),
         .ACTIVE_HIGH   (0),
         .OFF_ASSERTION (OFF_ASSERTION)
      ) efx_asyncreg_toggle_src (
         .clk     (dst_clk),
         .reset_n (dst_reset),
         .d_i     (toggle_src),
         .d_o     (toggle_sync)
      );
      
      always @ (posedge dst_clk or posedge dst_reset) begin
         if (!dst_reset) begin
            toggle_sync_r <= 1'b0;
         end 
         else begin
            toggle_sync_r <= toggle_sync;  // Delay for edge detect
         end
      end
   end
endgenerate

// Generate one-cycle pulse in destination domain
assign pulse_out = toggle_sync ^ toggle_sync_r;

endmodule



module `IP_MODULE_NAME(efx_data_pipeline)  #(
    parameter HBP = 1,
    parameter DATA_WIDTH = 256,
    parameter MUX_IN = 1
)(
  input               upstream_valid_i,
  output              upstream_ready_o,
  input      [DATA_WIDTH-1:0]   upstream_data_i,
  output              downstream_valid_o,
  input               downstream_ready_i,
  output     [DATA_WIDTH-1:0]   downstream_data_o,
  input               clk,
  input               resetn
);
//pragma protect
//pragma protect begin

/* Encryption Envelope */

`pragma protect begin_protected
`pragma protect version = 1
`pragma protect encrypt_agent = "QuestaSim" , encrypt_agent_info = "2021.1"
`pragma protect key_keyowner = "Aldec" , key_keyname = "ALDEC15_001"
`pragma protect key_method = "rsa"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 256 )
`pragma protect key_block
sGUIBVria/X0Ma8dN+cu2FAX8ze3kcaNJhdu97YBk5g7eH4tFB0uQdhRxczbAVTS
uLqvmPz424psdreRAMQ7uC9XHS14jhPgiMUYLC7360OhnyPrMOf5Qpu7uo1TNtIZ
hS11XIWDHT3Qf9ZT74gXi4bxRINTlXtNqiXRm/+kh5FIC8MkpJcuPc1H4JiCYLac
AWVEhg1FPDljEhfIFF9Y/2Qr024y5BHw3IqlWXRM/n28aRPMgbtRivK2Wx5Y1UYq
sZFuMjMCIIP59QZM27EDmB8YbxJR075/pS9RSPSUiFEYBeeZsPT15zmOFKKRF66s
skWHpEbwQo9WSnKF44nfkw==
`pragma protect data_method = "aes256-cbc"
`pragma protect encoding = ( enctype = "base64" , line_length = 64 , bytes = 2352 )
`pragma protect data_block
fbkpLoOYnIplUsl0w3OHq+m7y0LB1kv8PJrlzGkW43IanZ05muwy3UA074T3+SS2
15EHe9Oeqkj3vg638GKKJUX1U24kVXa+rsv9ufubp855PW3wuW8HV8j/V5Sp+DZB
X9Rr4oEE7cpohVHvf1PI50huy7mFHGYVjcr2XJyHo0a/62B3RG1haLL2UxqgJHtI
w70ikjFUF9lnMBdQp5sXuSEhslyhR5seB9MDvMtim14Zyo0zuo/EQTPW/xC8+Mnh
HAoG7YSv9/8kuDjQOiqK2fiUsYkQt6ThDy0Rri7kvYbhu+Zu9fvb/FHePm1EXG5O
qNWRKIgfMiqNN2E2bBjinkUpuaKVQa1j66ox4UWXHjZylID9ww/ilAK8tpIuVc++
k513ZUQSaq8e705bnPDG5Jjm3cBAyPBi/ceC5SKrLi6VyXrDndg9rilVtaBxMSRE
QPOmEeLFtKf7HYKUy1w48NfHqYhSQ29c3I95lFAhpXTpf1T9r7Y7ncEWydc3NMJX
7iwQ98g57DeW8UDXsgwpxhQ9lvRIwFM3ZHG26QaKqEjD3IH3/8mxZFRs7aY5tXMu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