6 #ifndef NET_MAC_STM32F4XX_HPP_
7 #define NET_MAC_STM32F4XX_HPP_
9 #include "RtosSemaphore.hpp"
10 #include "NetDefs.hpp"
17 static const int EMAC_RX_FRAG_COUNT = 4;
18 static const int EMAC_TX_FRAG_COUNT = 8;
21 const static uint32_t PHY_REG_BMCR = 0x00;
22 const static uint32_t PHY_REG_BMSR = 0x01;
23 const static uint32_t PHY_REG_IDR1 = 0x02;
24 const static uint32_t PHY_REG_IDR2 = 0x03;
25 const static uint32_t PHY_REG_ANAR = 0x04;
26 const static uint32_t PHY_REG_ANLPAR = 0x05;
27 const static uint32_t PHY_REG_ANER = 0x06;
28 const static uint32_t PHY_REG_ANNPTR = 0x07;
29 const static uint32_t PHY_REG_LPNPA = 0x08;
32 const static uint32_t PHY_BMCR_RESET = (1 << 15);
33 const static uint32_t PHY_BMCR_LOOPBACK = (1 << 14);
34 const static uint32_t PHY_BMCR_SPEED_SEL = (1 << 13);
35 const static uint32_t PHY_BMCR_AN = (1 << 12);
36 const static uint32_t PHY_BMCR_POWERDOWN = (1 << 11);
37 const static uint32_t PHY_BMCR_ISOLATE = (1 << 10);
38 const static uint32_t PHY_BMCR_RE_AN = (1 << 9);
39 const static uint32_t PHY_BMCR_DUPLEX = (1 << 8);
42 const static uint32_t PHY_BMSR_100BE_T4 = (1 << 15);
43 const static uint32_t PHY_BMSR_100TX_FULL = (1 << 14);
44 const static uint32_t PHY_BMSR_100TX_HALF = (1 << 13);
45 const static uint32_t PHY_BMSR_10BE_FULL = (1 << 12);
46 const static uint32_t PHY_BMSR_10BE_HALF = (1 << 11);
47 const static uint32_t PHY_BMSR_NOPREAM = (1 << 6);
48 const static uint32_t PHY_BMSR_AUTO_DONE = (1 << 5);
49 const static uint32_t PHY_BMSR_REMOTE_FAULT = (1 << 4);
50 const static uint32_t PHY_BMSR_NO_AUTO = (1 << 3);
51 const static uint32_t PHY_BMSR_LINK_ESTABLISHED = (1 << 2);
53 const static uint32_t RX_DESC0_OWN = 0x80000000;
54 const static uint32_t RX_DESC0_AFM = 0x40000000;
55 const static uint32_t RX_DESC0_FL = 0x3FFF0000;
56 const static uint32_t RX_DESC0_ES = 0x00008000;
57 const static uint32_t RX_DESC0_DE = 0x00004000;
58 const static uint32_t RX_DESC0_SAF = 0x00002000;
59 const static uint32_t RX_DESC0_LE = 0x00001000;
60 const static uint32_t RX_DESC0_OE = 0x00000800;
61 const static uint32_t RX_DESC0_VLAN = 0x00000400;
62 const static uint32_t RX_DESC0_FS = 0x00000200;
63 const static uint32_t RX_DESC0_LS = 0x00000100;
64 const static uint32_t RX_DESC0_IPV4HCE = 0x00000080;
65 const static uint32_t RX_DESC0_LC = 0x00000040;
66 const static uint32_t RX_DESC0_FT = 0x00000020;
67 const static uint32_t RX_DESC0_RWT = 0x00000010;
68 const static uint32_t RX_DESC0_RE = 0x00000008;
69 const static uint32_t RX_DESC0_DBE = 0x00000004;
70 const static uint32_t RX_DESC0_CE = 0x00000002;
71 const static uint32_t RX_DESC0_MAMPCE = 0x00000001;
73 const static uint32_t TX_DESC0_OWN = 0x80000000;
74 const static uint32_t TX_DESC0_IC = 0x40000000;
75 const static uint32_t TX_DESC0_LS = 0x20000000;
76 const static uint32_t TX_DESC0_FS = 0x10000000;
77 const static uint32_t TX_DESC0_DC = 0x08000000;
78 const static uint32_t TX_DESC0_DP = 0x04000000;
79 const static uint32_t TX_DESC0_TTSE = 0x02000000;
80 const static uint32_t TX_DESC0_CIC = 0x00C00000;
81 const static uint32_t TX_DESC0_CIC_ByPass = 0x00000000;
82 const static uint32_t TX_DESC0_CIC_IPV4Header = 0x00400000;
83 const static uint32_t TX_DESC0_CIC_TCPUDPICMP_Segment = 0x00800000;
84 const static uint32_t TX_DESC0_CIC_TCPUDPICMP_Full = 0x00C00000;
85 const static uint32_t TX_DESC0_TER = 0x00200000;
86 const static uint32_t TX_DESC0_TCH = 0x00100000;
87 const static uint32_t TX_DESC0_TTSS = 0x00020000;
88 const static uint32_t TX_DESC0_IHE = 0x00010000;
89 const static uint32_t TX_DESC0_ES = 0x00008000;
90 const static uint32_t TX_DESC0_JT = 0x00004000;
91 const static uint32_t TX_DESC0_FF = 0x00002000;
92 const static uint32_t TX_DESC0_PCE = 0x00001000;
93 const static uint32_t TX_DESC0_LCA = 0x00000800;
94 const static uint32_t TX_DESC0_NC = 0x00000400;
95 const static uint32_t TX_DESC0_LCO = 0x00000200;
96 const static uint32_t TX_DESC0_EC = 0x00000100;
97 const static uint32_t TX_DESC0_VF = 0x00000080;
98 const static uint32_t TX_DESC0_CC = 0x00000078;
99 const static uint32_t TX_DESC0_ED = 0x00000004;
100 const static uint32_t TX_DESC0_UF = 0x00000002;
101 const static uint32_t TX_DESC0_DB = 0x00000001;
107 uint32_t RMAM_PCE :1;
142 }__attribute__((packed)) RX_DESC;
144 typedef enum uint8_t {
145 TX_FRAG_NO_BUFFER = 0,
147 TX_FRAG_NOT_DISCARDABLE
196 }__attribute__((packed)) TX_DESC;
198 __attribute__ ((aligned (4))) RX_DESC sRxDesc[EMAC_RX_FRAG_COUNT];
199 __attribute__ ((aligned (4))) TX_DESC sTxDesc[EMAC_TX_FRAG_COUNT];
206 NetDefs::MAC_ADDR sAddr;
208 bool phyWrite(uint16_t reg, uint16_t value);
209 uint32_t phyRead(uint16_t reg);
218 void start(const NetDefs::MAC_ADDR& addr);
219 NetDefs::FRAME* getFrame();
220 void putHeader(NetDefs::FRAME& frame, const NetDefs::MAC_ADDR& dst, NetDefs::MAC_TYPE type);
221 bool flush(NetDefs::FRAME& frame,
size_t len,
bool discardable);
222 void freeSentFrames();