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
183
184
185
186
187
191
192
193
194
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
213
214
215
216
217
218
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
254
255
256
259
260
265
266
267
272
275
276
279
280
281
282
283
284
285
286
287
288
289
290
291
292
295
296
297
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
335
336
337
338
339
343
344
345
346
347
348
358
359
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
400
403
406
407
408
409
410
411
412
413
414
415
421
422
423
424
425
426
427
434
435
439
440
441
442
443
444
445
446
447
448
454
462
463
469
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
506
507
508
509
510
511
515
519
523
528
532
536
540
546
547
548
568
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
606
610
614
619
623
627
631
637
638
639
659
666
667
668
669
670
671
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
715
716
717
718
719
720
721
722
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
745
746
747
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
785
786
787
788
789
790
791
792
794
795
796
797
798
799
800
801
802
803
804
805
806
807
812
813
814
815
816
817
818
822
823
824
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
850
851
852
853
854
855
856
857
858
859
860
862
863
864
865
866
867
868
869
870
871
875
876
877
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
909
910
911
912
913
914
915
916
917
918
919
921
922
923
924
925
926
931
932
933
934
935
936
937
938
939
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
963
964
965
966
967
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1035
1036
1037
1038
1039
1040
1041
1042
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1094
1095
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1144
1145
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
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
1216
1217
1219
1220
1224
1229
1230
1231
1232
1233
1237
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
1283
1284
1285
1286
1287
1288
1289
1290
1296
1297
1298
1299
1300
1301
1302
1303
1304
1309
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1352
1353
1354
1355
1356
1357
1358
1359
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
1402
1403
1404
1405
1406
1407
1408
1409
1415
1416
1417
1418
1419
1420
1421
1422
1423
1428
1436
1437
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1466
1467
1468
1469
1470
1471
1472
1473
1477
1478
1479
1480
1487
1488
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1561
1562
1563
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
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
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1706
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
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
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1829
1830
1831
1832
1833
1834
1835
1841
1842
1843
1844
1845
1846
1847
1848
1849
1854
1862
1863
1864
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1883
1884
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1901
1902
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
1939
1940
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1957
1958
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1974
1975
1977
1978
1979
1980
1981
1987
1995
1996
2002
2010
2011
2017
2025
2026
2032
2040
2041
2042
2048
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
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
2153
2154
2155
2156
2157
2158
2159
2160
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
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2274
2275
2281
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2301
2302
2308
2312
2313
2314
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2339
2344
2349
2354
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2493
2494
2495
2496
2498
2499
2500
2501
2502
2503
2504
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2530
2534
2535
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2568
2569
2570
2571
2572
2573
2574
2575
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2613
2614
2615
2616
2617
2618
2623
2624
2625
2626
2627
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2654
2658
2659
2665
2669
2670
2676
2680
2681
2687
2691
2692
2698
2702
2703
2706
2707
2710
2711
2714
2715
2721
2722
2723
2724
2725
2726
2727
2728
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2817
2818
2819
2820
2821
2822
2823
2824
2826
2827
2828
2829
2830
2831
2832
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2959
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3013
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3070
3071
3075
3076
3077
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3101
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3162
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3208
3209
3212
3213
3214
3215
3216
3217
/* ... */
#include "stm32f4xx_hal.h"
/* ... */
#ifdef HAL_ETH_MODULE_ENABLED
#if defined(ETH)
/* ... */
/* ... */
#define ETH_MACCR_MASK 0xFFFB7F7CU
#define ETH_MACECR_MASK 0x3F077FFFU
#define ETH_MACFFR_MASK 0x800007FFU
#define ETH_MACWTR_MASK 0x0000010FU
#define ETH_MACTFCR_MASK 0xFFFF00F2U
#define ETH_MACRFCR_MASK 0x00000003U
#define ETH_MTLTQOMR_MASK 0x00000072U
#define ETH_MTLRQOMR_MASK 0x0000007BU
#define ETH_DMAMR_MASK 0x00007802U
#define ETH_DMASBMR_MASK 0x0000D001U
#define ETH_DMACCR_MASK 0x00013FFFU
#define ETH_DMACTCR_MASK 0x003F1010U
#define ETH_DMACRCR_MASK 0x803F0000U
#define ETH_MACPMTCSR_MASK (ETH_MACPMTCSR_PD | ETH_MACPMTCSR_WFE | \
ETH_MACPMTCSR_MPE | ETH_MACPMTCSR_GU)...
#define ETH_SWRESET_TIMEOUT 500U
#define ETH_MDIO_BUS_TIMEOUT 1000U
#define ETH_DMARXDESC_ERRORS_MASK ((uint32_t)(ETH_DMARXDESC_DBE | ETH_DMARXDESC_RE | \
ETH_DMARXDESC_OE | ETH_DMARXDESC_RWT |\
ETH_DMARXDESC_LC | ETH_DMARXDESC_CE |\
ETH_DMARXDESC_DE | ETH_DMARXDESC_IPV4HCE))...
#define ETH_MAC_US_TICK 1000000U
#define ETH_MACTSCR_MASK 0x0087FF2FU
#define ETH_PTPTSHR_VALUE 0xFFFFFFFFU
#define ETH_PTPTSLR_VALUE 0xBB9ACA00U
#define ETH_MACMIIAR_CR_MASK 0xFFFFFFE3U
#define ETH_REG_WRITE_DELAY 0x00000001U
#define ETH_MACCR_CLEAR_MASK 0xFF20810FU
#define ETH_MACFCR_CLEAR_MASK 0x0000FF41U
#define ETH_DMAOMR_CLEAR_MASK 0xF8DE3F23U
#define ETH_MAC_ADDR_HBASE (uint32_t)(ETH_MAC_BASE + 0x40U)
#define ETH_MAC_ADDR_LBASE (uint32_t)(ETH_MAC_BASE + 0x44U)
#define ETH_DMARXDESC_FRAMELENGTHSHIFT 16U
/* ... */
/* ... */
#define INCR_TX_DESC_INDEX(inx, offset) do {\
(inx) += (offset);\
if ((inx) >= (uint32_t)ETH_TX_DESC_CNT){\
(inx) = ((inx) - (uint32_t)ETH_TX_DESC_CNT);}if ((inx) >= (uint32_t)ETH_TX_DESC_CNT) { ... }\
...} while (0)...
#define INCR_RX_DESC_INDEX(inx, offset) do {\
(inx) += (offset);\
if ((inx) >= (uint32_t)ETH_RX_DESC_CNT){\
(inx) = ((inx) - (uint32_t)ETH_RX_DESC_CNT);}if ((inx) >= (uint32_t)ETH_RX_DESC_CNT) { ... }\
...} while (0)...
31 defines
/* ... */
/* ... */
static void ETH_SetMACConfig(ETH_HandleTypeDef *heth, ETH_MACConfigTypeDef *macconf);
static void ETH_SetDMAConfig(ETH_HandleTypeDef *heth, ETH_DMAConfigTypeDef *dmaconf);
static void ETH_MACDMAConfig(ETH_HandleTypeDef *heth);
static void ETH_DMATxDescListInit(ETH_HandleTypeDef *heth);
static void ETH_DMARxDescListInit(ETH_HandleTypeDef *heth);
static uint32_t ETH_Prepare_Tx_Descriptors(ETH_HandleTypeDef *heth, ETH_TxPacketConfig *pTxConfig, uint32_t ItMode);
static void ETH_UpdateDescriptor(ETH_HandleTypeDef *heth);
static void ETH_FlushTransmitFIFO(ETH_HandleTypeDef *heth);
static void ETH_MACAddressConfig(ETH_HandleTypeDef *heth, uint32_t MacAddr, uint8_t *Addr);
#if (USE_HAL_ETH_REGISTER_CALLBACKS == 1)
static void ETH_InitCallbacksToDefault(ETH_HandleTypeDef *heth);
#endif
/* ... */
Private function prototypes
/* ... */
/* ... */
/* ... */
HAL_StatusTypeDef HAL_ETH_Init(ETH_HandleTypeDef *heth)
{
uint32_t tickstart;
if (heth == NULL)
{
return HAL_ERROR;
}if (heth == NULL) { ... }
if (heth->gState == HAL_ETH_STATE_RESET)
{
heth->gState = HAL_ETH_STATE_BUSY;
#if (USE_HAL_ETH_REGISTER_CALLBACKS == 1)
ETH_InitCallbacksToDefault(heth);
if (heth->MspInitCallback == NULL)
{
heth->MspInitCallback = HAL_ETH_MspInit;
}if (heth->MspInitCallback == NULL) { ... }
heth->MspInitCallback(heth);/* ... */
#else
HAL_ETH_MspInit(heth);
/* ... */
#endif
}if (heth->gState == HAL_ETH_STATE_RESET) { ... }
__HAL_RCC_SYSCFG_CLK_ENABLE();
SYSCFG->PMC &= ~(SYSCFG_PMC_MII_RMII_SEL);
SYSCFG->PMC |= (uint32_t)heth->Init.MediaInterface;
(void)SYSCFG->PMC;
SET_BIT(heth->Instance->DMABMR, ETH_DMABMR_SR);
tickstart = HAL_GetTick();
while (READ_BIT(heth->Instance->DMABMR, ETH_DMABMR_SR) > 0U)
{
if (((HAL_GetTick() - tickstart) > ETH_SWRESET_TIMEOUT))
{
heth->ErrorCode = HAL_ETH_ERROR_TIMEOUT;
heth->gState = HAL_ETH_STATE_ERROR;
return HAL_ERROR;
}if (((HAL_GetTick() - tickstart) > ETH_SWRESET_TIMEOUT)) { ... }
}while (READ_BIT(heth->Instance->DMABMR, ETH_DMABMR_SR) > 0U) { ... }
ETH_MACDMAConfig(heth);
------------------ MAC, MTL and DMA default Configuration
ETH_DMATxDescListInit(heth);
------------------ DMA Tx Descriptors Configuration
ETH_DMARxDescListInit(heth);
------------------ DMA Rx Descriptors Configuration
ETH_MACAddressConfig(heth, ETH_MAC_ADDRESS0, heth->Init.MACAddr);
heth->ErrorCode = HAL_ETH_ERROR_NONE;
heth->gState = HAL_ETH_STATE_READY;
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_ETH_DeInit(ETH_HandleTypeDef *heth)
{
heth->gState = HAL_ETH_STATE_BUSY;
#if (USE_HAL_ETH_REGISTER_CALLBACKS == 1)
if (heth->MspDeInitCallback == NULL)
{
heth->MspDeInitCallback = HAL_ETH_MspDeInit;
}if (heth->MspDeInitCallback == NULL) { ... }
heth->MspDeInitCallback(heth);/* ... */
#else
HAL_ETH_MspDeInit(heth);
/* ... */
#endif
heth->gState = HAL_ETH_STATE_RESET;
return HAL_OK;
}{ ... }
/* ... */
__weak void HAL_ETH_MspInit(ETH_HandleTypeDef *heth)
{
UNUSED(heth);
/* ... */
}{ ... }
/* ... */
__weak void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth)
{
UNUSED(heth);
/* ... */
}{ ... }
#if (USE_HAL_ETH_REGISTER_CALLBACKS == 1)
/* ... */
HAL_StatusTypeDef HAL_ETH_RegisterCallback(ETH_HandleTypeDef *heth, HAL_ETH_CallbackIDTypeDef CallbackID,
pETH_CallbackTypeDef pCallback)
{
HAL_StatusTypeDef status = HAL_OK;
if (pCallback == NULL)
{
heth->ErrorCode |= HAL_ETH_ERROR_INVALID_CALLBACK;
return HAL_ERROR;
}if (pCallback == NULL) { ... }
if (heth->gState == HAL_ETH_STATE_READY)
{
switch (CallbackID)
{
case HAL_ETH_TX_COMPLETE_CB_ID :
heth->TxCpltCallback = pCallback;
break;
case HAL_ETH_TX_COMPLETE_CB_ID :
case HAL_ETH_RX_COMPLETE_CB_ID :
heth->RxCpltCallback = pCallback;
break;
case HAL_ETH_RX_COMPLETE_CB_ID :
case HAL_ETH_ERROR_CB_ID :
heth->ErrorCallback = pCallback;
break;
case HAL_ETH_ERROR_CB_ID :
case HAL_ETH_PMT_CB_ID :
heth->PMTCallback = pCallback;
break;
case HAL_ETH_PMT_CB_ID :
case HAL_ETH_WAKEUP_CB_ID :
heth->WakeUpCallback = pCallback;
break;
case HAL_ETH_WAKEUP_CB_ID :
case HAL_ETH_MSPINIT_CB_ID :
heth->MspInitCallback = pCallback;
break;
case HAL_ETH_MSPINIT_CB_ID :
case HAL_ETH_MSPDEINIT_CB_ID :
heth->MspDeInitCallback = pCallback;
break;
case HAL_ETH_MSPDEINIT_CB_ID :
default :
heth->ErrorCode |= HAL_ETH_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
break;default
}switch (CallbackID) { ... }
}if (heth->gState == HAL_ETH_STATE_READY) { ... }
else if (heth->gState == HAL_ETH_STATE_RESET)
{
switch (CallbackID)
{
case HAL_ETH_MSPINIT_CB_ID :
heth->MspInitCallback = pCallback;
break;
case HAL_ETH_MSPINIT_CB_ID :
case HAL_ETH_MSPDEINIT_CB_ID :
heth->MspDeInitCallback = pCallback;
break;
case HAL_ETH_MSPDEINIT_CB_ID :
default :
heth->ErrorCode |= HAL_ETH_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
break;default
}switch (CallbackID) { ... }
}else if (heth->gState == HAL_ETH_STATE_RESET) { ... }
else
{
heth->ErrorCode |= HAL_ETH_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
}else { ... }
return status;
}HAL_ETH_RegisterCallback (ETH_HandleTypeDef *heth, HAL_ETH_CallbackIDTypeDef CallbackID, pETH_CallbackTypeDef pCallback) { ... }
/* ... */
HAL_StatusTypeDef HAL_ETH_UnRegisterCallback(ETH_HandleTypeDef *heth, HAL_ETH_CallbackIDTypeDef CallbackID)
{
HAL_StatusTypeDef status = HAL_OK;
if (heth->gState == HAL_ETH_STATE_READY)
{
switch (CallbackID)
{
case HAL_ETH_TX_COMPLETE_CB_ID :
heth->TxCpltCallback = HAL_ETH_TxCpltCallback;
break;
case HAL_ETH_TX_COMPLETE_CB_ID :
case HAL_ETH_RX_COMPLETE_CB_ID :
heth->RxCpltCallback = HAL_ETH_RxCpltCallback;
break;
case HAL_ETH_RX_COMPLETE_CB_ID :
case HAL_ETH_ERROR_CB_ID :
heth->ErrorCallback = HAL_ETH_ErrorCallback;
break;
case HAL_ETH_ERROR_CB_ID :
case HAL_ETH_PMT_CB_ID :
heth->PMTCallback = HAL_ETH_PMTCallback;
break;
case HAL_ETH_PMT_CB_ID :
case HAL_ETH_WAKEUP_CB_ID :
heth->WakeUpCallback = HAL_ETH_WakeUpCallback;
break;
case HAL_ETH_WAKEUP_CB_ID :
case HAL_ETH_MSPINIT_CB_ID :
heth->MspInitCallback = HAL_ETH_MspInit;
break;
case HAL_ETH_MSPINIT_CB_ID :
case HAL_ETH_MSPDEINIT_CB_ID :
heth->MspDeInitCallback = HAL_ETH_MspDeInit;
break;
case HAL_ETH_MSPDEINIT_CB_ID :
default :
heth->ErrorCode |= HAL_ETH_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
break;default
}switch (CallbackID) { ... }
}if (heth->gState == HAL_ETH_STATE_READY) { ... }
else if (heth->gState == HAL_ETH_STATE_RESET)
{
switch (CallbackID)
{
case HAL_ETH_MSPINIT_CB_ID :
heth->MspInitCallback = HAL_ETH_MspInit;
break;
case HAL_ETH_MSPINIT_CB_ID :
case HAL_ETH_MSPDEINIT_CB_ID :
heth->MspDeInitCallback = HAL_ETH_MspDeInit;
break;
case HAL_ETH_MSPDEINIT_CB_ID :
default :
heth->ErrorCode |= HAL_ETH_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
break;default
}switch (CallbackID) { ... }
}else if (heth->gState == HAL_ETH_STATE_RESET) { ... }
else
{
heth->ErrorCode |= HAL_ETH_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
}else { ... }
return status;
}HAL_ETH_UnRegisterCallback (ETH_HandleTypeDef *heth, HAL_ETH_CallbackIDTypeDef CallbackID) { ... }
/* ... */#endif
/* ... */
/* ... */
/* ... */
HAL_StatusTypeDef HAL_ETH_Start(ETH_HandleTypeDef *heth)
{
uint32_t tmpreg1;
if (heth->gState == HAL_ETH_STATE_READY)
{
heth->gState = HAL_ETH_STATE_BUSY;
heth->RxDescList.RxBuildDescCnt = ETH_RX_DESC_CNT;
ETH_UpdateDescriptor(heth);
SET_BIT(heth->Instance->MACCR, ETH_MACCR_TE);
/* ... */
tmpreg1 = (heth->Instance)->MACCR;
HAL_Delay(ETH_REG_WRITE_DELAY);
(heth->Instance)->MACCR = tmpreg1;
SET_BIT(heth->Instance->MACCR, ETH_MACCR_RE);
/* ... */
tmpreg1 = (heth->Instance)->MACCR;
HAL_Delay(ETH_REG_WRITE_DELAY);
(heth->Instance)->MACCR = tmpreg1;
ETH_FlushTransmitFIFO(heth);
SET_BIT(heth->Instance->DMAOMR, ETH_DMAOMR_ST);
SET_BIT(heth->Instance->DMAOMR, ETH_DMAOMR_SR);
heth->gState = HAL_ETH_STATE_STARTED;
return HAL_OK;
}if (heth->gState == HAL_ETH_STATE_READY) { ... }
else
{
return HAL_ERROR;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_ETH_Start_IT(ETH_HandleTypeDef *heth)
{
uint32_t tmpreg1;
if (heth->gState == HAL_ETH_STATE_READY)
{
heth->gState = HAL_ETH_STATE_BUSY;
heth->RxDescList.ItMode = 1U;
SET_BIT(heth->Instance->MACIMR, ETH_MACIMR_TSTIM | ETH_MACIMR_PMTIM);
SET_BIT(heth->Instance->MMCRIMR, ETH_MMCRIMR_RGUFM | ETH_MMCRIMR_RFAEM | \
ETH_MMCRIMR_RFCEM);
SET_BIT(heth->Instance->MMCTIMR, ETH_MMCTIMR_TGFM | ETH_MMCTIMR_TGFMSCM | \
ETH_MMCTIMR_TGFSCM);
heth->RxDescList.RxBuildDescCnt = ETH_RX_DESC_CNT;
ETH_UpdateDescriptor(heth);
SET_BIT(heth->Instance->MACCR, ETH_MACCR_TE);
/* ... */
tmpreg1 = (heth->Instance)->MACCR;
HAL_Delay(ETH_REG_WRITE_DELAY);
(heth->Instance)->MACCR = tmpreg1;
SET_BIT(heth->Instance->MACCR, ETH_MACCR_RE);
/* ... */
tmpreg1 = (heth->Instance)->MACCR;
HAL_Delay(ETH_REG_WRITE_DELAY);
(heth->Instance)->MACCR = tmpreg1;
ETH_FlushTransmitFIFO(heth);
SET_BIT(heth->Instance->DMAOMR, ETH_DMAOMR_ST);
SET_BIT(heth->Instance->DMAOMR, ETH_DMAOMR_SR);
/* ... */
__HAL_ETH_DMA_ENABLE_IT(heth, (ETH_DMAIER_NISE | ETH_DMAIER_RIE | ETH_DMAIER_TIE |
ETH_DMAIER_FBEIE | ETH_DMAIER_AISE | ETH_DMAIER_RBUIE));
heth->gState = HAL_ETH_STATE_STARTED;
return HAL_OK;
}if (heth->gState == HAL_ETH_STATE_READY) { ... }
else
{
return HAL_ERROR;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_ETH_Stop(ETH_HandleTypeDef *heth)
{
uint32_t tmpreg1;
if (heth->gState == HAL_ETH_STATE_STARTED)
{
heth->gState = HAL_ETH_STATE_BUSY;
CLEAR_BIT(heth->Instance->DMAOMR, ETH_DMAOMR_ST);
CLEAR_BIT(heth->Instance->DMAOMR, ETH_DMAOMR_SR);
CLEAR_BIT(heth->Instance->MACCR, ETH_MACCR_RE);
/* ... */
tmpreg1 = (heth->Instance)->MACCR;
HAL_Delay(ETH_REG_WRITE_DELAY);
(heth->Instance)->MACCR = tmpreg1;
ETH_FlushTransmitFIFO(heth);
CLEAR_BIT(heth->Instance->MACCR, ETH_MACCR_TE);
/* ... */
tmpreg1 = (heth->Instance)->MACCR;
HAL_Delay(ETH_REG_WRITE_DELAY);
(heth->Instance)->MACCR = tmpreg1;
heth->gState = HAL_ETH_STATE_READY;
return HAL_OK;
}if (heth->gState == HAL_ETH_STATE_STARTED) { ... }
else
{
return HAL_ERROR;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_ETH_Stop_IT(ETH_HandleTypeDef *heth)
{
ETH_DMADescTypeDef *dmarxdesc;
uint32_t descindex;
uint32_t tmpreg1;
if (heth->gState == HAL_ETH_STATE_STARTED)
{
heth->gState = HAL_ETH_STATE_BUSY;
__HAL_ETH_DMA_DISABLE_IT(heth, (ETH_DMAIER_NISE | ETH_DMAIER_RIE | ETH_DMAIER_TIE |
ETH_DMAIER_FBEIE | ETH_DMAIER_AISE | ETH_DMAIER_RBUIE));
CLEAR_BIT(heth->Instance->DMAOMR, ETH_DMAOMR_ST);
CLEAR_BIT(heth->Instance->DMAOMR, ETH_DMAOMR_SR);
CLEAR_BIT(heth->Instance->MACCR, ETH_MACCR_RE);
/* ... */
tmpreg1 = (heth->Instance)->MACCR;
HAL_Delay(ETH_REG_WRITE_DELAY);
(heth->Instance)->MACCR = tmpreg1;
ETH_FlushTransmitFIFO(heth);
CLEAR_BIT(heth->Instance->MACCR, ETH_MACCR_TE);
/* ... */
tmpreg1 = (heth->Instance)->MACCR;
HAL_Delay(ETH_REG_WRITE_DELAY);
(heth->Instance)->MACCR = tmpreg1;
for (descindex = 0; descindex < (uint32_t)ETH_RX_DESC_CNT; descindex++)
{
dmarxdesc = (ETH_DMADescTypeDef *)heth->RxDescList.RxDesc[descindex];
SET_BIT(dmarxdesc->DESC1, ETH_DMARXDESC_DIC);
}for (descindex = 0; descindex < (uint32_t)ETH_RX_DESC_CNT; descindex++) { ... }
heth->RxDescList.ItMode = 0U;
heth->gState = HAL_ETH_STATE_READY;
return HAL_OK;
}if (heth->gState == HAL_ETH_STATE_STARTED) { ... }
else
{
return HAL_ERROR;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_ETH_Transmit(ETH_HandleTypeDef *heth, ETH_TxPacketConfig *pTxConfig, uint32_t Timeout)
{
uint32_t tickstart;
ETH_DMADescTypeDef *dmatxdesc;
if (pTxConfig == NULL)
{
heth->ErrorCode |= HAL_ETH_ERROR_PARAM;
return HAL_ERROR;
}if (pTxConfig == NULL) { ... }
if (heth->gState == HAL_ETH_STATE_STARTED)
{
if (ETH_Prepare_Tx_Descriptors(heth, pTxConfig, 0) != HAL_ETH_ERROR_NONE)
{
heth->ErrorCode |= HAL_ETH_ERROR_BUSY;
return HAL_ERROR;
}if (ETH_Prepare_Tx_Descriptors(heth, pTxConfig, 0) != HAL_ETH_ERROR_NONE) { ... }
__DSB();
dmatxdesc = (ETH_DMADescTypeDef *)(&heth->TxDescList)->TxDesc[heth->TxDescList.CurTxDesc];
INCR_TX_DESC_INDEX(heth->TxDescList.CurTxDesc, 1U);
WRITE_REG(heth->Instance->DMATPDR, (uint32_t)(heth->TxDescList.TxDesc[heth->TxDescList.CurTxDesc]));
tickstart = HAL_GetTick();
while ((dmatxdesc->DESC0 & ETH_DMATXDESC_OWN) != (uint32_t)RESET)
{
if ((heth->Instance->DMASR & ETH_DMASR_FBES) != (uint32_t)RESET)
{
heth->ErrorCode |= HAL_ETH_ERROR_DMA;
heth->DMAErrorCode = heth->Instance->DMASR;
return HAL_ERROR;
}if ((heth->Instance->DMASR & ETH_DMASR_FBES) != (uint32_t)RESET) { ... }
if (Timeout != HAL_MAX_DELAY)
{
if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
{
heth->ErrorCode |= HAL_ETH_ERROR_TIMEOUT;
dmatxdesc->DESC0 = (ETH_DMATXDESC_FS | ETH_DMATXDESC_LS);
return HAL_ERROR;
}if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U)) { ... }
}if (Timeout != HAL_MAX_DELAY) { ... }
}while ((dmatxdesc->DESC0 & ETH_DMATXDESC_OWN) != (uint32_t)RESET) { ... }
return HAL_OK;
}if (heth->gState == HAL_ETH_STATE_STARTED) { ... }
else
{
return HAL_ERROR;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_ETH_Transmit_IT(ETH_HandleTypeDef *heth, ETH_TxPacketConfig *pTxConfig)
{
if (pTxConfig == NULL)
{
heth->ErrorCode |= HAL_ETH_ERROR_PARAM;
return HAL_ERROR;
}if (pTxConfig == NULL) { ... }
if (heth->gState == HAL_ETH_STATE_STARTED)
{
heth->TxDescList.CurrentPacketAddress = (uint32_t *)pTxConfig->pData;
if (ETH_Prepare_Tx_Descriptors(heth, pTxConfig, 1) != HAL_ETH_ERROR_NONE)
{
heth->ErrorCode |= HAL_ETH_ERROR_BUSY;
return HAL_ERROR;
}if (ETH_Prepare_Tx_Descriptors(heth, pTxConfig, 1) != HAL_ETH_ERROR_NONE) { ... }
__DSB();
INCR_TX_DESC_INDEX(heth->TxDescList.CurTxDesc, 1U);
if (((heth->Instance)->DMASR & ETH_DMASR_TBUS) != (uint32_t)RESET)
{
(heth->Instance)->DMASR = ETH_DMASR_TBUS;
(heth->Instance)->DMATPDR = 0U;
}if (((heth->Instance)->DMASR & ETH_DMASR_TBUS) != (uint32_t)RESET) { ... }
return HAL_OK;
}if (heth->gState == HAL_ETH_STATE_STARTED) { ... }
else
{
return HAL_ERROR;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_ETH_ReadData(ETH_HandleTypeDef *heth, void **pAppBuff)
{
uint32_t descidx;
ETH_DMADescTypeDef *dmarxdesc;
uint32_t desccnt = 0U;
uint32_t desccntmax;
uint32_t bufflength;
uint8_t rxdataready = 0U;
if (pAppBuff == NULL)
{
heth->ErrorCode |= HAL_ETH_ERROR_PARAM;
return HAL_ERROR;
}if (pAppBuff == NULL) { ... }
if (heth->gState != HAL_ETH_STATE_STARTED)
{
return HAL_ERROR;
}if (heth->gState != HAL_ETH_STATE_STARTED) { ... }
descidx = heth->RxDescList.RxDescIdx;
dmarxdesc = (ETH_DMADescTypeDef *)heth->RxDescList.RxDesc[descidx];
desccntmax = ETH_RX_DESC_CNT - heth->RxDescList.RxBuildDescCnt;
while ((READ_BIT(dmarxdesc->DESC0, ETH_DMARXDESC_OWN) == (uint32_t)RESET) && (desccnt < desccntmax)
&& (rxdataready == 0U))
{
if (READ_BIT(dmarxdesc->DESC0, ETH_DMARXDESC_LS) != (uint32_t)RESET)
{
heth->RxDescList.TimeStamp.TimeStampHigh = dmarxdesc->DESC7;
heth->RxDescList.TimeStamp.TimeStampLow = dmarxdesc->DESC6;
}if (READ_BIT(dmarxdesc->DESC0, ETH_DMARXDESC_LS) != (uint32_t)RESET) { ... }
if ((READ_BIT(dmarxdesc->DESC0, ETH_DMARXDESC_FS) != (uint32_t)RESET) || (heth->RxDescList.pRxStart != NULL))
{
if (READ_BIT(dmarxdesc->DESC0, ETH_DMARXDESC_FS) != (uint32_t)RESET)
{
heth->RxDescList.RxDescCnt = 0;
heth->RxDescList.RxDataLength = 0;
}if (READ_BIT(dmarxdesc->DESC0, ETH_DMARXDESC_FS) != (uint32_t)RESET) { ... }
bufflength = heth->Init.RxBuffLen;
if (READ_BIT(dmarxdesc->DESC0, ETH_DMARXDESC_LS) != (uint32_t)RESET)
{
bufflength = ((dmarxdesc->DESC0 & ETH_DMARXDESC_FL) >> ETH_DMARXDESC_FRAMELENGTHSHIFT) - 4U;
heth->RxDescList.pRxLastRxDesc = dmarxdesc->DESC0;
rxdataready = 1;
}if (READ_BIT(dmarxdesc->DESC0, ETH_DMARXDESC_LS) != (uint32_t)RESET) { ... }
WRITE_REG(dmarxdesc->BackupAddr0, dmarxdesc->DESC2);
#if (USE_HAL_ETH_REGISTER_CALLBACKS == 1)
heth->rxLinkCallback(&heth->RxDescList.pRxStart, &heth->RxDescList.pRxEnd,
(uint8_t *)dmarxdesc->BackupAddr0, bufflength);/* ... */
#else
HAL_ETH_RxLinkCallback(&heth->RxDescList.pRxStart, &heth->RxDescList.pRxEnd,
(uint8_t *)dmarxdesc->BackupAddr0, (uint16_t) bufflength);/* ... */
#endif
heth->RxDescList.RxDescCnt++;
heth->RxDescList.RxDataLength += bufflength;
dmarxdesc->BackupAddr0 = 0;
}if ((READ_BIT(dmarxdesc->DESC0, ETH_DMARXDESC_FS) != (uint32_t)RESET) || (heth->RxDescList.pRxStart != NULL)) { ... }
INCR_RX_DESC_INDEX(descidx, 1U);
dmarxdesc = (ETH_DMADescTypeDef *)heth->RxDescList.RxDesc[descidx];
desccnt++;
}while ((READ_BIT(dmarxdesc->DESC0, ETH_DMARXDESC_OWN) == (uint32_t)RESET) && (desccnt < desccntmax) && (rxdataready == 0U)) { ... }
heth->RxDescList.RxBuildDescCnt += desccnt;
if ((heth->RxDescList.RxBuildDescCnt) != 0U)
{
ETH_UpdateDescriptor(heth);
}if ((heth->RxDescList.RxBuildDescCnt) != 0U) { ... }
heth->RxDescList.RxDescIdx = descidx;
if (rxdataready == 1U)
{
*pAppBuff = heth->RxDescList.pRxStart;
heth->RxDescList.pRxStart = NULL;
return HAL_OK;
}if (rxdataready == 1U) { ... }
return HAL_ERROR;
}{ ... }
/* ... */
static void ETH_UpdateDescriptor(ETH_HandleTypeDef *heth)
{
uint32_t tailidx;
uint32_t descidx;
uint32_t desccount;
ETH_DMADescTypeDef *dmarxdesc;
uint8_t *buff = NULL;
uint8_t allocStatus = 1U;
descidx = heth->RxDescList.RxBuildDescIdx;
dmarxdesc = (ETH_DMADescTypeDef *)heth->RxDescList.RxDesc[descidx];
desccount = heth->RxDescList.RxBuildDescCnt;
while ((desccount > 0U) && (allocStatus != 0U))
{
if (READ_REG(dmarxdesc->BackupAddr0) == 0U)
{
#if (USE_HAL_ETH_REGISTER_CALLBACKS == 1)
heth->rxAllocateCallback(&buff);/* ... */
#else
HAL_ETH_RxAllocateCallback(&buff);/* ... */
#endif
if (buff == NULL)
{
allocStatus = 0U;
}if (buff == NULL) { ... }
else
{
WRITE_REG(dmarxdesc->BackupAddr0, (uint32_t)buff);
WRITE_REG(dmarxdesc->DESC2, (uint32_t)buff);
}else { ... }
}if (READ_REG(dmarxdesc->BackupAddr0) == 0U) { ... }
if (allocStatus != 0U)
{
if (heth->RxDescList.ItMode == 0U)
{
WRITE_REG(dmarxdesc->DESC1, ETH_DMARXDESC_DIC | ETH_RX_BUF_SIZE | ETH_DMARXDESC_RCH);
}if (heth->RxDescList.ItMode == 0U) { ... }
else
{
WRITE_REG(dmarxdesc->DESC1, ETH_RX_BUF_SIZE | ETH_DMARXDESC_RCH);
}else { ... }
SET_BIT(dmarxdesc->DESC0, ETH_DMARXDESC_OWN);
INCR_RX_DESC_INDEX(descidx, 1U);
dmarxdesc = (ETH_DMADescTypeDef *)heth->RxDescList.RxDesc[descidx];
desccount--;
}if (allocStatus != 0U) { ... }
}while ((desccount > 0U) && (allocStatus != 0U)) { ... }
if (heth->RxDescList.RxBuildDescCnt != desccount)
{
tailidx = (descidx + 1U) % ETH_RX_DESC_CNT;
__DMB();
WRITE_REG(heth->Instance->DMARPDR, ((uint32_t)(heth->Init.RxDesc + (tailidx))));
heth->RxDescList.RxBuildDescIdx = descidx;
heth->RxDescList.RxBuildDescCnt = desccount;
}if (heth->RxDescList.RxBuildDescCnt != desccount) { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_ETH_RegisterRxAllocateCallback(ETH_HandleTypeDef *heth,
pETH_rxAllocateCallbackTypeDef rxAllocateCallback)
{
if (rxAllocateCallback == NULL)
{
return HAL_ERROR;
}if (rxAllocateCallback == NULL) { ... }
heth->rxAllocateCallback = rxAllocateCallback;
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_ETH_UnRegisterRxAllocateCallback(ETH_HandleTypeDef *heth)
{
heth->rxAllocateCallback = HAL_ETH_RxAllocateCallback;
return HAL_OK;
}{ ... }
/* ... */
__weak void HAL_ETH_RxAllocateCallback(uint8_t **buff)
{
UNUSED(buff);
/* ... */
}{ ... }
/* ... */
__weak void HAL_ETH_RxLinkCallback(void **pStart, void **pEnd, uint8_t *buff, uint16_t Length)
{
UNUSED(pStart);
UNUSED(pEnd);
UNUSED(buff);
UNUSED(Length);
/* ... */
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_ETH_RegisterRxLinkCallback(ETH_HandleTypeDef *heth, pETH_rxLinkCallbackTypeDef rxLinkCallback)
{
if (rxLinkCallback == NULL)
{
return HAL_ERROR;
}if (rxLinkCallback == NULL) { ... }
heth->rxLinkCallback = rxLinkCallback;
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_ETH_UnRegisterRxLinkCallback(ETH_HandleTypeDef *heth)
{
heth->rxLinkCallback = HAL_ETH_RxLinkCallback;
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_ETH_GetRxDataErrorCode(ETH_HandleTypeDef *heth, uint32_t *pErrorCode)
{
*pErrorCode = READ_BIT(heth->RxDescList.pRxLastRxDesc, ETH_DMARXDESC_ERRORS_MASK);
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_ETH_RegisterTxFreeCallback(ETH_HandleTypeDef *heth, pETH_txFreeCallbackTypeDef txFreeCallback)
{
if (txFreeCallback == NULL)
{
return HAL_ERROR;
}if (txFreeCallback == NULL) { ... }
heth->txFreeCallback = txFreeCallback;
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_ETH_UnRegisterTxFreeCallback(ETH_HandleTypeDef *heth)
{
heth->txFreeCallback = HAL_ETH_TxFreeCallback;
return HAL_OK;
}{ ... }
/* ... */
__weak void HAL_ETH_TxFreeCallback(uint32_t *buff)
{
UNUSED(buff);
/* ... */
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_ETH_ReleaseTxPacket(ETH_HandleTypeDef *heth)
{
ETH_TxDescListTypeDef *dmatxdesclist = &heth->TxDescList;
uint32_t numOfBuf = dmatxdesclist->BuffersInUse;
uint32_t idx = dmatxdesclist->releaseIndex;
uint8_t pktTxStatus = 1U;
uint8_t pktInUse;
#ifdef HAL_ETH_USE_PTP
ETH_TimeStampTypeDef *timestamp = &heth->TxTimestamp;
#endif
while ((numOfBuf != 0U) && (pktTxStatus != 0U))
{
pktInUse = 1U;
numOfBuf--;
if (dmatxdesclist->PacketAddress[idx] == NULL)
{
idx = (idx + 1U) & (ETH_TX_DESC_CNT - 1U);
pktInUse = 0U;
}if (dmatxdesclist->PacketAddress[idx] == NULL) { ... }
if (pktInUse != 0U)
{
if ((heth->Init.TxDesc[idx].DESC0 & ETH_DMATXDESC_OWN) == 0U)
{
#ifdef HAL_ETH_USE_PTP
timestamp->TimeStampLow = heth->Init.TxDesc[idx].DESC6;
timestamp->TimeStampHigh = heth->Init.TxDesc[idx].DESC7;/* ... */
#endif
#if (USE_HAL_ETH_REGISTER_CALLBACKS == 1)
#ifdef HAL_ETH_USE_PTP
heth->txPtpCallback(dmatxdesclist->PacketAddress[idx], timestamp);/* ... */
#endif
heth->txFreeCallback(dmatxdesclist->PacketAddress[idx]);/* ... */
#else
#ifdef HAL_ETH_USE_PTP
HAL_ETH_TxPtpCallback(dmatxdesclist->PacketAddress[idx], timestamp);/* ... */
#endif
HAL_ETH_TxFreeCallback(dmatxdesclist->PacketAddress[idx]);/* ... */
#endif
dmatxdesclist->PacketAddress[idx] = NULL;
idx = (idx + 1U) & (ETH_TX_DESC_CNT - 1U);
dmatxdesclist->BuffersInUse = numOfBuf;
dmatxdesclist->releaseIndex = idx;
}if ((heth->Init.TxDesc[idx].DESC0 & ETH_DMATXDESC_OWN) == 0U) { ... }
else
{
pktTxStatus = 0U;
}else { ... }
}if (pktInUse != 0U) { ... }
}while ((numOfBuf != 0U) && (pktTxStatus != 0U)) { ... }
return HAL_OK;
}{ ... }
#ifdef HAL_ETH_USE_PTP
/* ... */
HAL_StatusTypeDef HAL_ETH_PTP_SetConfig(ETH_HandleTypeDef *heth, ETH_PTP_ConfigTypeDef *ptpconfig)
{
uint32_t tmpTSCR;
ETH_TimeTypeDef time;
if (ptpconfig == NULL)
{
return HAL_ERROR;
}if (ptpconfig == NULL) { ... }
tmpTSCR = ptpconfig->Timestamp |
((uint32_t)ptpconfig->TimestampUpdate << ETH_PTPTSCR_TSFCU_Pos) |
((uint32_t)ptpconfig->TimestampAll << ETH_PTPTSCR_TSSARFE_Pos) |
((uint32_t)ptpconfig->TimestampRolloverMode << ETH_PTPTSCR_TSSSR_Pos) |
((uint32_t)ptpconfig->TimestampV2 << ETH_PTPTSCR_TSPTPPSV2E_Pos) |
((uint32_t)ptpconfig->TimestampEthernet << ETH_PTPTSCR_TSSPTPOEFE_Pos) |
((uint32_t)ptpconfig->TimestampIPv6 << ETH_PTPTSCR_TSSIPV6FE_Pos) |
((uint32_t)ptpconfig->TimestampIPv4 << ETH_PTPTSCR_TSSIPV4FE_Pos) |
((uint32_t)ptpconfig->TimestampEvent << ETH_PTPTSCR_TSSEME_Pos) |
((uint32_t)ptpconfig->TimestampMaster << ETH_PTPTSCR_TSSMRME_Pos) |
((uint32_t)ptpconfig->TimestampFilter << ETH_PTPTSCR_TSPFFMAE_Pos) |
((uint32_t)ptpconfig->TimestampClockType << ETH_PTPTSCR_TSCNT_Pos);
MODIFY_REG(heth->Instance->PTPTSCR, ETH_MACTSCR_MASK, tmpTSCR);
SET_BIT(heth->Instance->PTPTSCR, ETH_PTPTSCR_TSE);
WRITE_REG(heth->Instance->PTPSSIR, ptpconfig->TimestampSubsecondInc);
WRITE_REG(heth->Instance->PTPTSAR, ptpconfig->TimestampAddend);
if (ptpconfig->TimestampAddendUpdate == ENABLE)
{
SET_BIT(heth->Instance->PTPTSCR, ETH_PTPTSCR_TSARU);
while ((heth->Instance->PTPTSCR & ETH_PTPTSCR_TSARU) != 0) {}
}if (ptpconfig->TimestampAddendUpdate == ENABLE) { ... }
if (ptpconfig->TimestampUpdateMode == ENABLE)
{
SET_BIT(heth->Instance->PTPTSCR, ETH_PTPTSCR_TSFCU);
}if (ptpconfig->TimestampUpdateMode == ENABLE) { ... }
time.Seconds = 0;
time.NanoSeconds = 0;
HAL_ETH_PTP_SetTime(heth, &time);
SET_BIT(heth->Instance->PTPTSCR, ETH_PTPTSCR_TSSTI);
heth->IsPtpConfigured = HAL_ETH_PTP_CONFIGURATED;
return HAL_OK;
}HAL_ETH_PTP_SetConfig (ETH_HandleTypeDef *heth, ETH_PTP_ConfigTypeDef *ptpconfig) { ... }
/* ... */
HAL_StatusTypeDef HAL_ETH_PTP_GetConfig(ETH_HandleTypeDef *heth, ETH_PTP_ConfigTypeDef *ptpconfig)
{
if (ptpconfig == NULL)
{
return HAL_ERROR;
}if (ptpconfig == NULL) { ... }
ptpconfig->Timestamp = READ_BIT(heth->Instance->PTPTSCR, ETH_PTPTSCR_TSE);
ptpconfig->TimestampUpdate = ((READ_BIT(heth->Instance->PTPTSCR,
ETH_PTPTSCR_TSFCU) >> ETH_PTPTSCR_TSFCU_Pos) > 0U) ? ENABLE : DISABLE;
ptpconfig->TimestampAll = ((READ_BIT(heth->Instance->PTPTSCR,
ETH_PTPTSCR_TSSARFE) >> ETH_PTPTSCR_TSSARFE_Pos) > 0U) ? ENABLE : DISABLE;
ptpconfig->TimestampRolloverMode = ((READ_BIT(heth->Instance->PTPTSCR,
ETH_PTPTSCR_TSSSR) >> ETH_PTPTSCR_TSSSR_Pos) > 0U)
? ENABLE : DISABLE;
ptpconfig->TimestampV2 = ((READ_BIT(heth->Instance->PTPTSCR,
ETH_PTPTSCR_TSPTPPSV2E) >> ETH_PTPTSCR_TSPTPPSV2E_Pos) > 0U) ? ENABLE : DISABLE;
ptpconfig->TimestampEthernet = ((READ_BIT(heth->Instance->PTPTSCR,
ETH_PTPTSCR_TSSPTPOEFE) >> ETH_PTPTSCR_TSSPTPOEFE_Pos) > 0U)
? ENABLE : DISABLE;
ptpconfig->TimestampIPv6 = ((READ_BIT(heth->Instance->PTPTSCR,
ETH_PTPTSCR_TSSIPV6FE) >> ETH_PTPTSCR_TSSIPV6FE_Pos) > 0U) ? ENABLE : DISABLE;
ptpconfig->TimestampIPv4 = ((READ_BIT(heth->Instance->PTPTSCR,
ETH_PTPTSCR_TSSIPV4FE) >> ETH_PTPTSCR_TSSIPV4FE_Pos) > 0U) ? ENABLE : DISABLE;
ptpconfig->TimestampEvent = ((READ_BIT(heth->Instance->PTPTSCR,
ETH_PTPTSCR_TSSEME) >> ETH_PTPTSCR_TSSEME_Pos) > 0U) ? ENABLE : DISABLE;
ptpconfig->TimestampMaster = ((READ_BIT(heth->Instance->PTPTSCR,
ETH_PTPTSCR_TSSMRME) >> ETH_PTPTSCR_TSSMRME_Pos) > 0U) ? ENABLE : DISABLE;
ptpconfig->TimestampFilter = ((READ_BIT(heth->Instance->PTPTSCR,
ETH_PTPTSCR_TSPFFMAE) >> ETH_PTPTSCR_TSPFFMAE_Pos) > 0U) ? ENABLE : DISABLE;
ptpconfig->TimestampClockType = ((READ_BIT(heth->Instance->PTPTSCR,
ETH_PTPTSCR_TSCNT) >> ETH_PTPTSCR_TSCNT_Pos) > 0U) ? ENABLE : DISABLE;
return HAL_OK;
}HAL_ETH_PTP_GetConfig (ETH_HandleTypeDef *heth, ETH_PTP_ConfigTypeDef *ptpconfig) { ... }
/* ... */
HAL_StatusTypeDef HAL_ETH_PTP_SetTime(ETH_HandleTypeDef *heth, ETH_TimeTypeDef *time)
{
if (heth->IsPtpConfigured == HAL_ETH_PTP_CONFIGURATED)
{
heth->Instance->PTPTSHUR = time->Seconds;
heth->Instance->PTPTSLUR = time->NanoSeconds;
return HAL_OK;
}if (heth->IsPtpConfigured == HAL_ETH_PTP_CONFIGURATED) { ... }
else
{
return HAL_ERROR;
}else { ... }
}HAL_ETH_PTP_SetTime (ETH_HandleTypeDef *heth, ETH_TimeTypeDef *time) { ... }
/* ... */
HAL_StatusTypeDef HAL_ETH_PTP_GetTime(ETH_HandleTypeDef *heth, ETH_TimeTypeDef *time)
{
if (heth->IsPtpConfigured == HAL_ETH_PTP_CONFIGURATED)
{
time->Seconds = heth->Instance->PTPTSHR;
time->NanoSeconds = heth->Instance->PTPTSLR;
return HAL_OK;
}if (heth->IsPtpConfigured == HAL_ETH_PTP_CONFIGURATED) { ... }
else
{
return HAL_ERROR;
}else { ... }
}HAL_ETH_PTP_GetTime (ETH_HandleTypeDef *heth, ETH_TimeTypeDef *time) { ... }
/* ... */
HAL_StatusTypeDef HAL_ETH_PTP_AddTimeOffset(ETH_HandleTypeDef *heth, ETH_PtpUpdateTypeDef ptpoffsettype,
ETH_TimeTypeDef *timeoffset)
{
if (heth->IsPtpConfigured == HAL_ETH_PTP_CONFIGURATED)
{
if (ptpoffsettype == HAL_ETH_PTP_NEGATIVE_UPDATE)
{
heth->Instance->PTPTSHUR = ETH_PTPTSHR_VALUE - timeoffset->Seconds + 1U;
if (READ_BIT(heth->Instance->PTPTSCR, ETH_PTPTSCR_TSSSR) == ETH_PTPTSCR_TSSSR)
{
heth->Instance->PTPTSLUR = ETH_PTPTSLR_VALUE - timeoffset->NanoSeconds;
}if (READ_BIT(heth->Instance->PTPTSCR, ETH_PTPTSCR_TSSSR) == ETH_PTPTSCR_TSSSR) { ... }
else
{
heth->Instance->PTPTSLUR = ETH_PTPTSHR_VALUE - timeoffset->NanoSeconds + 1U;
}else { ... }
}if (ptpoffsettype == HAL_ETH_PTP_NEGATIVE_UPDATE) { ... }
else
{
heth->Instance->PTPTSHUR = timeoffset->Seconds;
heth->Instance->PTPTSLUR = timeoffset->NanoSeconds;
}else { ... }
return HAL_OK;
}if (heth->IsPtpConfigured == HAL_ETH_PTP_CONFIGURATED) { ... }
else
{
return HAL_ERROR;
}else { ... }
}HAL_ETH_PTP_AddTimeOffset (ETH_HandleTypeDef *heth, ETH_PtpUpdateTypeDef ptpoffsettype, ETH_TimeTypeDef *timeoffset) { ... }
/* ... */
HAL_StatusTypeDef HAL_ETH_PTP_InsertTxTimestamp(ETH_HandleTypeDef *heth)
{
ETH_TxDescListTypeDef *dmatxdesclist = &heth->TxDescList;
uint32_t descidx = dmatxdesclist->CurTxDesc;
ETH_DMADescTypeDef *dmatxdesc = (ETH_DMADescTypeDef *)dmatxdesclist->TxDesc[descidx];
if (heth->IsPtpConfigured == HAL_ETH_PTP_CONFIGURATED)
{
SET_BIT(dmatxdesc->DESC0, ETH_DMATXDESC_TTSE);
return HAL_OK;
}if (heth->IsPtpConfigured == HAL_ETH_PTP_CONFIGURATED) { ... }
else
{
return HAL_ERROR;
}else { ... }
}HAL_ETH_PTP_InsertTxTimestamp (ETH_HandleTypeDef *heth) { ... }
/* ... */
HAL_StatusTypeDef HAL_ETH_PTP_GetTxTimestamp(ETH_HandleTypeDef *heth, ETH_TimeStampTypeDef *timestamp)
{
ETH_TxDescListTypeDef *dmatxdesclist = &heth->TxDescList;
uint32_t idx = dmatxdesclist->releaseIndex;
ETH_DMADescTypeDef *dmatxdesc = (ETH_DMADescTypeDef *)dmatxdesclist->TxDesc[idx];
if (heth->IsPtpConfigured == HAL_ETH_PTP_CONFIGURATED)
{
timestamp->TimeStampLow = dmatxdesc->DESC0;
timestamp->TimeStampHigh = dmatxdesc->DESC1;
return HAL_OK;
}if (heth->IsPtpConfigured == HAL_ETH_PTP_CONFIGURATED) { ... }
else
{
return HAL_ERROR;
}else { ... }
}HAL_ETH_PTP_GetTxTimestamp (ETH_HandleTypeDef *heth, ETH_TimeStampTypeDef *timestamp) { ... }
/* ... */
HAL_StatusTypeDef HAL_ETH_PTP_GetRxTimestamp(ETH_HandleTypeDef *heth, ETH_TimeStampTypeDef *timestamp)
{
if (heth->IsPtpConfigured == HAL_ETH_PTP_CONFIGURATED)
{
timestamp->TimeStampLow = heth->RxDescList.TimeStamp.TimeStampLow;
timestamp->TimeStampHigh = heth->RxDescList.TimeStamp.TimeStampHigh;
return HAL_OK;
}if (heth->IsPtpConfigured == HAL_ETH_PTP_CONFIGURATED) { ... }
else
{
return HAL_ERROR;
}else { ... }
}HAL_ETH_PTP_GetRxTimestamp (ETH_HandleTypeDef *heth, ETH_TimeStampTypeDef *timestamp) { ... }
/* ... */
HAL_StatusTypeDef HAL_ETH_RegisterTxPtpCallback(ETH_HandleTypeDef *heth, pETH_txPtpCallbackTypeDef txPtpCallback)
{
if (txPtpCallback == NULL)
{
return HAL_ERROR;
}if (txPtpCallback == NULL) { ... }
heth->txPtpCallback = txPtpCallback;
return HAL_OK;
}HAL_ETH_RegisterTxPtpCallback (ETH_HandleTypeDef *heth, pETH_txPtpCallbackTypeDef txPtpCallback) { ... }
/* ... */
HAL_StatusTypeDef HAL_ETH_UnRegisterTxPtpCallback(ETH_HandleTypeDef *heth)
{
heth->txPtpCallback = HAL_ETH_TxPtpCallback;
return HAL_OK;
}HAL_ETH_UnRegisterTxPtpCallback (ETH_HandleTypeDef *heth) { ... }
/* ... */
__weak void HAL_ETH_TxPtpCallback(uint32_t *buff, ETH_TimeStampTypeDef *timestamp)
{
UNUSED(buff);
/* ... */
}HAL_ETH_TxPtpCallback (uint32_t *buff, ETH_TimeStampTypeDef *timestamp) { ... }
/* ... */#endif
/* ... */
void HAL_ETH_IRQHandler(ETH_HandleTypeDef *heth)
{
if (__HAL_ETH_DMA_GET_IT(heth, ETH_DMASR_RS))
{
if (__HAL_ETH_DMA_GET_IT_SOURCE(heth, ETH_DMAIER_RIE))
{
__HAL_ETH_DMA_CLEAR_IT(heth, ETH_DMASR_RS | ETH_DMASR_NIS);
#if (USE_HAL_ETH_REGISTER_CALLBACKS == 1)
heth->RxCpltCallback(heth);/* ... */
#else
HAL_ETH_RxCpltCallback(heth);/* ... */
#endif
}if (__HAL_ETH_DMA_GET_IT_SOURCE(heth, ETH_DMAIER_RIE)) { ... }
}if (__HAL_ETH_DMA_GET_IT(heth, ETH_DMASR_RS)) { ... }
if (__HAL_ETH_DMA_GET_IT(heth, ETH_DMASR_TS))
{
if (__HAL_ETH_DMA_GET_IT_SOURCE(heth, ETH_DMAIER_TIE))
{
__HAL_ETH_DMA_CLEAR_IT(heth, ETH_DMASR_TS | ETH_DMASR_NIS);
#if (USE_HAL_ETH_REGISTER_CALLBACKS == 1)
heth->TxCpltCallback(heth);/* ... */
#else
HAL_ETH_TxCpltCallback(heth);/* ... */
#endif
}if (__HAL_ETH_DMA_GET_IT_SOURCE(heth, ETH_DMAIER_TIE)) { ... }
}if (__HAL_ETH_DMA_GET_IT(heth, ETH_DMASR_TS)) { ... }
if (__HAL_ETH_DMA_GET_IT(heth, ETH_DMASR_AIS))
{
if (__HAL_ETH_DMA_GET_IT_SOURCE(heth, ETH_DMAIER_AISE))
{
heth->ErrorCode |= HAL_ETH_ERROR_DMA;
if (__HAL_ETH_DMA_GET_IT(heth, ETH_DMASR_FBES))
{
heth->DMAErrorCode = READ_BIT(heth->Instance->DMASR, (ETH_DMASR_FBES | ETH_DMASR_TPS | ETH_DMASR_RPS));
__HAL_ETH_DMA_DISABLE_IT(heth, ETH_DMAIER_NISE | ETH_DMAIER_AISE);
heth->gState = HAL_ETH_STATE_ERROR;
}if (__HAL_ETH_DMA_GET_IT(heth, ETH_DMASR_FBES)) { ... }
else
{
heth->DMAErrorCode = READ_BIT(heth->Instance->DMASR, (ETH_DMASR_ETS | ETH_DMASR_RWTS |
ETH_DMASR_RBUS | ETH_DMASR_AIS));
__HAL_ETH_DMA_CLEAR_IT(heth, (ETH_DMASR_ETS | ETH_DMASR_RWTS |
ETH_DMASR_RBUS | ETH_DMASR_AIS));
}else { ... }
#if (USE_HAL_ETH_REGISTER_CALLBACKS == 1)
heth->ErrorCallback(heth);/* ... */
#else
HAL_ETH_ErrorCallback(heth);/* ... */
#endif
}if (__HAL_ETH_DMA_GET_IT_SOURCE(heth, ETH_DMAIER_AISE)) { ... }
}if (__HAL_ETH_DMA_GET_IT(heth, ETH_DMASR_AIS)) { ... }
if (__HAL_ETH_MAC_GET_IT(heth, ETH_MAC_PMT_IT))
{
heth->MACWakeUpEvent = READ_BIT(heth->Instance->MACPMTCSR, (ETH_MACPMTCSR_WFR | ETH_MACPMTCSR_MPR));
#if (USE_HAL_ETH_REGISTER_CALLBACKS == 1)
heth->PMTCallback(heth);/* ... */
#else
HAL_ETH_PMTCallback(heth);/* ... */
#endif
heth->MACWakeUpEvent = (uint32_t)(0x0U);
}if (__HAL_ETH_MAC_GET_IT(heth, ETH_MAC_PMT_IT)) { ... }
if (__HAL_ETH_WAKEUP_EXTI_GET_FLAG(ETH_WAKEUP_EXTI_LINE) != (uint32_t)RESET)
{
__HAL_ETH_WAKEUP_EXTI_CLEAR_FLAG(ETH_WAKEUP_EXTI_LINE);
#if (USE_HAL_ETH_REGISTER_CALLBACKS == 1)
heth->WakeUpCallback(heth);/* ... */
#else
HAL_ETH_WakeUpCallback(heth);/* ... */
#endif
}if (__HAL_ETH_WAKEUP_EXTI_GET_FLAG(ETH_WAKEUP_EXTI_LINE) != (uint32_t)RESET) { ... }
}{ ... }
/* ... */
__weak void HAL_ETH_TxCpltCallback(ETH_HandleTypeDef *heth)
{
UNUSED(heth);
/* ... */
}{ ... }
/* ... */
__weak void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *heth)
{
UNUSED(heth);
/* ... */
}{ ... }
/* ... */
__weak void HAL_ETH_ErrorCallback(ETH_HandleTypeDef *heth)
{
UNUSED(heth);
/* ... */
}{ ... }
/* ... */
__weak void HAL_ETH_PMTCallback(ETH_HandleTypeDef *heth)
{
UNUSED(heth);
/* ... */
}{ ... }
/* ... */
__weak void HAL_ETH_WakeUpCallback(ETH_HandleTypeDef *heth)
{
UNUSED(heth);
/* ... */
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_ETH_ReadPHYRegister(ETH_HandleTypeDef *heth, uint32_t PHYAddr, uint32_t PHYReg,
uint32_t *pRegValue)
{
uint32_t tmpreg1;
uint32_t tickstart;
tmpreg1 = heth->Instance->MACMIIAR;
tmpreg1 &= ~ETH_MACMIIAR_CR_MASK;
tmpreg1 |= ((PHYAddr << 11U) & ETH_MACMIIAR_PA);
tmpreg1 |= (((uint32_t)PHYReg << 6U) & ETH_MACMIIAR_MR);
tmpreg1 &= ~ETH_MACMIIAR_MW;
tmpreg1 |= ETH_MACMIIAR_MB;
heth->Instance->MACMIIAR = tmpreg1;
tickstart = HAL_GetTick();
while ((tmpreg1 & ETH_MACMIIAR_MB) == ETH_MACMIIAR_MB)
{
if ((HAL_GetTick() - tickstart) > PHY_READ_TO)
{
return HAL_ERROR;
}if ((HAL_GetTick() - tickstart) > PHY_READ_TO) { ... }
tmpreg1 = heth->Instance->MACMIIAR;
}while ((tmpreg1 & ETH_MACMIIAR_MB) == ETH_MACMIIAR_MB) { ... }
*pRegValue = (uint16_t)(heth->Instance->MACMIIDR);
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_ETH_WritePHYRegister(const ETH_HandleTypeDef *heth, uint32_t PHYAddr, uint32_t PHYReg,
uint32_t RegValue)
{
uint32_t tmpreg1;
uint32_t tickstart;
tmpreg1 = heth->Instance->MACMIIAR;
tmpreg1 &= ~ETH_MACMIIAR_CR_MASK;
tmpreg1 |= ((PHYAddr << 11U) & ETH_MACMIIAR_PA);
tmpreg1 |= (((uint32_t)PHYReg << 6U) & ETH_MACMIIAR_MR);
tmpreg1 |= ETH_MACMIIAR_MW;
tmpreg1 |= ETH_MACMIIAR_MB;
heth->Instance->MACMIIDR = (uint16_t)RegValue;
heth->Instance->MACMIIAR = tmpreg1;
tickstart = HAL_GetTick();
while ((tmpreg1 & ETH_MACMIIAR_MB) == ETH_MACMIIAR_MB)
{
if ((HAL_GetTick() - tickstart) > PHY_WRITE_TO)
{
return HAL_ERROR;
}if ((HAL_GetTick() - tickstart) > PHY_WRITE_TO) { ... }
tmpreg1 = heth->Instance->MACMIIAR;
}while ((tmpreg1 & ETH_MACMIIAR_MB) == ETH_MACMIIAR_MB) { ... }
return HAL_OK;
}{ ... }
/* ... */
/* ... */
/* ... */
HAL_StatusTypeDef HAL_ETH_GetMACConfig(ETH_HandleTypeDef *heth, ETH_MACConfigTypeDef *macconf)
{
if (macconf == NULL)
{
return HAL_ERROR;
}if (macconf == NULL) { ... }
macconf->DeferralCheck = ((READ_BIT(heth->Instance->MACCR, ETH_MACCR_DC) >> 4) > 0U) ? ENABLE : DISABLE;
macconf->BackOffLimit = READ_BIT(heth->Instance->MACCR, ETH_MACCR_BL);
macconf->RetryTransmission = ((READ_BIT(heth->Instance->MACCR, ETH_MACCR_RD) >> 9) == 0U) ? ENABLE : DISABLE;
macconf->CarrierSenseDuringTransmit = ((READ_BIT(heth->Instance->MACCR, ETH_MACCR_CSD) >> 16) > 0U)
? ENABLE : DISABLE;
macconf->ReceiveOwn = ((READ_BIT(heth->Instance->MACCR, ETH_MACCR_ROD) >> 13) == 0U) ? ENABLE : DISABLE;
macconf->LoopbackMode = ((READ_BIT(heth->Instance->MACCR, ETH_MACCR_LM) >> 12) > 0U) ? ENABLE : DISABLE;
macconf->DuplexMode = READ_BIT(heth->Instance->MACCR, ETH_MACCR_DM);
macconf->Speed = READ_BIT(heth->Instance->MACCR, ETH_MACCR_FES);
macconf->Jabber = ((READ_BIT(heth->Instance->MACCR, ETH_MACCR_JD) >> 22) == 0U) ? ENABLE : DISABLE;
macconf->Watchdog = ((READ_BIT(heth->Instance->MACCR, ETH_MACCR_WD) >> 23) == 0U) ? ENABLE : DISABLE;
macconf->AutomaticPadCRCStrip = ((READ_BIT(heth->Instance->MACCR, ETH_MACCR_APCS) >> 7) > 0U) ? ENABLE : DISABLE;
macconf->InterPacketGapVal = READ_BIT(heth->Instance->MACCR, ETH_MACCR_IFG);
macconf->ChecksumOffload = ((READ_BIT(heth->Instance->MACCR, ETH_MACCR_IPCO) >> 10U) > 0U) ? ENABLE : DISABLE;
macconf->TransmitFlowControl = ((READ_BIT(heth->Instance->MACFCR, ETH_MACFCR_TFCE) >> 1) > 0U) ? ENABLE : DISABLE;
macconf->ZeroQuantaPause = ((READ_BIT(heth->Instance->MACFCR, ETH_MACFCR_ZQPD) >> 7) == 0U) ? ENABLE : DISABLE;
macconf->PauseLowThreshold = READ_BIT(heth->Instance->MACFCR, ETH_MACFCR_PLT);
macconf->PauseTime = (READ_BIT(heth->Instance->MACFCR, ETH_MACFCR_PT) >> 16);
macconf->ReceiveFlowControl = ((READ_BIT(heth->Instance->MACFCR, ETH_MACFCR_RFCE) >> 2U) > 0U) ? ENABLE : DISABLE;
macconf->UnicastPausePacketDetect = ((READ_BIT(heth->Instance->MACFCR, ETH_MACFCR_UPFD) >> 3U) > 0U)
? ENABLE : DISABLE;
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_ETH_GetDMAConfig(ETH_HandleTypeDef *heth, ETH_DMAConfigTypeDef *dmaconf)
{
if (dmaconf == NULL)
{
return HAL_ERROR;
}if (dmaconf == NULL) { ... }
dmaconf->DMAArbitration = READ_BIT(heth->Instance->DMABMR,
(ETH_DMAARBITRATION_RXPRIORTX | ETH_DMAARBITRATION_ROUNDROBIN_RXTX_4_1));
dmaconf->AddressAlignedBeats = ((READ_BIT(heth->Instance->DMABMR, ETH_DMABMR_AAB) >> 25U) > 0U) ? ENABLE : DISABLE;
dmaconf->BurstMode = READ_BIT(heth->Instance->DMABMR, ETH_DMABMR_FB | ETH_DMABMR_MB);
dmaconf->RxDMABurstLength = READ_BIT(heth->Instance->DMABMR, ETH_DMABMR_RDP);
dmaconf->TxDMABurstLength = READ_BIT(heth->Instance->DMABMR, ETH_DMABMR_PBL);
dmaconf->EnhancedDescriptorFormat = ((READ_BIT(heth->Instance->DMABMR, ETH_DMABMR_EDE) >> 7) > 0U) ? ENABLE : DISABLE;
dmaconf->DescriptorSkipLength = READ_BIT(heth->Instance->DMABMR, ETH_DMABMR_DSL) >> 2;
dmaconf->DropTCPIPChecksumErrorFrame = ((READ_BIT(heth->Instance->DMAOMR,
ETH_DMAOMR_DTCEFD) >> 26) > 0U) ? DISABLE : ENABLE;
dmaconf->ReceiveStoreForward = ((READ_BIT(heth->Instance->DMAOMR, ETH_DMAOMR_RSF) >> 25) > 0U) ? ENABLE : DISABLE;
dmaconf->FlushRxPacket = ((READ_BIT(heth->Instance->DMAOMR, ETH_DMAOMR_FTF) >> 20) > 0U) ? DISABLE : ENABLE;
dmaconf->TransmitStoreForward = ((READ_BIT(heth->Instance->DMAOMR, ETH_DMAOMR_TSF) >> 21) > 0U) ? ENABLE : DISABLE;
dmaconf->TransmitThresholdControl = READ_BIT(heth->Instance->DMAOMR, ETH_DMAOMR_TTC);
dmaconf->ForwardErrorFrames = ((READ_BIT(heth->Instance->DMAOMR, ETH_DMAOMR_FEF) >> 7) > 0U) ? ENABLE : DISABLE;
dmaconf->ForwardUndersizedGoodFrames = ((READ_BIT(heth->Instance->DMAOMR,
ETH_DMAOMR_FUGF) >> 6) > 0U) ? ENABLE : DISABLE;
dmaconf->ReceiveThresholdControl = READ_BIT(heth->Instance->DMAOMR, ETH_DMAOMR_RTC);
dmaconf->SecondFrameOperate = ((READ_BIT(heth->Instance->DMAOMR, ETH_DMAOMR_OSF) >> 2) > 0U) ? ENABLE : DISABLE;
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_ETH_SetMACConfig(ETH_HandleTypeDef *heth, ETH_MACConfigTypeDef *macconf)
{
if (macconf == NULL)
{
return HAL_ERROR;
}if (macconf == NULL) { ... }
if (heth->gState == HAL_ETH_STATE_READY)
{
ETH_SetMACConfig(heth, macconf);
return HAL_OK;
}if (heth->gState == HAL_ETH_STATE_READY) { ... }
else
{
return HAL_ERROR;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_ETH_SetDMAConfig(ETH_HandleTypeDef *heth, ETH_DMAConfigTypeDef *dmaconf)
{
if (dmaconf == NULL)
{
return HAL_ERROR;
}if (dmaconf == NULL) { ... }
if (heth->gState == HAL_ETH_STATE_READY)
{
ETH_SetDMAConfig(heth, dmaconf);
return HAL_OK;
}if (heth->gState == HAL_ETH_STATE_READY) { ... }
else
{
return HAL_ERROR;
}else { ... }
}{ ... }
/* ... */
void HAL_ETH_SetMDIOClockRange(ETH_HandleTypeDef *heth)
{
uint32_t hclk;
uint32_t tmpreg;
tmpreg = (heth->Instance)->MACMIIAR;
tmpreg &= ETH_MACMIIAR_CR_MASK;
hclk = HAL_RCC_GetHCLKFreq();
if ((hclk >= 20000000U) && (hclk < 35000000U))
{
tmpreg |= (uint32_t)ETH_MACMIIAR_CR_Div16;
}if ((hclk >= 20000000U) && (hclk < 35000000U)) { ... }
else if ((hclk >= 35000000U) && (hclk < 60000000U))
{
tmpreg |= (uint32_t)ETH_MACMIIAR_CR_Div26;
}else if ((hclk >= 35000000U) && (hclk < 60000000U)) { ... }
else if ((hclk >= 60000000U) && (hclk < 100000000U))
{
tmpreg |= (uint32_t)ETH_MACMIIAR_CR_Div42;
}else if ((hclk >= 60000000U) && (hclk < 100000000U)) { ... }
else if ((hclk >= 100000000U) && (hclk < 150000000U))
{
tmpreg |= (uint32_t)ETH_MACMIIAR_CR_Div62;
}else if ((hclk >= 100000000U) && (hclk < 150000000U)) { ... }
else
{
tmpreg |= (uint32_t)ETH_MACMIIAR_CR_Div102;
}else { ... }
(heth->Instance)->MACMIIAR = (uint32_t)tmpreg;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_ETH_SetMACFilterConfig(ETH_HandleTypeDef *heth, const ETH_MACFilterConfigTypeDef *pFilterConfig)
{
uint32_t filterconfig;
uint32_t tmpreg1;
if (pFilterConfig == NULL)
{
return HAL_ERROR;
}if (pFilterConfig == NULL) { ... }
filterconfig = ((uint32_t)pFilterConfig->PromiscuousMode |
((uint32_t)pFilterConfig->HashUnicast << 1) |
((uint32_t)pFilterConfig->HashMulticast << 2) |
((uint32_t)pFilterConfig->DestAddrInverseFiltering << 3) |
((uint32_t)pFilterConfig->PassAllMulticast << 4) |
((uint32_t)((pFilterConfig->BroadcastFilter == DISABLE) ? 1U : 0U) << 5) |
((uint32_t)pFilterConfig->SrcAddrInverseFiltering << 8) |
((uint32_t)pFilterConfig->SrcAddrFiltering << 9) |
((uint32_t)pFilterConfig->HachOrPerfectFilter << 10) |
((uint32_t)pFilterConfig->ReceiveAllMode << 31) |
pFilterConfig->ControlPacketsFilter);
MODIFY_REG(heth->Instance->MACFFR, ETH_MACFFR_MASK, filterconfig);
/* ... */
tmpreg1 = (heth->Instance)->MACFFR;
HAL_Delay(ETH_REG_WRITE_DELAY);
(heth->Instance)->MACFFR = tmpreg1;
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_ETH_GetMACFilterConfig(ETH_HandleTypeDef *heth, ETH_MACFilterConfigTypeDef *pFilterConfig)
{
if (pFilterConfig == NULL)
{
return HAL_ERROR;
}if (pFilterConfig == NULL) { ... }
pFilterConfig->PromiscuousMode = ((READ_BIT(heth->Instance->MACFFR, ETH_MACFFR_PM)) > 0U) ? ENABLE : DISABLE;
pFilterConfig->HashUnicast = ((READ_BIT(heth->Instance->MACFFR, ETH_MACFFR_HU) >> 1) > 0U) ? ENABLE : DISABLE;
pFilterConfig->HashMulticast = ((READ_BIT(heth->Instance->MACFFR, ETH_MACFFR_HM) >> 2) > 0U) ? ENABLE : DISABLE;
pFilterConfig->DestAddrInverseFiltering = ((READ_BIT(heth->Instance->MACFFR,
ETH_MACFFR_DAIF) >> 3) > 0U) ? ENABLE : DISABLE;
pFilterConfig->PassAllMulticast = ((READ_BIT(heth->Instance->MACFFR, ETH_MACFFR_PAM) >> 4) > 0U) ? ENABLE : DISABLE;
pFilterConfig->BroadcastFilter = ((READ_BIT(heth->Instance->MACFFR, ETH_MACFFR_BFD) >> 5) == 0U) ? ENABLE : DISABLE;
pFilterConfig->ControlPacketsFilter = READ_BIT(heth->Instance->MACFFR, ETH_MACFFR_PCF);
pFilterConfig->SrcAddrInverseFiltering = ((READ_BIT(heth->Instance->MACFFR,
ETH_MACFFR_SAIF) >> 8) > 0U) ? ENABLE : DISABLE;
pFilterConfig->SrcAddrFiltering = ((READ_BIT(heth->Instance->MACFFR, ETH_MACFFR_SAF) >> 9) > 0U) ? ENABLE : DISABLE;
pFilterConfig->HachOrPerfectFilter = ((READ_BIT(heth->Instance->MACFFR, ETH_MACFFR_HPF) >> 10) > 0U)
? ENABLE : DISABLE;
pFilterConfig->ReceiveAllMode = ((READ_BIT(heth->Instance->MACFFR, ETH_MACFFR_RA) >> 31) > 0U) ? ENABLE : DISABLE;
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_ETH_SetSourceMACAddrMatch(const ETH_HandleTypeDef *heth, uint32_t AddrNbr,
const uint8_t *pMACAddr)
{
uint32_t macaddrlr;
uint32_t macaddrhr;
if (pMACAddr == NULL)
{
return HAL_ERROR;
}if (pMACAddr == NULL) { ... }
macaddrhr = ((uint32_t) &(heth->Instance->MACA0HR) + AddrNbr);
macaddrlr = ((uint32_t) &(heth->Instance->MACA0LR) + AddrNbr);
(*(__IO uint32_t *)macaddrhr) = (((uint32_t)(pMACAddr[5]) << 8) | (uint32_t)pMACAddr[4]);
(*(__IO uint32_t *)macaddrlr) = (((uint32_t)(pMACAddr[3]) << 24) | ((uint32_t)(pMACAddr[2]) << 16) |
((uint32_t)(pMACAddr[1]) << 8) | (uint32_t)pMACAddr[0]);
(*(__IO uint32_t *)macaddrhr) |= (ETH_MACA1HR_AE | ETH_MACA1HR_SA);
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_ETH_SetHashTable(ETH_HandleTypeDef *heth, uint32_t *pHashTable)
{
uint32_t tmpreg1;
if (pHashTable == NULL)
{
return HAL_ERROR;
}if (pHashTable == NULL) { ... }
heth->Instance->MACHTHR = pHashTable[0];
/* ... */
tmpreg1 = (heth->Instance)->MACHTHR;
HAL_Delay(ETH_REG_WRITE_DELAY);
(heth->Instance)->MACHTHR = tmpreg1;
heth->Instance->MACHTLR = pHashTable[1];
/* ... */
tmpreg1 = (heth->Instance)->MACHTLR;
HAL_Delay(ETH_REG_WRITE_DELAY);
(heth->Instance)->MACHTLR = tmpreg1;
return HAL_OK;
}{ ... }
/* ... */
void HAL_ETH_SetRxVLANIdentifier(ETH_HandleTypeDef *heth, uint32_t ComparisonBits, uint32_t VLANIdentifier)
{
uint32_t tmpreg1;
MODIFY_REG(heth->Instance->MACVLANTR, ETH_MACVLANTR_VLANTI, VLANIdentifier);
if (ComparisonBits == ETH_VLANTAGCOMPARISON_16BIT)
{
CLEAR_BIT(heth->Instance->MACVLANTR, ETH_MACVLANTR_VLANTC);
}if (ComparisonBits == ETH_VLANTAGCOMPARISON_16BIT) { ... }
else
{
SET_BIT(heth->Instance->MACVLANTR, ETH_MACVLANTR_VLANTC);
}else { ... }
/* ... */
tmpreg1 = (heth->Instance)->MACVLANTR;
HAL_Delay(ETH_REG_WRITE_DELAY);
(heth->Instance)->MACVLANTR = tmpreg1;
}{ ... }
/* ... */
void HAL_ETH_EnterPowerDownMode(ETH_HandleTypeDef *heth, const ETH_PowerDownConfigTypeDef *pPowerDownConfig)
{
uint32_t powerdownconfig;
powerdownconfig = (((uint32_t)pPowerDownConfig->MagicPacket << ETH_MACPMTCSR_MPE_Pos) |
((uint32_t)pPowerDownConfig->WakeUpPacket << ETH_MACPMTCSR_WFE_Pos) |
((uint32_t)pPowerDownConfig->GlobalUnicast << ETH_MACPMTCSR_GU_Pos) |
ETH_MACPMTCSR_PD);
MODIFY_REG(heth->Instance->MACPMTCSR, ETH_MACPMTCSR_MASK, powerdownconfig);
}{ ... }
/* ... */
void HAL_ETH_ExitPowerDownMode(ETH_HandleTypeDef *heth)
{
uint32_t tmpreg1;
CLEAR_BIT(heth->Instance->MACPMTCSR, ETH_MACPMTCSR_WFE | ETH_MACPMTCSR_MPE | ETH_MACPMTCSR_GU);
/* ... */
tmpreg1 = (heth->Instance)->MACPMTCSR;
HAL_Delay(ETH_REG_WRITE_DELAY);
(heth->Instance)->MACPMTCSR = tmpreg1;
if (READ_BIT(heth->Instance->MACPMTCSR, ETH_MACPMTCSR_PD) != 0U)
{
CLEAR_BIT(heth->Instance->MACPMTCSR, ETH_MACPMTCSR_PD);
/* ... */
tmpreg1 = (heth->Instance)->MACPMTCSR;
HAL_Delay(ETH_REG_WRITE_DELAY);
(heth->Instance)->MACPMTCSR = tmpreg1;
}if (READ_BIT(heth->Instance->MACPMTCSR, ETH_MACPMTCSR_PD) != 0U) { ... }
SET_BIT(heth->Instance->MACIMR, ETH_MACIMR_PMTIM);
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_ETH_SetWakeUpFilter(ETH_HandleTypeDef *heth, uint32_t *pFilter, uint32_t Count)
{
uint32_t regindex;
if (pFilter == NULL)
{
return HAL_ERROR;
}if (pFilter == NULL) { ... }
SET_BIT(heth->Instance->MACPMTCSR, ETH_MACPMTCSR_WFFRPR);
for (regindex = 0; regindex < Count; regindex++)
{
WRITE_REG(heth->Instance->MACRWUFFR, pFilter[regindex]);
}for (regindex = 0; regindex < Count; regindex++) { ... }
return HAL_OK;
}{ ... }
/* ... */
/* ... */
/* ... */
HAL_ETH_StateTypeDef HAL_ETH_GetState(const ETH_HandleTypeDef *heth)
{
return heth->gState;
}{ ... }
/* ... */
uint32_t HAL_ETH_GetError(const ETH_HandleTypeDef *heth)
{
return heth->ErrorCode;
}{ ... }
/* ... */
uint32_t HAL_ETH_GetDMAError(const ETH_HandleTypeDef *heth)
{
return heth->DMAErrorCode;
}{ ... }
/* ... */
uint32_t HAL_ETH_GetMACError(const ETH_HandleTypeDef *heth)
{
return heth->MACErrorCode;
}{ ... }
/* ... */
uint32_t HAL_ETH_GetMACWakeUpSource(const ETH_HandleTypeDef *heth)
{
return heth->MACWakeUpEvent;
}{ ... }
/* ... */
/* ... */
/* ... */
/* ... */
static void ETH_FlushTransmitFIFO(ETH_HandleTypeDef *heth)
{
__IO uint32_t tmpreg = 0;
(heth->Instance)->DMAOMR |= ETH_DMAOMR_FTF;
/* ... */
tmpreg = (heth->Instance)->DMAOMR;
HAL_Delay(ETH_REG_WRITE_DELAY);
(heth->Instance)->DMAOMR = tmpreg;
}{ ... }
static void ETH_SetMACConfig(ETH_HandleTypeDef *heth, ETH_MACConfigTypeDef *macconf)
{
uint32_t tmpreg1;
tmpreg1 = (heth->Instance)->MACCR;
tmpreg1 &= ETH_MACCR_CLEAR_MASK;
tmpreg1 |= (uint32_t)(((uint32_t)((macconf->Watchdog == DISABLE) ? 1U : 0U) << 23U) |
((uint32_t)((macconf->Jabber == DISABLE) ? 1U : 0U) << 22U) |
(uint32_t)macconf->InterPacketGapVal |
((uint32_t)macconf->CarrierSenseDuringTransmit << 16U) |
macconf->Speed |
((uint32_t)((macconf->ReceiveOwn == DISABLE) ? 1U : 0U) << 13U) |
((uint32_t)macconf->LoopbackMode << 12U) |
macconf->DuplexMode |
((uint32_t)macconf->ChecksumOffload << 10U) |
((uint32_t)((macconf->RetryTransmission == DISABLE) ? 1U : 0U) << 9U) |
((uint32_t)macconf->AutomaticPadCRCStrip << 7U) |
macconf->BackOffLimit |
((uint32_t)macconf->DeferralCheck << 4U));
(heth->Instance)->MACCR = (uint32_t)tmpreg1;
/* ... */
tmpreg1 = (heth->Instance)->MACCR;
HAL_Delay(ETH_REG_WRITE_DELAY);
(heth->Instance)->MACCR = tmpreg1;
------------------------ ETHERNET MACCR Configuration
tmpreg1 = (heth->Instance)->MACFCR;
tmpreg1 &= ETH_MACFCR_CLEAR_MASK;
tmpreg1 |= (uint32_t)((macconf->PauseTime << 16U) |
((uint32_t)((macconf->ZeroQuantaPause == DISABLE) ? 1U : 0U) << 7U) |
macconf->PauseLowThreshold |
((uint32_t)((macconf->UnicastPausePacketDetect == ENABLE) ? 1U : 0U) << 3U) |
((uint32_t)((macconf->ReceiveFlowControl == ENABLE) ? 1U : 0U) << 2U) |
((uint32_t)((macconf->TransmitFlowControl == ENABLE) ? 1U : 0U) << 1U));
(heth->Instance)->MACFCR = (uint32_t)tmpreg1;
/* ... */
tmpreg1 = (heth->Instance)->MACFCR;
HAL_Delay(ETH_REG_WRITE_DELAY);
(heth->Instance)->MACFCR = tmpreg1;
}{ ... }
static void ETH_SetDMAConfig(ETH_HandleTypeDef *heth, ETH_DMAConfigTypeDef *dmaconf)
{
uint32_t tmpreg1;
tmpreg1 = (heth->Instance)->DMAOMR;
tmpreg1 &= ETH_DMAOMR_CLEAR_MASK;
tmpreg1 |= (uint32_t)(((uint32_t)((dmaconf->DropTCPIPChecksumErrorFrame == DISABLE) ? 1U : 0U) << 26U) |
((uint32_t)dmaconf->ReceiveStoreForward << 25U) |
((uint32_t)((dmaconf->FlushRxPacket == DISABLE) ? 1U : 0U) << 20U) |
((uint32_t)dmaconf->TransmitStoreForward << 21U) |
dmaconf->TransmitThresholdControl |
((uint32_t)dmaconf->ForwardErrorFrames << 7U) |
((uint32_t)dmaconf->ForwardUndersizedGoodFrames << 6U) |
dmaconf->ReceiveThresholdControl |
((uint32_t)dmaconf->SecondFrameOperate << 2U));
(heth->Instance)->DMAOMR = (uint32_t)tmpreg1;
/* ... */
tmpreg1 = (heth->Instance)->DMAOMR;
HAL_Delay(ETH_REG_WRITE_DELAY);
(heth->Instance)->DMAOMR = tmpreg1;
----------------------- ETHERNET DMAOMR Configuration
(heth->Instance)->DMABMR = (uint32_t)(((uint32_t)dmaconf->AddressAlignedBeats << 25U) |
dmaconf->BurstMode |
dmaconf->RxDMABurstLength |
/* ... */
dmaconf->TxDMABurstLength |
((uint32_t)dmaconf->EnhancedDescriptorFormat << 7U) |
(dmaconf->DescriptorSkipLength << 2U) |
dmaconf->DMAArbitration |
ETH_DMABMR_USP);
/* ... */
tmpreg1 = (heth->Instance)->DMABMR;
HAL_Delay(ETH_REG_WRITE_DELAY);
(heth->Instance)->DMABMR = tmpreg1;
}{ ... }
/* ... */
static void ETH_MACDMAConfig(ETH_HandleTypeDef *heth)
{
ETH_MACConfigTypeDef macDefaultConf;
ETH_DMAConfigTypeDef dmaDefaultConf;
macDefaultConf.Watchdog = ENABLE;
macDefaultConf.Jabber = ENABLE;
macDefaultConf.InterPacketGapVal = ETH_INTERFRAMEGAP_96BIT;
macDefaultConf.CarrierSenseDuringTransmit = DISABLE;
macDefaultConf.ReceiveOwn = ENABLE;
macDefaultConf.LoopbackMode = DISABLE;
macDefaultConf.ChecksumOffload = ENABLE;
macDefaultConf.RetryTransmission = DISABLE;
macDefaultConf.AutomaticPadCRCStrip = DISABLE;
macDefaultConf.BackOffLimit = ETH_BACKOFFLIMIT_10;
macDefaultConf.DeferralCheck = DISABLE;
macDefaultConf.PauseTime = 0x0U;
macDefaultConf.ZeroQuantaPause = DISABLE;
macDefaultConf.PauseLowThreshold = ETH_PAUSELOWTHRESHOLD_MINUS4;
macDefaultConf.ReceiveFlowControl = DISABLE;
macDefaultConf.TransmitFlowControl = DISABLE;
macDefaultConf.Speed = ETH_SPEED_100M;
macDefaultConf.DuplexMode = ETH_FULLDUPLEX_MODE;
macDefaultConf.UnicastPausePacketDetect = DISABLE;
ETH_SetMACConfig(heth, &macDefaultConf);
--------------- ETHERNET MAC registers default Configuration
dmaDefaultConf.DropTCPIPChecksumErrorFrame = ENABLE;
dmaDefaultConf.ReceiveStoreForward = ENABLE;
dmaDefaultConf.FlushRxPacket = ENABLE;
dmaDefaultConf.TransmitStoreForward = ENABLE;
dmaDefaultConf.TransmitThresholdControl = ETH_TRANSMITTHRESHOLDCONTROL_64BYTES;
dmaDefaultConf.ForwardErrorFrames = DISABLE;
dmaDefaultConf.ForwardUndersizedGoodFrames = DISABLE;
dmaDefaultConf.ReceiveThresholdControl = ETH_RECEIVEDTHRESHOLDCONTROL_64BYTES;
dmaDefaultConf.SecondFrameOperate = ENABLE;
dmaDefaultConf.AddressAlignedBeats = ENABLE;
dmaDefaultConf.BurstMode = ETH_BURSTLENGTH_FIXED;
dmaDefaultConf.RxDMABurstLength = ETH_RXDMABURSTLENGTH_32BEAT;
dmaDefaultConf.TxDMABurstLength = ETH_TXDMABURSTLENGTH_32BEAT;
dmaDefaultConf.EnhancedDescriptorFormat = ENABLE;
dmaDefaultConf.DescriptorSkipLength = 0x0U;
dmaDefaultConf.DMAArbitration = ETH_DMAARBITRATION_ROUNDROBIN_RXTX_1_1;
ETH_SetDMAConfig(heth, &dmaDefaultConf);
}{ ... }
/* ... */
static void ETH_MACAddressConfig(ETH_HandleTypeDef *heth, uint32_t MacAddr, uint8_t *Addr)
{
uint32_t tmpreg1;
UNUSED(heth);
tmpreg1 = ((uint32_t)Addr[5U] << 8U) | (uint32_t)Addr[4U];
(*(__IO uint32_t *)((uint32_t)(ETH_MAC_ADDR_HBASE + MacAddr))) = tmpreg1;
tmpreg1 = ((uint32_t)Addr[3U] << 24U) | ((uint32_t)Addr[2U] << 16U) | ((uint32_t)Addr[1U] << 8U) | Addr[0U];
(*(__IO uint32_t *)((uint32_t)(ETH_MAC_ADDR_LBASE + MacAddr))) = tmpreg1;
}{ ... }
/* ... */
static void ETH_DMATxDescListInit(ETH_HandleTypeDef *heth)
{
ETH_DMADescTypeDef *dmatxdesc;
uint32_t i;
for (i = 0; i < (uint32_t)ETH_TX_DESC_CNT; i++)
{
dmatxdesc = heth->Init.TxDesc + i;
WRITE_REG(dmatxdesc->DESC0, 0x0U);
WRITE_REG(dmatxdesc->DESC1, 0x0U);
WRITE_REG(dmatxdesc->DESC2, 0x0U);
WRITE_REG(dmatxdesc->DESC3, 0x0U);
WRITE_REG(heth->TxDescList.TxDesc[i], (uint32_t)dmatxdesc);
SET_BIT(dmatxdesc->DESC0, ETH_DMATXDESC_TCH);
if (i < ((uint32_t)ETH_TX_DESC_CNT - 1U))
{
WRITE_REG(dmatxdesc->DESC3, (uint32_t)(heth->Init.TxDesc + i + 1U));
}if (i < ((uint32_t)ETH_TX_DESC_CNT - 1U)) { ... }
else
{
WRITE_REG(dmatxdesc->DESC3, (uint32_t)(heth->Init.TxDesc));
}else { ... }
SET_BIT(dmatxdesc->DESC0, ETH_DMATXDESC_CHECKSUMTCPUDPICMPFULL);
}for (i = 0; i < (uint32_t)ETH_TX_DESC_CNT; i++) { ... }
heth->TxDescList.CurTxDesc = 0;
WRITE_REG(heth->Instance->DMATDLAR, (uint32_t) heth->Init.TxDesc);
}{ ... }
/* ... */
static void ETH_DMARxDescListInit(ETH_HandleTypeDef *heth)
{
ETH_DMADescTypeDef *dmarxdesc;
uint32_t i;
for (i = 0; i < (uint32_t)ETH_RX_DESC_CNT; i++)
{
dmarxdesc = heth->Init.RxDesc + i;
WRITE_REG(dmarxdesc->DESC0, 0x0U);
WRITE_REG(dmarxdesc->DESC1, 0x0U);
WRITE_REG(dmarxdesc->DESC2, 0x0U);
WRITE_REG(dmarxdesc->DESC3, 0x0U);
WRITE_REG(dmarxdesc->BackupAddr0, 0x0U);
WRITE_REG(dmarxdesc->BackupAddr1, 0x0U);
dmarxdesc->DESC0 = ETH_DMARXDESC_OWN;
dmarxdesc->DESC1 = ETH_DMARXDESC_RCH | ETH_RX_BUF_SIZE;
dmarxdesc->DESC1 &= ~ETH_DMARXDESC_DIC;
WRITE_REG(heth->RxDescList.RxDesc[i], (uint32_t)dmarxdesc);
if (i < ((uint32_t)ETH_RX_DESC_CNT - 1U))
{
WRITE_REG(dmarxdesc->DESC3, (uint32_t)(heth->Init.RxDesc + i + 1U));
}if (i < ((uint32_t)ETH_RX_DESC_CNT - 1U)) { ... }
else
{
WRITE_REG(dmarxdesc->DESC3, (uint32_t)(heth->Init.RxDesc));
}else { ... }
}for (i = 0; i < (uint32_t)ETH_RX_DESC_CNT; i++) { ... }
WRITE_REG(heth->RxDescList.RxDescIdx, 0U);
WRITE_REG(heth->RxDescList.RxDescCnt, 0U);
WRITE_REG(heth->RxDescList.RxBuildDescIdx, 0U);
WRITE_REG(heth->RxDescList.RxBuildDescCnt, 0U);
WRITE_REG(heth->RxDescList.ItMode, 0U);
WRITE_REG(heth->Instance->DMARDLAR, (uint32_t) heth->Init.RxDesc);
}{ ... }
/* ... */
static uint32_t ETH_Prepare_Tx_Descriptors(ETH_HandleTypeDef *heth, ETH_TxPacketConfig *pTxConfig, uint32_t ItMode)
{
ETH_TxDescListTypeDef *dmatxdesclist = &heth->TxDescList;
uint32_t descidx = dmatxdesclist->CurTxDesc;
uint32_t firstdescidx = dmatxdesclist->CurTxDesc;
uint32_t idx;
uint32_t descnbr = 0;
ETH_DMADescTypeDef *dmatxdesc = (ETH_DMADescTypeDef *)dmatxdesclist->TxDesc[descidx];
ETH_BufferTypeDef *txbuffer = pTxConfig->TxBuffer;
uint32_t bd_count = 0;
if ((READ_BIT(dmatxdesc->DESC0, ETH_DMATXDESC_OWN) == ETH_DMATXDESC_OWN)
|| (dmatxdesclist->PacketAddress[descidx] != NULL))
{
return HAL_ETH_ERROR_BUSY;
}if ((READ_BIT(dmatxdesc->DESC0, ETH_DMATXDESC_OWN) == ETH_DMATXDESC_OWN) || (dmatxdesclist->PacketAddress[descidx] != NULL)) { ... }
descnbr += 1U;
WRITE_REG(dmatxdesc->DESC2, (uint32_t)txbuffer->buffer);
MODIFY_REG(dmatxdesc->DESC1, ETH_DMATXDESC_TBS1, txbuffer->len);
if (READ_BIT(pTxConfig->Attributes, ETH_TX_PACKETS_FEATURES_CSUM) != 0U)
{
MODIFY_REG(dmatxdesc->DESC0, ETH_DMATXDESC_CIC, pTxConfig->ChecksumCtrl);
}if (READ_BIT(pTxConfig->Attributes, ETH_TX_PACKETS_FEATURES_CSUM) != 0U) { ... }
if (READ_BIT(pTxConfig->Attributes, ETH_TX_PACKETS_FEATURES_CRCPAD) != 0U)
{
MODIFY_REG(dmatxdesc->DESC0, ETH_CRC_PAD_DISABLE, pTxConfig->CRCPadCtrl);
}if (READ_BIT(pTxConfig->Attributes, ETH_TX_PACKETS_FEATURES_CRCPAD) != 0U) { ... }
if (READ_BIT(pTxConfig->Attributes, ETH_TX_PACKETS_FEATURES_VLANTAG) != 0U)
{
SET_BIT(dmatxdesc->DESC0, ETH_DMATXDESC_VF);
}if (READ_BIT(pTxConfig->Attributes, ETH_TX_PACKETS_FEATURES_VLANTAG) != 0U) { ... }
SET_BIT(dmatxdesc->DESC0, ETH_DMATXDESC_FS);
__DMB();
SET_BIT(dmatxdesc->DESC0, ETH_DMATXDESC_OWN);
while (txbuffer->next != NULL)
{
CLEAR_BIT(dmatxdesc->DESC0, ETH_DMATXDESC_LS);
if (ItMode != ((uint32_t)RESET))
{
SET_BIT(dmatxdesc->DESC0, ETH_DMATXDESC_IC);
}if (ItMode != ((uint32_t)RESET)) { ... }
else
{
CLEAR_BIT(dmatxdesc->DESC0, ETH_DMATXDESC_IC);
}else { ... }
INCR_TX_DESC_INDEX(descidx, 1U);
dmatxdesc = (ETH_DMADescTypeDef *)dmatxdesclist->TxDesc[descidx];
CLEAR_BIT(dmatxdesc->DESC0, ETH_DMATXDESC_FS);
if ((READ_BIT(dmatxdesc->DESC0, ETH_DMATXDESC_OWN) == ETH_DMATXDESC_OWN)
|| (dmatxdesclist->PacketAddress[descidx] != NULL))
{
descidx = firstdescidx;
dmatxdesc = (ETH_DMADescTypeDef *)dmatxdesclist->TxDesc[descidx];
for (idx = 0; idx < descnbr; idx ++)
{
__DMB();
CLEAR_BIT(dmatxdesc->DESC0, ETH_DMATXDESC_OWN);
INCR_TX_DESC_INDEX(descidx, 1U);
dmatxdesc = (ETH_DMADescTypeDef *)dmatxdesclist->TxDesc[descidx];
}for (idx = 0; idx < descnbr; idx ++) { ... }
return HAL_ETH_ERROR_BUSY;
}if ((READ_BIT(dmatxdesc->DESC0, ETH_DMATXDESC_OWN) == ETH_DMATXDESC_OWN) || (dmatxdesclist->PacketAddress[descidx] != NULL)) { ... }
descnbr += 1U;
txbuffer = txbuffer->next;
WRITE_REG(dmatxdesc->DESC2, (uint32_t)txbuffer->buffer);
MODIFY_REG(dmatxdesc->DESC1, ETH_DMATXDESC_TBS1, txbuffer->len);
bd_count += 1U;
__DMB();
SET_BIT(dmatxdesc->DESC0, ETH_DMATXDESC_OWN);
}while (txbuffer->next != NULL) { ... }
if (ItMode != ((uint32_t)RESET))
{
SET_BIT(dmatxdesc->DESC0, ETH_DMATXDESC_IC);
}if (ItMode != ((uint32_t)RESET)) { ... }
else
{
CLEAR_BIT(dmatxdesc->DESC0, ETH_DMATXDESC_IC);
}else { ... }
SET_BIT(dmatxdesc->DESC0, ETH_DMATXDESC_LS);
dmatxdesclist->PacketAddress[descidx] = dmatxdesclist->CurrentPacketAddress;
dmatxdesclist->CurTxDesc = descidx;
__disable_irq();
dmatxdesclist->BuffersInUse += bd_count + 1U;
__enable_irq();
return HAL_ETH_ERROR_NONE;
}{ ... }
#if (USE_HAL_ETH_REGISTER_CALLBACKS == 1)
static void ETH_InitCallbacksToDefault(ETH_HandleTypeDef *heth)
{
heth->TxCpltCallback = HAL_ETH_TxCpltCallback;
heth->RxCpltCallback = HAL_ETH_RxCpltCallback;
heth->ErrorCallback = HAL_ETH_ErrorCallback;
heth->PMTCallback = HAL_ETH_PMTCallback;
heth->WakeUpCallback = HAL_ETH_WakeUpCallback;
heth->rxLinkCallback = HAL_ETH_RxLinkCallback;
heth->txFreeCallback = HAL_ETH_TxFreeCallback;
#ifdef HAL_ETH_USE_PTP
heth->txPtpCallback = HAL_ETH_TxPtpCallback;
#endif
heth->rxAllocateCallback = HAL_ETH_RxAllocateCallback;
}ETH_InitCallbacksToDefault (ETH_HandleTypeDef *heth) { ... }
/* ... */#endif
/* ... */
/* ... */
/* ... */
#endif
/* ... */
#endif
/* ... */