Adding timeout for press button of 15 secs.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos
2022-05-05 20:03:17 +02:00
parent cddc3b2dec
commit 9c5250f6ca
2 changed files with 20 additions and 6 deletions

View File

@@ -379,17 +379,31 @@ void led_set_blink(uint32_t mode) {
void execute_tasks(); void execute_tasks();
static void wait_button() { static bool wait_button() {
uint32_t start_button = board_millis();
bool timeout = false;
led_set_blink((1000 << 16) | 100); led_set_blink((1000 << 16) | 100);
while (board_button_read() == false) { while (board_button_read() == false) {
execute_tasks(); execute_tasks();
//sleep_ms(10); //sleep_ms(10);
if (start_button + 15000 < board_millis()) { /* timeout */
timeout = true;
break;
}
} }
while (board_button_read() == true) { if (!timeout) {
execute_tasks(); while (board_button_read() == true) {
//sleep_ms(10); execute_tasks();
//sleep_ms(10);
if (start_button + 15000 < board_millis()) { /* timeout */
timeout = true;
break;
}
}
} }
led_set_blink(BLINK_PROCESSING); led_set_blink(BLINK_PROCESSING);
return timeout;
} }
void usb_tx_enable(const uint8_t *buf, uint32_t len) { void usb_tx_enable(const uint8_t *buf, uint32_t len) {
@@ -1419,8 +1433,7 @@ void ccid_task(void) {
ccid_prepare_receive(c); ccid_prepare_receive(c);
} }
else if (m == EV_PRESS_BUTTON) { else if (m == EV_PRESS_BUTTON) {
wait_button(); uint32_t flag = wait_button() ? EV_BUTTON_TIMEOUT : EV_BUTTON_PRESSED;
uint32_t flag = EV_BUTTON_PRESSED;
queue_try_add(&c->card_comm, &flag); queue_try_add(&c->card_comm, &flag);
} }
} }

View File

@@ -88,6 +88,7 @@ struct apdu {
#define EV_CMD_AVAILABLE 4 #define EV_CMD_AVAILABLE 4
#define EV_EXIT 8 #define EV_EXIT 8
#define EV_BUTTON_PRESSED 16 #define EV_BUTTON_PRESSED 16
#define EV_BUTTON_TIMEOUT 32
//Variables set by core1 //Variables set by core1
extern queue_t *ccid_comm; extern queue_t *ccid_comm;