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+ static spinlock_t g_irq_lock = SP_UNLOCKED ;
49+
4350/****************************************************************************
4451 * Private Functions
4552 ****************************************************************************/
@@ -59,7 +66,8 @@ static void a1x_dumpintc(const char *msg, int irq)
5966
6067 /* Dump some relevant ARMv7 register contents */
6168
62- flags = enter_critical_section ();
69+ flags = spin_lock_irqsave (& g_irq_lock );
70+ sched_lock ();
6371
6472 irqinfo ("ARMv7 (%s, irq=%d):\n" , msg , irq );
6573 irqinfo (" CPSR: %08x SCTLR: %08x\n" , flags , cp15_rdsctlr ());
@@ -96,7 +104,8 @@ static void a1x_dumpintc(const char *msg, int irq)
96104 getreg32 (A1X_INTC_PRIO2 ), getreg32 (A1X_INTC_PRIO3 ),
97105 getreg32 (A1X_INTC_PRIO4 ));
98106
99- leave_critical_section (flags );
107+ spin_unlock_irqrestore (& g_irq_lock , flags );
108+ sched_unlock ();
100109}
101110#else
102111# define a1x_dumpintc (msg , irq )
@@ -297,7 +306,8 @@ void up_disable_irq(int irq)
297306 {
298307 /* These operations must be atomic */
299308
300- flags = enter_critical_section ();
309+ flags = spin_lock_irqsave (& g_irq_lock );
310+ sched_lock ();
301311
302312 /* Make sure that the interrupt is disabled. */
303313
@@ -314,7 +324,8 @@ void up_disable_irq(int irq)
314324 putreg32 (regval , regaddr );
315325
316326 a1x_dumpintc ("disable" , irq );
317- leave_critical_section (flags );
327+ spin_unlock_irqrestore (& g_irq_lock , flags );
328+ sched_unlock ();
318329 }
319330
320331#ifdef CONFIG_A1X_PIO_IRQ
@@ -345,7 +356,8 @@ void up_enable_irq(int irq)
345356 {
346357 /* These operations must be atomic */
347358
348- flags = enter_critical_section ();
359+ flags = spin_lock_irqsave (& g_irq_lock );
360+ sched_lock ();
349361
350362 /* Make sure that the interrupt is enabled. */
351363
@@ -362,7 +374,8 @@ void up_enable_irq(int irq)
362374 putreg32 (regval , regaddr );
363375
364376 a1x_dumpintc ("enable" , irq );
365- leave_critical_section (flags );
377+ spin_unlock_irqrestore (& g_irq_lock , flags );
378+ sched_unlock ();
366379 }
367380
368381#ifdef CONFIG_A1X_PIO_IRQ
@@ -398,7 +411,8 @@ int up_prioritize_irq(int irq, int priority)
398411 {
399412 /* These operations must be atomic */
400413
401- flags = enter_critical_section ();
414+ flags = spin_lock_irqsave (& g_irq_lock );
415+ sched_lock ();
402416
403417 /* Set the new priority */
404418
@@ -409,7 +423,8 @@ int up_prioritize_irq(int irq, int priority)
409423 putreg32 (regval , regaddr );
410424
411425 a1x_dumpintc ("prioritize" , irq );
412- leave_critical_section (flags );
426+ spin_unlock_irqrestore (& g_irq_lock , flags );
427+ sched_unlock ();
413428 return OK ;
414429 }
415430
0 commit comments