Skip to content

Commit

Permalink
arch/xtensa/esp32: Replace nxsig_usleep() with up_udelay() to
Browse files Browse the repository at this point in the history
avoid context switching, and the actual time difference caused
by the setting of TICK in nxsig_usleep() is quite large.
  • Loading branch information
nuttxs committed Aug 8, 2024
1 parent 3862b71 commit 9aded43
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions arch/xtensa/src/esp32/esp32_emac.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ struct esp32_emac_s
****************************************************************************/

static struct esp32_emac_s s_esp32_emac;
static mutex_t g_lock = NXMUTEX_INITIALIZER;

/****************************************************************************
* Private Function Prototypes
Expand Down Expand Up @@ -564,7 +565,7 @@ static int emac_config(void)
/* Hardware reset PHY chip */

esp32_gpiowrite(EMAC_PHYRST_PIN, false);
nxsig_usleep(50);
up_udelay(50);
esp32_gpiowrite(EMAC_PHYRST_PIN, true);
#endif

Expand Down Expand Up @@ -597,7 +598,7 @@ static int emac_config(void)
break;
}

nxsig_usleep(10);
up_udelay(10);
}

if (i >= EMAC_RESET_TO)
Expand Down Expand Up @@ -942,7 +943,7 @@ static int emac_read_phy(uint16_t dev_addr,

for (i = 0; i < EMAC_READPHY_TO; i++)
{
nxsig_usleep(100);
up_udelay(100);

val = emac_get_reg(EMAC_MAR_OFFSET);
if (!(val & EMAC_PIB))
Expand Down Expand Up @@ -1004,7 +1005,7 @@ static int emac_write_phy(uint16_t dev_addr,

for (i = 0; i < EMAC_WRITEPHY_TO; i++)
{
nxsig_usleep(100);
up_udelay(100);

val = emac_get_reg(EMAC_MAR_OFFSET);
if (!(val & EMAC_PIB))
Expand Down Expand Up @@ -1047,7 +1048,7 @@ static int emac_wait_linkup(struct esp32_emac_s *priv)

for (i = 0; i < EMAC_WAITLINK_TO; i++)
{
nxsig_usleep(10);
up_udelay(10);

ret = emac_read_phy(EMAC_PHY_ADDR, MII_MSR, &val);
if (ret != 0)
Expand Down Expand Up @@ -1184,7 +1185,7 @@ static int emac_init_phy(struct esp32_emac_s *priv)

for (i = 0; i < EMAC_RSTPHY_TO; i++)
{
nxsig_usleep(100);
up_udelay(100);

ret = emac_read_phy(EMAC_PHY_ADDR, MII_MCR, &val);
if (ret != 0)
Expand Down Expand Up @@ -1947,11 +1948,16 @@ static int emac_rmmac(struct net_driver_s *dev, const uint8_t *mac)
#ifdef CONFIG_NETDEV_IOCTL
static int emac_ioctl(struct net_driver_s *dev, int cmd, unsigned long arg)
{
#if defined(CONFIG_NETDEV_PHY_IOCTL) && defined(CONFIG_ARCH_PHY_INTERRUPT)
struct esp32_emacmac_s *priv = NET2PRIV(dev);
#endif
int ret;

/* Get exclusive access to the device structures */

ret = nxmutex_lock(&g_lock);
if (ret < 0)
{
return ret;
}

switch (cmd)
{
#ifdef CONFIG_NETDEV_PHY_IOCTL
Expand Down Expand Up @@ -2003,6 +2009,7 @@ static int emac_ioctl(struct net_driver_s *dev, int cmd, unsigned long arg)
break;
}

nxmutex_unlock(&g_lock);
return ret;
}
#endif /* CONFIG_NETDEV_IOCTL */
Expand Down

0 comments on commit 9aded43

Please sign in to comment.