SAMV7 Ethernet: Support getting IP address from the XULT AT24 EEPROM
This commit is contained in:
parent
9849e22d3b
commit
d3724701b9
@ -109,7 +109,7 @@ static xcpt_t g_emac1_handler;
|
|||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
|
|
||||||
/************************************************************************************
|
/************************************************************************************
|
||||||
* Name: sam_emac_phy_enable and sam_gmac_enable
|
* Name: sam_emac0/1_phy_enable
|
||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_SAMA5_PIOE_IRQ
|
#ifdef CONFIG_SAMA5_PIOE_IRQ
|
||||||
|
@ -396,6 +396,8 @@ Selecting the GMAC peripheral
|
|||||||
|
|
||||||
System Type -> SAMV7 Peripheral Support
|
System Type -> SAMV7 Peripheral Support
|
||||||
CONFIG_SAMV7_EMAC0=y : Enable the GMAC peripheral (aka, EMAC0)
|
CONFIG_SAMV7_EMAC0=y : Enable the GMAC peripheral (aka, EMAC0)
|
||||||
|
CONFIG_SAMV7_TWIHS0=y : We will get the MAC address from the AT24 EEPROM
|
||||||
|
CONFIG_SAMV7_TWIHS0_FREQUENCY=100000
|
||||||
|
|
||||||
System Type -> EMAC device driver options
|
System Type -> EMAC device driver options
|
||||||
CONFIG_SAMV7_EMAC0_NRXBUFFERS=16 : Set aside some RS and TX buffers
|
CONFIG_SAMV7_EMAC0_NRXBUFFERS=16 : Set aside some RS and TX buffers
|
||||||
@ -434,6 +436,13 @@ Selecting the GMAC peripheral
|
|||||||
CONFIG_NETDEVICES=y : Enabled PHY selection
|
CONFIG_NETDEVICES=y : Enabled PHY selection
|
||||||
CONFIG_ETH0_PHY_KSZ8061=y : Select the KSZ8061 PHY used with EMAC0
|
CONFIG_ETH0_PHY_KSZ8061=y : Select the KSZ8061 PHY used with EMAC0
|
||||||
|
|
||||||
|
Device drivers -> Memory Technology Devices
|
||||||
|
CONFIG_MTD_AT24XX=y : Enable the AT24 device driver
|
||||||
|
CONFIG_AT24XX_SIZE=2 : Normal EEPROM is 2Kbit (256b)
|
||||||
|
CONFIG_AT24XX_ADDR=0x57 : Normal EEPROM address */
|
||||||
|
CONFIG_AT24XX_EXTENDED=y : Supports an extended memory region
|
||||||
|
CONFIG_AT24XX_EXTSIZE=160 : Extended address up to 0x9f
|
||||||
|
|
||||||
Application Configuration -> Network Utilities
|
Application Configuration -> Network Utilities
|
||||||
CONFIG_NETUTILS_DNSCLIENT=y : Enable host address resolution
|
CONFIG_NETUTILS_DNSCLIENT=y : Enable host address resolution
|
||||||
CONFIG_NETUTILS_TELNETD=y : Enable the Telnet daemon
|
CONFIG_NETUTILS_TELNETD=y : Enable the Telnet daemon
|
||||||
@ -446,7 +455,7 @@ Selecting the GMAC peripheral
|
|||||||
CONFIG_NSH_IPADDR=0x0a000002 : Select an IP address
|
CONFIG_NSH_IPADDR=0x0a000002 : Select an IP address
|
||||||
CONFIG_NSH_DRIPADDR=0x0a000001 : IP address of gateway/host PC
|
CONFIG_NSH_DRIPADDR=0x0a000001 : IP address of gateway/host PC
|
||||||
CONFIG_NSH_NETMASK=0xffffff00 : Netmask
|
CONFIG_NSH_NETMASK=0xffffff00 : Netmask
|
||||||
CONFIG_NSH_NOMAC=y : Need to make up a bogus MAC address
|
CONFIG_NSH_NOMAC=n : We will get the IP address from EEPROM
|
||||||
: Defaults should be okay for other options
|
: Defaults should be okay for other options
|
||||||
|
|
||||||
Using the network with NSH
|
Using the network with NSH
|
||||||
|
@ -89,12 +89,24 @@
|
|||||||
|
|
||||||
int sam_bringup(void)
|
int sam_bringup(void)
|
||||||
{
|
{
|
||||||
#if defined(HAVE_HSMCI) || defined(HAVE_USBHOST) || defined(HAVE_USBMONITOR) || \
|
#if defined(HAVE_MACADDR) || defined(HAVE_HSMCI) || defined(HAVE_USBHOST) || \
|
||||||
defined(HAVE_WM8904) || defined(HAVE_AUTOMOUNTER) || defined(HAVE_ELF) || \
|
defined(HAVE_USBMONITOR) || defined(HAVE_WM8904) || \
|
||||||
defined(HAVE_ROMFS)
|
defined(HAVE_AUTOMOUNTER) || defined(HAVE_ELF) || defined(HAVE_ROMFS)
|
||||||
int ret;
|
int ret;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_MACADDR
|
||||||
|
/* Read the Ethernet MAC address from the AT24 FLASH and configure the
|
||||||
|
* Ethernet driver with that address.
|
||||||
|
*/
|
||||||
|
|
||||||
|
ret = sam_emac0_setmac();
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
SYSLOG("ERROR: sam_emac0_setmac() failed: %d\n", ret);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_HSMCI
|
#ifdef HAVE_HSMCI
|
||||||
#ifdef CONFIG_SAMV7_HSMCI0
|
#ifdef CONFIG_SAMV7_HSMCI0
|
||||||
/* Initialize the HSMCI0 driver */
|
/* Initialize the HSMCI0 driver */
|
||||||
|
@ -50,12 +50,16 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
#include <nuttx/irq.h>
|
#include <nuttx/irq.h>
|
||||||
#include <nuttx/arch.h>
|
#include <nuttx/arch.h>
|
||||||
|
#include <nuttx/fs/ioctl.h>
|
||||||
|
#include <nuttx/mtd/mtd.h>
|
||||||
|
|
||||||
#include "sam_gpio.h"
|
#include "sam_gpio.h"
|
||||||
|
#include "sam_twihs.h"
|
||||||
#include "sam_ethernet.h"
|
#include "sam_ethernet.h"
|
||||||
|
|
||||||
#include "samv71-xult.h"
|
#include "samv71-xult.h"
|
||||||
@ -68,6 +72,8 @@
|
|||||||
|
|
||||||
#define SAMV7_EMAC0_DEVNAME "eth0"
|
#define SAMV7_EMAC0_DEVNAME "eth0"
|
||||||
|
|
||||||
|
#define AT24XX_MACADDR_OFFSET 0x9a
|
||||||
|
|
||||||
/* Debug ********************************************************************/
|
/* Debug ********************************************************************/
|
||||||
/* Extra, in-depth debug output that is only available if
|
/* Extra, in-depth debug output that is only available if
|
||||||
* CONFIG_NETDEV_PHY_DEBUG us defined.
|
* CONFIG_NETDEV_PHY_DEBUG us defined.
|
||||||
@ -94,7 +100,7 @@ static xcpt_t g_emac0_handler;
|
|||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
|
|
||||||
/************************************************************************************
|
/************************************************************************************
|
||||||
* Name: sam_emac_phy_enable and sam_gmac_enable
|
* Name: sam_emac0_phy_enable
|
||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_SAMV7_PIOA_IRQ
|
#ifdef CONFIG_SAMV7_PIOA_IRQ
|
||||||
@ -126,10 +132,99 @@ static void sam_emac0_phy_enable(bool enable)
|
|||||||
|
|
||||||
void weak_function sam_netinitialize(void)
|
void weak_function sam_netinitialize(void)
|
||||||
{
|
{
|
||||||
|
/* Configure the PHY interrupt GPIO */
|
||||||
|
|
||||||
phydbg("Configuring %08x\n", GPIO_INT_ETH0);
|
phydbg("Configuring %08x\n", GPIO_INT_ETH0);
|
||||||
sam_configgpio(GPIO_INT_ETH0);
|
sam_configgpio(GPIO_INT_ETH0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Name: sam_emac0_setmac
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Read the Ethernet MAC address from the AT24 FLASH and configure the Ethernet
|
||||||
|
* driver with that address.
|
||||||
|
*
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
#ifdef HAVE_MACADDR
|
||||||
|
int sam_emac0_setmac(void)
|
||||||
|
{
|
||||||
|
struct i2c_dev_s *i2c;
|
||||||
|
struct mtd_dev_s *at24;
|
||||||
|
uint8_t mac[6];
|
||||||
|
ssize_t nread;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
/* Get an instance of the TWI0 interface */
|
||||||
|
|
||||||
|
i2c = up_i2cinitialize(0);
|
||||||
|
if (!i2c)
|
||||||
|
{
|
||||||
|
ndbg("ERROR: Failed to initialize TWI0\n");
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Initialize the AT24 driver */
|
||||||
|
|
||||||
|
at24 = at24c_initialize(i2c);
|
||||||
|
if (!at24)
|
||||||
|
{
|
||||||
|
ndbg("ERROR: Failed to initialize the AT24 driver\n");
|
||||||
|
(void)up_i2cuninitialize(i2c);
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Configure the AT24 to access the extended memory region */
|
||||||
|
|
||||||
|
ret = at24->ioctl(at24, MTDIOC_EXTENDED, 1);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
ndbg("ERROR: AT24 ioctl(MTDIOC_EXTENDED) failed: %d\n", ret);
|
||||||
|
(void)up_i2cuninitialize(i2c);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Read the MAC address */
|
||||||
|
|
||||||
|
nread = at24->read(at24, AT24XX_MACADDR_OFFSET, 6, mac);
|
||||||
|
if (nread < 6)
|
||||||
|
{
|
||||||
|
ndbg("ERROR: AT24 read(AT24XX_MACADDR_OFFSET) failed: ld\n", (long)nread);
|
||||||
|
(void)up_i2cuninitialize(i2c);
|
||||||
|
return (int)nread;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Put the AT24 back in normal memory access mode */
|
||||||
|
|
||||||
|
ret = at24->ioctl(at24, MTDIOC_EXTENDED, 0);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
ndbg("ERROR: AT24 ioctl(MTDIOC_EXTENDED) failed: %d\n", ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Release the I2C instance.
|
||||||
|
* REVISIT: Need an interface to release the AT24 instance too
|
||||||
|
*/
|
||||||
|
|
||||||
|
ret = up_i2cuninitialize(i2c);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
ndbg("ERROR: Failed to release the I2C interface: %d\n", ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
nvdbg("MAC: %02x:%02x:%02x:%02x:%02x:%02x\n",
|
||||||
|
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||||
|
|
||||||
|
/* Now configure the EMAC driver to use this MAC address */
|
||||||
|
#warning Missing logic
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
# define sam_emac0_setmac()
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: arch_phy_irq
|
* Name: arch_phy_irq
|
||||||
*
|
*
|
||||||
@ -207,7 +302,6 @@ xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable)
|
|||||||
|
|
||||||
nvdbg("%s: handler=%p\n", intf, handler);
|
nvdbg("%s: handler=%p\n", intf, handler);
|
||||||
phydbg("EMAC0: devname=%s\n", SAMV7_EMAC0_DEVNAME);
|
phydbg("EMAC0: devname=%s\n", SAMV7_EMAC0_DEVNAME);
|
||||||
phydbg("EMAC1: devname=%s\n", SAMV7_EMAC1_DEVNAME);
|
|
||||||
|
|
||||||
if (strcmp(intf, SAMV7_EMAC0_DEVNAME) == 0)
|
if (strcmp(intf, SAMV7_EMAC0_DEVNAME) == 0)
|
||||||
{
|
{
|
||||||
|
@ -59,6 +59,7 @@
|
|||||||
#define HAVE_USBDEV 1
|
#define HAVE_USBDEV 1
|
||||||
#define HAVE_USBMONITOR 1
|
#define HAVE_USBMONITOR 1
|
||||||
#define HAVE_NETWORK 1
|
#define HAVE_NETWORK 1
|
||||||
|
#define HAVE_MACADDR 1
|
||||||
|
|
||||||
/* HSMCI */
|
/* HSMCI */
|
||||||
/* Can't support MMC/SD if the card interface is not enabled */
|
/* Can't support MMC/SD if the card interface is not enabled */
|
||||||
@ -160,6 +161,12 @@
|
|||||||
|
|
||||||
#if !defined(CONFIG_NET) || !defined(CONFIG_SAMV7_EMAC)
|
#if !defined(CONFIG_NET) || !defined(CONFIG_SAMV7_EMAC)
|
||||||
# undef HAVE_NETWORK
|
# undef HAVE_NETWORK
|
||||||
|
# undef HAVE_MACADDR
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(CONFIG_NSH_NOMAC) || !defined(CONFIG_SAMV7_TWIHS0) || \
|
||||||
|
!defined(CONFIG_MTD_AT24XX) || !defined(CONFIG_AT24XX_EXTENDED)
|
||||||
|
# undef HAVE_MACADDR
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* SAMV71-XULT GPIO Pin Definitions *************************************************/
|
/* SAMV71-XULT GPIO Pin Definitions *************************************************/
|
||||||
@ -365,6 +372,19 @@ int sam_hsmci_initialize(int slot, int minor);
|
|||||||
void weak_function sam_netinitialize(void);
|
void weak_function sam_netinitialize(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Name: sam_emac0_setmac
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Read the Ethernet MAC address from the AT24 FLASH and configure the Ethernet
|
||||||
|
* driver with that address.
|
||||||
|
*
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
#ifdef HAVE_MACADDR
|
||||||
|
int sam_emac0_setmac(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
/************************************************************************************
|
/************************************************************************************
|
||||||
* Name: sam_cardinserted
|
* Name: sam_cardinserted
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user