142 |
static err_t cs8900_output(struct netif *netif, struct pbuf *p); |
static err_t cs8900_output(struct netif *netif, struct pbuf *p); |
143 |
static struct pbuf *cs8900_input(struct netif *netif); |
static struct pbuf *cs8900_input(struct netif *netif); |
144 |
static void cs8900_service(struct netif *netif); |
static void cs8900_service(struct netif *netif); |
145 |
static u32_t cs8900_chksum(void *dataptr, int len); |
static u32_t cs8900_chksum(void *dataptr, s16_t len); |
146 |
static void cs8900_reset(struct netif *netif); |
static void cs8900_reset(struct netif *netif); |
147 |
|
|
148 |
// Define these to match your hardware setup |
// Define these to match your hardware setup |
320 |
*/ |
*/ |
321 |
static err_t cs8900_output(struct netif *netif, struct pbuf *p) |
static err_t cs8900_output(struct netif *netif, struct pbuf *p) |
322 |
{ |
{ |
323 |
int tries = 0; |
s16_t tries = 0; |
324 |
err_t result; |
err_t result; |
325 |
|
|
326 |
// exit if link has failed |
// exit if link has failed |
352 |
// ready to transmit? |
// ready to transmit? |
353 |
if ((PPDATA & 0x0100U/*Rdy4TxNOW*/) != 0) |
if ((PPDATA & 0x0100U/*Rdy4TxNOW*/) != 0) |
354 |
{ |
{ |
355 |
unsigned long sent_bytes = 0; |
u32_t sent_bytes = 0; |
356 |
/* q traverses through linked list of pbuf's |
/* q traverses through linked list of pbuf's |
357 |
* This list MUST consist of a single packet ONLY */ |
* This list MUST consist of a single packet ONLY */ |
358 |
struct pbuf *q; |
struct pbuf *q; |
440 |
event_type = 0; |
event_type = 0; |
441 |
// read RxLength |
// read RxLength |
442 |
len = RXTXREG; |
len = RXTXREG; |
443 |
LWIP_DEBUGF(NETIF_DEBUG, ("cs8900_input: packet len %u\n", len)); |
LWIP_DEBUGF(NETIF_DEBUG, ("cs8900_input: packet len %"U16_F"\n", len)); |
444 |
snmp_add_ifinoctets(len); |
snmp_add_ifinoctets(len); |
445 |
// positive length? |
// positive length? |
446 |
if (len > 0) |
if (len > 0) |
456 |
|
|
457 |
for (q = p; q != 0; q = q->next) |
for (q = p; q != 0; q = q->next) |
458 |
{ |
{ |
459 |
LWIP_DEBUGF(NETIF_DEBUG, ("cs8900_input: pbuf @%p tot_len %u len %u\n", q, q->tot_len, q->len)); |
LWIP_DEBUGF(NETIF_DEBUG, ("cs8900_input: pbuf @%p tot_len %"U16_F" len %"U16_F"\n", q, q->tot_len, q->len)); |
460 |
ptr = q->payload; |
ptr = q->payload; |
461 |
// TODO: CHECK: what if q->len is odd? we don't use the last byte? |
// TODO: CHECK: what if q->len is odd? we don't use the last byte? |
462 |
for (i = 0; i < (q->len + 1) / 2; i++) |
for (i = 0; i < (q->len + 1) / 2; i++) |
509 |
static void cs8900_service(struct netif *netif) |
static void cs8900_service(struct netif *netif) |
510 |
{ |
{ |
511 |
/* amount of ISQ's to handle (> 0) in one cs8900_service() call */ |
/* amount of ISQ's to handle (> 0) in one cs8900_service() call */ |
512 |
unsigned char events2service = 1; |
u8_t events2service = 1; |
513 |
#if (CS8900_STATS > 0) |
#if (CS8900_STATS > 0) |
514 |
unsigned int miss_count = 0, coll_count = 0; |
u16_t miss_count = 0, coll_count = 0; |
515 |
#endif |
#endif |
516 |
// NOTES: |
// NOTES: |
517 |
// static, so only initialized to zero at program start. |
// static, so only initialized to zero at program start. |
595 |
#if (CS8900_STATS > 0) |
#if (CS8900_STATS > 0) |
596 |
/* copy statistics counters into netif state fields */ |
/* copy statistics counters into netif state fields */ |
597 |
((struct cs8900if *)netif->state)->missed += miss_count; |
((struct cs8900if *)netif->state)->missed += miss_count; |
598 |
if (miss_count > 0) LWIP_DEBUGF(NETIF_DEBUG | 1, ("cs8900_input: %u missed packets due to rx buffer overrun\n", miss_count)); |
if (miss_count > 0) LWIP_DEBUGF(NETIF_DEBUG | 1, ("cs8900_input: %"U16_F" missed packets due to rx buffer overrun\n", miss_count)); |
599 |
|
|
600 |
((struct cs8900if *)netif->state)->collisions += coll_count; |
((struct cs8900if *)netif->state)->collisions += coll_count; |
601 |
if (coll_count > 0) LWIP_DEBUGF(NETIF_DEBUG | 1, ("cs8900_input: %u packet collisions\n", coll_count)); |
if (coll_count > 0) LWIP_DEBUGF(NETIF_DEBUG | 1, ("cs8900_input: %"U16_F" packet collisions\n", coll_count)); |
602 |
#endif |
#endif |
603 |
} |
} |
604 |
|
|
776 |
* @param p pointer to an array of bytes, at least with length 'len' |
* @param p pointer to an array of bytes, at least with length 'len' |
777 |
* @param len number of bytes available at the address pointed to by 'p' |
* @param len number of bytes available at the address pointed to by 'p' |
778 |
*/ |
*/ |
779 |
void cs8900_send_debug(unsigned char *p, unsigned int len) |
void cs8900_send_debug(u8_t *p, u16_t len) |
780 |
{ |
{ |
781 |
int tries = 0, i; |
s16_t tries = 0, i; |
782 |
|
|
783 |
// network interface state |
// network interface state |
784 |
extern struct netif *ethif; |
extern struct netif *ethif; |
887 |
} |
} |
888 |
} |
} |
889 |
|
|
890 |
static u32_t cs8900_chksum(void *dataptr, int len) |
static u32_t cs8900_chksum(void *dataptr, s16_t len) |
891 |
{ |
{ |
892 |
u32_t acc = 0; |
u32_t acc = 0; |
893 |
u16_t *ptr = (u16_t *)dataptr; |
u16_t *ptr = (u16_t *)dataptr; |