Allow calling chopstx_claim_irq when ready (disabled).
This commit is contained in:
@@ -1,3 +1,10 @@
|
|||||||
|
2019-05-10 NIIBE Yutaka <gniibe@fsij.org>
|
||||||
|
|
||||||
|
* chopstx.c (chopstx_claim_irq): Check INTR before the call.
|
||||||
|
|
||||||
|
* chopstx-cortex-m.c (chx_disable_intr): Have return value.
|
||||||
|
* chopstx-gnu-linux.c (chx_disable_intr): Likewise.
|
||||||
|
|
||||||
2019-05-10 NIIBE Yutaka <gniibe@fsij.org>
|
2019-05-10 NIIBE Yutaka <gniibe@fsij.org>
|
||||||
|
|
||||||
* mcu/sys-stm32f103.c: SYS version 4.0.
|
* mcu/sys-stm32f103.c: SYS version 4.0.
|
||||||
|
|||||||
@@ -179,10 +179,13 @@ chx_clr_intr (uint8_t irq_num)
|
|||||||
NVIC_ICPR (irq_num) = 1 << (irq_num & 0x1f);
|
NVIC_ICPR (irq_num) = 1 << (irq_num & 0x1f);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static int
|
||||||
chx_disable_intr (uint8_t irq_num)
|
chx_disable_intr (uint8_t irq_num)
|
||||||
{
|
{
|
||||||
|
int already_disabled = !!(NVIC_ICER (irq_num) & (1 << (irq_num & 0x1f)));
|
||||||
|
|
||||||
NVIC_ICER (irq_num) = 1 << (irq_num & 0x1f);
|
NVIC_ICER (irq_num) = 1 << (irq_num & 0x1f);
|
||||||
|
return already_disabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
* chopstx-gnu-linux.c - Threads and only threads: Arch specific code
|
* chopstx-gnu-linux.c - Threads and only threads: Arch specific code
|
||||||
* for GNU/Linux emulation
|
* for GNU/Linux emulation
|
||||||
*
|
*
|
||||||
* Copyright (C) 2017, 2018 Flying Stone Technology
|
* Copyright (C) 2017, 2018, 2019 Flying Stone Technology
|
||||||
* Author: NIIBE Yutaka <gniibe@fsij.org>
|
* Author: NIIBE Yutaka <gniibe@fsij.org>
|
||||||
*
|
*
|
||||||
* This file is a part of Chopstx, a thread library for embedded.
|
* This file is a part of Chopstx, a thread library for embedded.
|
||||||
@@ -89,10 +89,13 @@ chx_clr_intr (uint8_t irq_num)
|
|||||||
(void)irq_num;
|
(void)irq_num;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static int
|
||||||
chx_disable_intr (uint8_t irq_num)
|
chx_disable_intr (uint8_t irq_num)
|
||||||
{
|
{
|
||||||
|
int already_disabled = sigismember (&ss_cur, irq_num);
|
||||||
|
|
||||||
sigaddset (&ss_cur, irq_num);
|
sigaddset (&ss_cur, irq_num);
|
||||||
|
return already_disabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
@@ -1005,17 +1005,21 @@ chx_cond_hook (struct chx_px *px, struct chx_poll_head *pd)
|
|||||||
void
|
void
|
||||||
chopstx_claim_irq (chopstx_intr_t *intr, uint8_t irq_num)
|
chopstx_claim_irq (chopstx_intr_t *intr, uint8_t irq_num)
|
||||||
{
|
{
|
||||||
|
int intr_before_claim;
|
||||||
|
|
||||||
intr->type = CHOPSTX_POLL_INTR;
|
intr->type = CHOPSTX_POLL_INTR;
|
||||||
intr->ready = 0;
|
intr->ready = 0;
|
||||||
intr->irq_num = irq_num;
|
intr->irq_num = irq_num;
|
||||||
|
|
||||||
chx_cpu_sched_lock ();
|
chx_cpu_sched_lock ();
|
||||||
chx_spin_lock (&q_intr.lock);
|
chx_spin_lock (&q_intr.lock);
|
||||||
chx_disable_intr (irq_num);
|
intr_before_claim = chx_disable_intr (irq_num);
|
||||||
chx_clr_intr (irq_num);
|
chx_clr_intr (irq_num);
|
||||||
chx_set_intr_prio (irq_num);
|
chx_set_intr_prio (irq_num);
|
||||||
chx_spin_unlock (&q_intr.lock);
|
chx_spin_unlock (&q_intr.lock);
|
||||||
chx_cpu_sched_unlock ();
|
chx_cpu_sched_unlock ();
|
||||||
|
if (intr_before_claim)
|
||||||
|
intr->ready = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -660,31 +660,8 @@ tty_main (void *arg)
|
|||||||
struct usb_dev dev;
|
struct usb_dev dev;
|
||||||
int e;
|
int e;
|
||||||
|
|
||||||
#if defined(OLDER_SYS_H)
|
|
||||||
/*
|
|
||||||
* Historically (before sys < 3.0), NVIC priority setting for USB
|
|
||||||
* interrupt was done in usb_lld_sys_init. Thus this code.
|
|
||||||
*
|
|
||||||
* When USB interrupt occurs between usb_lld_init (which assumes
|
|
||||||
* ISR) and chopstx_claim_irq (which clears pending interrupt),
|
|
||||||
* invocation of usb_lld_event_handler won't occur.
|
|
||||||
*
|
|
||||||
* Calling usb_lld_event_handler is no harm even if there were no
|
|
||||||
* interrupts, thus, we call it unconditionally here, just in case
|
|
||||||
* if there is a request.
|
|
||||||
*
|
|
||||||
* We can't call usb_lld_init after chopstx_claim_irq, as
|
|
||||||
* usb_lld_init does its own setting for NVIC. Calling
|
|
||||||
* chopstx_claim_irq after usb_lld_init overrides that.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
usb_lld_init (&dev, VCOM_FEATURE_BUS_POWERED);
|
|
||||||
chopstx_claim_irq (&usb_intr, INTR_REQ_USB);
|
|
||||||
goto event_handle;
|
|
||||||
#else
|
|
||||||
chopstx_claim_irq (&usb_intr, INTR_REQ_USB);
|
chopstx_claim_irq (&usb_intr, INTR_REQ_USB);
|
||||||
usb_lld_init (&dev, VCOM_FEATURE_BUS_POWERED);
|
usb_lld_init (&dev, VCOM_FEATURE_BUS_POWERED);
|
||||||
#endif
|
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -675,24 +675,17 @@ tty_main (void *arg)
|
|||||||
#if defined(OLDER_SYS_H)
|
#if defined(OLDER_SYS_H)
|
||||||
/*
|
/*
|
||||||
* Historically (before sys < 3.0), NVIC priority setting for USB
|
* Historically (before sys < 3.0), NVIC priority setting for USB
|
||||||
* interrupt was done in usb_lld_sys_init. Thus this code.
|
* interrupt was done in usb_lld_sys_init for free standing
|
||||||
*
|
* application. Thus this compatibility code.
|
||||||
* When USB interrupt occurs between usb_lld_init (which assumes
|
|
||||||
* ISR) and chopstx_claim_irq (which clears pending interrupt),
|
|
||||||
* invocation of usb_lld_event_handler won't occur.
|
|
||||||
*
|
|
||||||
* Calling usb_lld_event_handler is no harm even if there were no
|
|
||||||
* interrupts, thus, we call it unconditionally here, just in case
|
|
||||||
* if there is a request.
|
|
||||||
*
|
*
|
||||||
* We can't call usb_lld_init after chopstx_claim_irq, as
|
* We can't call usb_lld_init after chopstx_claim_irq, as
|
||||||
* usb_lld_init does its own setting for NVIC. Calling
|
* usb_lld_init does its own setting for NVIC, which is incompatible
|
||||||
* chopstx_claim_irq after usb_lld_init overrides that.
|
* to Chopstx's interrupt handling. Calling chopstx_claim_irq after
|
||||||
|
* usb_lld_init overrides that for Chopstx.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
usb_lld_init (&dev, VCOM_FEATURE_BUS_POWERED);
|
usb_lld_init (&dev, VCOM_FEATURE_BUS_POWERED);
|
||||||
chopstx_claim_irq (&usb_intr, INTR_REQ_USB);
|
chopstx_claim_irq (&usb_intr, INTR_REQ_USB);
|
||||||
goto event_handle;
|
|
||||||
#else
|
#else
|
||||||
chopstx_claim_irq (&usb_intr, INTR_REQ_USB);
|
chopstx_claim_irq (&usb_intr, INTR_REQ_USB);
|
||||||
usb_lld_init (&dev, VCOM_FEATURE_BUS_POWERED);
|
usb_lld_init (&dev, VCOM_FEATURE_BUS_POWERED);
|
||||||
|
|||||||
@@ -660,24 +660,17 @@ tty_main (void *arg)
|
|||||||
#if defined(OLDER_SYS_H)
|
#if defined(OLDER_SYS_H)
|
||||||
/*
|
/*
|
||||||
* Historically (before sys < 3.0), NVIC priority setting for USB
|
* Historically (before sys < 3.0), NVIC priority setting for USB
|
||||||
* interrupt was done in usb_lld_sys_init. Thus this code.
|
* interrupt was done in usb_lld_sys_init for free standing
|
||||||
*
|
* application. Thus this compatibility code.
|
||||||
* When USB interrupt occurs between usb_lld_init (which assumes
|
|
||||||
* ISR) and chopstx_claim_irq (which clears pending interrupt),
|
|
||||||
* invocation of usb_lld_event_handler won't occur.
|
|
||||||
*
|
|
||||||
* Calling usb_lld_event_handler is no harm even if there were no
|
|
||||||
* interrupts, thus, we call it unconditionally here, just in case
|
|
||||||
* if there is a request.
|
|
||||||
*
|
*
|
||||||
* We can't call usb_lld_init after chopstx_claim_irq, as
|
* We can't call usb_lld_init after chopstx_claim_irq, as
|
||||||
* usb_lld_init does its own setting for NVIC. Calling
|
* usb_lld_init does its own setting for NVIC, which is incompatible
|
||||||
* chopstx_claim_irq after usb_lld_init overrides that.
|
* to Chopstx's interrupt handling. Calling chopstx_claim_irq after
|
||||||
|
* usb_lld_init overrides that for Chopstx.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
usb_lld_init (&dev, VCOM_FEATURE_BUS_POWERED);
|
usb_lld_init (&dev, VCOM_FEATURE_BUS_POWERED);
|
||||||
chopstx_claim_irq (&usb_intr, INTR_REQ_USB);
|
chopstx_claim_irq (&usb_intr, INTR_REQ_USB);
|
||||||
goto event_handle;
|
|
||||||
#else
|
#else
|
||||||
chopstx_claim_irq (&usb_intr, INTR_REQ_USB);
|
chopstx_claim_irq (&usb_intr, INTR_REQ_USB);
|
||||||
usb_lld_init (&dev, VCOM_FEATURE_BUS_POWERED);
|
usb_lld_init (&dev, VCOM_FEATURE_BUS_POWERED);
|
||||||
|
|||||||
@@ -725,24 +725,17 @@ cdc_main (void *arg)
|
|||||||
#if defined(OLDER_SYS_H)
|
#if defined(OLDER_SYS_H)
|
||||||
/*
|
/*
|
||||||
* Historically (before sys < 3.0), NVIC priority setting for USB
|
* Historically (before sys < 3.0), NVIC priority setting for USB
|
||||||
* interrupt was done in usb_lld_sys_init. Thus this code.
|
* interrupt was done in usb_lld_sys_init for free standing
|
||||||
*
|
* application. Thus this compatibility code.
|
||||||
* When USB interrupt occurs between usb_lld_init (which assumes
|
|
||||||
* ISR) and chopstx_claim_irq (which clears pending interrupt),
|
|
||||||
* invocation of usb_lld_event_handler won't occur.
|
|
||||||
*
|
|
||||||
* Calling usb_lld_event_handler is no harm even if there were no
|
|
||||||
* interrupts, thus, we call it unconditionally here, just in case
|
|
||||||
* if there is a request.
|
|
||||||
*
|
*
|
||||||
* We can't call usb_lld_init after chopstx_claim_irq, as
|
* We can't call usb_lld_init after chopstx_claim_irq, as
|
||||||
* usb_lld_init does its own setting for NVIC. Calling
|
* usb_lld_init does its own setting for NVIC, which is incompatible
|
||||||
* chopstx_claim_irq after usb_lld_init overrides that.
|
* to Chopstx's interrupt handling. Calling chopstx_claim_irq after
|
||||||
|
* usb_lld_init overrides that for Chopstx.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
usb_lld_init (&dev, VCOM_FEATURE_BUS_POWERED);
|
usb_lld_init (&dev, VCOM_FEATURE_BUS_POWERED);
|
||||||
chopstx_claim_irq (&usb_intr, INTR_REQ_USB);
|
chopstx_claim_irq (&usb_intr, INTR_REQ_USB);
|
||||||
goto event_handle;
|
|
||||||
#else
|
#else
|
||||||
chopstx_claim_irq (&usb_intr, INTR_REQ_USB);
|
chopstx_claim_irq (&usb_intr, INTR_REQ_USB);
|
||||||
usb_lld_init (&dev, VCOM_FEATURE_BUS_POWERED);
|
usb_lld_init (&dev, VCOM_FEATURE_BUS_POWERED);
|
||||||
|
|||||||
Reference in New Issue
Block a user