From 2b762267f39003ed89f59fa602ff25fd7cfded0e Mon Sep 17 00:00:00 2001 From: hujun5 Date: Thu, 19 Dec 2024 20:09:00 +0800 Subject: [PATCH] imx9_flexcan: use small lock in arch/arm/src/imx9/imx9_flexcan.c reason: We would like to replace the big lock with a small lock. Signed-off-by: hujun5 --- arch/arm/src/imx9/imx9_flexcan.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/arch/arm/src/imx9/imx9_flexcan.c b/arch/arm/src/imx9/imx9_flexcan.c index 83409d027b..36b51ef0c8 100644 --- a/arch/arm/src/imx9/imx9_flexcan.c +++ b/arch/arm/src/imx9/imx9_flexcan.c @@ -312,6 +312,7 @@ struct imx9_driver_s struct flexcan_timeseg data_timing; /* Timing for data phase */ const struct flexcan_config_s *config; + spinlock_t lock; #ifdef CONFIG_NET_CAN_RAW_TX_DEADLINE struct txmbstats txmb[TXMBCOUNT]; @@ -811,7 +812,8 @@ static int imx9_txpoll(struct net_driver_s *dev) * the field d_len is set to a value > 0. */ - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&priv->lock); + sched_lock(); if (priv->dev.d_len > 0) { @@ -827,12 +829,14 @@ static int imx9_txpoll(struct net_driver_s *dev) if (imx9_txringfull(priv)) { - spin_unlock_irqrestore(NULL, flags); + sched_unlock(); + spin_unlock_irqrestore(&priv->lock, flags); return -EBUSY; } } - spin_unlock_irqrestore(NULL, flags); + sched_unlock(); + spin_unlock_irqrestore(&priv->lock, flags); /* If zero is returned, the polling will continue until all connections * have been examined. @@ -1642,7 +1646,7 @@ static int imx9_init_eccram(struct imx9_driver_s *priv) uint32_t regval; irqstate_t flags; - flags = enter_critical_section(); + flags = spin_lock_irqsave(&priv->lock); regval = getreg32(priv->base + IMX9_CAN_CTRL2_OFFSET); @@ -1668,7 +1672,7 @@ static int imx9_init_eccram(struct imx9_driver_s *priv) regval &= ~CAN_CTRL2_WRMFRZ; - leave_critical_section(flags); + spin_unlock_irqrestore(&priv->lock, flags); return 0; } @@ -2105,6 +2109,7 @@ int imx9_caninitialize(int intf) priv->dev.d_ioctl = imx9_ioctl; /* Support CAN ioctl() calls */ #endif priv->dev.d_private = (void *)priv; /* Used to recover private state from dev */ + spin_lock_init(&priv->lock); /* Put the interface in the down state. This usually amounts to resetting * the device and/or calling imx9_ifdown().