diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2009-04-30 22:46:48 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2009-04-30 22:46:48 +0000 |
commit | 1e01021d528e896067ebe0f74a172e7c6b39c9ab (patch) | |
tree | 5a3cece005053f06809600fc0a620a7d44c9ab22 | |
parent | 0494067399d622417226329f3f818f8a529bbf2a (diff) | |
download | nuttx-1e01021d528e896067ebe0f74a172e7c6b39c9ab.tar.gz nuttx-1e01021d528e896067ebe0f74a172e7c6b39c9ab.tar.bz2 nuttx-1e01021d528e896067ebe0f74a172e7c6b39c9ab.zip |
more cs89x0 logic
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1749 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r-- | nuttx/drivers/net/cs89x0.c | 450 | ||||
-rwxr-xr-x | nuttx/drivers/net/cs89x0.h | 328 | ||||
-rw-r--r-- | nuttx/drivers/net/skeleton.c | 6 | ||||
-rwxr-xr-x | nuttx/include/nuttx/cs89x0.h | 162 |
4 files changed, 843 insertions, 103 deletions
diff --git a/nuttx/drivers/net/cs89x0.c b/nuttx/drivers/net/cs89x0.c index f8d5ba58a..5fe8c8702 100644 --- a/nuttx/drivers/net/cs89x0.c +++ b/nuttx/drivers/net/cs89x0.c @@ -65,7 +65,7 @@ # define CONFIG_CS89x0_NINTERFACES 1 #endif -/* TX poll deley = 1 seconds. CLK_TCK is the number of clock ticks per second */ +/* TX poll delay = 1 seconds. CLK_TCK is the number of clock ticks per second */ #define CS89x0_WDDELAY (1*CLK_TCK) #define CS89x0_POLLHSEC (1*2) @@ -76,37 +76,39 @@ /* This is a helper pointer for accessing the contents of the Ethernet header */ -#define BUF ((struct uip_eth_hdr *)cs89x0->sk_dev.d_buf) +#define BUF ((struct uip_eth_hdr *)cs89x0->cs_dev.d_buf) -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/* The cs89x0_driver_s encapsulates all state information for a single hardware - * interface +/* If there is only one CS89x0 instance, then mapping the CS89x0 IRQ to + * a driver state instance is trivial. */ -struct cs89x0_driver_s -{ - boolean sk_bifup; /* TRUE:ifup FALSE:ifdown */ - WDOG_ID sk_txpoll; /* TX poll timer */ - WDOG_ID sk_txtimeout; /* TX timeout timer */ - - /* This holds the information visible to uIP/NuttX */ +#if CONFIG_CS89x0_NINTERFACES == 1 +# define cs89x0_mapirq(irq) g_cs89x0[0] +#endif - struct uip_driver_s sk_dev; /* Interface understood by uIP */ -}; +/**************************************************************************** + * Private Types + ****************************************************************************/ /**************************************************************************** * Private Data ****************************************************************************/ -static struct cs89x0_driver_s g_cs89x0[CONFIG_CS89x0_NINTERFACES]; +static FAR struct cs89x0_driver_s *g_cs89x0[CONFIG_CS89x0_NINTERFACES]; /**************************************************************************** * Private Function Prototypes ****************************************************************************/ +/* CS89x0 register access */ + +static uint16 cs89x0_getreg(struct cs89x0_driver_s *cs89x0, int offset); +static void cs89x0_putreg(struct cs89x0_driver_s *cs89x0, int offset, + uint16 value); +static uint16 cs89x0_getppreg(struct cs89x0_driver_s *cs89x0, int addr); +static void cs89x0_putppreg(struct cs89x0_driver_s *cs89x0, int addr, + uint16 value); + /* Common TX logic */ static int cs89x0_transmit(struct cs89x0_driver_s *cs89x0); @@ -115,7 +117,10 @@ static int cs89x0_uiptxpoll(struct uip_driver_s *dev); /* Interrupt handling */ static void cs89x0_receive(struct cs89x0_driver_s *cs89x0); -static void cs89x0_txdone(struct cs89x0_driver_s *cs89x0); +static void cs89x0_txdone(struct cs89x0_driver_s *cs89x0, uint16 isq); +#if CONFIG_CS89x0_NINTERFACES > 1 +static inline FAR struct cs89x0_driver_s *cs89x0_mapirq(int irq); +#endif static int cs89x0_interrupt(int irq, FAR void *context); /* Watchdog timer expirations */ @@ -134,6 +139,80 @@ static int cs89x0_txavail(struct uip_driver_s *dev); ****************************************************************************/ /**************************************************************************** + * Function: cs89x0_getreg and cs89x0_putreg + * + * Description: + * Read from and write to a CS89x0 register + * + * Parameters: + * cs89x0 - Reference to the driver state structure + * offset - Offset to the CS89x0 register + * value - Value to be written (cs89x0_putreg only) + * + * Returned Value: + * cs89x0_getreg: The 16-bit value of the register + * cs89x0_putreg: None + * + ****************************************************************************/ + +static uint16 cs89x0_getreg(struct cs89x0_driver_s *cs89x0, int offset) +{ +#ifdef CONFIG_CS89x0_ALIGN16 + return getreg16(s89x0->cs_base + offset); +#else + return (uint16)getreg32(s89x0->cs_base + offset); +#endif +} + +static void cs89x0_putreg(struct cs89x0_driver_s *cs89x0, int offset, uint16 value) +{ +#ifdef CONFIG_CS89x0_ALIGN16 + return putreg16(value, s89x0->cs_base + offset); +#else + return (uint16)putreg32((uint32)value, s89x0->cs_base + offset); +#endif +} + +/**************************************************************************** + * Function: cs89x0_getppreg and cs89x0_putppreg + * + * Description: + * Read from and write to a CS89x0 page packet register + * + * Parameters: + * cs89x0 - Reference to the driver state structure + * addr - Address of the CS89x0 page packet register + * value - Value to be written (cs89x0_putppreg only) + * + * Returned Value: + * cs89x0_getppreg: The 16-bit value of the page packet register + * cs89x0_putppreg: None + * + ****************************************************************************/ + +static uint16 cs89x0_getppreg(struct cs89x0_driver_s *cs89x0, int addr) +{ +#ifdef CONFIG_CS89x0_ALIGN16 + putreg16((uint16)addr, cs89x0->cs_base + CS89x0_PPTR_OFFSET); + return getreg16(s89x0->cs_base + CS89x0_PDATA_OFFSET); +#else + putreg32((uint32)addr, cs89x0->cs_base + CS89x0_PPTR_OFFSET); + return (uint16)getreg32(s89x0->cs_base + CS89x0_PDATA_OFFSET); +#endif +} + +static void cs89x0_putppreg(struct cs89x0_driver_s *cs89x0, int addr, uint16 value) +{ +#ifdef CONFIG_CS89x0_ALIGN16 + putreg16((uint16)addr, cs89x0->cs_base + CS89x0_PPTR_OFFSET); + putreg16(value), cs89x0->cs_base + CS89x0_PDATA_OFFSET); +#else + putreg32((uint32)addr, cs89x0->cs_base + CS89x0_PPTR_OFFSET); + putreg32((uint32)value, cs89x0->cs_base + CS89x0_PDATA_OFFSET); +#endif +} + +/**************************************************************************** * Function: cs89x0_transmit * * Description: @@ -153,18 +232,23 @@ static int cs89x0_txavail(struct uip_driver_s *dev); static int cs89x0_transmit(struct cs89x0_driver_s *cs89x0) { /* Verify that the hardware is ready to send another packet */ +#warning "Missing logic" /* Increment statistics */ +#warning "Missing logic" /* Disable Ethernet interrupts */ +#warning "Missing logic" - /* Send the packet: address=cs89x0->sk_dev.d_buf, length=cs89x0->sk_dev.d_len */ + /* Send the packet: address=cs89x0->cs_dev.d_buf, length=cs89x0->cs_dev.d_len */ +#warning "Missing logic" /* Restore Ethernet interrupts */ +#warning "Missing logic" /* Setup the TX timeout watchdog (perhaps restarting the timer) */ - (void)wd_start(cs89x0->sk_txtimeout, CS89x0_TXTIMEOUT, cs89x0_txtimeout, 1, (uint32)cs89x0); + (void)wd_start(cs89x0->cs_txtimeout, CS89x0_TXTIMEOUT, cs89x0_txtimeout, 1, (uint32)cs89x0); return OK; } @@ -197,14 +281,15 @@ static int cs89x0_uiptxpoll(struct uip_driver_s *dev) * the field d_len is set to a value > 0. */ - if (cs89x0->sk_dev.d_len > 0) + if (cs89x0->cs_dev.d_len > 0) { - uip_arp_out(&cs89x0->sk_dev); + uip_arp_out(&cs89x0->cs_dev); cs89x0_transmit(cs89x0); /* Check if there is room in the CS89x0 to hold another packet. If not, * return a non-zero value to terminate the poll. */ +#warning "Missing logic" } /* If zero is returned, the polling will continue until all connections have @@ -222,6 +307,7 @@ static int cs89x0_uiptxpoll(struct uip_driver_s *dev) * * Parameters: * cs89x0 - Reference to the driver state structure + * isq - Interrupt status queue value read by interrupt handler * * Returned Value: * None @@ -230,55 +316,100 @@ static int cs89x0_uiptxpoll(struct uip_driver_s *dev) * ****************************************************************************/ -static void cs89x0_receive(struct cs89x0_driver_s *cs89x0) +static void cs89x0_receive(struct cs89x0_driver_s *cs89x0, uint16 isq) { - do + uint16 *dest; + uint16 rxlength; + int nbytes; + + /* Check for errors and update statistics */ + + rxlength = cs89x0_getreg(PPR_RXLENGTH); + if ((isq & RX_OK) == 0) { - /* Check for errors and update statistics */ +#ifdef CONFIG_C89x0_STATISTICS + cd89x0->cs_stats.rx_errors++; + if ((isq & RX_RUNT) != 0) + { + cd89x0->cs_stats.rx_lengtherrors++; + } + if ((isq & RX_EXTRA_DATA) != 0) + { + cd89x0->cs_stats.rx_lengtherrors++; + } + if (isq & RX_CRC_ERROR) != 0) + { + if (!(isq & (RX_EXTRA_DATA|RX_RUNT))) + { + cd89x0->cs_stats.rx_crcerrors++; + } + } + if ((isq & RX_DRIBBLE) != 0) + { + cd89x0->cs_stats.rx_frameerrors++; + } +#endif + return; + } - /* Check if the packet is a valid size for the uIP buffer configuration */ + /* Check if the packet is a valid size for the uIP buffer configuration */ - /* Copy the data data from the hardware to cs89x0->sk_dev.d_buf. Set - * amount of data in cs89x0->sk_dev.d_len - */ + if (rxlength > ???) + { +#ifdef CONFIG_C89x0_STATISTICS + cd89x0->cs_stats.rx_errors++; + cd89x0->cs_stats.rx_lengtherrors++; +#endif + return; + } + + /* Copy the data data from the hardware to cs89x0->cs_dev.d_buf. Set + * amount of data in cs89x0->cs_dev.d_len + */ + + dest = (uint16*)cs89x0->cs_dev.d_buf; + for (nbytes = 0; nbytes < rxlength; nbytes += sizeof(uint16)) + { + *dest++ = cs89x0_getreg(PPR_RXFRAMELOCATION); + } - /* We only accept IP packets of the configured type and ARP packets */ +#ifdef CONFIG_C89x0_STATISTICS + cd89x0->cs_stats.rx_packets++; +#endif + /* We only accept IP packets of the configured type and ARP packets */ #ifdef CONFIG_NET_IPv6 - if (BUF->type == HTONS(UIP_ETHTYPE_IP6)) + if (BUF->type == HTONS(UIP_ETHTYPE_IP6)) #else - if (BUF->type == HTONS(UIP_ETHTYPE_IP)) + if (BUF->type == HTONS(UIP_ETHTYPE_IP)) #endif + { + uip_arp_ipin(); + uip_input(&cs89x0->cs_dev); + + /* If the above function invocation resulted in data that should be + * sent out on the network, the field d_len will set to a value > 0. + */ + + if (cs89x0->cs_dev.d_len > 0) { - uip_arp_ipin(); - uip_input(&cs89x0->sk_dev); - - /* If the above function invocation resulted in data that should be - * sent out on the network, the field d_len will set to a value > 0. - */ - - if (cs89x0->sk_dev.d_len > 0) - { - uip_arp_out(&cs89x0->sk_dev); - cs89x0_transmit(cs89x0); - } - } - else if (BUF->type == htons(UIP_ETHTYPE_ARP)) - { - uip_arp_arpin(&cs89x0->sk_dev); + uip_arp_out(&cs89x0->cs_dev); + cs89x0_transmit(cs89x0); + } + } + else if (BUF->type == htons(UIP_ETHTYPE_ARP)) + { + uip_arp_arpin(&cs89x0->cs_dev); - /* If the above function invocation resulted in data that should be - * sent out on the network, the field d_len will set to a value > 0. - */ + /* If the above function invocation resulted in data that should be + * sent out on the network, the field d_len will set to a value > 0. + */ - if (cs89x0->sk_dev.d_len > 0) - { - cs89x0_transmit(cs89x0); - } - } - } + if (cs89x0->cs_dev.d_len > 0) + { + cs89x0_transmit(cs89x0); + } } - while (); /* While there are more packets to be processed */ } /**************************************************************************** @@ -297,20 +428,80 @@ static void cs89x0_receive(struct cs89x0_driver_s *cs89x0) * ****************************************************************************/ -static void cs89x0_txdone(struct cs89x0_driver_s *cs89x0) +static void cs89x0_txdone(struct cs89x0_driver_s *cs89x0, uint16 isq) { - /* Check for errors and update statistics */ + /* Check for errors and update statistics. The lower 6-bits of the ISQ + * hold the register address causing the interrupt. We got here because + * those bits indicated */ + +#ifdef CONFIG_C89x0_STATISTICS + cd89x0->cs_stats.tx_packets++; + if ((isq & ISQ_TXEVENT_TXOK) == 0) + { + cd89x0->cs_stats.tx_errors++; + } + if ((isq & ISQ_TXEVENT_LOSSOFCRS) != 0) + { + cd89x0->cs_stats.tx_carriererrors++; + } + if ((isq & ISQ_TXEVENT_SQEERROR) != 0) + { + cd89x0->cs_stats.tx_heartbeaterrors++; + } + if (i(sq & ISQ_TXEVENT_OUTWINDOW) != 0) + { + cd89x0->cs_stats.tx_windowerrors++; + } + if (isq & TX_16_COL) + { + cd89x0->cs_stats.tx_abortederrors++; + } +#endif /* If no further xmits are pending, then cancel the TX timeout */ - wd_cancel(cs89x0->sk_txtimeout); + wd_cancel(cs89x0->cs_txtimeout); /* Then poll uIP for new XMIT data */ - (void)uip_poll(&cs89x0->sk_dev, cs89x0_uiptxpoll); + (void)uip_poll(&cs89x0->cs_dev, cs89x0_uiptxpoll); } /**************************************************************************** + * Function: cs89x0_mapirq + * + * Description: + * Map an IRQ number to a CS89x0 device state instance. This is only + * necessary to handler the case where the architecture includes more than + * on CS89x0 chip. + * + * Parameters: + * irq - Number of the IRQ that generated the interrupt + * + * Returned Value: + * A reference to device state structure (NULL if irq does not correspond + * to any CS89x0 device). + * + * Assumptions: + * + ****************************************************************************/ + +#if CONFIG_CS89x0_NINTERFACES > 1 +static inline FAR struct cs89x0_driver_s *cs89x0_mapirq(int irq) +{ + int i; + for (i = 0; i < CONFIG_CS89x0_NINTERFACES; i++) + { + if (g_cs89x0[i] && g_cs89x0[i].irq == irq) + { + return g_cs89x0[i]; + } + } + return NULL' +} +#endif + +/**************************************************************************** * Function: cs89x0_interrupt * * Description: @@ -329,26 +520,63 @@ static void cs89x0_txdone(struct cs89x0_driver_s *cs89x0) static int cs89x0_interrupt(int irq, FAR void *context) { - register struct cs89x0_driver_s *cs89x0 = &g_cs89x0[0]; - - /* Disable Ethernet interrupts */ - - /* Get and clear interrupt status bits */ - - /* Handle interrupts according to status bit settings */ + register struct cs89x0_driver_s *cs89x0 = s89x0_mapirq(irq); + uint16 isq; + +#ifdef CONFIG_DEBUG + if (!cs89x0) + { + return -ENODEV; + } +#endif - /* Check if we received an incoming packet, if so, call cs89x0_receive() */ + /* Read and process all of the events from the ISQ */ - cs89x0_receive(cs89x0); + while ((isq = cs89x0_getreg(dev, CS89x0_ISQ_OFFSET)) != 0) + { + nvdbg("ISQ: %04x\n", isq); + switch (isq & ISQ_EVENTMASK) + { + case ISQ_RXEVENT: + cs89x0_receive(cs89x0); + break; - /* Check is a packet transmission just completed. If so, call cs89x0_txdone */ + case ISQ_TXEVENT: + cs89x0_txdone(cs89x0, isq); + break; - cs89x0_txdone(cs89x0); + case ISQ_BUFEVENT: + if ((isq & ISQ_BUFEVENT_TXUNDERRUN) != 0) + { + ndbg("Transmit underrun\n"); +#ifdef CONFIG_CS89x0_XMITEARLY + + cd89x0->cs_txunderrun++; + if (cd89x0->cs_txunderrun == 3) + { + cd89x0->send_cmd = TX_AFTER_381; + } + else if (cd89x0->cs_txunderrun == 6) + { + cd89x0->send_cmd = TX_AFTER_ALL; + } +#endif + } + break; - /* Enable Ethernet interrupts (perhaps excluding the TX done interrupt if - * there are no pending transmissions. - */ + case ISQ_RXMISSEVENT: +#ifdef CONFIG_C89x0_STATISTICS + cd89x0->cs_stats.rx_missederrors += (isq >>6); +#endif + break; + case ISQ_TXCOLEVENT: +#ifdef CONFIG_C89x0_STATISTICS + cd89x0->cs_stats.collisions += (isq >>6); +#endif + break; + } + } return OK; } @@ -375,12 +603,14 @@ static void cs89x0_txtimeout(int argc, uint32 arg, ...) struct cs89x0_driver_s *cs89x0 = (struct cs89x0_driver_s *)arg; /* Increment statistics and dump debug info */ +#warning "Missing logic" /* Then reset the hardware */ +#warning "Missing logic" /* Then poll uIP for new XMIT data */ - (void)uip_poll(&cs89x0->sk_dev, cs89x0_uiptxpoll); + (void)uip_poll(&cs89x0->cs_dev, cs89x0_uiptxpoll); } /**************************************************************************** @@ -405,14 +635,15 @@ static void cs89x0_polltimer(int argc, uint32 arg, ...) struct cs89x0_driver_s *cs89x0 = (struct cs89x0_driver_s *)arg; /* Check if there is room in the send another TXr packet. */ +#warning "Missing logic" /* If so, update TCP timing states and poll uIP for new XMIT data */ - (void)uip_timer(&cs89x0->sk_dev, cs89x0_uiptxpoll, CS89x0_POLLHSEC); + (void)uip_timer(&cs89x0->cs_dev, cs89x0_uiptxpoll, CS89x0_POLLHSEC); /* Setup the watchdog poll timer again */ - (void)wd_start(cs89x0->sk_txpoll, CS89x0_WDDELAY, cs89x0_polltimer, 1, arg); + (void)wd_start(cs89x0->cs_txpoll, CS89x0_WDDELAY, cs89x0_polltimer, 1, arg); } /**************************************************************************** @@ -440,15 +671,16 @@ static int cs89x0_ifup(struct uip_driver_s *dev) dev->d_ipaddr & 0xff, (dev->d_ipaddr >> 8) & 0xff, (dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24 ); - /* Initilize Ethernet interface */ + /* Initialize the Ethernet interface */ +#warning "Missing logic" /* Set and activate a timer process */ - (void)wd_start(cs89x0->sk_txpoll, CS89x0_WDDELAY, cs89x0_polltimer, 1, (uint32)cs89x0); + (void)wd_start(cs89x0->cs_txpoll, CS89x0_WDDELAY, cs89x0_polltimer, 1, (uint32)cs89x0); /* Enable the Ethernet interrupt */ - cs89x0->sk_bifup = TRUE; + cs89x0->cs_bifup = TRUE; up_enable_irq(CONFIG_CS89x0_IRQ); return OK; } @@ -481,12 +713,12 @@ static int cs89x0_ifdown(struct uip_driver_s *dev) /* Cancel the TX poll timer and TX timeout timers */ - wd_cancel(cs89x0->sk_txpoll); - wd_cancel(cs89x0->sk_txtimeout); + wd_cancel(cs89x0->cs_txpoll); + wd_cancel(cs89x0->cs_txtimeout); /* Reset the device */ - cs89x0->sk_bifup = FALSE; + cs89x0->cs_bifup = FALSE; irqrestore(flags); return OK; } @@ -519,13 +751,14 @@ static int cs89x0_txavail(struct uip_driver_s *dev) /* Ignore the notification if the interface is not yet up */ - if (cs89x0->sk_bifup) + if (cs89x0->cs_bifup) { /* Check if there is room in the hardware to hold another outgoing packet. */ +#warning "Missing logic" /* If so, then poll uIP for new XMIT data */ - (void)uip_poll(&cs89x0->sk_dev, cs89x0_uiptxpoll); + (void)uip_poll(&cs89x0->cs_dev, cs89x0_uiptxpoll); } irqrestore(flags); @@ -543,7 +776,13 @@ static int cs89x0_txavail(struct uip_driver_s *dev) * Initialize the Ethernet driver * * Parameters: - * None + * impl - decribes the the implementation of the cs89x00 implementation. + * This reference is retained so so must remain stable throughout the + * life of the driver instance. + * devno - Identifies the device number. This must be a number between + * zero CONFIG_CS89x0_NINTERFACES and the same devno must not be + * initialized twice. The associated network device will be referred + * to with the name "eth" followed by this number (eth0, eth1, etc). * * Returned Value: * OK on success; Negated errno on failure. @@ -554,13 +793,24 @@ static int cs89x0_txavail(struct uip_driver_s *dev) /* Initialize the CS89x0 chip and driver */ -int cs89x0_initialize(void) +int cs89x0_initialize(FAR const cs89x0_driver_s *cs89x0, int devno) { + /* Sanity checks -- only performed with debug enabled */ + +#ifdef CONFIG_DEBUG + if (!cs89x0 || (unsigned)devno > CONFIG_CS89x0_NINTERFACES || g_cs89x00[devno]) + { + return -EINVAL; + } +#endif + /* Check if a Ethernet chip is recognized at its I/O base */ +#warning "Missing logic" + /* Attach the IRQ to the driver */ - if (irq_attach(CONFIG_CS89x0_IRQ, cs89x0_interrupt)) + if (irq_attach(cs89x0->irq, cs89x0_interrupt)) { /* We could not attach the ISR to the ISR */ @@ -569,22 +819,22 @@ int cs89x0_initialize(void) /* Initialize the driver structure */ - memset(g_cs89x0, 0, CONFIG_CS89x0_NINTERFACES*sizeof(struct cs89x0_driver_s)); - g_cs89x0[0].sk_dev.d_ifup = cs89x0_ifup; /* I/F down callback */ - g_cs89x0[0].sk_dev.d_ifdown = cs89x0_ifdown; /* I/F up (new IP address) callback */ - g_cs89x0[0].sk_dev.d_txavail = cs89x0_txavail; /* New TX data callback */ - g_cs89x0[0].sk_dev.d_private = (void*)g_cs89x0; /* Used to recover private state from dev */ + g_cs89x[devno] = cs89x0; /* Used to map IRQ back to instance */ + cs89x0->cs_dev.d_ifup = cs89x0_ifup; /* I/F down callback */ + cs89x0->cs_dev.d_ifdown = cs89x0_ifdown; /* I/F up (new IP address) callback */ + cs89x0->cs_dev.d_txavail = cs89x0_txavail; /* New TX data callback */ + cs89x0->cs_dev.d_private = (void*)cs89x0; /* Used to recover private state from dev */ /* Create a watchdog for timing polling for and timing of transmisstions */ - g_cs89x0[0].sk_txpoll = wd_create(); /* Create periodic poll timer */ - g_cs89x0[0].sk_txtimeout = wd_create(); /* Create TX timeout timer */ + cs89x0->cs_txpoll = wd_create(); /* Create periodic poll timer */ + cs89x0->cs_txtimeout = wd_create(); /* Create TX timeout timer */ - /* Read the MAC address from the hardware into g_cs89x0[0].sk_dev.d_mac.ether_addr_octet */ + /* Read the MAC address from the hardware into cs89x0->cs_dev.d_mac.ether_addr_octet */ /* Register the device with the OS so that socket IOCTLs can be performed */ - (void)netdev_register(&g_cs89x0[0].sk_dev); + (void)netdev_register(&cs89x0->cs_dev); return OK; } diff --git a/nuttx/drivers/net/cs89x0.h b/nuttx/drivers/net/cs89x0.h new file mode 100755 index 000000000..2ea664db4 --- /dev/null +++ b/nuttx/drivers/net/cs89x0.h @@ -0,0 +1,328 @@ +/****************************************************************************
+ * drivers/net/cs89x0.h
+ *
+ * Copyright (C) 2009 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+#ifndef __DRIVERS_NET_CS89x0_H
+#define __DRIVERS_NET_CS89x0_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* CONFIG_CS89x0_ALIGN16/32 determines if the 16-bit CS89x0 registers are
+ * aligned to 16-bit or 32-bit address boundaries. NOTE: If there multiple
+ * CS89x00 parts in the board architecture, we assume that the address
+ * alignment is the same for all implementations. If that is not the
+ * case, then it will be necessary to move a shift value into
+ * the cs89x0_driver_s structure and calculate the offsets dynamically in
+ * the putreg and getreg functions.
+ */
+
+#if defined(CONFIG_CS89x0_ALIGN16)
+# define CS89x0_RTDATA_OFFSET (0 << 1)
+# define CS89x0_TxCMD_OFFSET (2 << 1)
+# define CS89x0_TxLEN_OFFSET (3 << 1)
+# define CS89x0_ISQ_OFFSET (4 << 1)
+# define CS89x0_PPTR_OFFSET (5 << 1)
+# define CS89x0_PDATA_OFFSET (6 << 1)
+#elif defined(CONFIG_CS89x0_ALIGN32)
+# define CS89x0_RTDATA_OFFSET (0 << 2)
+# define CS89x0_TxCMD_OFFSET (2 << 2)
+# define CS89x0_TxLEN_OFFSET (3 << 2)
+# define CS89x0_ISQ_OFFSET (4 << 2)
+# define CS89x0_PPTR_OFFSET (5 << 2)
+# define CS89x0_PDATA_OFFSET (6 << 2)
+#else
+# error "CS89x00 address alignment is not defined"
+#endif
+
+/* ISQ register bit definitions */
+
+#define ISQ_EVENTMASK 0x003f /* Bits 0-5 indicate the status register */
+#define ISQ_RXEVENT 0x0004
+#define ISQ_TXEVENT 0x0008
+#define ISQ_BUFEVENT 0x000c
+#define ISQ_RXMISSEVENT 0x0010
+#define ISQ_TXCOLEVENT 0x0012
+
+/* ISQ register TxEVENT bit definitions*/
+
+#define ISQ_RXEVENT_IAHASH (1 << 6)
+#define ISQ_RXEVENT_DRIBBLE (1 << 7)
+#define ISQ_RXEVENT_RXOK (1 << 8)
+#define ISQ_RXEVENT_HASHED (1 << 9)
+#define ISQ_RXEVENT_HASHNDX_SHIFT 10
+#define ISQ_RXEVENT_HASHNDX_MASK (0x3f << ISQ_RXEVENT_HASHNDX_SHIFT)
+
+/* ISQ register TxEVENT bit definitions*/
+
+#define ISQ_TXEVENT_LOSSOFCRS (1 << 6)
+#define ISQ_TXEVENT_SQEERROR (1 << 7)
+#define ISQ_TXEVENT_TXOK (1 << 8)
+#define ISQ_TXEVENT_OUTWINDOW (1 << 9)
+#define ISQ_TXEVENT_JABBER (1 << 10)
+#define ISQ_TXEVENT_NCOLLISION_SHIFT 11
+#define ISQ_TXEVENT_NCOLLISION_MASK (15 << ISQ_TXEVENT_NCOLLISION_SHIFT)
+#define ISQ_TXEVENT_16COLL (1 << 15)
+
+/* ISQ register BufEVENT bit definitions */
+
+#define ISQ_BUFEVENT_SWINT (1 << 6)
+#define ISQ_BUFEVENT_RXDMAFRAME (1 << 7)
+#define ISQ_BUFEVENT_RDY4TX (1 << 8)
+#define ISQ_BUFEVENT_TXUNDERRUN (1 << 9)
+#define ISQ_BUFEVENT_RXMISS (1 << 10)
+#define ISQ_BUFEVENT_RX128 (1 << 11)
+#define ISQ_BUFEVENT_RXDEST (1 << 15)
+
+/* Packet page register offsets *********************************************/
+
+/* 0x0000 Bus interface registers */
+
+#define PPR_CHIPID 0x0000 /* Chip identifier - must be 0x630E */
+#define PPR_CHIPREV 0x0002 /* Chip revision, model codes */
+#define PPR_IOBASEADDRESS 0x0020 /* I/O Base Address */
+#define PPR_INTREG 0x0022 /* Interrupt configuration */
+# define PPR_INTREG_IRQ0 0x0000 /* Use INTR0 pin */
+# define PPR_INTREG_IRQ1 0x0001 /* Use INTR1 pin */
+# define PPR_INTREG_IRQ2 0x0002 /* Use INTR2 pin */
+# define PPR_INTREG_IRQ3 0x0003 /* Use INTR3 pin */
+
+#define PPR_DMACHANNELNUMBER 0x0024 /* DMA Channel Number (0,1, or 2) */
+#define PPR_DMASTARTOFFRAME 0x0026 /* DMA Start of Frame */
+#define PPR_DMAFRAMECOUNT 0x0028 /* DMA Frame Count (12-bits) */
+#define PPR_RXDMABYTECOUNT 0x002a /* Rx DMA Byte Count */
+#define PPR_MEMORYBASEADDRESS 0x002c /* Memory Base Address Register (20-bit) */
+#define PPR_BOOTPROMBASEADDRESS 0x0030 /* Boot PROM Base Address */
+#define PPR_BOOTPROMADDRESSMASK 0x0034 /* Boot PROM Address Mask */
+#define PPR_EEPROMCOMMAND 0x0040 /* EEPROM Command */
+#define PPR_EEPROMDATA 0x0042 /* EEPROM Data */
+#define PPR_RECVFRAMEBYTES 0x0050 /* Received Frame Byte Counter */
+
+/* 0x0100 - Configuration and control registers */
+
+#define PPR_RXCFG 0x0102 /* Receiver configuration */
+# define PPR_RXCFG_SKIP1 (1 << 6) /* Skip (discard) current frame */
+# define PPR_RXCFG_STREAM (1 << 7) /* Enable streaming mode */
+# define PPR_RXCFG_RXOK (1 << 8) /* RxOK interrupt enable */
+# define PPR_RxCFG_RxDMAonly (1 << 9) /* Use RxDMA for all frames */
+# define PPR_RxCFG_AutoRxDMA (1 << 10) /* Select RxDMA automatically */
+# define PPR_RxCFG_BufferCRC (1 << 11) /* Include CRC characters in frame */
+# define PPR_RxCFG_CRC (1 << 12) /* Enable interrupt on CRC error */
+# define PPR_RxCFG_RUNT (1 << 13) /* Enable interrupt on RUNT frames */
+# define PPR_RxCFG_EXTRA (1 << 14) /* Enable interrupt on frames with extra data */
+
+#define PPR_RXCTL 0x0104 /* Receiver control */
+# define PPR_RXCTL_IAHASH (1 << 6) /* Accept frames that match hash */
+# define PPR_RXCTL_PROMISCUOUS (1 << 7) /* Accept any frame */
+# define PPR_RXCTL_RXOK (1 << 8) /* Accept well formed frames */
+# define PPR_RXCTL_MULTICAST (1 << 9) /* Accept multicast frames */
+# define PPR_RXCTL_IA (1 << 10) /* Accept frame that matches IA */
+# define PPR_RXCTL_BROADCAST (1 << 11) /* Accept broadcast frames */
+# define PPR_RXCTL_CRC (1 << 12) /* Accept frames with bad CRC */
+# define PPR_RXCTL_RUNT (1 << 13) /* Accept runt frames */
+# define PPR_RXCTL_EXTRA (1 << 14) /* Accept frames that are too long */
+
+#define PPR_TXCFG 0x0106 /* Transmit configuration */
+# define PPR_TXCFG_CRS (1 << 6) /* Enable interrupt on loss of carrier */
+# define PPR_TXCFG_SQE (1 << 7) /* Enable interrupt on Signal Quality Error */
+# define PPR_TXCFG_TXOK (1 << 8) /* Enable interrupt on successful xmits */
+# define PPR_TXCFG_LATE (1 << 9) /* Enable interrupt on "out of window" */
+# define PPR_TXCFG_JABBER (1 << 10) /* Enable interrupt on jabber detect */
+# define PPR_TXCFG_COLLISION (1 << 11) /* Enable interrupt if collision */
+# define PPR_TXCFG_16COLLISIONS (1 << 15) /* Enable interrupt if > 16 collisions */
+
+#define PPR_TXCMD 0x0108 /* Transmit command status */
+# define PPR_TXCMD_TXSTART5 (0 << 6) /* Start after 5 bytes in buffer */
+# define PPR_TXCMD_TXSTART381 (1 << 6) /* Start after 381 bytes in buffer */
+# define PPR_TXCMD_TXSTART1021 (2 << 6) /* Start after 1021 bytes in buffer */
+# define PPR_TXCMD_TXSTARTFULL (3 << 6) /* Start after all bytes loaded */
+# define PPR_TXCMD_FORCE (1 << 8) /* Discard any pending packets */
+# define PPR_TXCMD_ONECOLLISION (1 << 9) /* Abort after a single collision */
+# define PPR_TXCMD_NOCRC (1 << 12) /* Do not add CRC */
+# define PPR_TXCMD_NOPAD (1 << 13) /* Do not pad short packets */
+
+#define PPR_BUFCFG 0x010a /* Buffer configuration */
+# define PPR_BUFCFG_SWI (1 << 6) /* Force interrupt via software */
+# define PPR_BUFCFG_RXDMA (1 << 7) /* Enable interrupt on Rx DMA */
+# define PPR_BUFCFG_TXRDY (1 << 8) /* Enable interrupt when ready for Tx */
+# define PPR_BUFCFG_TXUE (1 << 9) /* Enable interrupt in Tx underrun */
+# define PPR_BUFCFG_RXMISS (1 << 10) /* Enable interrupt on missed Rx packets */
+# define PPR_BUFCFG_RX128 (1 << 11) /* Enable Rx interrupt after 128 bytes */
+# define PPR_BUFCFG_TXCOL (1 << 12) /* Enable int on Tx collision ctr overflow */
+# define PPR_BUFCFG_MISS (1 << 13) /* Enable int on Rx miss ctr overflow */
+# define PPR_BUFCFG_RXDEST (1 << 15) /* Enable int on Rx dest addr match */
+
+#define PPR_LINECTL 0x0112 /* Line control */
+# define PPR_LINECTL_RX (1 << 6) /* Enable receiver */
+# define PPR_LINECTL_TX (1 << 7) /* Enable transmitter */
+# define PPR_LINECTL_AUIONLY (1 << 8) /* AUI interface only */
+# define PPR_LINECTL_AUTOAUI10BT (1 << 9) /* Autodetect AUI or 10BaseT interface */
+# define PPR_LINECTL_MODBACKOFFE (1 << 11) /* Enable modified backoff algorithm */
+# define PPR_LINECTL_POLARITYDIS (1 << 12) /* Disable Rx polarity autodetect */
+# define PPR_LINECTL_2PARTDEFDIS (1 << 13) /* Disable two-part defferal */
+# define PPR_LINECTL_LORXSQUELCH (1 << 14) /* Reduce receiver squelch threshold */
+
+#define PPR_SELFCTL 0x0114 /* Chip self control */
+# define PPR_SELFCTL_RESET (1 << 6) /* Self-clearing reset */
+# define PPR_SELFCTL_SWSUSPEND (1 << 8) /* Initiate suspend mode */
+# define PPR_SELFCTL_HWSLEEPE (1 << 9) /* Enable SLEEP input */
+# define PPR_SELFCTL_HWSTANDBYE (1 << 10) /* Enable standby mode */
+# define PPR_SELFCTL_HC0E (1 << 12) /* Use HCB0 for LINK LED */
+# define PPR_SELFCTL_HC1E (1 << 13) /* Use HCB1 for BSTATUS LED */
+# define PPR_SELFCTL_HCB0 (1 << 14) /* Control LINK LED if HC0E set */
+# define PPR_SELFCTL_HCB1 (1 << 15) /* Cntrol BSTATUS LED if HC1E set */
+
+#define PPR_BUSCTL 0x0116 /* Bus control */
+# define PPR_BUSCTL_RESETRXDMA (1 << 6) /* Reset RxDMA pointer */
+# define PPR_BUSCTL_DMAEXTEND (1 << 8) /* Extend DMA cycle */
+# define PPR_BUSCTL_USESA (1 << 9) /* Assert MEMCS16 on address decode */
+# define PPR_BUSCTL_MEMORYE (1 << 10) /* Enable memory mode */
+# define PPR_BUSCTL_DMABURST (1 << 11) /* Limit DMA access burst */
+# define PPR_BUSCTL_IOCHRDYE (1 << 12) /* Set IOCHRDY high impedence */
+# define PPR_BUSCTL_RXDMASIZE (1 << 13) /* Set DMA buffer size 64KB */
+# define PPR_BUSCTL_ENABLEIRQ (1 << 15) /* Generate interrupt on interrupt event */
+
+#define PPR_TESTCTL 0x0118 /* Test control */
+# define PPR_TESTCTL_DISABLELT (1 << 7) /* Disable link status */
+# define PPR_TESTCTL_ENDECLOOP (1 << 9) /* Internal loopback */
+# define PPR_TESTCTL_AUILOOP (1 << 10) /* AUI loopback */
+# define PPR_TESTCTL_DISBACKOFF (1 << 11) /* Disable backoff algorithm */
+# define PPR_TESTCTL_FDX (1 << 14) /* Enable full duplex mode */
+
+/* 0x0120 - Status and Event Registers */
+
+#define PPR_ISQ 0x0120 /* Interrupt Status Queue */
+#define PPR_RER 0x0124 /* Receive event */
+# define PPR_RER_IAHASH (1 << 6) /* Frame hash match */
+# define PPR_RER_DRIBBLE (1 << 7) /* Frame had 1-7 extra bits after last byte */
+# define PPR_RER_RXOK (1 << 8) /* Frame received with no errors */
+# define PPR_RER_HASHED (1 << 9) /* Frame address hashed OK */
+# define PPR_RER_IA (1 << 10) /* Frame address matched IA */
+# define PPR_RER_BROADCAST (1 << 11) /* Broadcast frame */
+# define PPR_RER_CRC (1 << 12) /* Frame had CRC error */
+# define PPR_RER_RUNT (1 << 13) /* Runt frame */
+# define PPR_RER_EXTRA (1 << 14) /* Frame was too long */
+
+#define PPR_TER 0x0128 /* Transmit event */
+# define PPR_TER_CRS (1 << 6) /* Carrier lost */
+# define PPR_TER_SQE (1 << 7) /* Signal Quality Error */
+# define PPR_TER_TXOK (1 << 8) /* Packet sent without error */
+# define PPR_TER_LATE (1 << 9) /* Out of window */
+# define PPR_TER_JABBER (1 << 10) /* Stuck transmit? */
+# define PPR_TER_NUMCOLLISIONS_SHIFT 11
+# define PPR_TER_NUMCOLLISIONS_MASK (15 << PPR_TER_NUMCOLLISIONS_SHIFT)
+# define PPR_TER_16COLLISIONS (1 << 15) /* > 16 collisions */
+
+#define PPR_BER 0x012C /* Buffer event */
+# define PPR_BER_SWINT (1 << 6) /* Software interrupt */
+# define PPR_BER_RXDMAFRAME (1 << 7) /* Received framed DMAed */
+# define PPR_BER_RDY4TX (1 << 8) /* Ready for transmission */
+# define PPR_BER_TXUNDERRUN (1 << 9) /* Transmit underrun */
+# define PPR_BER_RXMISS (1 << 10) /* Received frame missed */
+# define PPR_BER_RX128 (1 << 11) /* 128 bytes received */
+# define PPR_BER_RXDEST (1 << 15) /* Received framed passed address filter */
+
+#define PPR_RXMISS 0x0130 /* Receiver miss counter */
+#define PPR_TXCOL 0x0132 /* Transmit collision counter */
+#define PPR_LINESTAT 0x0134 /* Line status */
+# define PPR_LINESTAT_LINKOK (1 << 7) /* Line is connected and working */
+# define PPR_LINESTAT_AUI (1 << 8) /* Connected via AUI */
+# define PPR_LINESTAT_10BT (1 << 9) /* Connected via twisted pair */
+# define PPR_LINESTAT_POLARITY (1 << 12) /* Line polarity OK (10BT only) */
+# define PPR_LINESTAT_CRS (1 << 14) /* Frame being received */
+
+#define PPR_SELFSTAT 0x0136 /* Chip self status */
+# define PPR_SELFSTAT_33VACTIVE (1 << 6) /* supply voltage is 3.3V */
+# define PPR_SELFSTAT_INITD (1 << 7) /* Chip initialization complete */
+# define PPR_SELFSTAT_SIBSY (1 << 8) /* EEPROM is busy */
+# define PPR_SELFSTAT_EEPROM (1 << 9) /* EEPROM present */
+# define PPR_SELFSTAT_EEPROMOK (1 << 10) /* EEPROM checks out */
+# define PPR_SELFSTAT_ELPRESENT (1 << 11) /* External address latch logic available */
+# define PPR_SELFSTAT_EESIZE (1 << 12) /* Size of EEPROM */
+
+#define PPR_BUSSTAT 0x0138 /* Bus status */
+# define PPR_BUSSTAT_TXBID (1 << 7) /* Tx error */
+# define PPR_BUSSTAT_TXRDY (1 << 8) /* Ready for Tx data */
+
+#define PPR_TDR 0x013C /* AUI Time Domain Reflectometer */
+
+/* 0x0144 - Initiate transmit registers */
+
+#define PPR_TXCOMMAND 0x0144 /* Tx Command */
+#define PPR_TXLENGTH 0x0146 /* Tx Length */
+
+/* 0x0150 - Address filter registers */
+
+#define PPR_LAF 0x0150 /* Logical address filter (6 bytes) */
+#define PPR_IA 0x0158 /* Individual address (MAC) */
+
+/* 0x0400 - Frame location registers */
+
+#define PPR_RXSTATUS 0x0400 /* Rx Status */
+#define PPR_RXLENGTH 0x0402 /* Rx Length */
+#define PPR_RXFRAMELOCATION 0x0404 /* Rx Frame Location */
+#define PPR_TXFRAMELOCATION 0x0a00 /* Tx Frame Location */
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __DRIVERS_NET_CS89x0_H */
diff --git a/nuttx/drivers/net/skeleton.c b/nuttx/drivers/net/skeleton.c index 1108a9405..5a47de221 100644 --- a/nuttx/drivers/net/skeleton.c +++ b/nuttx/drivers/net/skeleton.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/net/skeleton.c * - * Copyright (C) 2007 Gregory Nutt. All rights reserved. + * Copyright (C) 2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -202,7 +202,7 @@ static int skel_uiptxpoll(struct uip_driver_s *dev) uip_arp_out(&skel->sk_dev); skel_transmit(skel); - /* Check if there is room in the DM90x0 to hold another packet. If not, + /* Check if there is room in the device to hold another packet. If not, * return a non-zero value to terminate the poll. */ } @@ -553,7 +553,7 @@ static int skel_txavail(struct uip_driver_s *dev) * ****************************************************************************/ -/* Initialize the DM90x0 chip and driver */ +/* Initialize the Ethernet controller and driver */ int skel_initialize(void) { diff --git a/nuttx/include/nuttx/cs89x0.h b/nuttx/include/nuttx/cs89x0.h new file mode 100755 index 000000000..29fffdc5a --- /dev/null +++ b/nuttx/include/nuttx/cs89x0.h @@ -0,0 +1,162 @@ +/****************************************************************************
+ * include/nuttx/cs89x0.h
+ *
+ * Copyright (C) 2009 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_CS89x0_H
+#define __INCLUDE_NUTTX_CS89x0_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <wdog.h>
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* This structure returns driver statistics (if enabled) */
+
+#ifdef CONFIG_C89x0_STATISTICS
+struct cs89x0_statistics_s
+{
+ uint32 tx_packets;
+ uint32 tx_errors;
+ uint32 tx_carriererrors;
+ uint32 tx_heartbeaterrors;
+ uint32 tx_windowerrors;
+ uint32 tx_abortederrors;
+ uint32 rx_missederrors;
+ uint32 rx_packets;
+ uint32 rx_errors;
+ uint32 rx_lengtherrors;
+ uint32 rx_crcerrors;
+ uint32 rx_frameerrors;
+ uint32 rx_dropped;
+ uint32 rx_missederrors;
+ uint32 collisions;
+};
+#endif
+
+/* This structure encapsulates all state information for a single hardware
+ * interface. It includes values that must be provided by the user to in
+ * to describe details of the CS89x00 implementation on a particular board.
+ * An instance if this structure is passed to cs89x00 to instantiate the
+ * driver.
+ *
+ * This structure also includes internal driver state information that should
+ * be of no concern to the caller of cs89x0_initialize(). These fields must
+ * be zeroed.
+ */
+
+struct cs89x0_driver_s
+{
+ /* User-provided CS89x00 platform-specific implementation details. The
+ * caller of cs89x0_initialize() must provide all of these values.
+ */
+
+ FAR void *cs_base; /* CS89x0 region base address */
+ FAR void *cs_ppbase; /* CS89x0 page packet base address */
+ ubyte cs_irq; /* CS89x00 IRQ number */
+
+ /* Driver internal state fields. These must be zeroed by before the
+ * instance of this structure is passed to cs89x0_initialize
+ */
+
+ boolean cs_bifup; /* TRUE:ifup FALSE:ifdown */
+ WDOG_ID cs_txpoll; /* TX poll timer */
+ WDOG_ID cs_txtimeout; /* TX timeout timer */
+#ifdef CONFIG_CS89x0_XMITEARLY
+ uint32 cs_txunderrun; /* Count of Tx underrun errors */
+#endif
+
+ /* This holds the information visible to uIP/NuttX */
+
+ struct uip_driver_s cs_dev; /* Interface understood by uIP */
+
+ /* Driver statistics */
+
+#ifdef CONFIG_C89x0_STATISTICS
+ struct cs89x0_statistics_s cs_stats;
+#endif
+};
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Function: cs89x0_initialize
+ *
+ * Description:
+ * Initialize the Ethernet driver
+ *
+ * Parameters:
+ * impl - decribes the the implementation of the cs89x00 implementation.
+ * This reference is retained so so must remain stable throughout the
+ * life of the driver instance.
+ * devno - Identifies the device number. This must be a number between
+ * zero CONFIG_CS89x0_NINTERFACES and the same devno must not be
+ * initialized twice. The associated network device will be referred
+ * to with the name "eth" followed by this number (eth0, eth1, etc).
+ *
+ * Returned Value:
+ * OK on success; Negated errno on failure.
+ *
+ * Assumptions:
+ *
+ ****************************************************************************/
+
+/* Initialize the CS89x0 chip and driver */
+
+EXTERN int cs89x0_initialize(FAR const cs89x0_driver_s *cs89x0, int devno);
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __INCLUDE_NUTTX_CS89x0_H */
|