Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions arch/arm/src/am335x/am335x_can.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
#include <nuttx/config.h>

#include <assert.h>
#include <sched.h>

#include <arch/board/board.h>
#include <nuttx/irq.h>
#include <nuttx/spinlock.h>
#include <nuttx/arch.h>
#include <nuttx/can/can.h>

Expand Down Expand Up @@ -205,6 +207,8 @@ static struct can_dev_s g_can1dev =
};
#endif

static spinlock_t g_can_lock = SP_UNLOCKED;

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -1079,7 +1083,8 @@ struct can_dev_s *am335x_can_initialize(int port)

syslog(LOG_DEBUG, "CAN%d\n", port);

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_can_lock);
sched_lock();

#ifdef CONFIG_AM335X_CAN0
if (port == 0)
Expand Down Expand Up @@ -1109,11 +1114,13 @@ struct can_dev_s *am335x_can_initialize(int port)
{
canerr("Unsupported port: %d\n", port);
Comment thread
wangzhi16 marked this conversation as resolved.

leave_critical_section(flags);
spin_unlock_irqrestore(&g_can_lock, flags);
Comment thread
wangzhi16 marked this conversation as resolved.
sched_unlock();
return NULL;
}

leave_critical_section(flags);
spin_unlock_irqrestore(&g_can_lock, flags);
sched_unlock();

return candev;
}
Expand All @@ -1124,7 +1131,8 @@ void am335x_can_uninitialize(struct can_dev_s *dev)

DEBUGASSERT(dev);

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_can_lock);
sched_lock();

#ifdef CONFIG_AM335X_CAN0
if (dev == &g_can0dev)
Expand All @@ -1151,7 +1159,8 @@ void am335x_can_uninitialize(struct can_dev_s *dev)
canerr("Not a CAN device: %p\n", dev);
Comment thread
wangzhi16 marked this conversation as resolved.
}

leave_critical_section(flags);
spin_unlock_irqrestore(&g_can_lock, flags);
sched_unlock();
}

#endif
15 changes: 9 additions & 6 deletions arch/arm/src/am335x/am335x_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <errno.h>

#include <nuttx/irq.h>
#include <nuttx/spinlock.h>

#include "chip.h"
#include "arm_internal.h"
Expand Down Expand Up @@ -219,6 +220,8 @@ static const uint8_t *g_gpio_padctl[AM335X_GPIO_NPORTS] =
g_gpio3_padctl, /* GPIO3 */
};

static spinlock_t g_gpio_lock = SP_UNLOCKED;

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -364,7 +367,7 @@ int am335x_gpio_config(gpio_pinset_t pinset)

/* Configure the pin as an input initially to avoid any spurious outputs */

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_gpio_lock);

/* Configure based upon the pin mode */

Expand Down Expand Up @@ -407,7 +410,7 @@ int am335x_gpio_config(gpio_pinset_t pinset)
break;
}

leave_critical_section(flags);
spin_unlock_irqrestore(&g_gpio_lock, flags);
return ret;
}

Expand All @@ -425,9 +428,9 @@ void am335x_gpio_write(gpio_pinset_t pinset, bool value)
int port = (pinset & GPIO_PORT_MASK) >> GPIO_PORT_SHIFT;
int pin = (pinset & GPIO_PIN_MASK) >> GPIO_PIN_SHIFT;

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_gpio_lock);
am335x_gpio_setoutput(port, pin, value);
leave_critical_section(flags);
spin_unlock_irqrestore(&g_gpio_lock, flags);
}

/****************************************************************************
Expand All @@ -445,9 +448,9 @@ bool am335x_gpio_read(gpio_pinset_t pinset)
int pin = (pinset & GPIO_PIN_MASK) >> GPIO_PIN_SHIFT;
bool value;

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_gpio_lock);
value = am335x_gpio_getinput(port, pin);
leave_critical_section(flags);
spin_unlock_irqrestore(&g_gpio_lock, flags);
return value;
}

Expand Down
25 changes: 17 additions & 8 deletions arch/arm/src/am335x/am335x_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

#include <nuttx/arch.h>
#include <nuttx/irq.h>
#include <nuttx/spinlock.h>
#include <nuttx/clock.h>
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
Expand Down Expand Up @@ -185,6 +186,7 @@ struct am335x_i2c_priv_s

int refs; /* Reference count */
mutex_t lock; /* Mutual exclusion mutex */
spinlock_t spinlock; /* Spinlock */
Comment thread
wangzhi16 marked this conversation as resolved.
#ifndef CONFIG_I2C_POLLED
sem_t sem_isr; /* Interrupt wait semaphore */
#endif
Expand Down Expand Up @@ -317,6 +319,7 @@ static struct am335x_i2c_priv_s am335x_i2c0_priv =
.config = &am335x_i2c0_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
.spinlock = SP_UNLOCKED,
#ifndef CONFIG_I2C_POLLED
.sem_isr = SEM_INITIALIZER(0),
#endif
Expand Down Expand Up @@ -352,6 +355,7 @@ static struct am335x_i2c_priv_s am335x_i2c1_priv =
.config = &am335x_i2c1_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
.spinlock = SP_UNLOCKED,
#ifndef CONFIG_I2C_POLLED
.sem_isr = SEM_INITIALIZER(0),
#endif
Expand Down Expand Up @@ -387,6 +391,7 @@ static struct am335x_i2c_priv_s am335x_i2c2_priv =
.config = &am335x_i2c2_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
.spinlock = SP_UNLOCKED,
#ifndef CONFIG_I2C_POLLED
.sem_isr = SEM_INITIALIZER(0),
#endif
Expand Down Expand Up @@ -492,7 +497,7 @@ static inline int am335x_i2c_sem_waitdone(struct am335x_i2c_priv_s *priv)
uint32_t regval;
int ret;

flags = enter_critical_section();
flags = spin_lock_irqsave(&priv->spinlock);
Comment thread
xiaoxiang781216 marked this conversation as resolved.

/* Enable Interrupts when master mode */

Expand Down Expand Up @@ -529,6 +534,8 @@ static inline int am335x_i2c_sem_waitdone(struct am335x_i2c_priv_s *priv)
*/

priv->intstate = INTSTATE_WAITING;
spin_unlock_irqrestore(&priv->spinlock, flags);

do
{
/* Wait until either the transfer is complete or the timeout expires */
Expand All @@ -551,6 +558,8 @@ static inline int am335x_i2c_sem_waitdone(struct am335x_i2c_priv_s *priv)
}
}

flags = spin_lock_irqsave(&priv->spinlock);

/* Loop until the interrupt level transfer is complete. */

while (priv->intstate != INTSTATE_DONE);
Expand All @@ -563,7 +572,7 @@ static inline int am335x_i2c_sem_waitdone(struct am335x_i2c_priv_s *priv)

am335x_i2c_putreg(priv, AM335X_I2C_IRQ_EN_CLR_OFFSET, I2C_ICR_CLEARMASK);

leave_critical_section(flags);
spin_unlock_irqrestore(&priv->spinlock, flags);
return ret;
}
#else
Expand Down Expand Up @@ -992,7 +1001,7 @@ static int am335x_i2c_isr_process(struct am335x_i2c_priv_s *priv)
*/

#ifdef CONFIG_I2C_POLLED
irqstate_t flags = enter_critical_section();
irqstate_t flags = spin_lock_irqsave(&priv->spinlock);
#endif

/* Transmit a byte */
Expand All @@ -1001,7 +1010,7 @@ static int am335x_i2c_isr_process(struct am335x_i2c_priv_s *priv)
priv->dcnt--;

#ifdef CONFIG_I2C_POLLED
leave_critical_section(flags);
spin_unlock_irqrestore(&priv->spinlock, flags);
#endif
if ((priv->dcnt == 0) && ((priv->flags & I2C_M_NOSTOP) == 0))
{
Expand All @@ -1026,7 +1035,7 @@ static int am335x_i2c_isr_process(struct am335x_i2c_priv_s *priv)
*/

#ifdef CONFIG_I2C_POLLED
irqstate_t flags = enter_critical_section();
irqstate_t flags = spin_lock_irqsave(&priv->spinlock);
#endif

/* Receive a byte */
Expand All @@ -1036,7 +1045,7 @@ static int am335x_i2c_isr_process(struct am335x_i2c_priv_s *priv)
priv->dcnt--;

#ifdef CONFIG_I2C_POLLED
leave_critical_section(flags);
spin_unlock_irqrestore(&priv->spinlock, flags);
#endif
if ((priv->msgc <= 0) && (priv->dcnt == 0))
{
Expand Down Expand Up @@ -1100,7 +1109,7 @@ static int am335x_i2c_isr_process(struct am335x_i2c_priv_s *priv)
*/

#ifdef CONFIG_I2C_POLLED
irqstate_t flags = enter_critical_section();
irqstate_t flags = spin_lock_irqsave(&priv->spinlock);
#endif

/* Transmit a byte */
Expand All @@ -1109,7 +1118,7 @@ static int am335x_i2c_isr_process(struct am335x_i2c_priv_s *priv)
priv->dcnt--;

#ifdef CONFIG_I2C_POLLED
leave_critical_section(flags);
spin_unlock_irqrestore(&priv->spinlock, flags);
#endif
if ((priv->dcnt == 0) && ((priv->flags & I2C_M_NOSTOP) == 0))
{
Expand Down
12 changes: 10 additions & 2 deletions arch/arm/src/am335x/am335x_irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,21 @@
#include <assert.h>

#include <nuttx/arch.h>
#include <nuttx/spinlock.h>

#include "arm_internal.h"
#include "sctlr.h"

#include "am335x_gpio.h"
#include "am335x_irq.h"

/****************************************************************************
* Private Data
****************************************************************************/
#ifdef CONFIG_ARCH_IRQPRIO
static spinlock_t g_irq_lock = SP_UNLOCKED;
#endif

/****************************************************************************
* Public Data
****************************************************************************/
Expand Down Expand Up @@ -328,7 +336,7 @@ int up_prioritize_irq(int irq, int priority)
{
/* These operations must be atomic */

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_irq_lock);

#if 0 // TODO
/* Set the new priority */
Expand All @@ -340,7 +348,7 @@ int up_prioritize_irq(int irq, int priority)
putreg32(regval, regaddr);
#endif

leave_critical_section(flags);
spin_unlock_irqrestore(&g_irq_lock, flags);
return OK;
}

Expand Down
Loading