| 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 |
#include "lwip/opt.h" |
| 105 |
#include "lwip/def.h" |
| 106 |
#include "lwip/err.h" |
| 107 |
#include "lwip/mem.h" |
| 108 |
#include "lwip/pbuf.h" |
| 109 |
#include "lwip/stats.h" |
| 110 |
#include "lwip/sys.h" |
| 111 |
#include "netif/etharp.h" |
| 112 |
|
| 113 |
#if 0 |
| 114 |
|
| 115 |
# define LWIP_DBG_LEVEL 1 |
| 116 |
# include "leds.h" |
| 117 |
# include "display.h" |
| 118 |
|
| 119 |
# define LED_NEED_SERVICE LED_FP1 |
| 120 |
#else |
| 121 |
|
| 122 |
# define leds_on() |
| 123 |
# define leds_off() |
| 124 |
#endif |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
#define ETH_MIN_FRAME_LEN 60 |
| 131 |
|
| 132 |
#include "cs8900if.h" |
| 133 |
#include "lwip/snmp.h" |
| 134 |
|
| 135 |
|
| 136 |
#define IFNAME0 'e' |
| 137 |
#define IFNAME1 'n' |
| 138 |
|
| 139 |
|
| 140 |
static err_t cs8900_output(struct netif *netif, struct pbuf *p); |
| 141 |
static struct pbuf *cs8900_input(struct netif *netif); |
| 142 |
static void cs8900_service(struct netif *netif); |
| 143 |
static u32_t cs8900_chksum(void *dataptr, s16_t len); |
| 144 |
static void cs8900_reset(struct netif *netif); |
| 145 |
|
| 146 |
|
| 147 |
#define MEM_BASE 0x00E000 |
| 148 |
#define IO_BASE 0x800 |
| 149 |
#define INT_NR 0x00 |
| 150 |
|
| 151 |
#define RXTXREG *((volatile u16_t *)(MEM_BASE + IO_BASE)) |
| 152 |
#define TXCMD *((volatile u16_t *)(MEM_BASE + IO_BASE + 0x04)) |
| 153 |
#define TXLENGTH *((volatile u16_t *)(MEM_BASE + IO_BASE + 0x06)) |
| 154 |
#define ISQ *((volatile u16_t *)(MEM_BASE + IO_BASE + 0x08)) |
| 155 |
#define PACKETPP *((volatile u16_t *)(MEM_BASE + IO_BASE + 0x0A)) |
| 156 |
#define PPDATA *((volatile u16_t *)(MEM_BASE + IO_BASE + 0x0C)) |
| 157 |
|
| 158 |
|
| 159 |
#define CS_PP_EISA 0x0000 // EISA Registration number of CS8900 |
| 160 |
#define CS_PP_PRODID 0x0002 // Product ID Number |
| 161 |
#define CS_PP_IOBASE 0x0020 // I/O Base Address |
| 162 |
#define CS_PP_INTNUM 0x0022 // Interrupt number (0,1,2, or 3) |
| 163 |
#define CS_PP_RXCFG 0x0102 // Receiver Configuration |
| 164 |
#define CS_PP_RXCTL 0x0104 // Receiver Control |
| 165 |
#define CS_PP_TXCFG 0x0106 // Transmit Configuration |
| 166 |
#define CS_PP_BUFCFG 0x010A // Buffer Configuration |
| 167 |
#define CS_PP_LINECTL 0x0112 // Line Control Register offset |
| 168 |
#define CS_PP_SELFCTL 0x0114 // Self Control |
| 169 |
#define CS_PP_BUSCTL 0x0116 // Bus Control |
| 170 |
#define CS_PP_TESTCTL 0x0118 // Test Control |
| 171 |
#define CS_PP_ISQ 0x0120 // Interrupt status queue |
| 172 |
#define CS_PP_RXEVENT 0x0124 // Receiver Event |
| 173 |
#define CS_PP_TX_EVENT 0x0128 // Transmitter Event |
| 174 |
#define CS_PP_BUF_EVENT 0x012C // Buffer Event |
| 175 |
#define CS_PP_RXMISS 0x0130 // Receiver Miss Counter |
| 176 |
#define CS_PP_TXCOL 0x0132 // Transmit Collision Counter |
| 177 |
#define CS_PP_LINESTATUS 0x0134 // Line Status |
| 178 |
#define CS_PP_SELFTEST 0x0136 // Self Status |
| 179 |
#define CS_PP_BUSSTATUS 0x0138 // Bus Status |
| 180 |
#define CS_PP_TXCMD 0x0144 // Transmit Command Request |
| 181 |
#define CS_PP_TXLEN 0x0146 // Transmit Length |
| 182 |
#define CS_PP_IA1 0x0158 // Individual Address (IA) |
| 183 |
#define CS_PP_IA2 0x015A // Individual Address (IA) |
| 184 |
#define CS_PP_IA3 0x015C // Individual Address (IA) |
| 185 |
|
| 186 |
#define CS_PP_RXSTATUS 0x0400 // Receive Status |
| 187 |
#define CS_PP_RXLEN 0x0402 // Receive Length |
| 188 |
#define CS_PP_RXFRAME 0x0404 // Receive Frame Location |
| 189 |
#define CS_PP_TXFRAME 0x0A00 // Transmit Frame Location |
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
#if 0 |
| 194 |
|
| 195 |
_interrupt(0x18) void cs8900_interrupt(void) |
| 196 |
{ |
| 197 |
struct cs8900if *cs8900if = cs8900if_netif->state; |
| 198 |
|
| 199 |
if (cs8900if != NULL) |
| 200 |
{ |
| 201 |
|
| 202 |
cs8900if->needs_service = 1; |
| 203 |
#if (CS8900_STATS > 0) |
| 204 |
cs8900if->interrupts++; |
| 205 |
#endif |
| 206 |
} |
| 207 |
} |
| 208 |
#endif |
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
static void cs8900_reset(struct netif *netif) |
| 217 |
{ |
| 218 |
(void)netif; |
| 219 |
|
| 220 |
PACKETPP = CS_PP_SELFCTL; |
| 221 |
PPDATA = 0x0055U; |
| 222 |
} |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
static err_t cs8900_init(struct netif *netif) |
| 229 |
{ |
| 230 |
#ifdef LED_NEED_SERVICE |
| 231 |
leds_off(LED_NEED_SERVICE); |
| 232 |
#endif |
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
while ((PPDATA & 0x0040U) != 0); |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
PACKETPP = CS_PP_SELFTEST; |
| 243 |
|
| 244 |
while ((PPDATA & 0x0080U) == 0); |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
while ((PPDATA & 0x0100U) == 0x0100); |
| 249 |
|
| 250 |
|
| 251 |
#if 1 |
| 252 |
{ |
| 253 |
u16_t dummy; |
| 254 |
|
| 255 |
dummy = *(u16_t *)(MEM_BASE + IO_BASE + 0x0D); |
| 256 |
|
| 257 |
dummy = *(u16_t *)(MEM_BASE + IO_BASE + 0x0D); |
| 258 |
} |
| 259 |
#endif |
| 260 |
|
| 261 |
|
| 262 |
PACKETPP = CS_PP_IA1; |
| 263 |
PPDATA = (u16_t)(netif->hwaddr[0]) | (u16_t)(netif->hwaddr[1] << 8U); |
| 264 |
PACKETPP = CS_PP_IA2; |
| 265 |
PPDATA = (u16_t)(netif->hwaddr[2]) | (u16_t)(netif->hwaddr[3] << 8U); |
| 266 |
PACKETPP = CS_PP_IA3; |
| 267 |
PPDATA = (u16_t)(netif->hwaddr[4]) | (u16_t)(netif->hwaddr[5] << 8U); |
| 268 |
|
| 269 |
|
| 270 |
PACKETPP = CS_PP_RXCTL; |
| 271 |
PPDATA = (0x0005U | 0x0800U | 0x0400U | 0x0100U); |
| 272 |
|
| 273 |
|
| 274 |
PACKETPP = CS_PP_RXCFG; |
| 275 |
PPDATA = (0x0003U | 0x0100U); |
| 276 |
|
| 277 |
|
| 278 |
PACKETPP = CS_PP_TXCFG; |
| 279 |
PPDATA = (0x0007U | 0); |
| 280 |
|
| 281 |
|
| 282 |
PACKETPP = CS_PP_INTNUM; |
| 283 |
PPDATA = (0x0000U); |
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
PACKETPP = CS_PP_BUFCFG; |
| 289 |
PPDATA = (0x000bU | |
| 290 |
#if (CS8900_STATS > 0) |
| 291 |
(0x2000U | 0x1000U) | |
| 292 |
#endif |
| 293 |
#if (CS8900_STATS > 1) |
| 294 |
(0x0400U) | |
| 295 |
#endif |
| 296 |
0x0000); |
| 297 |
|
| 298 |
|
| 299 |
PACKETPP = CS_PP_BUSCTL; |
| 300 |
PPDATA = (0x0017U | 0x8000U); |
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
PACKETPP = CS_PP_LINECTL; |
| 306 |
PPDATA = (0x0013U | 0x0080U | 0x0040U); |
| 307 |
|
| 308 |
return ERR_OK; |
| 309 |
} |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
static err_t cs8900_output(struct netif *netif, struct pbuf *p) |
| 320 |
{ |
| 321 |
s16_t tries = 0; |
| 322 |
err_t result; |
| 323 |
|
| 324 |
|
| 325 |
PACKETPP = CS_PP_LINESTATUS; |
| 326 |
if ((PPDATA & 0x0080U) == 0) return ERR_CONN; |
| 327 |
|
| 328 |
result = ERR_OK; |
| 329 |
|
| 330 |
|
| 331 |
#if ETH_PAD_SIZE |
| 332 |
pbuf_header(p, -ETH_PAD_SIZE); |
| 333 |
#endif |
| 334 |
|
| 335 |
|
| 336 |
TXCMD = 0x00C9U; |
| 337 |
|
| 338 |
TXLENGTH = (p->tot_len < ETH_MIN_FRAME_LEN? ETH_MIN_FRAME_LEN: p->tot_len); |
| 339 |
|
| 340 |
PACKETPP = CS_PP_BUSSTATUS; |
| 341 |
|
| 342 |
while (((PPDATA & 0x0100U) == 0) && (tries++ < 100)) |
| 343 |
{ |
| 344 |
|
| 345 |
PACKETPP = CS_PP_RXCFG; |
| 346 |
PPDATA = (0x0003U | 0x0040U | 0x0100U); |
| 347 |
PACKETPP = CS_PP_BUSSTATUS; |
| 348 |
|
| 349 |
} |
| 350 |
|
| 351 |
if ((PPDATA & 0x0100U) != 0) |
| 352 |
{ |
| 353 |
u16_t sent_bytes = 0; |
| 354 |
|
| 355 |
|
| 356 |
struct pbuf *q; |
| 357 |
u16_t pbuf_index = 0; |
| 358 |
u8_t word_index = 0; |
| 359 |
u8_t word[2]; |
| 360 |
q = p; |
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
while (q) |
| 365 |
{ |
| 366 |
if (pbuf_index < q->len) |
| 367 |
{ |
| 368 |
word[word_index++] = ((u8_t*)q->payload)[pbuf_index++]; |
| 369 |
if (word_index == 2) |
| 370 |
{ |
| 371 |
RXTXREG = (word[1] << 8) | word[0]; |
| 372 |
word_index = 0; |
| 373 |
sent_bytes += 2; |
| 374 |
} |
| 375 |
} |
| 376 |
else |
| 377 |
{ |
| 378 |
q = q->next; |
| 379 |
pbuf_index = 0; |
| 380 |
} |
| 381 |
} |
| 382 |
|
| 383 |
if (word_index == 1) |
| 384 |
{ |
| 385 |
RXTXREG = word[0]; |
| 386 |
sent_bytes += 2; |
| 387 |
} |
| 388 |
|
| 389 |
|
| 390 |
while (sent_bytes < ETH_MIN_FRAME_LEN) |
| 391 |
{ |
| 392 |
RXTXREG = 0x0000; |
| 393 |
sent_bytes += 2; |
| 394 |
} |
| 395 |
|
| 396 |
#if (CS8900_STATS > 0) |
| 397 |
((struct cs8900if *)netif->state)->sentpackets++; |
| 398 |
((struct cs8900if *)netif->state)->sentbytes += sent_bytes; |
| 399 |
#endif |
| 400 |
snmp_add_ifoutoctets(netif,sent_bytes); |
| 401 |
} |
| 402 |
else |
| 403 |
{ |
| 404 |
|
| 405 |
snmp_inc_ifoutdiscards(netif); |
| 406 |
|
| 407 |
result = ERR_IF; |
| 408 |
} |
| 409 |
#if ETH_PAD_SIZE |
| 410 |
|
| 411 |
pbuf_header(p, ETH_PAD_SIZE); |
| 412 |
#endif |
| 413 |
return result; |
| 414 |
} |
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
static struct pbuf *cs8900_input(struct netif *netif) |
| 429 |
{ |
| 430 |
volatile u16_t* rxtx_reg; |
| 431 |
volatile u32_t rxtx_num = (MEM_BASE + IO_BASE); |
| 432 |
u16_t* ptr = NULL; |
| 433 |
struct pbuf *p = NULL, *q = NULL; |
| 434 |
u16_t len = 0; |
| 435 |
u16_t event_type; |
| 436 |
u16_t i; |
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
rxtx_reg = ((volatile u16_t *)(rxtx_num)); |
| 441 |
|
| 442 |
event_type = *rxtx_reg; |
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
if ((event_type & 0x0100U) && (event_type & 0x0c00U)) |
| 447 |
{ |
| 448 |
#if LWIP_SNMP > 0 |
| 449 |
|
| 450 |
if (event_type & 0x0400U) |
| 451 |
{ |
| 452 |
snmp_inc_ifinucastpkts(netif); |
| 453 |
} |
| 454 |
else |
| 455 |
{ |
| 456 |
snmp_inc_ifinnucastpkts(netif); |
| 457 |
} |
| 458 |
#endif |
| 459 |
event_type = 0; |
| 460 |
|
| 461 |
len = *rxtx_reg; |
| 462 |
LWIP_DEBUGF(NETIF_DEBUG, ("cs8900_input: packet len %"U16_F"\n", len)); |
| 463 |
snmp_add_ifinoctets(netif,len); |
| 464 |
|
| 465 |
if (len > 0) |
| 466 |
{ |
| 467 |
|
| 468 |
p = pbuf_alloc(PBUF_RAW, len + ETH_PAD_SIZE, PBUF_POOL); |
| 469 |
if (p != NULL) |
| 470 |
{ |
| 471 |
#if ETH_PAD_SIZE |
| 472 |
|
| 473 |
pbuf_header(p, -ETH_PAD_SIZE); |
| 474 |
#endif |
| 475 |
for (q = p; q != 0; q = q->next) |
| 476 |
{ |
| 477 |
LWIP_DEBUGF(NETIF_DEBUG, ("cs8900_input: pbuf @%p tot_len %"U16_F" len %"U16_F"\n", q, q->tot_len, q->len)); |
| 478 |
|
| 479 |
|
| 480 |
ptr = q->payload; |
| 481 |
i = q->len / 8; |
| 482 |
while(i > 0) |
| 483 |
{ |
| 484 |
*ptr = *rxtx_reg; |
| 485 |
ptr++; |
| 486 |
*ptr = *rxtx_reg; |
| 487 |
ptr++; |
| 488 |
*ptr = *rxtx_reg; |
| 489 |
ptr++; |
| 490 |
*ptr = *rxtx_reg; |
| 491 |
ptr++; |
| 492 |
i--; |
| 493 |
} |
| 494 |
|
| 495 |
i = ((q->len % 8) + 1) / 2; |
| 496 |
while(i > 0) |
| 497 |
{ |
| 498 |
*ptr = *rxtx_reg; |
| 499 |
ptr++; |
| 500 |
i--; |
| 501 |
} |
| 502 |
} |
| 503 |
#if ETH_PAD_SIZE |
| 504 |
|
| 505 |
pbuf_header(p, ETH_PAD_SIZE); |
| 506 |
#endif |
| 507 |
} |
| 508 |
|
| 509 |
else |
| 510 |
{ |
| 511 |
|
| 512 |
|
| 513 |
PACKETPP = CS_PP_RXCFG; |
| 514 |
PPDATA = (0x0003U | 0x0100U | 0x0040U); |
| 515 |
#if (CS8900_STATS > 0) |
| 516 |
((struct cs8900if *)netif->state)->dropped++; |
| 517 |
#endif |
| 518 |
snmp_inc_ifindiscards(netif); |
| 519 |
len = 0; |
| 520 |
} |
| 521 |
} |
| 522 |
|
| 523 |
else |
| 524 |
{ |
| 525 |
} |
| 526 |
} |
| 527 |
return p; |
| 528 |
} |
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
static void cs8900_service(struct netif *netif) |
| 545 |
{ |
| 546 |
u8_t events2service = CS8900_EVTS2SRV; |
| 547 |
#if (CS8900_STATS > 0) |
| 548 |
u16_t miss_count = 0, coll_count = 0; |
| 549 |
#endif |
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
static u16_t irq_status = 0x0000U; |
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
((struct cs8900if *)netif->state)->needs_service = 0; |
| 566 |
#ifdef LED_NEED_SERVICE |
| 567 |
leds_off(LED_NEED_SERVICE); |
| 568 |
#endif |
| 569 |
|
| 570 |
if (irq_status == 0x0000U) |
| 571 |
{ |
| 572 |
|
| 573 |
irq_status = ISQ; |
| 574 |
} |
| 575 |
|
| 576 |
while ((irq_status != 0x0000U) && (events2service-- > 0)) |
| 577 |
{ |
| 578 |
|
| 579 |
if ((irq_status & 0x003fU) == 0x0004U) |
| 580 |
{ |
| 581 |
|
| 582 |
|
| 583 |
if ((irq_status & 0x0100U) && (irq_status & 0x0c00U)) |
| 584 |
{ |
| 585 |
|
| 586 |
cs8900if_input(netif); |
| 587 |
} |
| 588 |
else |
| 589 |
{ |
| 590 |
|
| 591 |
PACKETPP = CS_PP_RXCFG; |
| 592 |
PPDATA |= 0x0040U; |
| 593 |
#if (CS8900_STATS > 0) |
| 594 |
((struct cs8900if *)netif->state)->dropped++; |
| 595 |
#endif |
| 596 |
} |
| 597 |
} |
| 598 |
#if (CS8900_STATS > 0) |
| 599 |
else if ((irq_status & 0x003fU) == 0x0010U) |
| 600 |
{ |
| 601 |
miss_count += (irq_status >> 6); |
| 602 |
} |
| 603 |
else if ((irq_status & 0x003fU) == 0x0012U) |
| 604 |
{ |
| 605 |
coll_count += (irq_status >> 6); |
| 606 |
} |
| 607 |
#endif |
| 608 |
|
| 609 |
irq_status = ISQ; |
| 610 |
} |
| 611 |
|
| 612 |
|
| 613 |
if (irq_status != 0x0000U) |
| 614 |
{ |
| 615 |
|
| 616 |
((struct cs8900if *)netif->state)->needs_service = 1; |
| 617 |
#ifdef LED_NEED_SERVICE |
| 618 |
leds_on(LED_NEED_SERVICE); |
| 619 |
#endif |
| 620 |
} |
| 621 |
#if (CS8900_STATS > 1) |
| 622 |
|
| 623 |
PACKETPP = CS_PP_RXMISS; |
| 624 |
miss_count += (PPDATA >> 6); |
| 625 |
|
| 626 |
PACKETPP = CS_PP_TXCOL; |
| 627 |
coll_count += (PPDATA >> 6); |
| 628 |
#endif |
| 629 |
#if (CS8900_STATS > 0) |
| 630 |
|
| 631 |
((struct cs8900if *)netif->state)->missed += miss_count; |
| 632 |
if (miss_count > 0) LWIP_DEBUGF(NETIF_DEBUG | 1, ("cs8900_input: %"U16_F" missed packets due to rx buffer overrun\n", miss_count)); |
| 633 |
|
| 634 |
((struct cs8900if *)netif->state)->collisions += coll_count; |
| 635 |
if (coll_count > 0) LWIP_DEBUGF(NETIF_DEBUG | 1, ("cs8900_input: %"U16_F" packet collisions\n", coll_count)); |
| 636 |
#endif |
| 637 |
} |
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
void cs8900if_service(struct netif *netif) |
| 649 |
{ |
| 650 |
|
| 651 |
if ((((struct cs8900if *)netif->state)->needs_service) || |
| 652 |
(((struct cs8900if *)netif->state)->use_polling)) |
| 653 |
{ |
| 654 |
cs8900_service(netif); |
| 655 |
} |
| 656 |
} |
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
void cs8900if_input(struct netif *netif) |
| 673 |
{ |
| 674 |
struct eth_hdr *ethhdr = NULL; |
| 675 |
struct pbuf *p = NULL; |
| 676 |
|
| 677 |
|
| 678 |
p = cs8900_input(netif); |
| 679 |
|
| 680 |
if (p == NULL) { |
| 681 |
|
| 682 |
return; |
| 683 |
} |
| 684 |
|
| 685 |
ethhdr = p->payload; |
| 686 |
|
| 687 |
switch (htons(ethhdr->type)) { |
| 688 |
|
| 689 |
case ETHTYPE_IP: |
| 690 |
#if 0 |
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
etharp_ip_input(netif, p); |
| 695 |
#endif |
| 696 |
|
| 697 |
pbuf_header(p, -(s16_t)sizeof(struct eth_hdr)); |
| 698 |
LWIP_DEBUGF(NETIF_DEBUG, ("cs8900_input: passing packet up to IP\n")); |
| 699 |
|
| 700 |
netif->input(p, netif); |
| 701 |
break; |
| 702 |
|
| 703 |
case ETHTYPE_ARP: |
| 704 |
|
| 705 |
etharp_arp_input(netif, (struct eth_addr *)&netif->hwaddr, p); |
| 706 |
break; |
| 707 |
|
| 708 |
default: |
| 709 |
|
| 710 |
pbuf_free(p); |
| 711 |
p = NULL; |
| 712 |
break; |
| 713 |
} |
| 714 |
} |
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
void cs8900if_reset(struct netif *netif) |
| 725 |
{ |
| 726 |
|
| 727 |
cs8900_reset(netif); |
| 728 |
} |
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
err_t cs8900if_init(struct netif *netif) |
| 738 |
{ |
| 739 |
struct cs8900if *cs8900if; |
| 740 |
|
| 741 |
cs8900if = mem_malloc(sizeof(struct cs8900if)); |
| 742 |
if (cs8900if == NULL) |
| 743 |
{ |
| 744 |
LWIP_DEBUGF(NETIF_DEBUG, ("cs8900_input: out of memory for cs8900if\n")); |
| 745 |
return ERR_MEM; |
| 746 |
} |
| 747 |
|
| 748 |
#if LWIP_SNMP |
| 749 |
|
| 750 |
netif->link_type = 6; |
| 751 |
netif->link_speed = 10000000; |
| 752 |
netif->ts = 0; |
| 753 |
netif->ifinoctets = 0; |
| 754 |
netif->ifinucastpkts = 0; |
| 755 |
netif->ifinnucastpkts = 0; |
| 756 |
netif->ifindiscards = 0; |
| 757 |
netif->ifoutoctets = 0; |
| 758 |
netif->ifoutucastpkts = 0; |
| 759 |
netif->ifoutnucastpkts = 0; |
| 760 |
netif->ifoutdiscards = 0; |
| 761 |
#endif |
| 762 |
|
| 763 |
|
| 764 |
netif->name[0] = IFNAME0; |
| 765 |
netif->name[1] = IFNAME1; |
| 766 |
|
| 767 |
|
| 768 |
netif->output = etharp_output; |
| 769 |
netif->linkoutput = cs8900_output; |
| 770 |
|
| 771 |
|
| 772 |
netif->state = cs8900if; |
| 773 |
|
| 774 |
|
| 775 |
netif->mtu = 1500; |
| 776 |
|
| 777 |
|
| 778 |
netif->flags = NETIF_FLAG_BROADCAST; |
| 779 |
|
| 780 |
|
| 781 |
netif->hwaddr_len = 6; |
| 782 |
|
| 783 |
|
| 784 |
cs8900if->needs_service = 0; |
| 785 |
|
| 786 |
cs8900if->use_polling = 0; |
| 787 |
|
| 788 |
#if (CS8900_STATS > 0) |
| 789 |
|
| 790 |
cs8900if->interrupts = 0; |
| 791 |
cs8900if->missed = 0; |
| 792 |
cs8900if->dropped = 0; |
| 793 |
cs8900if->collisions = 0; |
| 794 |
cs8900if->sentpackets = 0; |
| 795 |
cs8900if->sentbytes = 0; |
| 796 |
#endif |
| 797 |
|
| 798 |
|
| 799 |
return cs8900_init(netif); |
| 800 |
} |
| 801 |
|
| 802 |
#if 1 |
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
void cs8900_send_debug(u8_t *p, u16_t len) |
| 813 |
{ |
| 814 |
s16_t tries = 0, i; |
| 815 |
|
| 816 |
|
| 817 |
extern struct netif *ethif; |
| 818 |
|
| 819 |
|
| 820 |
PACKETPP = CS_PP_LINESTATUS; |
| 821 |
if ((PPDATA & 0x0080U) == 0) return; |
| 822 |
|
| 823 |
|
| 824 |
TXCMD = 0x00C9U; |
| 825 |
|
| 826 |
TXLENGTH = (14 + 20 + 8 + len < 60) ? 60 : (14 + 20 + 8 + len); |
| 827 |
|
| 828 |
PACKETPP = CS_PP_BUSSTATUS; |
| 829 |
|
| 830 |
while (((PPDATA & 0x0100U) == 0) && (tries++ < 100)) |
| 831 |
{ |
| 832 |
|
| 833 |
PACKETPP = CS_PP_RXCFG; |
| 834 |
PPDATA = (0x0003U | 0x0040U | 0x0100U); |
| 835 |
PACKETPP = CS_PP_BUSSTATUS; |
| 836 |
|
| 837 |
} |
| 838 |
|
| 839 |
if ((PPDATA & 0x0100U) != 0) |
| 840 |
{ |
| 841 |
u16_t data, checksum = 0; |
| 842 |
u32_t udp_checksum = 0; |
| 843 |
|
| 844 |
|
| 845 |
RXTXREG = 0xa000U; |
| 846 |
RXTXREG = 0xc524U; |
| 847 |
RXTXREG = 0x6d72U; |
| 848 |
|
| 849 |
RXTXREG = htons(((u16_t)ethif->hwaddr[0] << 8U) | (u16_t)ethif->hwaddr[1]); |
| 850 |
RXTXREG = htons(((u16_t)ethif->hwaddr[2] << 8U) | (u16_t)ethif->hwaddr[3]); |
| 851 |
RXTXREG = htons(((u16_t)ethif->hwaddr[4] << 8U) | (u16_t)ethif->hwaddr[5]); |
| 852 |
|
| 853 |
RXTXREG = htons(0x0800); |
| 854 |
|
| 855 |
RXTXREG = htons(data = ((0x40 | 0x05) << 8) | 0x00); |
| 856 |
checksum += data; |
| 857 |
|
| 858 |
RXTXREG = htons(data = 20 + 8 + len); |
| 859 |
checksum += data; |
| 860 |
|
| 861 |
RXTXREG = htons(data = 0); |
| 862 |
checksum += data; |
| 863 |
|
| 864 |
RXTXREG = htons(data = 0); |
| 865 |
checksum += data; |
| 866 |
|
| 867 |
RXTXREG = htons(data = (255U << 8) | 17U); |
| 868 |
checksum += data; |
| 869 |
|
| 870 |
checksum += (htonl(ethif->ip_addr.addr) & 0xffff0000U) >> 16; |
| 871 |
checksum += (htonl(ethif->ip_addr.addr) & 0x0000ffffU); |
| 872 |
checksum += 0xc0a8U; |
| 873 |
checksum += 0x0001U; |
| 874 |
checksum += 6; |
| 875 |
|
| 876 |
|
| 877 |
RXTXREG = htons(~checksum); |
| 878 |
|
| 879 |
|
| 880 |
RXTXREG = htons((htonl(ethif->ip_addr.addr) & 0xffff0000U) >> 16); |
| 881 |
|
| 882 |
RXTXREG = htons( htonl(ethif->ip_addr.addr) & 0x0000ffffU); |
| 883 |
|
| 884 |
RXTXREG = htons(0xc0a8U); |
| 885 |
|
| 886 |
RXTXREG = htons(0x0001U); |
| 887 |
|
| 888 |
RXTXREG = htons(3000U); |
| 889 |
|
| 890 |
RXTXREG = htons(3000U); |
| 891 |
|
| 892 |
RXTXREG = htons(len); |
| 893 |
|
| 894 |
|
| 895 |
udp_checksum = (htonl(ethif->ip_addr.addr) & 0xffff0000U) >> 16; |
| 896 |
udp_checksum += (htonl(ethif->ip_addr.addr) & 0x0000ffffU); |
| 897 |
udp_checksum += 0xc0a8U; |
| 898 |
udp_checksum += 0x0001U; |
| 899 |
udp_checksum += 0x0011U; |
| 900 |
udp_checksum += (8 + len); |
| 901 |
udp_checksum += 3000; |
| 902 |
udp_checksum += 3000; |
| 903 |
udp_checksum += (8 + len); |
| 904 |
udp_checksum += cs8900_chksum(p, len); |
| 905 |
while (udp_checksum >> 16) { |
| 906 |
udp_checksum = (udp_checksum & 0xffffUL) + (udp_checksum >> 16); |
| 907 |
} |
| 908 |
|
| 909 |
RXTXREG = htons(~(udp_checksum & 0xffff)); |
| 910 |
for (i = 0; i < len; i += 2) |
| 911 |
{ |
| 912 |
RXTXREG = htons((p[i] << 8) | p[i + 1]); |
| 913 |
} |
| 914 |
|
| 915 |
while (i < 60) |
| 916 |
{ |
| 917 |
RXTXREG = 0; |
| 918 |
i += 2; |
| 919 |
} |
| 920 |
} |
| 921 |
} |
| 922 |
|
| 923 |
static u32_t cs8900_chksum(void *dataptr, s16_t len) |
| 924 |
{ |
| 925 |
u32_t acc = 0; |
| 926 |
u16_t *ptr = (u16_t *)dataptr; |
| 927 |
|
| 928 |
for(acc = 0; len > 1; len -= 2) { |
| 929 |
acc += *ptr; |
| 930 |
ptr++; |
| 931 |
} |
| 932 |
|
| 933 |
if (len == 1) { |
| 934 |
acc += htons((u16_t)((*(u8_t *)ptr) & 0xffU) << 8); |
| 935 |
} |
| 936 |
return acc; |
| 937 |
} |
| 938 |
|
| 939 |
#endif |