3030#include <assert.h>
3131#include <errno.h>
3232#include <debug.h>
33+ #include <sched.h>
3334
34- #include <nuttx/irq .h>
35+ #include <nuttx/spinlock .h>
3536#include <nuttx/arch.h>
3637
3738#include "arm_internal.h"
4041#include "a1x_pio.h"
4142#include "a1x_irq.h"
4243
44+ /****************************************************************************
45+ * Private Data
46+ ****************************************************************************/
47+
48+ #if defined(CONFIG_DEBUG_IRQ_INFO )
49+ static spinlock_t g_irq_lock = SP_UNLOCKED ;
50+ #endif
51+
4352/****************************************************************************
4453 * Private Functions
4554 ****************************************************************************/
@@ -59,7 +68,8 @@ static void a1x_dumpintc(const char *msg, int irq)
5968
6069 /* Dump some relevant ARMv7 register contents */
6170
62- flags = enter_critical_section ();
71+ flags = spin_lock_irqsave (& g_irq_lock );
72+ sched_lock ();
6373
6474 irqinfo ("ARMv7 (%s, irq=%d):\n" , msg , irq );
6575 irqinfo (" CPSR: %08x SCTLR: %08x\n" , flags , cp15_rdsctlr ());
@@ -96,7 +106,8 @@ static void a1x_dumpintc(const char *msg, int irq)
96106 getreg32 (A1X_INTC_PRIO2 ), getreg32 (A1X_INTC_PRIO3 ),
97107 getreg32 (A1X_INTC_PRIO4 ));
98108
99- leave_critical_section (flags );
109+ spin_unlock_irqrestore (& g_irq_lock , flags );
110+ sched_unlock ();
100111}
101112#else
102113# define a1x_dumpintc (msg , irq )
@@ -297,7 +308,8 @@ void up_disable_irq(int irq)
297308 {
298309 /* These operations must be atomic */
299310
300- flags = enter_critical_section ();
311+ flags = spin_lock_irqsave (& g_irq_lock );
312+ sched_lock ();
301313
302314 /* Make sure that the interrupt is disabled. */
303315
@@ -314,7 +326,8 @@ void up_disable_irq(int irq)
314326 putreg32 (regval , regaddr );
315327
316328 a1x_dumpintc ("disable" , irq );
317- leave_critical_section (flags );
329+ spin_unlock_irqrestore (& g_irq_lock , flags );
330+ sched_unlock ();
318331 }
319332
320333#ifdef CONFIG_A1X_PIO_IRQ
@@ -345,7 +358,8 @@ void up_enable_irq(int irq)
345358 {
346359 /* These operations must be atomic */
347360
348- flags = enter_critical_section ();
361+ flags = spin_lock_irqsave (& g_irq_lock );
362+ sched_lock ();
349363
350364 /* Make sure that the interrupt is enabled. */
351365
@@ -362,7 +376,8 @@ void up_enable_irq(int irq)
362376 putreg32 (regval , regaddr );
363377
364378 a1x_dumpintc ("enable" , irq );
365- leave_critical_section (flags );
379+ spin_unlock_irqrestore (& g_irq_lock , flags );
380+ sched_unlock ();
366381 }
367382
368383#ifdef CONFIG_A1X_PIO_IRQ
@@ -398,7 +413,8 @@ int up_prioritize_irq(int irq, int priority)
398413 {
399414 /* These operations must be atomic */
400415
401- flags = enter_critical_section ();
416+ flags = spin_lock_irqsave (& g_irq_lock );
417+ sched_lock ();
402418
403419 /* Set the new priority */
404420
@@ -409,7 +425,8 @@ int up_prioritize_irq(int irq, int priority)
409425 putreg32 (regval , regaddr );
410426
411427 a1x_dumpintc ("prioritize" , irq );
412- leave_critical_section (flags );
428+ spin_unlock_irqrestore (& g_irq_lock , flags );
429+ sched_unlock ();
413430 return OK ;
414431 }
415432
0 commit comments