102 #ifndef LANC111_BASE_ADDR
103 #define LANC111_BASE_ADDR 0xC000
106 #ifndef LANC111_SIGNAL_IRQ
107 #define LANC111_SIGNAL_IRQ INT5
110 #ifdef LANC111_RESET_BIT
112 #if (LANC111_RESET_AVRPORT == AVRPORTB)
113 #define LANC111_RESET_PORT PORTB
114 #define LANC111_RESET_DDR DDRB
116 #elif (LANC111_RESET_AVRPORT == AVRPORTD)
117 #define LANC111_RESET_PORT PORTD
118 #define LANC111_RESET_DDR DDRD
120 #elif (LANC111_RESET_AVRPORT == AVRPORTE)
121 #define LANC111_RESET_PORT PORTE
122 #define LANC111_RESET_DDR DDRE
124 #elif (LANC111_RESET_AVRPORT == AVRPORTF)
125 #define LANC111_RESET_PORT PORTF
126 #define LANC111_RESET_DDR DDRF
135 #if (LANC111_SIGNAL_IRQ == INT0)
136 #define LANC111_SIGNAL sig_INTERRUPT0
137 #define LANC111_SIGNAL_MODE() sbi(EICRA, ISC00); sbi(EICRA, ISC01)
139 #elif (LANC111_SIGNAL_IRQ == INT1)
140 #define LANC111_SIGNAL sig_INTERRUPT1
141 #define LANC111_SIGNAL_MODE() sbi(EICRA, ISC10); sbi(EICRA, ISC11)
143 #elif (LANC111_SIGNAL_IRQ == INT2)
144 #define LANC111_SIGNAL sig_INTERRUPT2
145 #define LANC111_SIGNAL_MODE() sbi(EICRA, ISC20); sbi(EICRA, ISC21)
147 #elif (LANC111_SIGNAL_IRQ == INT3)
148 #define LANC111_SIGNAL sig_INTERRUPT3
149 #define LANC111_SIGNAL_MODE() sbi(EICRA, ISC30); sbi(EICRA, ISC31)
151 #elif (LANC111_SIGNAL_IRQ == INT4)
152 #define LANC111_SIGNAL sig_INTERRUPT4
153 #define LANC111_SIGNAL_MODE() sbi(EICRB, ISC40); sbi(EICRB, ISC41)
155 #elif (LANC111_SIGNAL_IRQ == INT6)
156 #define LANC111_SIGNAL sig_INTERRUPT6
157 #define LANC111_SIGNAL_MODE() sbi(EICRB, ISC60); sbi(EICRB, ISC61)
159 #elif (LANC111_SIGNAL_IRQ == INT7)
160 #define LANC111_SIGNAL sig_INTERRUPT7
161 #define LANC111_SIGNAL_MODE() sbi(EICRB, ISC70); sbi(EICRB, ISC71)
164 #define LANC111_SIGNAL sig_INTERRUPT5
165 #define LANC111_SIGNAL_MODE() sbi(EICRB, ISC50); sbi(EICRB, ISC51)
177 #define NIC_BSR (LANC111_BASE_ADDR + 0x0E)
182 #define NIC_TCR (LANC111_BASE_ADDR + 0x00)
184 #define TCR_SWFDUP 0x8000
185 #define TCR_EPH_LOOP 0x2000
186 #define TCR_STP_SQET 0x1000
187 #define TCR_FDUPLX 0x0800
188 #define TCR_MON_CSN 0x0400
189 #define TCR_NOCRC 0x0100
190 #define TCR_PAD_EN 0x0080
191 #define TCR_FORCOL 0x0004
192 #define TCR_LOOP 0x0002
193 #define TCR_TXENA 0x0001
199 #define NIC_EPHSR (LANC111_BASE_ADDR + 0x02)
204 #define NIC_RCR (LANC111_BASE_ADDR + 0x04)
206 #define RCR_SOFT_RST 0x8000
207 #define RCR_FILT_CAR 0x4000
208 #define RCR_ABORT_ENB 0x2000
209 #define RCR_STRIP_CRC 0x0200
210 #define RCR_RXEN 0x0100
211 #define RCR_ALMUL 0x0004
212 #define RCR_PRMS 0x0002
213 #define RCR_RX_ABORT 0x0001
218 #define NIC_ECR (LANC111_BASE_ADDR + 0x06)
223 #define NIC_MIR (LANC111_BASE_ADDR + 0x08)
228 #define NIC_RPCR (LANC111_BASE_ADDR + 0x0A)
230 #define RPCR_SPEED 0x2000
231 #define RPCR_DPLX 0x1000
232 #define RPCR_ANEG 0x0800
233 #define RPCR_LEDA_PAT 0x0000
234 #define RPCR_LEDB_PAT 0x0010
239 #define NIC_CR (LANC111_BASE_ADDR + 0x00)
241 #define CR_EPH_EN 0x8000
246 #define NIC_BAR (LANC111_BASE_ADDR + 0x02)
251 #define NIC_IAR (LANC111_BASE_ADDR + 0x04)
256 #define NIC_GPR (LANC111_BASE_ADDR + 0x0A)
261 #define NIC_CTR (LANC111_BASE_ADDR + 0x0C)
263 #define CTR_RCV_BAD 0x4000
264 #define CTR_AUTO_RELEASE 0x0800
269 #define NIC_MMUCR (LANC111_BASE_ADDR + 0x00)
271 #define MMUCR_BUSY 0x0001
274 #define MMU_ALO (1<<5)
275 #define MMU_RST (2<<5)
276 #define MMU_REM (3<<5)
277 #define MMU_TOP (4<<5)
278 #define MMU_PKT (5<<5)
279 #define MMU_ENQ (6<<5)
280 #define MMU_RTX (7<<5)
287 #define NIC_PNR (LANC111_BASE_ADDR + 0x02)
294 #define NIC_ARR (LANC111_BASE_ADDR + 0x03)
296 #define ARR_FAILED 0x80
301 #define NIC_FIFO (LANC111_BASE_ADDR + 0x04)
306 #define NIC_PTR (LANC111_BASE_ADDR + 0x06)
308 #define PTR_RCV 0x8000
309 #define PTR_AUTO_INCR 0x4000
310 #define PTR_READ 0x2000
311 #define PTR_ETEN 0x1000
312 #define PTR_NOT_EMPTY 0x0800
317 #define NIC_DATA (LANC111_BASE_ADDR + 0x08)
322 #define NIC_IST (LANC111_BASE_ADDR + 0x0C)
327 #define NIC_ACK (LANC111_BASE_ADDR + 0x0C)
332 #define NIC_MSK (LANC111_BASE_ADDR + 0x0D)
335 #define INT_ERCV 0x40
337 #define INT_RX_OVRN 0x10
338 #define INT_ALLOC 0x08
339 #define INT_TX_EMPTY 0x04
346 #define NIC_MT (LANC111_BASE_ADDR + 0x00)
351 #define NIC_MGMT (LANC111_BASE_ADDR + 0x08)
353 #define MGMT_MDOE 0x08
354 #define MGMT_MCLK 0x04
355 #define MGMT_MDI 0x02
356 #define MGMT_MDO 0x01
361 #define NIC_REV (LANC111_BASE_ADDR + 0x0A)
366 #define NIC_ERCV (LANC111_BASE_ADDR + 0x0C)
373 #define PHYCR_RST 0x8000
374 #define PHYCR_LPBK 0x4000
375 #define PHYCR_SPEED 0x2000
376 #define PHYCR_ANEG_EN 0x1000
377 #define PHYCR_PDN 0x0800
378 #define PHYCR_MII_DIS 0x0400
379 #define PHYCR_ANEG_RST 0x0200
380 #define PHYCR_DPLX 0x0100
381 #define PHYCR_COLST 0x0080
389 #define PHYSR_CAP_T4 0x8000
390 #define PHYSR_CAP_TXF 0x4000
391 #define PHYSR_CAP_TXH 0x2000
392 #define PHYSR_CAP_TF 0x1000
393 #define PHYSR_CAP_TH 0x0800
394 #define PHYSR_CAP_SUPR 0x0040
395 #define PHYSR_ANEG_ACK 0x0020
396 #define PHYSR_REM_FLT 0x0010
397 #define PHYSR_CAP_ANEG 0x0008
398 #define PHYSR_LINK 0x0004
399 #define PHYSR_JAB 0x0002
400 #define PHYSR_EXREG 0x0001
416 #define NIC_PHYANAD 4
418 #define PHYANAD_NP 0x8000
419 #define PHYANAD_ACK 0x4000
420 #define PHYANAD_RF 0x2000
421 #define PHYANAD_T4 0x0200
422 #define PHYANAD_TX_FDX 0x0100
423 #define PHYANAD_TX_HDX 0x0080
424 #define PHYANAD_10FDX 0x0040
425 #define PHYANAD_10_HDX 0x0020
426 #define PHYANAD_CSMA 0x0001
431 #define NIC_PHYANRC 5
436 #define NIC_PHYCFR1 16
441 #define NIC_PHYCFR2 17
446 #define NIC_PHYSOR 18
448 #define PHYSOR_INT 0x8000
449 #define PHYSOR_LNKFAIL 0x4000
450 #define PHYSOR_LOSSSYNC 0x2000
451 #define PHYSOR_CWRD 0x1000
452 #define PHYSOR_SSD 0x0800
453 #define PHYSOR_ESD 0x0400
454 #define PHYSOR_RPOL 0x0200
455 #define PHYSOR_JAB 0x0100
456 #define PHYSOR_SPDDET 0x0080
457 #define PHYSOR_DPLXDET 0x0040
462 #define NIC_PHYMSK 19
464 #define PHYMSK_MINT 0x8000
465 #define PHYMSK_MLNKFAIL 0x4000
466 #define PHYMSK_MLOSSSYN 0x2000
467 #define PHYMSK_MCWRD 0x1000
468 #define PHYMSK_MSSD 0x0800
469 #define PHYMSK_MESD 0x0400
470 #define PHYMSK_MRPOL 0x0200
471 #define PHYMSK_MJAB 0x0100
472 #define PHYMSK_MSPDDT 0x0080
473 #define PHYMSK_MDPLDT 0x0040
477 #define MSBV(bit) (1 << ((bit) - 8))
479 #define nic_outlb(addr, val) (*(volatile u8_t *)(addr) = (val))
480 #define nic_outhb(addr, val) (*(volatile u8_t *)((addr) + 1) = (val))
481 #define nic_outwx(addr, val) (*(volatile u16_t *)(addr) = (val))
482 #define nic_outw(addr, val) { \
483 *(volatile u8_t *)(addr) = (u8_t)(val); \
484 *((volatile u8_t *)(addr) + 1) = (u8_t)((val) >> 8); \
487 #define nic_inlb(addr) (*(volatile u8_t *)(addr))
488 #define nic_inhb(addr) (*(volatile u8_t *)((addr) + 1))
489 #define nic_inw(addr) (*(volatile u16_t *)(addr))
491 #define nic_bs(bank) nic_outlb(NIC_BSR, bank)
516 static u8_t NicPhyRegSelect(u8_t reg, u8_t we)
526 for (i = 0; i < 33; i++) {
551 for (i = 0; i < 5; i++) {
557 for (msk = 0x10; msk; msk >>= 1) {
580 static u16_t NicPhyRead(u8_t reg)
587 rs = NicPhyRegSelect(reg, 0);
595 for (i = 0; i < 16; i++) {
616 static void NicPhyWrite(u8_t reg, u16_t val)
622 rs = NicPhyRegSelect(reg, 1);
631 for (msk = 0x8000; msk; msk >>= 1) {
650 static int NicPhyConfig(
void)
664 for (phy_to = 0;; phy_to++) {
709 for (phy_to = 0, phy_sr = 0;; phy_to++) {
714 if ((phy_to & 127) == 0 ) {
742 static INLINE
int NicMmuWait(u16_t tmo)
745 if ((nic_inlb(
NIC_MMUCR) & MMUCR_BUSY) == 0)
757 static int NicReset(
void)
759 #ifdef LANC111_RESET_BIT
760 sbi(LANC111_RESET_DDR, LANC111_RESET_BIT);
761 sbi(LANC111_RESET_PORT, LANC111_RESET_BIT);
763 cbi(LANC111_RESET_PORT, LANC111_RESET_BIT);
793 if (NicMmuWait(1000))
806 static int NicStart(CONST u8_t * mac)
829 for (i = 0; i < 6; i++)
830 nic_outlb(
NIC_IAR + i, mac[i]);
844 static void NicInterrupt(
void *arg)
848 NICINFO *ni = (NICINFO *) ((NUTDEVICE *) arg)->dev_dcb;
868 nic_outlb(
NIC_ACK, INT_TX_EMPTY);
869 imr &= ~INT_TX_EMPTY;
870 NutEventPostFromIrq(&ni->ni_tx_rdy);
882 NutEventPostFromIrq(&ni->ni_tx_rdy);
891 nic_outlb(
NIC_ACK, INT_RX_OVRN);
896 NutEventPostFromIrq(&ni->ni_rx_rdy);
901 NutEventPostFromIrq(&ni->ni_rx_rdy);
906 NutEventPostFromIrq(&maq);
915 static void NicWrite(u8_t * buf, u16_t len)
917 register u16_t l = len - 1;
918 register u8_t ih = (
u16_t) l >> 8;
919 register u8_t il = (
u8_t) l;
934 static void NicRead(u8_t * buf, u16_t len)
936 register u16_t l = len - 1;
937 register u8_t ih = (
u16_t) l >> 8;
938 register u8_t il = (
u8_t) l;
960 static NETBUF *NicGetPacket(
void)
975 nic_outw(
NIC_PTR, PTR_READ | PTR_RCV | PTR_AUTO_INCR);
988 nb = (NETBUF *) 0xFFFF;
991 else if (fbc < 66 || fbc > 1524) {
992 nb = (NETBUF *) 0xFFFF;
1029 static int NicPutPacket(NETBUF * nb)
1042 if ((sz = nb->nb_nw.sz + nb->nb_tp.sz + nb->nb_ap.sz) > ETHERMTU)
1052 if (NicMmuWait(100))
1068 if (NutEventWait(&maq, 125)) {
1072 if (NicMmuWait(100) || (nic_inlb(
NIC_IST) & INT_ALLOC) == 0) {
1073 if (NutEventWait(&maq, 125)) {
1097 NicWrite(nb->nb_dl.vp, nb->nb_dl.sz);
1098 NicWrite(nb->nb_nw.vp, nb->nb_nw.sz);
1099 NicWrite(nb->nb_tp.vp, nb->nb_tp.sz);
1100 NicWrite(nb->nb_ap.vp, nb->nb_ap.sz);
1109 if (NicMmuWait(100))
1168 LANC111_SIGNAL_MODE();
1169 sbi(EIMSK, LANC111_SIGNAL_IRQ);
1197 nic_outlb(
NIC_MSK, imsk | INT_RCV | INT_ERCV);
1214 int LancOutput(NUTDEVICE * dev, NETBUF * nb)
1216 static u_long mx_wait = 5000;
1224 if (NutEventWait(&mutex, mx_wait) == 0) {
1225 ni = (NICINFO *) dev->dev_dcb;
1227 if (NicPutPacket(nb) == 0) {
1228 ni->ni_tx_packets++;
1234 NutEventPost(&mutex);
1264 int LancInit(NUTDEVICE * dev)
1267 cbi(EIMSK, LANC111_SIGNAL_IRQ);
1268 memset(dev->dev_dcb, 0,
sizeof(NICINFO));
1271 if (NutRegisterIrqHandler(&LANC111_SIGNAL, NicInterrupt, dev))
1277 NutThreadCreate(
"rxi5", NicRxLanc, dev, 640);
1291 static NICINFO dcb_eth0;
1298 static IFNET ifn_eth0 = {
1321 NUTDEVICE devSmsc111 = {
1323 {
'e',
't',
'h',
'0', 0, 0, 0, 0, 0},
1347 cbi(EIMSK, LANC111_SIGNAL_IRQ);