apm32f10x_eth.c 64.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203
/*!
 * @file        apm32f10x_eth.c
 *
 * @brief       This file provides all the ETH firmware functions
 *
 * @version     V1.0.3
 *
 * @date        2022-12-01
 *
 * @attention
 *
 *  Copyright (C) 2021-2022 Geehy Semiconductor
 *
 *  You may not use this file except in compliance with the
 *  GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
 *
 *  The program is only for reference, which is distributed in the hope
 *  that it will be useful and instructional for customers to develop
 *  their software. Unless required by applicable law or agreed to in
 *  writing, the program is distributed on an "AS IS" BASIS, WITHOUT
 *  ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
 *  and limitations under the License.
 */

#if defined(APM32F10X_CL)

#include "apm32f10x_eth.h"
#include "apm32f10x_rcm.h"

/** @addtogroup APM32F10x_ETHDriver
  @{
*/

/** @defgroup ETH_Driver
  * @brief ETH driver modules
  @{
*/

#if defined   (__CC_ARM) /*!< ARM Compiler */
    __align(4)
    ETH_DMADescConfig_T  DMARxDscrTab[ETH_RXBUFNB]; /*!< Ethernet Rx MA Descriptor */
    __align(4)
    ETH_DMADescConfig_T  DMATxDscrTab[ETH_TXBUFNB]; /*!< Ethernet Tx DMA Descriptor */
    __align(4)
    uint8_t Rx_Buff[ETH_RXBUFNB][ETH_RX_BUF_SIZE];  /*!< Ethernet Receive Buffer */
    __align(4)
    uint8_t Tx_Buff[ETH_TXBUFNB][ETH_TX_BUF_SIZE];  /*!< Ethernet Transmit Buffer */

#elif defined ( __ICCARM__ )

    ETH_DMADescConfig_T  DMARxDscrTab[ETH_RXBUFNB]; /*!< Ethernet Rx MA Descriptor */
    ETH_DMADescConfig_T  DMATxDscrTab[ETH_TXBUFNB]; /*!< Ethernet Tx DMA Descriptor */
    uint8_t Rx_Buff[ETH_RXBUFNB][ETH_RX_BUF_SIZE];  /*!< Ethernet Receive Buffer */
    uint8_t Tx_Buff[ETH_TXBUFNB][ETH_TX_BUF_SIZE];  /*!< Ethernet Transmit Buffer */

#elif defined (__GNUC__) /*!< GNU Compiler */
ETH_DMADescConfig_T  DMARxDscrTab[ETH_RXBUFNB] __attribute__ ((aligned (4))); /*!< Ethernet Rx MA Descriptor */
ETH_DMADescConfig_T  DMATxDscrTab[ETH_TXBUFNB] __attribute__ ((aligned (4))); /*!< Ethernet Tx DMA Descriptor */
uint8_t Rx_Buff[ETH_RXBUFNB][ETH_RX_BUF_SIZE] __attribute__ ((aligned (4)));  /*!< Ethernet Receive Buffer */
uint8_t Tx_Buff[ETH_TXBUFNB][ETH_TX_BUF_SIZE] __attribute__ ((aligned (4)));  /*!< Ethernet Transmit Buffer */

#endif

/** @defgroup Global_Definition
  @{
*/

/* Global pointers on Tx and Rx descriptor used to transmit and receive descriptors */
__IO ETH_DMADescConfig_T*  DMATxDescToSet;
__IO ETH_DMADescConfig_T*  DMARxDescToGet;

/* Structure used to hold the last received packet descriptors info */
ETH_DMARxFrameInformations      RxFrameDescriptor;
__IO ETH_DMARxFrameInformations* DMARxFraminfos;
__IO uint32_t FrameRxindex;

/**
  * @}
  */

/** @defgroup ETH_Functions
  @{
*/

/*!
 * @brief  Inserts a delay time.
 *
 * @param  count: specifies the delay time length.
 *
 * @retval None
 */
static void ETH_Delay(__IO uint32_t count)
{
    __IO uint32_t i = 0;
    for (i = count; i != 0; i--)
    {
    }
}

/* ETH Configuration */

/*!
 * @brief  Reset ETH peripheral registers to their default reset values.
 *
 * @param  None
 *
 * @retval None
 */
void ETH_Reset(void)
{
    RCM_EnableAHBPeriphReset(RCM_AHB_PERIPH_ETH_MAC);

    RCM_DisableAHBPeriphReset(RCM_AHB_PERIPH_ETH_MAC);
}

/*!
 * @brief  Config ETH_Config_T member with its default value.
 *
 * @param  ethConfig: pointer to a ETH_Config_T structure which will be initialized.
 *
 * @retval None
 */
void ETH_ConfigStructInit(ETH_Config_T* ethConfig)
{
    /* MAC Configuration */
    ethConfig->autoNegotiation = ETH_AUTONEGOTIATION_ENABLE;
    ethConfig->watchDog = ETH_WATCHDOG_ENABLE;
    ethConfig->jabber = ETH_JABBER_ENABLE;
    ethConfig->interFrameGap = ETH_INTERFRAMEGAP_96BIT;
    ethConfig->carrierSense = ETH_CARRIERSENCE_ENABLE;
    ethConfig->speed = ETH_SPEED_100M;
    ethConfig->receiveOwn = ETH_RECEIVEOWN_ENABLE;
    ethConfig->loopbackMode = ETH_LOOPBACKMODE_DISABLE;
    ethConfig->mode = ETH_MODE_FULLDUPLEX;
    ethConfig->checksumOffload = ETH_CHECKSUMOFFLAOD_DISABLE;
    ethConfig->retryTransmission = ETH_RETRYTRANSMISSION_ENABLE;
    ethConfig->automaticPadCRCStrip = ETH_AUTOMATICPADCRCSTRIP_DISABLE;
    ethConfig->backOffLimit = ETH_BACKOFFLIMIT_10;
    ethConfig->deferralCheck = ETH_DEFFERRALCHECK_DISABLE;
    ethConfig->receiveAll = ETH_RECEIVEAll_DISABLE;
    ethConfig->sourceAddrFilter = ETH_SOURCEADDRFILTER_DISABLE;
    ethConfig->passControlFrames = ETH_PASSCONTROLFRAMES_BLOCKALL;
    ethConfig->broadcastFramesReception = ETH_BROADCASTFRAMESRECEPTION_DISABLE;
    ethConfig->destinationAddrFilter = ETH_DESTINATIONADDRFILTER_NORMAL;
    ethConfig->promiscuousMode = ETH_PROMISCUOUS_MODE_DISABLE;
    ethConfig->multicastFramesFilter = ETH_MULTICASTFRAMESFILTER_PERFECT;
    ethConfig->unicastFramesFilter = ETH_UNICASTFRAMESFILTER_PERFECT;
    ethConfig->hashTableHigh = 0x0000;
    ethConfig->hashTableLow = 0x0000;
    ethConfig->pauseTime = 0x0000;
    ethConfig->zeroQuantaPause = ETH_ZEROQUANTAPAUSE_DISABLE;
    ethConfig->pauseLowThreshold = ETH_PAUSELOWTHRESHOLD_MINUS4;
    ethConfig->unicastPauseFrameDetect = ETH_UNICASTPAUSEFRAMEDETECT_DISABLE;
    ethConfig->receiveFlowControl = ETH_RECEIVEFLOWCONTROL_DISABLE;
    ethConfig->transmitFlowControl = ETH_TRANSMITFLOWCONTROL_DISABLE;
    ethConfig->VLANTagComparison = ETH_VLANTAGCOMPARISON_16BIT;
    ethConfig->VLANTagIdentifier = 0x0000;
    /* DMA Configuration */
    ethConfig->dropTCPIPChecksumErrorFrame = ETH_DROPTCPIPCHECKSUMERRORFRAME_DISABLE;
    ethConfig->receiveStoreForward = ETH_RECEIVESTOREFORWARD_ENABLE;
    ethConfig->flushReceivedFrame = ETH_FLUSHRECEIVEDFRAME_ENABLE;
    ethConfig->transmitStoreForward = ETH_TRANSMITSTOREFORWARD_ENABLE;
    ethConfig->transmitThresholdControl = ETH_TRANSMITTHRESHOLDCONTROL_64BYTES;
    ethConfig->forwardErrorFrames = ETH_FORWARDERRORFRAMES_DISABLE;
    ethConfig->forwardUndersizedGoodFrames = ETH_FORWARDUNDERSIZEDGOODFRAMES_DISABLE;
    ethConfig->receiveThresholdControl = ETH_RECEIVEDTHRESHOLDCONTROL_64BYTES;
    ethConfig->secondFrameOperate = ETH_SECONDFRAMEOPERARTE_DISABLE;
    ethConfig->addressAlignedBeats = ETH_ADDRESSALIGNEDBEATS_ENABLE;
    ethConfig->fixedBurst = ETH_FIXEDBURST_ENABLE;
    ethConfig->rxDMABurstLength = ETH_RXDMABURSTLENGTH_32BEAT;
    ethConfig->txDMABurstLength = ETH_TXDMABURSTLENGTH_32BEAT;
    ethConfig->descriptorSkipLength = 0x00;
    ethConfig->DMAArbitration = ETH_DMAARBITRATION_ROUNDROBIN_RXTX_1_1;
}

/*!
 * @brief  Config the ETH peripheral parameters in the ethConfig.
 *
 * @param  ethConfig: pointer to a ETH_Config_T structure.
 *
 * @param  addr: external PHY address
 *
 * @retval ETH_ERROR: Ethernet initialization error
 *         ETH_SUCCESS: Ethernet initialization success
 */
uint32_t ETH_Config(ETH_Config_T* ethConfig, uint16_t addr)
{
    uint32_t regValue = 0;
    uint32_t hclk = 60000000;
    __IO uint32_t timeout = 0, err = ETH_SUCCESS;

    hclk = RCM_ReadHCLKFreq();

    if ((hclk >= 20000000) && (hclk <= 35000000))
    {
        ETH->ADDR_B.CR = ETH_MACMIIAR_CR_DIV16;
    }
    else if ((hclk >= 35000000) && (hclk < 60000000))
    {
        ETH->ADDR_B.CR = ETH_MACMIIAR_CR_DIV26;
    }
    else if ((hclk >= 60000000) && (hclk < 100000000))
    {
        ETH->ADDR_B.CR = ETH_MACMIIAR_CR_DIV42;
    }
    else if ((hclk >= 100000000) && (hclk < 150000000))
    {
        ETH->ADDR_B.CR = ETH_MACMIIAR_CR_DIV62;
    }
    else
    {
        ETH->ADDR_B.CR = ETH_MACMIIAR_CR_DIV102;
    }

    /* PHY initialization and configuration */
    if (!(ETH_WritePHYRegister(addr, PHY_BCR, PHY_RESET)))
    {
        /* Return ERROR in case of write timeout */
        err = ETH_ERROR;
        goto error;
    }

    ETH_Delay(PHY_RESET_DELAY);

    if (ethConfig->autoNegotiation == ETH_AUTONEGOTIATION_ENABLE)
    {
        /* Wait for linked status */
        do
        {
            timeout++ ;
        }
        while (!(ETH_ReadPHYRegister(addr, PHY_BSR) & PHY_LINKED_STATUS) && (timeout < PHY_READ_TIMEOUT));

        /* Return ERROR in case of timeout */
        if (timeout == PHY_READ_TIMEOUT)
        {
            err = ETH_ERROR;
            goto error;
        }

        timeout = 0;
        /* Enable Auto-Negotiation */
        if (!(ETH_WritePHYRegister(addr, PHY_BCR, PHY_AUTONEGOTIATION)))
        {
            /* Return ERROR in case of write timeout */
            err = ETH_ERROR;
        }

        /* Wait until the auto-negotiation will be completed */
        do
        {
            timeout++;
        }
        while (!(ETH_ReadPHYRegister(addr, PHY_BSR) & PHY_AUTONEGO_COMPLETE) && (timeout < (uint32_t)PHY_READ_TIMEOUT));

        /* Return ERROR in case of timeout */
        if (timeout == PHY_READ_TIMEOUT)
        {
            err = ETH_ERROR;
            goto error;
        }

        timeout = 0;
        /* Read the result of the auto-negotiation */
        regValue = ETH_ReadPHYRegister(addr, PHY_SR);

        if ((regValue & PHY_DUPLEX_STATUS) != (uint32_t)RESET)
        {
            ethConfig->mode = ETH_MODE_FULLDUPLEX;
        }
        else
        {
            ethConfig->mode = ETH_MODE_HALFDUPLEX;
        }
        if (regValue & PHY_SPEED_STATUS)
        {
            ethConfig->speed = ETH_SPEED_10M;
        }
        else
        {
            ethConfig->speed = ETH_SPEED_100M;
        }
    }
    else
    {
        if (!ETH_WritePHYRegister(addr, PHY_BCR, ((uint16_t)(ethConfig->speed << 8) |
                                  (uint16_t)(ethConfig->mode  << 13))))
        {
            err = ETH_ERROR;
        }

        ETH_Delay(PHY_CONFIG_DELAY);
    }
error:
    if (err == ETH_ERROR)
    {
        ethConfig->speed = ETH_SPEED_100M;
        ethConfig->mode = ETH_MODE_FULLDUPLEX;
    }

    /* ETHERNET MAC_CFG Configuration */
    ETH->CFG_B.WDTDIS = ethConfig->watchDog;
    ETH->CFG_B.JDIS   = ethConfig->jabber;
    ETH->CFG_B.IFG    = ethConfig->interFrameGap;
    ETH->CFG_B.DISCRS = ethConfig->carrierSense;
    ETH->CFG_B.SSEL   = ethConfig->speed;
    ETH->CFG_B.DISRXO = ethConfig->receiveOwn;
    ETH->CFG_B.LBM    = ethConfig->loopbackMode;
    ETH->CFG_B.DM     = ethConfig->mode;
    ETH->CFG_B.IPC    = ethConfig->checksumOffload;
    ETH->CFG_B.DISR   = ethConfig->retryTransmission;
    ETH->CFG_B.ACS    = ethConfig->automaticPadCRCStrip;
    ETH->CFG_B.BL     = ethConfig->backOffLimit;
    ETH->CFG_B.DC     = ethConfig->deferralCheck;
    ETH_Delay(ETH_REG_WRITE_DELAY);

    /* ETHERNET MAC_FRAF Configuration */
    ETH->FRAF_B.RXA    = ethConfig->receiveAll;
    ETH->FRAF         |= ethConfig->sourceAddrFilter;
    ETH->FRAF_B.PCTRLF = ethConfig->passControlFrames;
    ETH->FRAF_B.DISBF  = ethConfig->broadcastFramesReception;
    ETH->FRAF_B.DAIF   = ethConfig->destinationAddrFilter;
    ETH->FRAF_B.PR     = ethConfig->promiscuousMode;
    ETH->FRAF         |= ethConfig->multicastFramesFilter;
    ETH->FRAF         |= ethConfig->unicastFramesFilter;
    ETH_Delay(ETH_REG_WRITE_DELAY);

    /* ETHERNET MAC_HTH/HTL Configuration */
    ETH->HTH = ethConfig->hashTableHigh;
    ETH->HTL = ethConfig->hashTableLow;

    /* ETHERNET MAC_FCTRL Configuration */
    ETH->FCTRL_B.PT        = ethConfig->pauseTime;
    ETH->FCTRL_B.ZQPDIS    = ethConfig->zeroQuantaPause;
    ETH->FCTRL_B.PTSEL     = ethConfig->pauseLowThreshold;
    ETH->FCTRL_B.UNPFDETE  = ethConfig->unicastPauseFrameDetect;
    ETH->FCTRL_B.RXFCTRLEN = ethConfig->receiveFlowControl;
    ETH->FCTRL_B.TXFCTRLEN = ethConfig->transmitFlowControl;
    ETH_Delay(ETH_REG_WRITE_DELAY);

    /* ETHERNET MAC_VLANT Configuration */
    ETH->VLANT_B.VLANTCOMP = ethConfig->VLANTagComparison;
    ETH->VLANT_B.VLANTID   = ethConfig->VLANTagIdentifier;
    ETH_Delay(ETH_REG_WRITE_DELAY);

    /* ETHERNET DMA_OPMOD Configuration */
    ETH->DMAOPMOD_B.DISDT    = ethConfig->dropTCPIPChecksumErrorFrame;
    ETH->DMAOPMOD_B.RXSF     = ethConfig->receiveStoreForward;
    ETH->DMAOPMOD_B.DISFRXF  = ethConfig->flushReceivedFrame;
    ETH->DMAOPMOD_B.TXSF     = ethConfig->transmitStoreForward;
    ETH->DMAOPMOD_B.TXTHCTRL = ethConfig->transmitThresholdControl;
    ETH->DMAOPMOD_B.FERRF    = ethConfig->forwardErrorFrames;
    ETH->DMAOPMOD_B.FUF      = ethConfig->forwardUndersizedGoodFrames;
    ETH->DMAOPMOD_B.RXTHCTRL = ethConfig->receiveThresholdControl;
    ETH->DMAOPMOD_B.OSECF    = ethConfig->secondFrameOperate;
    ETH_Delay(ETH_REG_WRITE_DELAY);

    /* ETHERNET DMA_BMOD Configuration */
    ETH->DMABMOD = RESET;
    ETH->DMABMOD_B.AAL = ethConfig->addressAlignedBeats;
    ETH->DMABMOD_B.FB = ethConfig->fixedBurst;
    ETH->DMABMOD |= ethConfig->rxDMABurstLength;
    ETH->DMABMOD |= ethConfig->txDMABurstLength;
    ETH->DMABMOD_B.DSL = ethConfig->descriptorSkipLength;
    ETH->DMABMOD |= ethConfig->DMAArbitration;
    ETH->DMABMOD_B.USP = SET;
    ETH_Delay(ETH_REG_WRITE_DELAY);

    if (err == ETH_SUCCESS)
    {
        return ETH_SUCCESS;
    }
    else
    {
        return ETH_ERROR;
    }
}

/*!
 * @brief  Resets all MAC subsystem internal registers and logic.
 *
 * @param  None
 *
 * @retval None
 */
void ETH_SoftwareReset(void)
{
    ETH->DMABMOD_B.SWR = SET;
}

/*!
 * @brief  Read the ETH software reset bit.
 *
 * @param  None
 *
 * @retval SET or RESET.
 */
uint8_t ETH_ReadSoftwareReset(void)
{
    return ETH->DMABMOD_B.SWR;
}

/*!
 * @brief     Enables ETH MAC and DMA reception/transmission
 *
 * @param     None
 *
 * @retval    None
 */
void ETH_Start(void)
{
    ETH_EnableMACTransmission();
    ETH_EnableMACReceiver();
    ETH_FlushTransmitFIFO();
    ETH_EnableDMATransmission();
    ETH_EnableDMAReceiver();
}

/*!
 * @brief     Disables ETH MAC and DMA reception/transmission
 *
 * @param     None
 *
 * @retval    None
 */
void ETH_Stop(void)
{
    ETH_DisableDMATransmission();
    ETH_DisableDMAReceiver();
    ETH_DisableMACReceiver();
    ETH_FlushTransmitFIFO();
    ETH_DisableMACTransmission();
}

/*!
 * @brief  Read the size of the received packet.
 *
 * @param  None
 *
 * @retval frameLength: received packet size
 */
uint32_t ETH_ReadRxPacketSize(ETH_DMADescConfig_T* DMARxDesc)
{
    uint32_t frameLength = 0;
    if (((DMARxDesc->Status & ETH_DMARXDESC_OWN) == (uint32_t)RESET) &&
            ((DMARxDesc->Status & ETH_DMARXDESC_ERRS)  == (uint32_t)RESET) &&
            ((DMARxDesc->Status & ETH_DMARXDESC_LDES)  != (uint32_t)RESET))
    {
        frameLength =  ETH_ReadDMARxDescFrameLength(DMARxDesc);
    }
    return frameLength;
}

/* PHY functions */

/*!
 * @brief  Read a PHY register
 *
 * @param  addr: PHY device address
 *               This parameter can be one of the following values: 0,..,31
 *
 * @param  reg:  PHY register
 *               This parameter can be one of the following values:
 *               @arg PHY_BCR : Transceiver Basic Control Register
 *               @arg PHY_BSR : Transceiver Basic Status Register
 *               @arg PHY_SR  :  Transceiver Status Register
 *
 * @retval ETH_ERROR: in case of timeout
 *         MAC DATA register value: Data read from the selected PHY register
 */
uint16_t ETH_ReadPHYRegister(uint16_t addr, uint16_t reg)
{
    __IO uint32_t timeout = 0;

    ETH->ADDR_B.PA = addr;
    ETH->ADDR_B.MR = reg;
    ETH->ADDR_B.MW = RESET;
    ETH->ADDR_B.MB = SET;
    /* Check for the Busy flag */
    do
    {
        timeout++ ;
    }
    while ((ETH->ADDR_B.MB == SET) && (timeout < PHY_READ_TIMEOUT));
    /* Return ERROR in case of timeout */
    if (timeout == PHY_READ_TIMEOUT)
    {
        return ETH_ERROR;
    }
    /* Return data register value */
    return (uint16_t)(ETH->DATA);
}

/*!
 * @brief  Write to a PHY register
 *
 * @param  addr: PHY device address
 *               This parameter can be one of the following values: 0,..,31

 * @param  reg:  PHY register
 *               This parameter can be one of the following values:
 *               @arg PHY_BCR : Transceiver Basic Control Register

 * @param  data: the data to write
 *
 * @retval ETH_ERROR: write timeout
 *         ETH_SUCCESS: write success
 */
uint32_t ETH_WritePHYRegister(uint16_t addr, uint16_t reg, uint16_t data)
{
    __IO uint32_t timeout = 0;

    ETH->DATA = data;
    ETH->ADDR_B.PA = addr;
    ETH->ADDR_B.MR = reg;
    ETH->ADDR_B.MW = SET;
    ETH->ADDR_B.MB = SET;

    /* Check for the Busy flag */
    do
    {
        timeout++ ;
    }
    while ((ETH->ADDR_B.MB == SET) && (timeout < PHY_WRITE_TIMEOUT));
    /* Return ERROR in case of timeout */
    if (timeout == PHY_WRITE_TIMEOUT)
    {
        return ETH_ERROR;
    }
    /* Return data register value */
    return ETH_SUCCESS;
}

/*!
 * @brief  Enable the PHY loopBack mode.
 *
 * @param  addr: PHY device address
 *               This parameter can be one of the following values: 0,..,31
 *
 * @retval ETH_ERROR or ETH_SUCCESS
 */
uint32_t ETH_EnablePHYLoopBack(uint16_t addr)
{
    uint16_t temp = 0;

    temp = ETH_ReadPHYRegister(addr, PHY_BCR);
    temp |= PHY_LOOPBACK;

    if (ETH_WritePHYRegister(addr, PHY_BCR, temp) == SET)
    {
        return ETH_SUCCESS;
    }
    else
    {
        return ETH_ERROR;
    }
}

/*!
 * @brief  Disable the PHY loopBack mode.
 *
 * @param  addr: PHY device address
 *               This parameter can be one of the following values: 0,..,31
 *
 * @retval ETH_ERROR or ETH_SUCCESS
 */
uint32_t ETH_DisablePHYLoopBack(uint16_t addr)
{
    uint16_t temp = 0;

    temp = ETH_ReadPHYRegister(addr, PHY_BCR);
    temp &= ((uint16_t)~PHY_LOOPBACK);

    if (ETH_WritePHYRegister(addr, PHY_BCR, temp) == SET)
    {
        return ETH_SUCCESS;
    }
    else
    {
        return ETH_ERROR;
    }
}

/* MAC functions */

/*!
 * @brief  Enable the MAC transmission.
 *
 * @param  None
 *
 * @retval None
 */
void ETH_EnableMACTransmission(void)
{
    ETH->CFG_B.TXEN = SET;
    ETH_Delay(ETH_REG_WRITE_DELAY);
}

/*!
 * @brief  Disable the MAC transmission.
 *
 * @param  None
 *
 * @retval None
 */
void ETH_DisableMACTransmission(void)
{
    ETH->CFG_B.TXEN = RESET;
    ETH_Delay(ETH_REG_WRITE_DELAY);
}

/*!
 * @brief  Enable the MAC receiver.
 *
 * @param  None
 *
 * @retval None
 */
void ETH_EnableMACReceiver(void)
{
    ETH->CFG_B.RXEN = SET;
    ETH_Delay(ETH_REG_WRITE_DELAY);
}

/*!
 * @brief  Disable the MAC receiver.
 *
 * @param  None
 *
 * @retval None
 */
void ETH_DisableMACReceiver(void)
{
    ETH->CFG_B.RXEN = RESET;
    ETH_Delay(ETH_REG_WRITE_DELAY);
}

/*!
 * @brief  Read the ETH flow control busy status
 *
 * @param  None
 *
 * @retval SET or RESET
 */
uint8_t ETH_ReadFlowControlBusyStatus(void)
{
    return ETH->FCTRL_B.FCTRLB;
}

/*!
 * @brief  Set a Pause Control Frame (Full-duplex only).
 *
 * @param  None
 *
 * @retval None
 */
void ETH_SetPauseControlFrame(void)
{
    ETH->FCTRL_B.FCTRLB = SET;
    ETH_Delay(ETH_REG_WRITE_DELAY);
}

/*!
 * @brief  Enable the MAC Back Pressure operation activation (Half-duplex only).
 *
 * @param  None
 *
 * @retval None
 */
void ETH_EnableBackPressureActivation(void)
{
    ETH->FCTRL_B.FCTRLB = SET;
    ETH_Delay(ETH_REG_WRITE_DELAY);
}

/*!
 * @brief  Disable the MAC Back Pressure operation activation (Half-duplex only).
 *
 * @param  None
 *
 * @retval None
 */
void ETH_DisableBackPressureActivation(void)
{
    ETH->FCTRL_B.FCTRLB = RESET;
    ETH_Delay(ETH_REG_WRITE_DELAY);
}

/*!
 * @brief  Read the specified ETH MAC flag
 *
 * @param  flag: Ethernet MAC flag:
 *         This parameter can be one of the following values:
 *           @arg ETH_MAC_FLAG_TST  : Time stamp trigger flag
 *           @arg ETH_MAC_FLAG_MMCT : MMC transmit flag
 *           @arg ETH_MAC_FLAG_MMCR : MMC receive flag
 *           @arg ETH_MAC_FLAG_MMC  : MMC flag
 *           @arg ETH_MAC_FLAG_PMT  : PMT flag
 *
 * @retval SET or RESET.
 */
uint8_t ETH_ReadMACFlagStatus(ETH_MAC_FLAG_T flag)
{
    return (ETH->ISTS & flag) ? SET : RESET;
}

/*!
 * @brief  Enable the specified ETH MAC interrupts.
 *
 * @param  interrupt: Ethernet MAC interrupt flag:
 *         This parameter can be any combination of the following values:
 *           @arg ETH_MAC_INT_TST : Time stamp trigger interrupt
 *           @arg ETH_MAC_INT_PMT : PMT interrupt
 *
 * @retval None
 */
void ETH_EnableMACInterrupt(uint32_t interrupt)
{
    ETH->IMASK |= interrupt;
}

/*!
 * @brief  Disable the specified ETH MAC interrupts.
 *
 * @param  interrupt: Ethernet MAC interrupt flag:
 *         This parameter can be any combination of the following values:
 *           @arg ETH_MAC_INT_TST : Time stamp trigger interrupt
 *           @arg ETH_MAC_INT_PMT : PMT interrupt
 *
 * @retval None
 */
void ETH_DisableMACInterrupt(uint32_t interrupt)
{
    ETH->IMASK &= (~(uint32_t)interrupt);
}

/*!
 * @brief  Config the MAC address.
 *
 * @param  macAddr: The MAC address.
 *         This parameter can be one of the following values:
 *           @arg ETH_MAC_ADDRESS0 : MAC Address0
 *           @arg ETH_MAC_ADDRESS1 : MAC Address1
 *           @arg ETH_MAC_ADDRESS2 : MAC Address2
 *           @arg ETH_MAC_ADDRESS3 : MAC Address3
 *
 * @param  addr: Pointer on MAC address buffer data (6 bytes).
 *
 * @retval None
 */
void ETH_ConfigMACAddress(ETH_MAC_ADDRESS_T macAddr, uint8_t* addr)
{
    uint32_t temp;

    temp = ((uint32_t)addr[5] << 8) | (uint32_t)addr[4];
    (*(__IO uint32_t*)(ETH_MAC_ADDR_HBASE + macAddr)) = temp;

    temp = ((uint32_t)addr[3] << 24) | ((uint32_t)addr[2] << 16) | ((uint32_t)addr[1] << 8) | addr[0];
    (*(__IO uint32_t*)(ETH_MAC_ADDR_LBASE + macAddr)) = temp;
}

/*!
 * @brief  Read the MAC address.
 *
 * @param  macAddr: The MAC address.
 *         This parameter can be one of the following values:
 *           @arg ETH_MAC_ADDRESS0 : MAC Address0
 *           @arg ETH_MAC_ADDRESS1 : MAC Address1
 *           @arg ETH_MAC_ADDRESS2 : MAC Address2
 *           @arg ETH_MAC_ADDRESS3 : MAC Address3
 *
 * @param  addr: Pointer on MAC address buffer data (6 bytes).
 *
 * @retval None
 */
void ETH_ReadMACAddress(ETH_MAC_ADDRESS_T macAddr, uint8_t* addr)
{
    uint32_t temp;

    temp = (*(__IO uint32_t*)(ETH_MAC_ADDR_HBASE + macAddr));

    addr[5] = ((temp >> 8) & 0xFF);
    addr[4] = (temp & 0xFF);

    temp = (*(__IO uint32_t*)(ETH_MAC_ADDR_LBASE + macAddr));
    addr[3] = ((temp >> 24) & 0xFF);
    addr[2] = ((temp >> 16) & 0xFF);
    addr[1] = ((temp >> 8)  & 0xFF);
    addr[0] = (temp & 0xFF);
}

/*!
 * @brief  Enable address filters module uses the MAC address for perfect filtering.
 *
 * @param  macAddr: The MAC address.
 *         This parameter can be one of the following values:
 *           @arg ETH_MAC_ADDRESS1 : MAC Address1
 *           @arg ETH_MAC_ADDRESS2 : MAC Address2
 *           @arg ETH_MAC_ADDRESS3 : MAC Address3
 *
 * @retval None
 */
void ETH_EnableMACAddressPerfectFilter(ETH_MAC_ADDRESS_T macAddr)
{
    __IO uint32_t temp = 0;
    (*(__IO uint32_t*)(ETH_MAC_ADDR_HBASE + macAddr)) |= BIT31;
    ETH_Delay(ETH_REG_WRITE_DELAY);
    (*(__IO uint32_t*)(ETH_MAC_ADDR_HBASE + macAddr)) = temp;
}

/*!
 * @brief  Disable address filters module uses the MAC address for perfect filtering.
 *
 * @param  macAddr: The MAC address.
 *         This parameter can be one of the following values:
 *           @arg ETH_MAC_ADDRESS1 : MAC Address1
 *           @arg ETH_MAC_ADDRESS2 : MAC Address2
 *           @arg ETH_MAC_ADDRESS3 : MAC Address3
 *
 * @retval None
 */
void ETH_DisableMACAddressPerfectFilter(ETH_MAC_ADDRESS_T macAddr)
{
    __IO uint32_t temp = 0;
    (*(__IO uint32_t*)(ETH_MAC_ADDR_HBASE + macAddr)) &= (~BIT31);
    ETH_Delay(ETH_REG_WRITE_DELAY);
    (*(__IO uint32_t*)(ETH_MAC_ADDR_HBASE + macAddr)) = temp;
}

/*!
 * @brief  Config the filter type for the MAC address
 *
 * @param  macAddr: The MAC address.
 *         This parameter can be one of the following values:
 *           @arg ETH_MAC_ADDRESS1 : MAC Address1
 *           @arg ETH_MAC_ADDRESS2 : MAC Address2
 *           @arg ETH_MAC_ADDRESS3 : MAC Address3
 *
 * @param  filter: Comparison with the SA/DA fields of the received frame.
 *         This parameter can be one of the following values:
 *           @arg ETH_MAC_ADDRESSFILTER_SA : MAC Address is used to compare with the
 *                                           SA fields of the received frame.
 *           @arg ETH_MAC_ADDRESSFILTER_DA : MAC Address is used to compare with the
 *                                           DA fields of the received frame.
 * @retval None
 */
void ETH_ConfigMACAddressFilter(ETH_MAC_ADDRESS_T macAddr, ETH_MAC_ADDRESSFILTER_T filter)
{
    if (filter == ETH_MAC_ADDRESSFILTER_SA)
    {
        (*(__IO uint32_t*)(ETH_MAC_ADDR_HBASE + macAddr)) |= ETH_MAC_ADDRESSFILTER_SA;
    }
    else
    {
        (*(__IO uint32_t*)(ETH_MAC_ADDR_HBASE + macAddr)) |= ETH_MAC_ADDRESSFILTER_DA;
    }

}

/*!
 * @brief  Config the filter type for the ETH MAC address.
 *
 * @param  macAddr: The MAC address.
 *         This parameter can be one of the following values:
 *           @arg ETH_MAC_ADDRESS1 : MAC Address1
 *           @arg ETH_MAC_ADDRESS2 : MAC Address2
 *           @arg ETH_MAC_ADDRESS3 : MAC Address3
 *
 * @param  MaskByte: specifies the used address bytes for comparison
 *         This parameter can be any combination of the following values:
 *           @arg ETH_MAC_ADDRESSMASK_BYTE6 : Mask MAC Address high reg bits [15:8].
 *           @arg ETH_MAC_ADDRESSMASK_BYTE5 : Mask MAC Address high reg bits [7:0].
 *           @arg ETH_MAC_ADDRESSMASK_BYTE4 : Mask MAC Address low reg bits [31:24].
 *           @arg ETH_MAC_ADDRESSMASK_BYTE3 : Mask MAC Address low reg bits [23:16].
 *           @arg ETH_MAC_ADDRESSMASK_BYTE2 : Mask MAC Address low reg bits [15:8].
 *           @arg ETH_MAC_ADDRESSMASK_BYTE1 : Mask MAC Address low reg bits [7:0].
 *
 * @retval None
 */
void ETH_ConfigMACAddressMaskBytesFilter(ETH_MAC_ADDRESS_T macAddr, uint32_t maskByte)
{
    __IO uint32_t temp = 0;

    (*(__IO uint32_t*)(ETH_MAC_ADDR_HBASE + macAddr)) &= (~(uint32_t)0x3F000000);

    temp = (*(__IO uint32_t*)(ETH_MAC_ADDR_HBASE + macAddr));
    ETH_Delay(ETH_REG_WRITE_DELAY);
    (*(__IO uint32_t*)(ETH_MAC_ADDR_HBASE + macAddr)) = temp;

    /* Set the selected Filter mask bytes */
    (*(__IO uint32_t*)(ETH_MAC_ADDR_HBASE + macAddr)) |= maskByte;

    temp = (*(__IO uint32_t*)(ETH_MAC_ADDR_HBASE + macAddr));
    ETH_Delay(ETH_REG_WRITE_DELAY);
    (*(__IO uint32_t*)(ETH_MAC_ADDR_HBASE + macAddr)) = temp;
}

/* DMA Descriptors functions */

/*!
 * @brief  Config the DMA Rx descriptors in chain mode.
 *
 * @param  DMARxDescTab: Pointer on the first Rx desc list
 *
 * @param  rxBuff: Pointer on the first RxBuffer list
 *
 * @param  rxBuffcount: Number of the used Rx desc in the list
 *
 * @retval None
 */
void ETH_ConfigDMARxDescChain(ETH_DMADescConfig_T* DMARxDescTab, uint8_t* rxBuff, uint32_t rxBuffcount)
{
    uint32_t i = 0;
    ETH_DMADescConfig_T* DMARxDesc;
    DMARxDescToGet = DMARxDescTab;

    for (i = 0; i < rxBuffcount; i++)
    {
        DMARxDesc = DMARxDescTab + i;
        DMARxDesc->Status = ETH_DMARXDESC_OWN;
        DMARxDesc->ControlBufferSize = ETH_DMARXDESC_RXCH | ETH_RX_BUF_SIZE;
        DMARxDesc->Buffer1Addr = (uint32_t)(&rxBuff[i * ETH_RX_BUF_SIZE]);
        if (i < (rxBuffcount - 1))
        {
            DMARxDesc->Buffer2NextDescAddr = (uint32_t)(DMARxDescTab + i + 1);
        }
        else
        {
            DMARxDesc->Buffer2NextDescAddr = (uint32_t)(DMARxDescTab);
        }
    }


    ETH->DMARXDLADDR = (uint32_t) DMARxDescTab;
    DMARxFraminfos = &RxFrameDescriptor;
}

/*!
 * @brief  Initializes the DMA Tx descriptors in chain mode.
 *
 * @param  DMATxDescTab: Pointer on the first Tx desc list
 *
 * @param  txBuff: Pointer on the first TxBuffer list
 *
 * @param  txBuffcount: Number of the used Tx desc in the list
 *
 * @retval None
  */
void ETH_ConfigDMATxDescChain(ETH_DMADescConfig_T* DMATxDescTab, uint8_t* txBuff, uint32_t txBuffcount)
{
    uint32_t i = 0;
    ETH_DMADescConfig_T* DMATxDesc;
    DMATxDescToSet = DMATxDescTab;

    for (i = 0; i < txBuffcount; i++)
    {
        DMATxDesc = DMATxDescTab + i;
        DMATxDesc->Status = ETH_DMATXDESC_TXCH;
        DMATxDesc->Buffer1Addr = (uint32_t)(&txBuff[i * ETH_TX_BUF_SIZE]);
        if (i < (txBuffcount - 1))
        {
            DMATxDesc->Buffer2NextDescAddr = (uint32_t)(DMATxDescTab + i + 1);
        }
        else
        {
            DMATxDesc->Buffer2NextDescAddr = (uint32_t)(DMATxDescTab);
        }
    }

    ETH->DMATXDLADDR = (uint32_t) DMATxDescTab;
}

/*!
 * @brief  This function polls for a frame receiver
 *
 * @param  None
 *
 * @retval Returns 1 when a frame is received, 0 if none.
 */
uint32_t ETH_CheckReceivedFrame(void)
{
    if (((DMARxDescToGet->Status & ETH_DMARXDESC_OWN) == (uint32_t)RESET) &&
            ((DMARxDescToGet->Status & ETH_DMARXDESC_LDES) != (uint32_t)RESET))
    {
        DMARxFraminfos->segCount++;
        if (DMARxFraminfos->segCount == 1)
        {
            DMARxFraminfos->FS_RxDesc = DMARxDescToGet;
        }
        DMARxFraminfos->LS_RxDesc = DMARxDescToGet;
        return 1;
    }
    else if (((DMARxDescToGet->Status & ETH_DMARXDESC_OWN) == (uint32_t)RESET) &&
             ((DMARxDescToGet->Status & ETH_DMARXDESC_FDES) != (uint32_t)RESET) &&
             ((DMARxDescToGet->Status & ETH_DMARXDESC_LDES) == (uint32_t)RESET))
    {
        DMARxFraminfos->FS_RxDesc = DMARxDescToGet;
        DMARxFraminfos->LS_RxDesc = NULL;
        DMARxFraminfos->segCount  = 1;
        DMARxDescToGet = (ETH_DMADescConfig_T*)(DMARxDescToGet->Buffer2NextDescAddr);
    }
    else if (((DMARxDescToGet->Status & ETH_DMARXDESC_OWN) == (uint32_t)RESET) &&
             ((DMARxDescToGet->Status & ETH_DMARXDESC_FDES) == (uint32_t)RESET) &&
             ((DMARxDescToGet->Status & ETH_DMARXDESC_LDES) == (uint32_t)RESET))
    {
        (DMARxFraminfos->segCount) ++;
        DMARxDescToGet = (ETH_DMADescConfig_T*)(DMARxDescToGet->Buffer2NextDescAddr);
    }
    return 0;
}

/*!
 * @brief  Prepares DMA Tx descriptors to transmit an ethernet frame
 *
 * @param  FrameLength : length of the frame to send
 *
 * @retval ETH_ERROR or ETH_SUCCESS
 */
uint32_t ETH_Transmit_Descriptors(u16 frameLength)
{
    uint32_t count = 0, size = 0, i = 0;
    __IO ETH_DMADescConfig_T*  DMATxDesc;

    if ((DMATxDescToSet->Status & ETH_DMATXDESC_OWN) == SET)
    {
        return ETH_ERROR;
    }

    DMATxDesc = DMATxDescToSet;

    if (frameLength > ETH_TX_BUF_SIZE)
    {
        count = frameLength / ETH_TX_BUF_SIZE;
        if (frameLength % ETH_TX_BUF_SIZE) count++;
    }
    else count = 1;

    if (count == 1)
    {
        DMATxDesc->Status |= ETH_DMATXDESC_FS | ETH_DMATXDESC_LS;
        DMATxDesc->ControlBufferSize = (frameLength & ETH_DMATXDESC_TXBS1);
        DMATxDesc->Status |= ETH_DMATXDESC_OWN;
        DMATxDesc = (ETH_DMADescConfig_T*)(DMATxDesc->Buffer2NextDescAddr);
    }
    else
    {
        for (i = 0; i < count; i++)
        {
            DMATxDesc->Status &= ~(ETH_DMATXDESC_FS | ETH_DMATXDESC_LS);

            if (i == 0)
            {
                DMATxDesc->Status |= ETH_DMATXDESC_FS;
            }
            DMATxDesc->ControlBufferSize = (ETH_TX_BUF_SIZE & ETH_DMATXDESC_TXBS1);

            if (i == (count - 1))
            {
                DMATxDesc->Status |= ETH_DMATXDESC_LS;
                size = frameLength - (count - 1) * ETH_TX_BUF_SIZE;
                DMATxDesc->ControlBufferSize = (size & ETH_DMATXDESC_TXBS1);
            }

            DMATxDesc->Status |= ETH_DMATXDESC_OWN;
            DMATxDesc = (ETH_DMADescConfig_T*)(DMATxDesc->Buffer2NextDescAddr);
        }
    }
    DMATxDescToSet = DMATxDesc;

    if (ETH->DMASTS_B.TXBU == SET)
    {
        ETH->DMASTS = BIT2;
        ETH->DMATXPD = 0;
    }

    return ETH_SUCCESS;
}

/*!
 * @brief  Read the received frame.
 *
 * @param  none
 *
 * @retval Structure of type ETH_Frame_T
 */
ETH_Frame_T ETH_ReadReceivedFrame(void)
{
    uint32_t frameLength = 0;
    ETH_Frame_T frame = {0, 0, 0};

    frameLength = ((DMARxDescToGet->Status & ETH_DMARXDESC_FL) >> ETH_DMARXDESC_FRAMELENGTHSHIFT) - 4;
    frame.length = frameLength;

    frame.descriptor = DMARxFraminfos->FS_RxDesc;
    frame.buffer = (DMARxFraminfos->FS_RxDesc)->Buffer1Addr;
    DMARxDescToGet = (ETH_DMADescConfig_T*)(DMARxDescToGet->Buffer2NextDescAddr);

    return (frame);
}

/*!
 * @brief  Read ETH DMA Tx Descriptor flag.
 *
 * @param  DMATxDesc: pointer on a DMA Tx descriptor
 *
 * @param  flag: Specifies the flag to check.
 *         This parameter can be one of the following values:
 *           @arg ETH_DMATXDESC_OWN   : Descriptor is owned by DMA engine
 *           @arg ETH_DMATXDESC_INTC  : Interrupt on completion
 *           @arg ETH_DMATXDESC_LS    : Last Segment
 *           @arg ETH_DMATXDESC_FS    : First Segment
 *           @arg ETH_DMATXDESC_DISC  : Disable CRC
 *           @arg ETH_DMATXDESC_DISP  : Disable Pad
 *           @arg ETH_DMATXDESC_TXTSEN: Transmit Time Stamp Enable
 *           @arg ETH_DMATXDESC_TXENDR: Transmit End of Ring
 *           @arg ETH_DMATXDESC_TXCH  : Second Address Chained
 *           @arg ETH_DMATXDESC_TXTSS : Tx Time Stamp Status
 *           @arg ETH_DMATXDESC_IHERR : IP Header Error
 *           @arg ETH_DMATXDESC_ERRS  : Error summary
 *           @arg ETH_DMATXDESC_JTO   : Jabber Timeout
 *           @arg ETH_DMATXDESC_FF    : Frame Flushed: DMA/MTL flushed the frame due to SW flush
 *           @arg ETH_DMATXDESC_IPERR : Payload Checksum Error
 *           @arg ETH_DMATXDESC_LSC   : Loss of Carrier: carrier lost during transmission
 *           @arg ETH_DMATXDESC_NC    : No Carrier: no carrier signal from the transceiver
 *           @arg ETH_DMATXDESC_LC    : Late Collision: transmission aborted due to collision
 *           @arg ETH_DMATXDESC_EC    : Excessive Collision: transmission aborted after 16 collisions
 *           @arg ETH_DMATXDESC_VLANF : VLAN Frame
 *           @arg ETH_DMATXDESC_CCNT  : Collision Count
 *           @arg ETH_DMATXDESC_EDEF  : Excessive Deferral
 *           @arg ETH_DMATXDESC_UFERR : Underflow Error: late data arrival from the memory
 *           @arg ETH_DMATXDESC_DEF   : Deferred Bit
 *
 * @retval SET or RESET.
 */
uint8_t ETH_ReadDMATxDescFlagStatus(ETH_DMADescConfig_T* DMATxDesc, ETH_DMATXDESC_FLAG_T flag)
{
    return (DMATxDesc->Status & flag) ? SET : RESET;
}

/*!
 * @brief  Returns ETH DMA Tx Descriptor collision count.
 *
 * @param  DMATxDesc: pointer on a DMA Tx descriptor
 *
 * @retval The Transmit descriptor collision counter value.
 */
uint32_t ETH_ReadDMATxDescCollisionCount(ETH_DMADescConfig_T* DMATxDesc)
{
    return ((DMATxDesc->Status & ETH_DMATXDESC_CCNT) >> ETH_DMATXDESC_COLLISION_COUNTSHIFT);
}

/*!
 * @brief  Config the ETH DMA Tx Descriptor Own bit.
 *
 * @param  DMATxDesc: pointer on a DMA Tx descriptor
 *
 * @retval None
 */
void ETH_ConfigDMATxDescOwnBit(ETH_DMADescConfig_T* DMATxDesc)
{
    DMATxDesc->Status |= ETH_DMATXDESC_OWN;
}

/*!
 * @brief  Enable the ETH DMA Tx Descriptor Transmit interrupt.
 *
 * @param  DMATxDesc: pointer on a DMA Tx descriptor
 *
 * @retval None
 */
void ETH_EnableDMATxDescTransmitInterrupt(ETH_DMADescConfig_T* DMATxDesc)
{
    DMATxDesc->Status |= ETH_DMATXDESC_INTC;
}

/*!
 * @brief  Disable the ETH DMA Tx Descriptor Transmit interrupt.
 *
 * @param  DMATxDesc: pointer on a DMA Tx descriptor
 *
 * @retval None
 */
void ETH_DisableDMATxDescTransmitInterrupt(ETH_DMADescConfig_T* DMATxDesc)
{
    DMATxDesc->Status &= (~(uint32_t)ETH_DMATXDESC_INTC);
}

/*!
 * @brief  Config Tx descriptor as last or first segment
 *
 * @param  DMATxDesc: pointer on a DMA Tx descriptor
 *
 * @param  frameSegment: Tx desc contain last or first segment.
 *         This parameter can be one of the following values:
 *           @arg ETH_DMATXDESC_LASTSEGMENTS : Actual Tx desc contain last segment
 *           @arg ETH_DMATXDESC_FIRSTSEGMENT : Actual Tx desc contain first segment
 *
 * @retval None
 */
void ETH_ConfigDMATxDescFrameSegment(ETH_DMADescConfig_T* DMATxDesc, ETH_DMATXDESC_SEGMENTS_T frameSegment)
{
    DMATxDesc->Status |= frameSegment;
}
/*!
 * @brief  Config ETH DMA Tx Desc Checksum Insertion.
 *
 * @param  DMATxDesc: pointer on a DMA Tx descriptor
 *
 * @param  checksum: specifies is the DMA Tx desc checksum insertion.
 *         This parameter can be one of the following values:
 *           @arg ETH_DMATXDESC_CHECKSUMBYPASS              : Checksum bypass
 *           @arg ETH_DMATXDESC_CHECKSUMIPV4HEADER          : IPv4 header checksum
 *           @arg ETH_DMATXDESC_CHECKSUMTCPUDPICMPSEGMENT   : TCP/UDP/ICMP checksum. Pseudo header checksum is assumed to be present
 *           @arg ETH_DMATXDESC_CHECKSUMTCPUDPICMPFULL      : TCP/UDP/ICMP checksum fully in hardware including pseudo header
 *
 * @retval None
 */
void ETH_ConfigDMATxDescChecksumInsertion(ETH_DMADescConfig_T* DMATxDesc, ETH_DMATXDESC_CHECKSUMB_T checksum)
{
    DMATxDesc->Status |= checksum;
}

/*!
 * @brief  Enable the DMA Tx Desc CRC.
 *
 * @param  DMATxDesc: pointer on a DMA Tx descriptor
 *
 * @retval None
 */
void ETH_EnableDMATxDescCRC(ETH_DMADescConfig_T* DMATxDesc)
{
    DMATxDesc->Status &= (~(uint32_t)ETH_DMATXDESC_DISC);
}

/*!
 * @brief  Disable the DMA Tx Desc CRC.
 *
 * @param  DMATxDesc: pointer on a DMA Tx descriptor
 *
 * @retval None
 */
void ETH_DisableDMATxDescCRC(ETH_DMADescConfig_T* DMATxDesc)
{
    DMATxDesc->Status |= ETH_DMATXDESC_DISC;
}

/*!
 * @brief  Enable the DMA Tx Desc second address chained.
 *
 * @param  DMATxDesc: pointer on a DMA Tx descriptor
 *
 * @retval None
 */
void ETH_EnableDMATxDescSecondAddressChained(ETH_DMADescConfig_T* DMATxDesc)
{
    DMATxDesc->Status |= ETH_DMATXDESC_TXCH;
}

/*!
 * @brief  Disable the DMA Tx Desc second address chained.
 *
 * @param  DMATxDesc: pointer on a DMA Tx descriptor
 *
 * @retval None
 */
void ETH_DisableDMATxDescSecondAddressChained(ETH_DMADescConfig_T* DMATxDesc)
{
    DMATxDesc->Status &= (~(uint32_t)ETH_DMATXDESC_TXCH);
}

/*!
 * @brief  Enable the DMA Tx Desc padding for frame shorter than 64 bytes.
 *
 * @param  DMATxDesc: pointer on a DMA Tx descriptor
 *
 * @retval None
 */
void ETH_EnableDMATxDescShortFramePadding(ETH_DMADescConfig_T* DMATxDesc)
{
    DMATxDesc->Status &= (~(uint32_t)ETH_DMATXDESC_DISP);
}

/*!
 * @brief  Disable the DMA Tx Desc padding for frame shorter than 64 bytes.
 *
 * @param  DMATxDesc: pointer on a DMA Tx descriptor
 *
 * @retval None
 */
void ETH_DisableDMATxDescShortFramePadding(ETH_DMADescConfig_T* DMATxDesc)
{
    DMATxDesc->Status |= ETH_DMATXDESC_DISP;
}

/*!
 * @brief  Config the ETH DMA Tx Desc buffer1 and buffer2 sizes.
 *
 * @param  DMATxDesc: pointer on a DMA Tx descriptor
 *
 * @param  bufferSize1: specifies the Tx desc buffer1 size.
 *
 * @param  bufferSize2: specifies the Tx desc buffer2 size.
 *
 * @retval None
 */
void ETH_ConfigDMATxDescBufferSize(ETH_DMADescConfig_T* DMATxDesc, uint32_t bufferSize1, uint32_t bufferSize2)
{
    DMATxDesc->ControlBufferSize |= (bufferSize1 | (bufferSize2 << ETH_DMATXDESC_BUFFER2_SIZESHIFT));
}

/*!
 * @brief  Checks whether the specified ETHERNET Rx Desc flag is set or not.
 *
 * @param  DMARxDesc: pointer on a DMA Rx descriptor

 * @param  flag: specifies the flag to check.
 *         This parameter can be one of the following values:
 *           @arg ETH_DMARXDESC_OWN    :    Descriptor is owned by DMA engine
 *           @arg ETH_DMARXDESC_ADDRF  :    DA Filter Fail for the rx frame
 *           @arg ETH_DMARXDESC_ERRS   :    Error summary
 *           @arg ETH_DMARXDESC_DESERR :    Descriptor error: no more descriptors for receive frame
 *           @arg ETH_DMARXDESC_SADDRF :    SA Filter Fail for the received frame
 *           @arg ETH_DMARXDESC_LERR   :    Frame size not matching with length field
 *           @arg ETH_DMARXDESC_OFERR  :    Overflow Error: Frame was damaged due to buffer overflow
 *           @arg ETH_DMARXDESC_VLANF  :    VLAN Tag: received frame is a VLAN frame
 *           @arg ETH_DMARXDESC_FDES   :    First descriptor of the frame
 *           @arg ETH_DMARXDESC_LDES   :    Last descriptor of the frame
 *           @arg ETH_DMARXDESC_IPV4HCE:    IPC Checksum Error/Giant Frame: Rx Ipv4 header checksum error
 *           @arg ETH_DMARXDESC_LC     :    Late collision occurred during reception
 *           @arg ETH_DMARXDESC_FT     :    Frame type - Ethernet, otherwise 802.3
 *           @arg ETH_DMARXDESC_RXWDTTO:    Receive Watchdog Timeout: watchdog timer expired during reception
 *           @arg ETH_DMARXDESC_RERR   :    Receive error: error reported by MII interface
 *           @arg ETH_DMARXDESC_DERR   :    Dribble bit error: frame contains non int multiple of 8 bits
 *           @arg ETH_DMARXDESC_CERR   :    CRC error
 *           @arg ETH_DMARXDESC_MAMPCE :    Rx MAC Address/Payload Checksum Error: Rx MAC address matched/ Rx Payload Checksum Error
 *
 * @retval SET or RESET.
 */
uint8_t ETH_ReadDMARxDescFlagStatus(ETH_DMADescConfig_T* DMARxDesc, ETH_DMARXDESC_FLAG_T flag)
{
    return (DMARxDesc->Status & flag) ? SET : RESET;
}

/*!
 * @brief  Config the ETH DMA Rx Desc Own bit.
 *
 * @param  DMARxDesc: pointer on a DMA Rx descriptor
 *
 * @retval None
 */
void ETH_ConfigDMARxDescOwnBit(ETH_DMADescConfig_T* DMARxDesc)
{
    DMARxDesc->Status |= ETH_DMARXDESC_OWN;
}

/*!
 * @brief  Returns the ETH DMA Rx descriptor frame length.
 *
 * @param  DMARxDesc: pointer on a DMA Rx descriptor
 *
 * @retval The Rx descriptor received frame length.
 */
uint32_t ETH_ReadDMARxDescFrameLength(ETH_DMADescConfig_T* DMARxDesc)
{
    return ((DMARxDesc->Status & ETH_DMARXDESC_FL) >> ETH_DMARXDESC_FRAME_LENGTHSHIFT);
}

/*!
 * @brief  Enable the ETH DMA Rx Desc receive interrupt.
 *
 * @param  DMARxDesc: pointer on a DMA Rx descriptor
 *
 * @retval None
 */
void ETH_EnableDMARxDescReceiveInterrupt(ETH_DMADescConfig_T* DMARxDesc)
{
    DMARxDesc->ControlBufferSize &= (~(uint32_t)ETH_DMARXDESC_DINTC);
}

/*!
 * @brief  Disable the ETH DMA Rx Desc receive interrupt.
 *
 * @param  DMARxDesc: pointer on a DMA Rx descriptor
 *
 * @retval None
 */
void ETH_DisableDMARxDescReceiveInterrupt(ETH_DMADescConfig_T* DMARxDesc)
{
    DMARxDesc->ControlBufferSize |= ETH_DMARXDESC_DINTC;
}

/*!
 * @brief  Returns the ETH DMA Rx Desc buffer size.
 *
 * @param  DMARxDesc: pointer on a DMA Rx descriptor
 *
 * @param  buffer: specifies the DMA Rx Desc buffer.
 *         This parameter can be one of the following values:
 *           @arg ETH_DMARxDesc_Buffer1 : DMA Rx Desc Buffer1
 *           @arg ETH_DMARxDesc_Buffer2 : DMA Rx Desc Buffer2
 *
 * @retval The Receive descriptor frame length.
 */
uint32_t ETH_ReadDMARxDescBufferSize(ETH_DMADescConfig_T* DMARxDesc, ETH_DMARXDESC_BUFFER_T buffer)
{
    if (buffer == ETH_DMARXDESC_BUFFER1)
    {
        return (DMARxDesc->ControlBufferSize & ETH_DMARXDESC_RXBS1);
    }
    else
    {
        return ((DMARxDesc->ControlBufferSize & ETH_DMARXDESC_RXBS2) >> ETH_DMARXDESC_BUFFER2_SIZESHIFT);
    }
}

/*!
 * @brief  Read frame using DMA Receive interrupt.
 *         it allows scanning of Rx descriptors to get the the receive frame
 *
 * @param  None
 *
 * @retval Structure of type ETH_Frame_T
 */
ETH_Frame_T ETH_ReadReceivedFrameInterrupt(void)
{
    __IO uint32_t count = 0;
    ETH_Frame_T frame = {0, 0, 0};

    while (((DMARxDescToGet->Status & ETH_DMARXDESC_OWN) == (uint32_t)RESET) && (count < ETH_RXBUFNB))
    {
        count ++;

        if (((DMARxDescToGet->Status & ETH_DMARXDESC_FDES) != (uint32_t)RESET) &&
                ((DMARxDescToGet->Status & ETH_DMARXDESC_LDES) == (uint32_t)RESET))
        {
            DMARxFraminfos->FS_RxDesc = DMARxDescToGet;
            DMARxFraminfos->segCount = 1;
            DMARxDescToGet = (ETH_DMADescConfig_T*)(DMARxDescToGet->Buffer2NextDescAddr);
        }
        else if (((DMARxDescToGet->Status & ETH_DMARXDESC_FDES) == (uint32_t)RESET) &&
                 ((DMARxDescToGet->Status & ETH_DMARXDESC_LDES) == (uint32_t)RESET))
        {
            (DMARxFraminfos->segCount) ++;
            DMARxDescToGet = (ETH_DMADescConfig_T*)(DMARxDescToGet->Buffer2NextDescAddr);
        }
        else
        {
            DMARxFraminfos->LS_RxDesc = DMARxDescToGet;
            (DMARxFraminfos->segCount)++;

            if ((DMARxFraminfos->segCount) == 1)
                DMARxFraminfos->FS_RxDesc = DMARxDescToGet;

            frame.length = ((DMARxDescToGet->Status & ETH_DMARXDESC_FL) >> ETH_DMARXDESC_FRAMELENGTHSHIFT) - 4;

            if (DMARxFraminfos->segCount > 1)
            {
                frame.buffer = (DMARxFraminfos->FS_RxDesc)->Buffer1Addr;
            }
            else
            {
                frame.buffer = DMARxDescToGet->Buffer1Addr;
            }

            frame.descriptor = DMARxFraminfos->FS_RxDesc;
            DMARxDescToGet = (ETH_DMADescConfig_T*)(DMARxDescToGet->Buffer2NextDescAddr);

            return (frame);
        }
    }
    return (frame);
}

/* DMA functions */

/*!
 * @brief  Read the ETH DMA flag.
 *
 * @param  flag: specifies the flag to check.
 *         This parameter can be one of the following values:
 *           @arg ETH_DMA_FLAG_TST                  : Time-stamp trigger flag
 *           @arg ETH_DMA_FLAG_PMT                  : PMT flag
 *           @arg ETH_DMA_FLAG_MMC                  : MMC flag
 *           @arg ETH_DMA_FLAG_DATATRANSFERERROR    : Error bits 0-data buffer, 1-desc. access
 *           @arg ETH_DMA_FLAG_READWRITEERROR       : Error bits 0-write trnsf, 1-read transfr
 *           @arg ETH_DMA_FLAG_ACCESSERROR          : Error bits 0-Rx DMA, 1-Tx DMA
 *           @arg ETH_DMA_FLAG_NIS                  : Normal interrupt summary flag
 *           @arg ETH_DMA_FLAG_AIS                  : Abnormal interrupt summary flag
 *           @arg ETH_DMA_FLAG_ER                   : Early receive flag
 *           @arg ETH_DMA_FLAG_FBE                  : Fatal bus error flag
 *           @arg ETH_DMA_FLAG_ET                   : Early transmit flag
 *           @arg ETH_DMA_FLAG_RWT                  : Receive watchdog timeout flag
 *           @arg ETH_DMA_FLAG_RPS                  : Receive process stopped flag
 *           @arg ETH_DMA_FLAG_RBU                  : Receive buffer unavailable flag
 *           @arg ETH_DMA_FLAG_RX                   : Receive flag
 *           @arg ETH_DMA_FLAG_TU                   : Underflow flag
 *           @arg ETH_DMA_FLAG_RO                   : Overflow flag
 *           @arg ETH_DMA_FLAG_TJT                  : Transmit jabber timeout flag
 *           @arg ETH_DMA_FLAG_TBU                  : Transmit buffer unavailable flag
 *           @arg ETH_DMA_FLAG_TPS                  : Transmit process stopped flag
 *           @arg ETH_DMA_FLAG_TX                   : Transmit flag
 *
 * @retval SET or RESET.
 */
uint8_t ETH_ReadDMAFlagStatus(ETH_DMA_FLAG_T flag)
{
    return (ETH->DMASTS & flag) ? SET : RESET;
}

/*!
 * @brief  Clears the ETH DMA flag.
 *
 * @param  flag: specifies the flag to clear.
 *         This parameter can be any combination of the following values:
 *           @arg ETH_DMA_FLAG_NIS : Normal interrupt summary flag
 *           @arg ETH_DMA_FLAG_AIS : Abnormal interrupt summary flag
 *           @arg ETH_DMA_FLAG_ER  : Early receive flag
 *           @arg ETH_DMA_FLAG_FBE : Fatal bus error flag
 *           @arg ETH_DMA_FLAG_ET  : Early transmit flag
 *           @arg ETH_DMA_FLAG_RWT : Receive watchdog timeout flag
 *           @arg ETH_DMA_FLAG_RPS : Receive process stopped flag
 *           @arg ETH_DMA_FLAG_RBU : Receive buffer unavailable flag
 *           @arg ETH_DMA_FLAG_RX  : Receive flag
 *           @arg ETH_DMA_FLAG_TU  : Transmit Underflow flag
 *           @arg ETH_DMA_FLAG_RO  : Receive Overflow flag
 *           @arg ETH_DMA_FLAG_TJT : Transmit jabber timeout flag
 *           @arg ETH_DMA_FLAG_TBU : Transmit buffer unavailable flag
 *           @arg ETH_DMA_FLAG_TPS : Transmit process stopped flag
 *           @arg ETH_DMA_FLAG_TX  : Transmit flag
 *
 * @retval None
 */
void ETH_ClearDMAFlag(uint32_t flag)
{
    ETH->DMASTS = flag;
}

/*!
 * @brief  Read the ETH DMA interrupt flag.
 *
 * @param  flag: specifies the interrupt source to check.
 *         This parameter can be one of the following values:
 *           @arg ETH_DMA_INT_TST : Time-stamp trigger interrupt
 *           @arg ETH_DMA_INT_PMT : PMT interrupt
 *           @arg ETH_DMA_INT_MMC : MMC interrupt
 *           @arg ETH_DMA_INT_NIS : Normal interrupt summary
 *           @arg ETH_DMA_INT_AIS : Abnormal interrupt summary
 *           @arg ETH_DMA_INT_ER  : Early receive interrupt
 *           @arg ETH_DMA_INT_FBE : Fatal bus error interrupt
 *           @arg ETH_DMA_INT_ET  : Early transmit interrupt
 *           @arg ETH_DMA_INT_RWT : Receive watchdog timeout interrupt
 *           @arg ETH_DMA_INT_RPS : Receive process stopped interrupt
 *           @arg ETH_DMA_INT_RBU : Receive buffer unavailable interrupt
 *           @arg ETH_DMA_INT_RX  : Receive interrupt
 *           @arg ETH_DMA_INT_TU  : Underflow interrupt
 *           @arg ETH_DMA_INT_RO  : Overflow interrupt
 *           @arg ETH_DMA_INT_TJT : Transmit jabber timeout interrupt
 *           @arg ETH_DMA_INT_TBU : Transmit buffer unavailable interrupt
 *           @arg ETH_DMA_INT_TPS : Transmit process stopped interrupt
 *           @arg ETH_DMA_INT_TX  : Transmit interrupt
 *
 * @retval SET or RESET.
 */
uint8_t ETH_ReadDMAIntFlag(ETH_DMA_INT_T flag)
{
    return (ETH->DMASTS & flag) ? SET : RESET;
}

/*!
 * @brief  Clears the ETH DMA interrupt flag.
 *
 * @param  flag: specifies the interrupt flag to clear.
 *         This parameter can be any combination of the following values:
 *           @arg ETH_DMA_INT_NIS : Normal interrupt summary
 *           @arg ETH_DMA_INT_AIS : Abnormal interrupt summary
 *           @arg ETH_DMA_INT_ER  : Early receive interrupt
 *           @arg ETH_DMA_INT_FBE : Fatal bus error interrupt
 *           @arg ETH_DMA_INT_ET  : Early transmit interrupt
 *           @arg ETH_DMA_INT_RWT : Receive watchdog timeout interrupt
 *           @arg ETH_DMA_INT_RPS : Receive process stopped interrupt
 *           @arg ETH_DMA_INT_RBU : Receive buffer unavailable interrupt
 *           @arg ETH_DMA_INT_RX  : Receive interrupt
 *           @arg ETH_DMA_INT_TU  : Transmit Underflow interrupt
 *           @arg ETH_DMA_INT_RO  : Receive Overflow interrupt
 *           @arg ETH_DMA_INT_TJT : Transmit jabber timeout interrupt
 *           @arg ETH_DMA_INT_TBU : Transmit buffer unavailable interrupt
 *           @arg ETH_DMA_INT_TPS : Transmit process stopped interrupt
 *           @arg ETH_DMA_INT_TX  : Transmit interrupt
 *
 * @retval None
 */
void ETH_ClearDMAIntFlag(uint32_t flag)
{
    ETH->DMASTS = flag;
}

/*!
 * @brief  Returns the ETH DMA Transmit Process State.
 *
 * @param  None

 * @retval The new ETH DMA Transmit Process State:
 *         This can be one of the following values:
 *           - ETH_DMA_TRANSMITPROCESS_STOPPED   : Stopped - Reset or Stop Tx Command issued
 *           - ETH_DMA_TRANSMITPROCESS_FETCHING  : Running - fetching the Tx descriptor
 *           - ETH_DMA_TRANSMITPROCESS_WAITING   : Running - waiting for status
 *           - ETH_DMA_TRANSMITPROCESS_READING   : Running - reading the data from host memory
 *           - ETH_DMA_TRANSMITPROCESS_SUSPENDED : Suspended - Tx Descriptor unavailable
 *           - ETH_DMA_TRANSMITPROCESS_CLOSING   : Running - closing Rx descriptor
 */
uint32_t ETH_ReadTransmitProcessState(void)
{
    return ((uint32_t)(ETH->DMASTS & BIT0) ? SET : RESET);
}

/*!
 * @brief  Returns the ETH DMA Receive Process State.
 *
 * @param  None
 *
 * @retval The new ETH DMA Receive Process State:
 *         This can be one of the following values:
 *           - ETH_DMA_RECEIVEPROCESS_STOPPED   : Stopped - Reset or Stop Rx Command issued
 *           - ETH_DMA_RECEIVEPROCESS_FETCHING  : Running - fetching the Rx descriptor
 *           - ETH_DMA_RECEIVEPROCESS_WAITING   : Running - waiting for packet
 *           - ETH_DMA_RECEIVEPROCESS_SUSPENDED : Suspended - Rx Descriptor unavailable
 *           - ETH_DMA_RECEIVEPROCESS_CLOSING   : Running - closing descriptor
 *           - ETH_DMA_RECEIVEPROCESS_QUEUING   : Running - queuing the receive frame into host memory
 */
uint32_t ETH_ReadReceiveProcessState(void)
{
    return ((uint32_t)(ETH->DMASTS & BIT6) ? SET : RESET);
}

/*!
 * @brief  Flush the ETH transmit FIFO.
 *
 * @param  None
 *
 * @retval None
  */
void ETH_FlushTransmitFIFO(void)
{
    ETH->DMAOPMOD_B.FTXF = SET;
    ETH_Delay(ETH_REG_WRITE_DELAY);
}

/*!
 * @brief  Read the ETH flush transmit FIFO status.
 *
 * @param  None
 *
 * @retval SET or RESET.
 */
uint8_t ETH_ReadFlushTransmitFIFOStatus(void)
{
    return ETH->DMAOPMOD_B.FTXF;
}

/*!
 * @brief  Enable the DMA transmission.
 *
 * @param  None
 *
 * @retval None
 */
void ETH_EnableDMATransmission(void)
{
    ETH->DMAOPMOD_B.STTX = SET;
    ETH_Delay(ETH_REG_WRITE_DELAY);
}

/*!
 * @brief  Disable the DMA transmission.
 *
 * @param  None
 *
 * @retval None
 */
void ETH_DisableDMATransmission(void)
{
    ETH->DMAOPMOD_B.STTX = RESET;
    ETH_Delay(ETH_REG_WRITE_DELAY);
}

/*!
 * @brief  Enable the DMA receiver.
 *
 * @param  None
 *
 * @retval None
 */
void ETH_EnableDMAReceiver(void)
{
    ETH->DMAOPMOD_B.STRX = SET;
    ETH_Delay(ETH_REG_WRITE_DELAY);
}

/*!
 * @brief  Disable the DMA receiver.
 *
 * @param  None
 *
 * @retval None
 */
void ETH_DisableDMAReceiver(void)
{
    ETH->DMAOPMOD_B.STRX = RESET;
    ETH_Delay(ETH_REG_WRITE_DELAY);
}

/*!
 * @brief  Enable the ETH DMA interrupts.
 *
 * @param  interrupt: specifies the ETH DMA interrupt sources.
 *         This parameter can be any combination of the following values:
 *           @arg ETH_DMA_INT_NIS : Normal interrupt summary
 *           @arg ETH_DMA_INT_AIS : Abnormal interrupt summary
 *           @arg ETH_DMA_INT_ER  : Early receive interrupt
 *           @arg ETH_DMA_INT_FBE : Fatal bus error interrupt
 *           @arg ETH_DMA_INT_ET  : Early transmit interrupt
 *           @arg ETH_DMA_INT_RWT : Receive watchdog timeout interrupt
 *           @arg ETH_DMA_INT_RPS : Receive process stopped interrupt
 *           @arg ETH_DMA_INT_RBU : Receive buffer unavailable interrupt
 *           @arg ETH_DMA_INT_RX  : Receive interrupt
 *           @arg ETH_DMA_INT_TU  : Underflow interrupt
 *           @arg ETH_DMA_INT_RO  : Overflow interrupt
 *           @arg ETH_DMA_INT_TJT : Transmit jabber timeout interrupt
 *           @arg ETH_DMA_INT_TBU : Transmit buffer unavailable interrupt
 *           @arg ETH_DMA_INT_TPS : Transmit process stopped interrupt
 *           @arg ETH_DMA_INT_TX  : Transmit interrupt
 *
 * @retval None
 */
void ETH_EnableDMAInterrupt(uint32_t interrupt)
{
    ETH->DMAINTEN |= interrupt;
}

/*!
 * @brief  Disable the ETH DMA interrupts.
 *
 * @param  interrupt: specifies the ETH DMA interrupt sources.
 *         This parameter can be any combination of the following values:
 *           @arg ETH_DMA_INT_NIS : Normal interrupt summary
 *           @arg ETH_DMA_INT_AIS : Abnormal interrupt summary
 *           @arg ETH_DMA_INT_ER  : Early receive interrupt
 *           @arg ETH_DMA_INT_FBE : Fatal bus error interrupt
 *           @arg ETH_DMA_INT_ET  : Early transmit interrupt
 *           @arg ETH_DMA_INT_RWT : Receive watchdog timeout interrupt
 *           @arg ETH_DMA_INT_RPS : Receive process stopped interrupt
 *           @arg ETH_DMA_INT_RBU : Receive buffer unavailable interrupt
 *           @arg ETH_DMA_INT_RX  : Receive interrupt
 *           @arg ETH_DMA_INT_TU  : Underflow interrupt
 *           @arg ETH_DMA_INT_RO  : Overflow interrupt
 *           @arg ETH_DMA_INT_TJT : Transmit jabber timeout interrupt
 *           @arg ETH_DMA_INT_TBU : Transmit buffer unavailable interrupt
 *           @arg ETH_DMA_INT_TPS : Transmit process stopped interrupt
 *           @arg ETH_DMA_INT_TX  : Transmit interrupt
 *
 * @retval None
 */
void ETH_DisableDMAInterrupt(uint32_t interrupt)
{
    ETH->DMAINTEN &= ((uint32_t)~interrupt);
}

/*!
 * @brief  Read the ETH DMA overflow flag.
 *
 * @param  overflow: specifies the DMA overflow flag to check.
 *         This parameter can be one of the following values:
 *           @arg ETH_DMA_OVERFLOW_RXFIFOCOUNTER        : Overflow for FIFO Overflows Counter
 *           @arg ETH_DMA_OVERFLOW_MISSEDFRAMECOUNTER   : Overflow for Buffer Unavailable Missed Frame Counter
 *
 * @retval SET or RESET.
 */
uint8_t ETH_ReadDMAOverflowStatus(ETH_DMA_OVERFLOW_T overflow)
{
    return (ETH->DMAMFABOCNT & overflow) ? SET : RESET;
}

/*!
 * @brief  Read the ETH DMA Rx Overflow Missed Frame Counter value.
 *
 * @param  None
 *
 * @retval The value of Rx overflow Missed Frame Counter.
 */
uint32_t ETH_ReadRxOverflowMissedFrameCounter(void)
{
    return (uint32_t)(ETH->DMAMFABOCNT_B.AMISFCNT);
}

/*!
 * @brief  Read the ETH DMA Buffer Unavailable Missed Frame Counter value.
 *
 * @param  None
 *
 * @retval The value of Buffer unavailable Missed Frame Counter.
 */
uint32_t ETH_ReadBufferUnavailableMissedFrameCounter(void)
{
    return (uint32_t)(ETH->DMAMFABOCNT_B.MISFCNT);
}

/*!
 * @brief  Read the ETH DMA DMAHTXD register value.
 *
 * @param  None
 *
 * @retval The value of the current Tx desc start address.
 */
uint32_t ETH_ReadCurrentTxDescStartAddress(void)
{
    return ((uint32_t)(ETH->DMAHTXD));
}

/*!
 * @brief  Read the ETHERNET DMA DMAHRXD register value.
 *
 * @param  None
 *
 * @retval The value of the current Rx desc start address.
 */
uint32_t ETH_ReadCurrentRxDescStartAddress(void)
{
    return ((uint32_t)(ETH->DMAHRXD));
}

/*!
 * @brief  Read the ETH DMA DMAHTXBADDR register value.
 *
 * @param  None
 *
 * @retval The value of the current transmit descriptor data buffer address.
 */
uint32_t ETH_ReadCurrentTxBufferAddress(void)
{
    return ((uint32_t)(ETH->DMAHTXBADDR));
}

/*!
 * @brief  Read the ETH DMA DMAHRXBADDR register value.
 *
 * @param  None
 *
 * @retval The value of the current receive descriptor data buffer address.
 */
uint32_t ETH_ReadCurrentRxBufferAddress(void)
{
    return ((uint32_t)(ETH->DMAHRXBADDR));
}

/*!
 * @brief  Reset the DMA Transmission by writing to the DmaTxPollDemand register
 *
 * @param  None

 * @retval None.
 */
void ETH_ResetDMATransmission(void)
{
    ETH->DMATXPD = 0;
}

/*!
 * @brief  Reset the DMA Transmission by writing to the DmaRxPollDemand register
 *
 * @param  None
 *
 * @retval None.
 */
void ETH_ResetDMAReception(void)
{
    ETH->DMARXPD = 0;
}

/** Power Management(PMT) functions */

/*!
 * @brief  Reset Wakeup frame filter register pointer.
 *
 * @param  None
 *
 * @retval None
 */
void ETH_ResetWakeUpFrameFilterRegisterPointer(void)
{
    ETH->PMTCTRLSTS_B.WKUPFRST = SET;
    ETH_Delay(ETH_REG_WRITE_DELAY);
}

/*!
 * @brief  Enable any unicast packet filtered by the MAC address
 *         recognition to be a wake-up frame.
 *
 * @retval None
 */
void ETH_EnableGlobalUnicastWakeUp(void)
{
    ETH->PMTCTRLSTS_B.GUN = SET;
    ETH_Delay(ETH_REG_WRITE_DELAY);
}

/*!
 * @brief  Disable any unicast packet filtered by the MAC address
 *         recognition to be a wake-up frame.
 *
 * @retval None
 */
void ETH_DisableGlobalUnicastWakeUp(void)
{
    ETH->PMTCTRLSTS_B.GUN = RESET;
    ETH_Delay(ETH_REG_WRITE_DELAY);
}

/*!
 * @brief  Read the ETH PMT flag.
 *
 * @param  flag: specifies the flag to check.
 *         This parameter can be one of the following values:
 *           @arg ETH_PMT_FLAG_WUFFRPR : Wake-Up Frame Filter Register Pointer Reset
 *           @arg ETH_PMT_FLAG_WUFR    : Wake-Up Frame Received
 *           @arg ETH_PMT_FLAG_MPR     : Magic Packet Received
 *
 * @retval SET or RESET.
 */
uint8_t ETH_ReadPMTFlagStatus(ETH_PMT_FLAG_T flag)
{
    return (ETH->PMTCTRLSTS & flag) ? SET : RESET;
}

/*!
 * @brief  Enable the MAC Wake-Up Frame Detection.
 *
 * @param  None
 *
 * @retval None
 */
void ETH_EnableWakeUpFrameDetection(void)
{
    ETH->PMTCTRLSTS_B.WKUPFEN = SET;
    ETH_Delay(ETH_REG_WRITE_DELAY);
}

/*!
 * @brief  Disable the MAC Wake-Up Frame Detection.
 *
 * @param  None
 *
 * @retval None
 */
void ETH_DisableWakeUpFrameDetection(void)
{
    ETH->PMTCTRLSTS_B.WKUPFEN = RESET;
    ETH_Delay(ETH_REG_WRITE_DELAY);
}

/*!
 * @brief  Enable the MAC Magic Packet Detection.
 *
 * @param  None
 *
 * @retval None
 */
void ETH_EnableMagicPacketDetection(void)
{
    ETH->PMTCTRLSTS_B.MPEN = SET;
    ETH_Delay(ETH_REG_WRITE_DELAY);
}

/*!
 * @brief  Disable the MAC Magic Packet Detection.
 *
 * @param  None
 *
 * @retval None
 */
void ETH_DisableMagicPacketDetection(void)
{
    ETH->PMTCTRLSTS_B.MPEN = RESET;
    ETH_Delay(ETH_REG_WRITE_DELAY);
}

/*!
 * @brief  Enable the MAC Power Down.
 *
 * @param  None
 *
 * @retval None
 */
void ETH_EnablePowerDown(void)
{
    ETH->PMTCTRLSTS_B.PD = SET;
    ETH_Delay(ETH_REG_WRITE_DELAY);
}

/*!
 * @brief  Disable the MAC Power Down.
 *
 * @param  None
 *
 * @retval None
 */
void ETH_DisablePowerDown(void)
{
    ETH->PMTCTRLSTS_B.PD = RESET;
    ETH_Delay(ETH_REG_WRITE_DELAY);
}

/*!
 * @brief  Enable the MMC Counter Freeze.
 *
 * @param  None
 *
 * @retval None
 */
void ETH_EnableMMCCounterFreeze(void)
{
    ETH->CTRL_B.MCNTF = SET;
}

/*!
 * @brief  Disable the MMC Counter Freeze.
 *
 * @param  None
 *
 * @retval None
 */
void ETH_DisableMMCCounterFreeze(void)
{
    ETH->CTRL_B.MCNTF = RESET;
}

/*!
 * @brief  Enable the MMC Reset On Read.
 *
 * @param  None
 *
 * @retval None
 */
void ETH_EnableMMCResetOnRead(void)
{
    ETH->CTRL_B.RSTOR = SET;
}

/*!
 * @brief  Disable the MMC Reset On Read.
 *
 * @param  None
 *
 * @retval None
 */
void ETH_DisableMMCResetOnRead(void)
{
    ETH->CTRL_B.RSTOR = RESET;
}

/*!
 * @brief  Enble the MMC Counter Stop Rollover.
 *
 * @param  None
 *
 * @retval None
 */
void ETH_EnableMMCCounterRollover(void)
{
    ETH->CTRL_B.CNTSTOPRO = RESET;
}

/*!
 * @brief  Disable the MMC Counter Stop Rollover.
 *
 * @param  None
 *
 * @retval None
 */
void ETH_DisableMMCCounterRollover(void)
{
    ETH->CTRL_B.CNTSTOPRO = SET;
}

/**
  * @brief  Resets the MMC Counters.
  * @param  None
  * @retval None
  */
void ETH_ResetMMCCounters(void)
{
    ETH->CTRL_B.CNTRST = SET;
}

/*!
 * @brief  Enable the ETH MMC interrupts.
 *
 * @param  interrupt: specifies the ETH MMC interrupt sources.
 *         This parameter can be any combination of Tx interrupt or
 *         any combination of Rx interrupt (but not both)of the following values:
 *           @arg ETH_MMC_INT_TGF   : When Tx good frame counter reaches half the maximum value
 *           @arg ETH_MMC_INT_TGFMSC: When Tx good multi col counter reaches half the maximum value
 *           @arg ETH_MMC_INT_TGFSC : When Tx good single col counter reaches half the maximum value
 *           @arg ETH_MMC_INT_RGUF  : When Rx good unicast frames counter reaches half the maximum value
 *           @arg ETH_MMC_INT_RFAE  : When Rx alignment error counter reaches half the maximum value
 *           @arg ETH_MMC_INT_RFCE  : When Rx crc error counter reaches half the maximum value
 *
 * @retval None
 */
void ETH_EnableMMCInterrupt(uint32_t interrupt)
{
    if ((interrupt & 0x10000000) == SET)
    {
        ETH->RXINTMASK &= (~(uint32_t)interrupt);
    }
    else
    {
        ETH->TXINTMASK &= (~(uint32_t)interrupt);
    }
}

/*!
 * @brief  Disable the ETH MMC interrupts.
 *
 * @param  interrupt: specifies the ETH MMC interrupt sources.
 *         This parameter can be any combination of Tx interrupt or
 *         any combination of Rx interrupt (but not both)of the following values:
 *           @arg ETH_MMC_INT_TGF   : When Tx good frame counter reaches half the maximum value
 *           @arg ETH_MMC_INT_TGFMSC: When Tx good multi col counter reaches half the maximum value
 *           @arg ETH_MMC_INT_TGFSC : When Tx good single col counter reaches half the maximum value
 *           @arg ETH_MMC_INT_RGUF  : When Rx good unicast frames counter reaches half the maximum value
 *           @arg ETH_MMC_INT_RFAE  : When Rx alignment error counter reaches half the maximum value
 *           @arg ETH_MMC_INT_RFCE  : When Rx crc error counter reaches half the maximum value
 *
 * @retval None
 */
void ETH_DisableMMCInterrupt(uint32_t interrupt)
{
    if ((interrupt & 0x10000000) == SET)
    {
        ETH->RXINTMASK |= interrupt;
    }
    else
    {
        ETH->TXINTMASK |= interrupt;
    }
}

/*!
 * @brief  Read the ETH MMC interrupt flag.
 *
 * @param  flag: specifies the ETH MMC interrupt.
 *         This parameter can be one of the following values:
 *           @arg ETH_MMC_INT_TGF   : When Tx good frame counter reaches half the maximum value
 *           @arg ETH_MMC_INT_TGFMSC: When Tx good multi col counter reaches half the maximum value
 *           @arg ETH_MMC_INT_TGFSC : When Tx good single col counter reaches half the maximum value
 *           @arg ETH_MMC_INT_RGUF  : When Rx good unicast frames counter reaches half the maximum value
 *           @arg ETH_MMC_INT_RFAE  : When Rx alignment error counter reaches half the maximum value
 *           @arg ETH_MMC_INT_RFCE  : When Rx crc error counter reaches half the maximum value
 *
 * @retval SET or RESET.
 */
uint8_t ETH_ReadMMCIntFlag(uint32_t flag)
{
    if ((flag & 0x10000000) == SET)
    {
        return ((((ETH->RXINT & flag) != RESET)) && ((ETH->RXINTMASK & flag) == RESET));
    }
    else
    {
        return ((((ETH->TXINT & flag) != RESET)) && ((ETH->TXINTMASK & flag) == RESET));
    }
}

/*!
 * @brief  Read the ETH MMC register value.
 *
 * @param  MMCReg: specifies the ETH MMC register.
 *         This parameter can be one of the following values:
 *           @arg ETH_MMC_CTRL      : MMC CTRL register
 *           @arg ETH_MMC_RXINT     : MMC RXINT register
 *           @arg ETH_MMC_TXINT     : MMC TXINT register
 *           @arg ETH_MMC_RXINTMASK : MMC RXINTMASK register
 *           @arg ETH_MMC_TXINTMASK : MMC TXINTMASK register
 *           @arg ETH_MMC_TXGFSCCNT : MMC TXGFSCCNT register
 *           @arg ETH_MMC_TXGFMCCNT : MMC TXGFMCCNT register
 *           @arg ETH_MMC_TXGFCNT   : MMC TXGFCNT register
 *           @arg ETH_MMC_RXFCECNT  : MMC RXFCECNT register
 *           @arg ETH_MMC_RXFAECNT  : MMC RXFAECNT register
 *           @arg ETH_MMC_RXGUNCNT  : MMC RXGUNCNT register
 *
 * @retval Return ETH MMC Register value.
 */
uint32_t ETH_ReadMMCRegister(ETH_MMC_REG_T MMCReg)
{
    return (*(__IO uint32_t*)(ETH_MAC_BASE + MMCReg));
}

#endif

/**@} end of group ETH_Functions */
/**@} end of group ETH_Driver */
/**@} end of group APM32F10x_ETHDriver */