1 /**************************************************************************//**
2 * @copyright (C) 2019 Nuvoton Technology Corp. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without modification,
5 * are permitted provided that the following conditions are met:
6 * 1. Redistributions of source code must retain the above copyright notice,
7 * this list of conditions and the following disclaimer.
8 * 2. Redistributions in binary form must reproduce the above copyright notice,
9 * this list of conditions and the following disclaimer in the documentation
10 * and/or other materials provided with the distribution.
11 * 3. Neither the name of Nuvoton Technology Corp. nor the names of its contributors
12 * may be used to endorse or promote products derived from this software
13 * without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *****************************************************************************/
30 /* Generic MII registers. */
32 #define MII_BMCR 0x00 /* Basic mode control register */
33 #define MII_BMSR 0x01 /* Basic mode status register */
34 #define MII_PHYSID1 0x02 /* PHYS ID 1 */
35 #define MII_PHYSID2 0x03 /* PHYS ID 2 */
36 #define MII_ADVERTISE 0x04 /* Advertisement control reg */
37 #define MII_LPA 0x05 /* Link partner ability reg */
38 #define MII_EXPANSION 0x06 /* Expansion register */
39 #define MII_DCOUNTER 0x12 /* Disconnect counter */
40 #define MII_FCSCOUNTER 0x13 /* False carrier counter */
41 #define MII_NWAYTEST 0x14 /* N-way auto-neg test reg */
42 #define MII_RERRCOUNTER 0x15 /* Receive error counter */
43 #define MII_SREVISION 0x16 /* Silicon revision */
44 #define MII_RESV1 0x17 /* Reserved... */
45 #define MII_LBRERROR 0x18 /* Lpback, rx, bypass error */
46 #define MII_PHYADDR 0x19 /* PHY address */
47 #define MII_RESV2 0x1a /* Reserved... */
48 #define MII_TPISTATUS 0x1b /* TPI status for 10mbps */
49 #define MII_NCONFIG 0x1c /* Network interface config */
51 /* Basic mode control register. */
52 #define BMCR_RESV 0x007f /* Unused... */
53 #define BMCR_CTST 0x0080 /* Collision test */
54 #define BMCR_FULLDPLX 0x0100 /* Full duplex */
55 #define BMCR_ANRESTART 0x0200 /* Auto negotiation restart */
56 #define BMCR_ISOLATE 0x0400 /* Disconnect DP83840 from MII */
57 #define BMCR_PDOWN 0x0800 /* Powerdown the DP83840 */
58 #define BMCR_ANENABLE 0x1000 /* Enable auto negotiation */
59 #define BMCR_SPEED100 0x2000 /* Select 100Mbps */
60 #define BMCR_LOOPBACK 0x4000 /* TXD loopback bits */
61 #define BMCR_RESET 0x8000 /* Reset the DP83840 */
63 /* Basic mode status register. */
64 #define BMSR_ERCAP 0x0001 /* Ext-reg capability */
65 #define BMSR_JCD 0x0002 /* Jabber detected */
66 #define BMSR_LSTATUS 0x0004 /* Link status */
67 #define BMSR_ANEGCAPABLE 0x0008 /* Able to do auto-negotiation */
68 #define BMSR_RFAULT 0x0010 /* Remote fault detected */
69 #define BMSR_ANEGCOMPLETE 0x0020 /* Auto-negotiation complete */
70 #define BMSR_RESV 0x07c0 /* Unused... */
71 #define BMSR_10HALF 0x0800 /* Can do 10mbps, half-duplex */
72 #define BMSR_10FULL 0x1000 /* Can do 10mbps, full-duplex */
73 #define BMSR_100HALF 0x2000 /* Can do 100mbps, half-duplex */
74 #define BMSR_100FULL 0x4000 /* Can do 100mbps, full-duplex */
75 #define BMSR_100BASE4 0x8000 /* Can do 100mbps, 4k packets */
77 /* Advertisement control register. */
78 #define ADVERTISE_SLCT 0x001f /* Selector bits */
79 #define ADVERTISE_CSMA 0x0001 /* Only selector supported */
80 #define ADVERTISE_10HALF 0x0020 /* Try for 10mbps half-duplex */
81 #define ADVERTISE_10FULL 0x0040 /* Try for 10mbps full-duplex */
82 #define ADVERTISE_100HALF 0x0080 /* Try for 100mbps half-duplex */
83 #define ADVERTISE_100FULL 0x0100 /* Try for 100mbps full-duplex */
84 #define ADVERTISE_100BASE4 0x0200 /* Try for 100mbps 4k packets */
85 #define ADVERTISE_RESV 0x1c00 /* Unused... */
86 #define ADVERTISE_RFAULT 0x2000 /* Say we can detect faults */
87 #define ADVERTISE_LPACK 0x4000 /* Ack link partners response */
88 #define ADVERTISE_NPAGE 0x8000 /* Next page bit */
90 #define RX_DESCRIPTOR_NUM 4 //8 // Max Number of Rx Frame Descriptors
91 #define TX_DESCRIPTOR_NUM 2 //4 // Max number of Tx Frame Descriptors
93 #define PACKET_BUFFER_SIZE 1520
95 #define CONFIG_PHY_ADDR 1
98 // Frame Descriptor's Owner bit
99 #define OWNERSHIP_EMAC 0x80000000 // 1 = EMAC
100 //#define OWNERSHIP_CPU 0x7fffffff // 0 = CPU
104 // Rx Frame Descriptor Status
105 #define RXFD_RXGD 0x00100000 // Receiving Good Packet Received
106 #define RXFD_RTSAS 0x00800000 // RX Time Stamp Available
109 // Tx Frame Descriptor's Control bits
110 #define TXFD_TTSEN 0x08 // Tx Time Stamp Enable
111 #define TXFD_INTEN 0x04 // Interrupt Enable
112 #define TXFD_CRCAPP 0x02 // Append CRC
113 #define TXFD_PADEN 0x01 // Padding Enable
115 // Tx Frame Descriptor Status
116 #define TXFD_TXCP 0x00080000 // Transmission Completion
117 #define TXFD_TTSAS 0x08000000 // TX Time Stamp Available
119 // Tx/Rx buffer descriptor structure
120 struct eth_descriptor;
121 struct eth_descriptor {
125 struct eth_descriptor *next;
136 #define ETH_TS_ENABLE() do{EMAC->TSCTL = EMAC_TSCTL_TSEN_Msk;}while(0)
137 #define ETH_TS_START() do{EMAC->TSCTL |= (EMAC_TSCTL_TSMODE_Msk | EMAC_TSCTL_TSIEN_Msk);}while(0)
138 s32_t ETH_settime(u32_t sec, u32_t nsec);
139 s32_t ETH_gettime(u32_t *sec, u32_t *nsec);
140 s32_t ETH_updatetime(u32_t neg, u32_t sec, u32_t nsec);
141 s32_t ETH_adjtimex(int ppm);
142 void ETH_setinc(void);
147 #define NU_DEBUGF(x) { printf x; }
152 void numaker_set_mac_addr(uint8_t *addr);
153 int numaker_eth_init(uint8_t *mac_addr);
154 uint8_t *numaker_eth_get_tx_buf(void);
155 void numaker_eth_trigger_tx(uint16_t length, void *p);
156 int numaker_eth_get_rx_buf(uint16_t *len, uint8_t **buf);
157 void numaker_eth_rx_next(void);
158 void numaker_eth_trigger_rx(void);
159 int numaker_eth_link_ok(void);
160 void numaker_mac_address(uint8_t *mac);
161 void numaker_eth_enable_interrupts(void);
162 void numaker_eth_disable_interrupts(void);
164 #endif /* _M480_ETH_ */