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
5 changes: 0 additions & 5 deletions arch/arm/src/phy62xx/irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include <assert.h>
#include <debug.h>

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

Expand Down Expand Up @@ -68,8 +67,6 @@ static void phy62xx_dumpnvic(const char *msg, int irq)
{
irqstate_t flags;

flags = enter_critical_section();

irqinfo("NVIC (%s, irq=%d):\n", msg, irq);
irqinfo(" ISER: %08x ICER: %08x\n",
getreg32(ARMV6M_NVIC_ISER), getreg32(ARMV6M_NVIC_ICER));
Expand All @@ -91,8 +88,6 @@ static void phy62xx_dumpnvic(const char *msg, int irq)
getreg32(ARMV6M_SYSCON_SCR), getreg32(ARMV6M_SYSCON_CCR));
irqinfo(" SHPR2: %08x SHPR3: %08x\n",
getreg32(ARMV6M_SYSCON_SHPR2), getreg32(ARMV6M_SYSCON_SHPR3));

leave_critical_section(flags);
}

#else
Expand Down
9 changes: 6 additions & 3 deletions arch/arm/src/phy62xx/phyplus_timer_lowerhalf.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#include <errno.h>
#include <assert.h>
#include <debug.h>
#include <nuttx/irq.h>
#include <nuttx/spinlock.h>
#include <nuttx/timers/timer.h>

#include <arch/board/board.h>
Expand Down Expand Up @@ -78,6 +78,7 @@ struct phyplus_lowerhalf_s
void *arg; /* Argument to upper half cb */
bool started; /* True: Timer has been started */
uint32_t timeout; /* Current timeout value (us) */
spinlock_t lock; /* Ensure mutually exclusive access */
};

/****************************************************************************
Expand Down Expand Up @@ -369,7 +370,7 @@ static void phyplus_setcallback(struct timer_lowerhalf_s *lower,
struct phyplus_lowerhalf_s *priv =
(struct phyplus_lowerhalf_s *)lower;
int ret = OK;
irqstate_t flags = enter_critical_section();
irqstate_t flags = spin_lock_irqsave_nopreempt(&priv->lock);

/* Save the new callback */

Expand Down Expand Up @@ -397,7 +398,7 @@ static void phyplus_setcallback(struct timer_lowerhalf_s *lower,
ret = phyplus_tim_setisr(priv->tim, NULL, NULL);
}

leave_critical_section(flags);
spin_unlock_irqrestore_nopreempt(&priv->lock, flags);
ASSERT(ret == OK);

/* #if 0
Expand Down Expand Up @@ -519,6 +520,8 @@ int phyplus_timer_initialize(const char *devpath, int timer)
return -EINVAL;
}

spin_lock_init(&lower->lock);

/* Register the timer driver as /dev/timerX. The returned value from
* timer_register is a handle that could be uswithed timer_unregister().
* REVISIT: The returned handle is discard here.
Expand Down
14 changes: 8 additions & 6 deletions arch/arm/src/phy62xx/phyplus_wdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <debug.h>
#include <assert.h>

#include <nuttx/irq.h>
#include <nuttx/spinlock.h>
#include <nuttx/clock.h>
#include <nuttx/timers/watchdog.h>
#include <arch/board/board.h>
Expand Down Expand Up @@ -102,6 +102,7 @@ struct phyplus_lowerhalf_s
bool started; /* true: The watchdog timer has been started */
bool intr_mode; /* 0: not use intr_callback handle, 1: use intr_callback handle */
WDG_CYCLE_Type_e wdt_cycle;
spinlock_t lock; /* Ensure mutually exclusive access */
};

static struct phyplus_lowerhalf_s g_wdgdev;
Expand Down Expand Up @@ -240,10 +241,10 @@ static int phyplus_wdt_start(struct watchdog_lowerhalf_s *lower)
* option bits, the watchdog is automatically enabled at power-on.
*/

flags = enter_critical_section();
flags = spin_lock_irqsave_nopreempt(&priv->lock);
pp_watchdog_start(priv->intr_mode, priv->wdt_cycle);
priv->started = true;
leave_critical_section(flags);
priv->started = true;
spin_unlock_irqrestore_nopreempt(&priv->lock, flags);
}

return OK;
Expand Down Expand Up @@ -307,11 +308,11 @@ static int phyplus_wdt_keepalive(struct watchdog_lowerhalf_s *lower)

wdinfo("wdt_feed\n");

flags = enter_critical_section();
flags = spin_lock_irqsave_nopreempt(&lower->lock);

pp_watchdog_feed();

leave_critical_section(flags);
spin_unlock_irqrestore_nopreempt(&lower->lock, flags);

return OK;
}
Expand Down Expand Up @@ -456,6 +457,7 @@ void phyplus_wdt_initialize(const char *devpath)
priv->started = false;
priv->intr_mode = false;
priv->wdt_cycle = WDG_2S;
spin_lock_init(&priv->lock);

pp_watchdog_init();

Expand Down
7 changes: 5 additions & 2 deletions arch/arm/src/rtl8720c/ameba_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <nuttx/kmalloc.h>
#include <nuttx/fs/fs.h>
#include <nuttx/fs/partition.h>
#include <nuttx/spinlock.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -131,14 +132,16 @@ static const struct partition_s ptable[5] =
},
};

static spinlock_t g_lock = SP_UNLOCKED;

/****************************************************************************
* Private Functions
****************************************************************************/

static irqstate_t flash_resource_lock(void)
{
irqstate_t state;
state = enter_critical_section();
state = spin_lock_irqsave(&g_lock);
icache_disable();
dcache_disable();
return state;
Expand All @@ -149,7 +152,7 @@ static void flash_resource_unlock(irqstate_t state)
dcache_enable();
icache_enable();
icache_invalidate();
leave_critical_section(state);
spin_unlock_irqrestore(&g_lock, state);
}

static int ameba_flash_erase(struct mtd_dev_s *dev,
Expand Down
15 changes: 10 additions & 5 deletions arch/arm/src/rtl8720c/ameba_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include <string.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/irq.h>
#include <nuttx/spinlock.h>
#include <nuttx/arch.h>
#include <nuttx/serial/serial.h>
#include <nuttx/fs/ioctl.h>
Expand Down Expand Up @@ -107,6 +107,7 @@ struct ameba_s
bool flow; /* flow control (RTS/CTS) enabled */
#endif
#endif
spinlock_t lock; /* Ensure mutually exclusive access */
};

/****************************************************************************
Expand Down Expand Up @@ -213,6 +214,7 @@ static struct ameba_s g_uart0priv =
.flow = true,
#endif
#endif
.lock = SP_UNLOCKED,
};

static uart_dev_t g_uart0port =
Expand Down Expand Up @@ -251,6 +253,7 @@ static struct ameba_s g_uart1priv =
.flow = true,
#endif
#endif
.lock = SP_UNLOCKED,
};

static uart_dev_t g_uart1port =
Expand Down Expand Up @@ -289,6 +292,7 @@ static struct ameba_s g_uart2priv =
.flow = true,
#endif
#endif
.lock = SP_UNLOCKED,
};

static uart_dev_t g_uart2port =
Expand Down Expand Up @@ -327,6 +331,7 @@ static struct ameba_s g_uart3priv =
.flow = true,
#endif
#endif
.lock = SP_UNLOCKED,
};

static uart_dev_t g_uart3port =
Expand Down Expand Up @@ -753,7 +758,7 @@ static int ameba_ioctl(struct file *filep, int cmd, unsigned long arg)
break;
}

flags = enter_critical_section();
flags = spin_lock_irqsave(&priv->lock);
cfsetispeed(termiosp, priv->baud);
termiosp->c_cflag = ((priv->parity != 0) ? PARENB : 0) |
((priv->parity == 1) ? PARODD : 0);
Expand All @@ -778,7 +783,7 @@ static int ameba_ioctl(struct file *filep, int cmd, unsigned long arg)
break;
}

leave_critical_section(flags);
spin_unlock_irqrestore(&priv->lock, flags);
}

break;
Expand All @@ -792,7 +797,7 @@ static int ameba_ioctl(struct file *filep, int cmd, unsigned long arg)
break;
}

flags = enter_critical_section();
flags = spin_lock_irqsave(&priv->lock);
switch (termiosp->c_cflag & CSIZE)
{
case CS5:
Expand Down Expand Up @@ -826,7 +831,7 @@ static int ameba_ioctl(struct file *filep, int cmd, unsigned long arg)
priv->flow = (termiosp->c_cflag & CRTSCTS) != 0;
#endif
ameba_setup(dev);
leave_critical_section(flags);
spin_unlock_irqrestore(&priv->lock, flags);
}

break;
Expand Down
19 changes: 11 additions & 8 deletions arch/arm/src/rtl8720c/ameba_wdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <nuttx/config.h>
#include <nuttx/arch.h>
#include <nuttx/spinlock.h>
#include <nuttx/timers/watchdog.h>
#include <stdint.h>
#include <sys/types.h>
Expand Down Expand Up @@ -53,6 +54,7 @@ struct ameba_lowerhalf_s
bool started; /* true: The watchdog timer has
* been started
*/
spinlock_t lock; /* Ensure mutually exclusive access */
};

/****************************************************************************
Expand Down Expand Up @@ -113,11 +115,11 @@ static int ameba_start(struct watchdog_lowerhalf_s *lower)
{
struct ameba_lowerhalf_s *priv = (struct ameba_lowerhalf_s *)lower;
irqstate_t flags;
flags = enter_critical_section();
flags = spin_lock_irqsave(&priv->lock);
priv->started = true;
priv->lastreset = clock_systime_ticks();
hal_misc_wdt_enable();
leave_critical_section(flags);
spin_unlock_irqrestore(&priv->lock, flags);
return OK;
}

Expand All @@ -140,12 +142,12 @@ static int ameba_stop(struct watchdog_lowerhalf_s *lower)
{
struct ameba_lowerhalf_s *priv = (struct ameba_lowerhalf_s *)lower;
irqstate_t flags;
flags = enter_critical_section();
flags = spin_lock_irqsave(&priv->lock);
hal_misc_wdt_disable();
priv->started = false;
priv->timeout = 0;
priv->lastreset = 0;
leave_critical_section(flags);
spin_unlock_irqrestore(&priv->lock, flags);
return OK;
}

Expand Down Expand Up @@ -176,10 +178,10 @@ static int ameba_keepalive(struct watchdog_lowerhalf_s *lower)

/* Reload the WDT timer */

flags = enter_critical_section();
flags = spin_lock_irqsave(&priv->lock);
priv->lastreset = clock_systime_ticks();
hal_misc_wdt_refresh();
leave_critical_section(flags);
spin_unlock_irqrestore(&priv->lock, flags);
return OK;
}

Expand Down Expand Up @@ -254,10 +256,10 @@ static int ameba_settimeout(struct watchdog_lowerhalf_s *lower,
{
struct ameba_lowerhalf_s *priv = (struct ameba_lowerhalf_s *)lower;
irqstate_t flags;
flags = enter_critical_section();
flags = spin_lock_irqsave(&priv->lock);
priv->timeout = timeout;
hal_misc_wdt_init(timeout * 1000);
leave_critical_section(flags);
spin_unlock_irqrestore(&priv->lock, flags);
return OK;
}

Expand Down Expand Up @@ -287,6 +289,7 @@ void ameba_wdt_initialize(void)
/* Initialize the driver state structure. */

priv->ops = &g_wdgops;
spin_lock_init(&priv->lock);
watchdog_register(CONFIG_WATCHDOG_DEVPATH,
(struct watchdog_lowerhalf_s *)priv);
}
Expand Down
31 changes: 12 additions & 19 deletions arch/arm/src/rtl8720c/amebaz_depend.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <nuttx/mqueue.h>
#include <nuttx/semaphore.h>
#include <nuttx/signal.h>
#include <nuttx/spinlock.h>
#include <nuttx/syslog/syslog.h>

/****************************************************************************
Expand All @@ -52,24 +53,23 @@ int __wrap_printf(const char *fmt, ...)

/* stdio.h Wrapper End */

static int uxcriticalnesting = 0;
static rspinlock_t g_lock = RSPINLOCK_INITIALIZER;
static irqstate_t g_flags = 0;

/* Critical Operation Start */

void save_and_cli(void)
{
enter_critical_section();
uxcriticalnesting++;
irqstate_t flags = rspin_lock_irqsave(&g_lock);
if (!rspin_lock_is_recursive(&g_lock))
{
g_flags = flags;
}
}

void restore_flags(void)
{
ASSERT(uxcriticalnesting);
uxcriticalnesting--;
if (uxcriticalnesting == 0)
{
leave_critical_section(0);
}
rspin_unlock_irqrestore(&g_lock, g_flags);
}

void rtw_enter_critical(void **plock, unsigned long *pirql)
Expand Down Expand Up @@ -871,21 +871,14 @@ uint32_t rtw_end_of_queue_search(struct list_head *head,

/* Device lock Wrapper Start */

static uint32_t mutex_init;
static atomic_t mutex_init;
static void *device_mutex[5];
static void device_mutex_init(uint32_t device)
{
irqstate_t status;
if (!(mutex_init & (1 << device)))
if (atomic_fetch_or(&mutex_init, (1 << device)) & (1 << device) == 0)
{
status = enter_critical_section();
if (!(mutex_init & (1 << device)))
{
rtw_mutex_init(&device_mutex[device]);
mutex_init |= (1 << device);
}

leave_critical_section(status);
rtw_mutex_init(&device_mutex[device]);
}
}

Expand Down
Loading
Loading