From 9697694e4549e9a5a258f69bb6ad575fbebe268f Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Wed, 6 Jul 2016 11:32:14 +0900 Subject: [PATCH] pin CIR fixes --- ChangeLog | 6 ++++++ src/gnuk.h | 1 + src/pin-cir.c | 49 ++++++++++++++++++++++++++++++------------------- src/usb-ccid.c | 6 ++++-- src/usb_ctrl.c | 2 +- 5 files changed, 42 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index 902e3b7..9e073ef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2016-07-06 NIIBE Yutaka + + * src/pin-cir.c (cir_getchar): Use chopstx_poll. + * src/usb-ccid.c (usb_tx_done): Fix ifdef condition. + * src/usb_ctrl.c (usb_ctrl_write_finish): Fix ifdef nesting. + 2016-07-04 NIIBE Yutaka * doc/conf.py: Remove 'sphinx.ext.pngmath' and 'sphinx.ext.mathjax'. diff --git a/src/gnuk.h b/src/gnuk.h index 401dbac..8cc3db4 100644 --- a/src/gnuk.h +++ b/src/gnuk.h @@ -233,6 +233,7 @@ int gpg_change_keystring (int who_old, const uint8_t *old_ks, extern struct key_data kd[3]; #ifdef DEBUG +void stdout_init (void); #define DEBUG_MORE 1 /* * Debug functions in debug.c diff --git a/src/pin-cir.c b/src/pin-cir.c index f46b95d..915c152 100644 --- a/src/pin-cir.c +++ b/src/pin-cir.c @@ -28,7 +28,7 @@ #include "config.h" #include "board.h" #include "gnuk.h" -#include "stm32f103.h" +#include "mcu/stm32f103.h" #ifdef DEBUG #define DEBUG_CIR 1 @@ -51,10 +51,9 @@ cir_ext_enable (void) EXTI->IMR |= EXTI_IMR; } - -static chopstx_t pin_thread; -static uint32_t wait_usec; -static uint8_t notification; +static chopstx_mutex_t cir_input_mtx; +static chopstx_cond_t cir_input_cnd; +static int input_avail; uint8_t pin_input_buffer[MAX_PIN_CHARS]; uint8_t pin_input_len; @@ -500,9 +499,18 @@ hex (int x) return (x - 10) + 'a'; } +static int +check_input (void *arg) +{ + (void)arg; + return input_avail; +} + static int cir_getchar (uint32_t timeout) { + chopstx_poll_cond_t poll_desc; + struct chx_poll_head *pd_array[1] = { (struct chx_poll_head *)&poll_desc }; uint16_t cir_addr; #if defined(DEBUG_CIR) uint16_t *p; @@ -514,10 +522,15 @@ cir_getchar (uint32_t timeout) cir_ll_init (); - notification = 0; - wait_usec = timeout; - chopstx_usec_wait_var (&wait_usec); - if (notification == 0) + poll_desc.type = CHOPSTX_POLL_COND; + poll_desc.ready = 0; + poll_desc.cond = &cir_input_cnd; + poll_desc.mutex = &cir_input_mtx; + poll_desc.check = check_input; + poll_desc.arg = NULL; + + input_avail = 0; + if (chopstx_poll (&timeout, 1, pd_array) == 0) return -1; /* Sleep 200ms to avoid detecting chatter inputs. */ @@ -631,13 +644,10 @@ cir_getchar (uint32_t timeout) int pinpad_getline (int msg_code, uint32_t timeout) { - extern chopstx_t openpgp_card_thd; - (void)msg_code; DEBUG_INFO (">>>\r\n"); - pin_thread = openpgp_card_thd; pin_input_len = 0; while (1) { @@ -663,7 +673,6 @@ pinpad_getline (int msg_code, uint32_t timeout) } cir_ext_disable (); - pin_thread = NULL; return pin_input_len; } @@ -932,13 +941,12 @@ cir_timer_interrupt (void) { /* * Notify the thread, when it's waiting the input. - * If else, throw away the input. + * If else, the input is thrown away. */ - if (pin_thread) - { - notification = 1; - chopstx_wakeup_usec_wait (pin_thread); - } + chopstx_mutex_lock (&cir_input_mtx); + input_avail = 1; + chopstx_cond_signal (&cir_input_cnd); + chopstx_mutex_unlock (&cir_input_mtx); } #if defined(DEBUG_CIR) @@ -1004,6 +1012,9 @@ ext_main (void *arg) void cir_init (void) { + chopstx_mutex_init (&cir_input_mtx); + chopstx_cond_init (&cir_input_cnd); + /* * We use XOR function for three signals: TIMx_CH1, TIMx_CH2, and TIMx_CH3. * diff --git a/src/usb-ccid.c b/src/usb-ccid.c index 663d202..d9b4e60 100644 --- a/src/usb-ccid.c +++ b/src/usb-ccid.c @@ -709,7 +709,7 @@ usb_tx_done (uint8_t ep_num, uint16_t len) chopstx_mutex_unlock (&stdout.m_dev); } #endif -#ifdef PINPAD_SUPPORT +#ifdef PINPAD_DND_SUPPORT else if (ep_num == ENDP6) EP6_IN_Callback (len); #endif @@ -1659,7 +1659,9 @@ ccid_thread (void *arg) #ifdef DEBUG -static void +#include "usb-cdc.h" + +void stdout_init (void) { chopstx_mutex_init (&stdout.m); diff --git a/src/usb_ctrl.c b/src/usb_ctrl.c index 6464edb..9d5dfba 100644 --- a/src/usb_ctrl.c +++ b/src/usb_ctrl.c @@ -415,8 +415,8 @@ usb_ctrl_write_finish (struct usb_dev *dev) hid_report_saved = hid_report; } - } # endif + } #endif }