Fix ackbtn clearing the edge detector.

This commit is contained in:
NIIBE Yutaka
2018-10-01 12:56:41 +09:00
parent 02aa678d4c
commit 0ed2e95ea2
4 changed files with 54 additions and 14 deletions

View File

@@ -1,3 +1,18 @@
2018-10-01 NIIBE Yutaka <gniibe@fsij.org>
* contrib/ackbtn-stm32f103.c (PINCFG_EDGE): New.
(ackbtn_init): Use PINCFG_EDGE bit.
(ackbtn_enable): Configure the edge detector here.
(ackbtn_disable): Disable the edge detector.
* chopstx.c (chopstx_poll): Don't clear ->ready here.
(chx_cond_hook): Set ->ready = 0 when condition does
not meet.
(chopstx_claim_irq): Make sure clearing the interrupt.
(chx_intr_hook): Add the case when ->ready == 1.
(chopstx_intr_done): Set ->ready = 0.
(chx_join_hook): Set ->ready = 0 when it is still alive.
2018-09-29 NIIBE Yutaka <gniibe@fsij.org> 2018-09-29 NIIBE Yutaka <gniibe@fsij.org>
* VERSION: 1.10. * VERSION: 1.10.

16
NEWS
View File

@@ -1,6 +1,22 @@
NEWS - Noteworthy changes NEWS - Noteworthy changes
* Major changes in Chopstx 1.11
Released 2018-10-01
** Support calling chopstx_poll with intr->ready==1.
In version <= 1.10, it assumed that all events should be handled after
chopstx_poll, before calling chopstx_poll again. With having
chopstx_intr_done, it's OK now that chopstx_poll can be called again
not examining/handling all poll descriptors, but only parts of them.
** Acknowledge button change.
In 1.10, the action was "memorized" by the edge detector. Now, edge
detector is disabled by ackbtn_disable, and it is enabled by
ackbtn_enable. So, the status is cleared correctly.
* Major changes in Chopstx 1.10 * Major changes in Chopstx 1.10
Released 2018-09-29 Released 2018-09-29

View File

@@ -999,6 +999,7 @@ chopstx_claim_irq (chopstx_intr_t *intr, uint8_t 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); chx_disable_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 ();

View File

@@ -35,6 +35,8 @@
#include "sys.h" #include "sys.h"
static uint32_t pin_config; static uint32_t pin_config;
#define PINCFG_EDGE 0x80000000
#define PINCFG_EDGE_RISING PINCFG_EDGE
void void
ackbtn_init (chopstx_intr_t *intr) ackbtn_init (chopstx_intr_t *intr)
@@ -42,7 +44,6 @@ ackbtn_init (chopstx_intr_t *intr)
uint8_t irq_num; uint8_t irq_num;
uint32_t afio_exticr_index; uint32_t afio_exticr_index;
uint32_t afio_exticr_extiX_pY; uint32_t afio_exticr_extiX_pY;
int rising_edge;
switch (SYS_BOARD_ID) switch (SYS_BOARD_ID)
{ {
@@ -53,36 +54,43 @@ ackbtn_init (chopstx_intr_t *intr)
afio_exticr_extiX_pY = AFIO_EXTICR1_EXTI3_PA; afio_exticr_extiX_pY = AFIO_EXTICR1_EXTI3_PA;
irq_num = EXTI3_IRQ; irq_num = EXTI3_IRQ;
pin_config = 0x0008; /* EXTI_PR_PR3 == EXTI_IMR_MR3 == EXTI_RTSR_TR3 */ pin_config = 0x0008; /* EXTI_PR_PR3 == EXTI_IMR_MR3 == EXTI_RTSR_TR3 */
rising_edge = 1; pin_config |= PINCFG_EDGE_RISING;
break; break;
} }
chopstx_claim_irq (intr, irq_num);
/* Configure EXTI line */ /* Configure EXTI line */
if (afio_exticr_extiX_pY) if (afio_exticr_extiX_pY)
AFIO->EXTICR[afio_exticr_index] |= afio_exticr_extiX_pY; AFIO->EXTICR[afio_exticr_index] |= afio_exticr_extiX_pY;
/* Interrupt is masked, now */ /* Interrupt is masked, now */
EXTI->IMR &= ~pin_config; EXTI->IMR &= ~(pin_config & ~PINCFG_EDGE);
/* Configure which edge is detected */ chopstx_claim_irq (intr, irq_num);
if (rising_edge)
EXTI->RTSR |= pin_config;
else
EXTI->FTSR |= pin_config;
} }
void void
ackbtn_enable (void) ackbtn_enable (void)
{ {
EXTI->PR |= pin_config; /* Clear pending interrupt */ /* Clear pending interrupt */
EXTI->IMR |= pin_config; /* Enable interrupt clearing the mask */ EXTI->PR |= (pin_config & ~PINCFG_EDGE);
/* Enable interrupt, clearing the mask */
EXTI->IMR |= (pin_config & ~PINCFG_EDGE);
/* Configure which edge is detected */
if ((pin_config & PINCFG_EDGE))
EXTI->RTSR |= (pin_config & ~PINCFG_EDGE);
else
EXTI->FTSR |= (pin_config & ~PINCFG_EDGE);
} }
void void
ackbtn_disable (void) ackbtn_disable (void)
{ {
EXTI->IMR &= ~pin_config; /* Disable interrupt having the mask */ /* Disable interrupt having the mask */
EXTI->PR |= pin_config; /* Clear pending interrupt */ EXTI->IMR &= ~(pin_config & ~PINCFG_EDGE);
/* Clear pending interrupt */
/* Disable edge detection */
EXTI->RTSR &= ~(pin_config & ~PINCFG_EDGE);
EXTI->FTSR &= ~(pin_config & ~PINCFG_EDGE);
} }