LED status loop change.

Using chopstx_poll, it requires more memory on stack.
This commit is contained in:
NIIBE Yutaka
2017-11-17 17:20:52 +09:00
parent ce82b347f9
commit fe94e1885b
3 changed files with 66 additions and 40 deletions

View File

@@ -1,3 +1,10 @@
2017-11-17 NIIBE Yutaka <gniibe@fsij.org>
* src/stack-def.h (SIZE_0): Increase.
* src/main.c (emit_led, display_status_code, main): Use
eventflag_wait_timeout instead of chopstx_usec_wait.
2017-11-17 NIIBE Yutaka <gniibe@fsij.org> 2017-11-17 NIIBE Yutaka <gniibe@fsij.org>
* regnual/regnual.c (calc_crc32): Enable CRC module. * regnual/regnual.c (calc_crc32): Enable CRC module.

View File

@@ -132,39 +132,52 @@ static void display_fatal_code (void)
static uint8_t led_inverted; static uint8_t led_inverted;
static void emit_led (int on_time, int off_time) static eventmask_t
emit_led (int on_time, int off_time)
{ {
eventmask_t m;
set_led (!led_inverted); set_led (!led_inverted);
chopstx_usec_wait (on_time); m = eventflag_wait_timeout (&led_event, on_time);
set_led (led_inverted); set_led (led_inverted);
chopstx_usec_wait (off_time); if (!m)
m = eventflag_wait_timeout (&led_event, off_time);
return m;
} }
static void display_status_code (void) static eventmask_t
display_status_code (void)
{ {
eventmask_t m;
enum ccid_state ccid_state = *ccid_state_p; enum ccid_state ccid_state = *ccid_state_p;
if (ccid_state == CCID_STATE_START) if (ccid_state == CCID_STATE_START)
emit_led (LED_TIMEOUT_ONE, LED_TIMEOUT_STOP); m = emit_led (LED_TIMEOUT_ONE, LED_TIMEOUT_STOP);
else else
/* OpenPGP card thread is running */ /* OpenPGP card thread is running */
{ {
emit_led ((auth_status & AC_ADMIN_AUTHORIZED)? m = emit_led ((auth_status & AC_ADMIN_AUTHORIZED)?
LED_TIMEOUT_ONE : LED_TIMEOUT_ZERO, LED_TIMEOUT_INTERVAL); LED_TIMEOUT_ONE : LED_TIMEOUT_ZERO, LED_TIMEOUT_INTERVAL);
emit_led ((auth_status & AC_OTHER_AUTHORIZED)? if (m) return m;
LED_TIMEOUT_ONE : LED_TIMEOUT_ZERO, LED_TIMEOUT_INTERVAL); m = emit_led ((auth_status & AC_OTHER_AUTHORIZED)?
emit_led ((auth_status & AC_PSO_CDS_AUTHORIZED)? LED_TIMEOUT_ONE : LED_TIMEOUT_ZERO, LED_TIMEOUT_INTERVAL);
LED_TIMEOUT_ONE : LED_TIMEOUT_ZERO, LED_TIMEOUT_INTERVAL); if (m) return m;
m = emit_led ((auth_status & AC_PSO_CDS_AUTHORIZED)?
LED_TIMEOUT_ONE : LED_TIMEOUT_ZERO, LED_TIMEOUT_INTERVAL);
if (m) return m;
if (ccid_state == CCID_STATE_WAIT) if (ccid_state == CCID_STATE_WAIT)
chopstx_usec_wait (LED_TIMEOUT_STOP * 2); m = eventflag_wait_timeout (&led_event, LED_TIMEOUT_STOP * 2);
else else
{ {
chopstx_usec_wait (LED_TIMEOUT_INTERVAL); m = eventflag_wait_timeout (&led_event, LED_TIMEOUT_INTERVAL);
emit_led (ccid_state == CCID_STATE_RECEIVE? if (m) return m;
LED_TIMEOUT_ONE : LED_TIMEOUT_ZERO, LED_TIMEOUT_STOP); m = emit_led (ccid_state == CCID_STATE_RECEIVE?
LED_TIMEOUT_ONE : LED_TIMEOUT_ZERO, LED_TIMEOUT_STOP);
} }
} }
return m;
} }
void void
@@ -344,30 +357,36 @@ main (int argc, const char *argv[])
eventmask_t m; eventmask_t m;
m = eventflag_wait (&led_event); m = eventflag_wait (&led_event);
switch (m)
{ do
case LED_ONESHOT: switch (m)
emit_led (100*1000, LED_TIMEOUT_STOP); {
break; case LED_ONESHOT:
case LED_TWOSHOTS: m = emit_led (100*1000, LED_TIMEOUT_STOP);
emit_led (50*1000, 50*1000); break;
emit_led (50*1000, LED_TIMEOUT_STOP); case LED_TWOSHOTS:
break; m = emit_led (50*1000, 50*1000);
case LED_SHOW_STATUS: if (m)
display_status_code (); break;
break; m = emit_led (50*1000, LED_TIMEOUT_STOP);
case LED_FATAL: break;
display_fatal_code (); case LED_SHOW_STATUS:
break; m = display_status_code ();
case LED_SYNC: break;
set_led (led_inverted); case LED_FATAL:
break; display_fatal_code ();
case LED_GNUK_EXEC: break;
goto exec; case LED_SYNC:
default: set_led (led_inverted);
emit_led (LED_TIMEOUT_ZERO, LED_TIMEOUT_STOP); m = 0;
break; break;
} case LED_GNUK_EXEC:
goto exec;
default:
m = emit_led (LED_TIMEOUT_ZERO, LED_TIMEOUT_STOP);
break;
}
while (m);
} }
exec: exec:

View File

@@ -3,7 +3,7 @@
#define SIZE_2 4096 #define SIZE_2 4096
#define SIZE_3 (5 * 4096) #define SIZE_3 (5 * 4096)
#else #else
#define SIZE_0 0x0100 /* Main */ #define SIZE_0 0x0160 /* Main */
#define SIZE_1 0x01a0 /* CCID */ #define SIZE_1 0x01a0 /* CCID */
#define SIZE_2 0x0180 /* RNG */ #define SIZE_2 0x0180 /* RNG */
#if MEMORY_SIZE >= 32 #if MEMORY_SIZE >= 32