mirror of
https://github.com/apache/nuttx.git
synced 2026-09-27 18:58:27 +08:00
sched/irq: declare the object in scope
An object should be declared in block scope if its identifier is only referenced within one function(MISRA C-2012 Rule 8.9) Signed-off-by: pangzhen1 <pangzhen1@xiaomi.com>
This commit is contained in:
@@ -53,12 +53,6 @@ struct irq_thread_info_s
|
|||||||
FAR sem_t *sem; /* irq sem used to notify irq thread */
|
FAR sem_t *sem; /* irq sem used to notify irq thread */
|
||||||
};
|
};
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static pid_t g_irq_thread_pid[NR_IRQS];
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -151,6 +145,8 @@ int irq_attach_thread(int irq, xcpt_t isr, xcpt_t isrthread, FAR void *arg,
|
|||||||
int priority, int stack_size)
|
int priority, int stack_size)
|
||||||
{
|
{
|
||||||
#if NR_IRQS > 0
|
#if NR_IRQS > 0
|
||||||
|
static pid_t irq_thread_pid[NR_IRQS];
|
||||||
|
|
||||||
FAR char *argv[5];
|
FAR char *argv[5];
|
||||||
char arg1[32]; /* irq */
|
char arg1[32]; /* irq */
|
||||||
char arg2[32]; /* isr */
|
char arg2[32]; /* isr */
|
||||||
@@ -175,14 +171,14 @@ int irq_attach_thread(int irq, xcpt_t isr, xcpt_t isrthread, FAR void *arg,
|
|||||||
if (isrthread == NULL)
|
if (isrthread == NULL)
|
||||||
{
|
{
|
||||||
irq_detach(irq);
|
irq_detach(irq);
|
||||||
DEBUGASSERT(g_irq_thread_pid[ndx] != 0);
|
DEBUGASSERT(irq_thread_pid[ndx] != 0);
|
||||||
kthread_delete(g_irq_thread_pid[ndx]);
|
kthread_delete(irq_thread_pid[ndx]);
|
||||||
g_irq_thread_pid[ndx] = 0;
|
irq_thread_pid[ndx] = 0;
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_irq_thread_pid[ndx] != 0)
|
if (irq_thread_pid[ndx] != 0)
|
||||||
{
|
{
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
@@ -204,7 +200,7 @@ int irq_attach_thread(int irq, xcpt_t isr, xcpt_t isrthread, FAR void *arg,
|
|||||||
return pid;
|
return pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_irq_thread_pid[ndx] = pid;
|
irq_thread_pid[ndx] = pid;
|
||||||
|
|
||||||
#endif /* NR_IRQS */
|
#endif /* NR_IRQS */
|
||||||
|
|
||||||
|
|||||||
@@ -57,29 +57,6 @@ struct irq_work_info_s
|
|||||||
FAR struct kwork_wqueue_s *wqueue; /* Work queue. */
|
FAR struct kwork_wqueue_s *wqueue; /* Work queue. */
|
||||||
};
|
};
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#ifdef CONFIG_ARCH_MINIMAL_VECTORTABLE
|
|
||||||
static struct irq_work_info_s
|
|
||||||
g_irq_work_vector[CONFIG_ARCH_NUSER_INTERRUPTS];
|
|
||||||
#else
|
|
||||||
static struct irq_work_info_s g_irq_work_vector[NR_IRQS];
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static mutex_t g_irq_wqueue_lock = NXMUTEX_INITIALIZER;
|
|
||||||
static FAR struct kwork_wqueue_s *g_irq_wqueue[CONFIG_IRQ_NWORKS];
|
|
||||||
|
|
||||||
#ifdef IRQ_WORK_SECTION
|
|
||||||
static aligned_data(STACK_ALIGNMENT) uint8_t
|
|
||||||
g_irq_work_stack[CONFIG_IRQ_NWORKS][CONFIG_IRQ_WORK_STACKSIZE]
|
|
||||||
locate_data(IRQ_WORK_SECTION);
|
|
||||||
#else
|
|
||||||
static aligned_data(STACK_ALIGNMENT) uint8_t
|
|
||||||
g_irq_work_stack[CONFIG_IRQ_NWORKS][CONFIG_IRQ_WORK_STACKSIZE];
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -87,31 +64,42 @@ g_irq_work_stack[CONFIG_IRQ_NWORKS][CONFIG_IRQ_WORK_STACKSIZE];
|
|||||||
static
|
static
|
||||||
inline_function FAR struct kwork_wqueue_s *irq_get_wqueue(int priority)
|
inline_function FAR struct kwork_wqueue_s *irq_get_wqueue(int priority)
|
||||||
{
|
{
|
||||||
|
#ifdef IRQ_WORK_SECTION
|
||||||
|
static aligned_data(STACK_ALIGNMENT) uint8_t
|
||||||
|
irq_work_stack[CONFIG_IRQ_NWORKS][CONFIG_IRQ_WORK_STACKSIZE]
|
||||||
|
locate_data(CONFIG_IRQ_WORK_SECTION);
|
||||||
|
#else
|
||||||
|
static aligned_data(STACK_ALIGNMENT) uint8_t
|
||||||
|
irq_work_stack[CONFIG_IRQ_NWORKS][CONFIG_IRQ_WORK_STACKSIZE];
|
||||||
|
#endif
|
||||||
|
static mutex_t irq_wqueue_lock = NXMUTEX_INITIALIZER;
|
||||||
|
static FAR struct kwork_wqueue_s *irq_wqueue[CONFIG_IRQ_NWORKS];
|
||||||
|
|
||||||
FAR struct kwork_wqueue_s *queue;
|
FAR struct kwork_wqueue_s *queue;
|
||||||
int wqueue_priority;
|
int wqueue_priority;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
nxmutex_lock(&g_irq_wqueue_lock);
|
nxmutex_lock(&irq_wqueue_lock);
|
||||||
for (i = 0; g_irq_wqueue[i] != NULL && i < CONFIG_IRQ_NWORKS; i++)
|
for (i = 0; irq_wqueue[i] != NULL && i < CONFIG_IRQ_NWORKS; i++)
|
||||||
{
|
{
|
||||||
wqueue_priority = work_queue_priority_wq(g_irq_wqueue[i]);
|
wqueue_priority = work_queue_priority_wq(irq_wqueue[i]);
|
||||||
DEBUGASSERT(wqueue_priority >= SCHED_PRIORITY_MIN &&
|
DEBUGASSERT(wqueue_priority >= SCHED_PRIORITY_MIN &&
|
||||||
wqueue_priority <= SCHED_PRIORITY_MAX);
|
wqueue_priority <= SCHED_PRIORITY_MAX);
|
||||||
|
|
||||||
if (wqueue_priority == priority)
|
if (wqueue_priority == priority)
|
||||||
{
|
{
|
||||||
nxmutex_unlock(&g_irq_wqueue_lock);
|
nxmutex_unlock(&irq_wqueue_lock);
|
||||||
return g_irq_wqueue[i];
|
return irq_wqueue[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUGASSERT(i < CONFIG_IRQ_NWORKS);
|
DEBUGASSERT(i < CONFIG_IRQ_NWORKS);
|
||||||
|
|
||||||
queue = work_queue_create("isrwork", priority, g_irq_work_stack[i],
|
queue = work_queue_create("isrwork", priority, irq_work_stack[i],
|
||||||
CONFIG_IRQ_WORK_STACKSIZE, 1);
|
CONFIG_IRQ_WORK_STACKSIZE, 1);
|
||||||
|
|
||||||
g_irq_wqueue[i] = queue;
|
irq_wqueue[i] = queue;
|
||||||
nxmutex_unlock(&g_irq_wqueue_lock);
|
nxmutex_unlock(&irq_wqueue_lock);
|
||||||
return queue;
|
return queue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,6 +162,13 @@ static int irq_default_handler(int irq, FAR void *regs, FAR void *arg)
|
|||||||
int irq_attach_wqueue(int irq, xcpt_t isr, xcpt_t isrwork,
|
int irq_attach_wqueue(int irq, xcpt_t isr, xcpt_t isrwork,
|
||||||
FAR void *arg, int priority)
|
FAR void *arg, int priority)
|
||||||
{
|
{
|
||||||
|
#ifdef CONFIG_ARCH_MINIMAL_VECTORTABLE
|
||||||
|
static struct irq_work_info_s
|
||||||
|
irq_work_vector[CONFIG_ARCH_NUSER_INTERRUPTS];
|
||||||
|
#else
|
||||||
|
static struct irq_work_info_s irq_work_vector[NR_IRQS];
|
||||||
|
#endif
|
||||||
|
|
||||||
FAR struct irq_work_info_s *info;
|
FAR struct irq_work_info_s *info;
|
||||||
|
|
||||||
#if NR_IRQS > 0
|
#if NR_IRQS > 0
|
||||||
@@ -192,7 +187,7 @@ int irq_attach_wqueue(int irq, xcpt_t isr, xcpt_t isrwork,
|
|||||||
|
|
||||||
/* If the isrwork is NULL, then the ISR is being detached. */
|
/* If the isrwork is NULL, then the ISR is being detached. */
|
||||||
|
|
||||||
info = &g_irq_work_vector[ndx];
|
info = &irq_work_vector[ndx];
|
||||||
|
|
||||||
if (isrwork == NULL)
|
if (isrwork == NULL)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user