From 25fed157e1b25bd3f6d672b8d3a4313d31cc80e8 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Thu, 19 May 2016 11:50:13 +0900 Subject: [PATCH] Follow the change of eventflag change, fixining long-standing bug of LED --- ChangeLog | 5 +++++ chopstx | 2 +- src/gnuk.h | 4 ++-- src/gnuk.ld.in | 4 ++-- src/usb-icc.c | 21 +++++++++++++-------- 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1c879e8..f9d90ae 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-05-19 Niibe Yutaka + + * src/gnuk.h (LED_START_COMMAND, LED_FINISH_COMMAND): Change the + values for a case both flags will be handled. + 2016-05-18 Niibe Yutaka * src/gnuk.ld.in: Tweak thread size. diff --git a/chopstx b/chopstx index 1b0fe5a..03bba13 160000 --- a/chopstx +++ b/chopstx @@ -1 +1 @@ -Subproject commit 1b0fe5a6e8141a2c37770e67d24ec341b02b7fc3 +Subproject commit 03bba13005914068dbf0707c77e6c22c5e76c9f5 diff --git a/src/gnuk.h b/src/gnuk.h index 1247a82..6f4c2b7 100644 --- a/src/gnuk.h +++ b/src/gnuk.h @@ -421,8 +421,8 @@ extern const uint8_t gnuk_string_serial[]; #define LED_ONESHOT 1 #define LED_TWOSHOTS 2 #define LED_SHOW_STATUS 4 -#define LED_START_COMMAND 8 -#define LED_FINISH_COMMAND 16 +#define LED_FINISH_COMMAND 8 +#define LED_START_COMMAND 16 #define LED_FATAL 32 #define LED_GNUK_EXEC 64 void led_blink (int spec); diff --git a/src/gnuk.ld.in b/src/gnuk.ld.in index 9ec8617..6283d7d 100644 --- a/src/gnuk.ld.in +++ b/src/gnuk.ld.in @@ -2,8 +2,8 @@ * ST32F103 memory setup. */ __main_stack_size__ = 0x0080; /* Exception handlers */ -__process0_stack_size__ = 0x0120; /* main */ -__process1_stack_size__ = 0x0160; /* ccid */ +__process0_stack_size__ = 0x0100; /* main */ +__process1_stack_size__ = 0x0180; /* ccid */ __process2_stack_size__ = 0x0160; /* rng */ __process3_stack_size__ = 0x1640; /* gpg */ __process4_stack_size__ = 0; /* --- */ diff --git a/src/usb-icc.c b/src/usb-icc.c index b15ef87..6588222 100644 --- a/src/usb-icc.c +++ b/src/usb-icc.c @@ -266,9 +266,7 @@ static void ccid_init (struct ccid *c, struct ep_in *epi, struct ep_out *epo, memset (&c->icc_header, 0, sizeof (struct icc_header)); c->sw1sw2[0] = 0x90; c->sw1sw2[1] = 0x00; - eventflag_init (&c->ccid_comm); c->application = 0; - eventflag_init (&c->openpgp_comm); c->epi = epi; c->epo = epo; c->a = a; @@ -1373,6 +1371,7 @@ void * ccid_thread (void *arg) { chopstx_intr_t interrupt; + uint32_t timeout; struct ep_in *epi = &endpoint_in; struct ep_out *epo = &endpoint_out; @@ -1380,9 +1379,13 @@ ccid_thread (void *arg) struct apdu *a = &apdu; (void)arg; + + eventflag_init (&ccid.ccid_comm); + eventflag_init (&ccid.openpgp_comm); + usb_lld_init (USB_INITIAL_FEATURE); chopstx_claim_irq (&interrupt, INTR_REQ_USB); - usb_interrupt_handler (); + usb_interrupt_handler (); /* For old SYS < 3.0 */ reset: epi_init (epi, ENDP1, notify_tx, c); @@ -1394,16 +1397,18 @@ ccid_thread (void *arg) while (1) { eventmask_t m; - uint32_t timeout = USB_ICC_TIMEOUT; chopstx_poll_cond_t poll_desc; - eventflag_set_poll_desc (&c->ccid_comm, &poll_desc); + eventflag_prepare_poll (&c->ccid_comm, &poll_desc); chopstx_poll (&timeout, 2, &interrupt, &poll_desc); if (interrupt.ready) - usb_interrupt_handler (); + { + usb_interrupt_handler (); + continue; + } - if (poll_desc.ready) - m = eventflag_wait (&c->ccid_comm); + timeout = USB_ICC_TIMEOUT; + m = eventflag_get (&c->ccid_comm); if (m == EV_USB_RESET) {