fsm completion event handling from main loop

The main loop will now poll for finished/failed transactions and handle
them, this was previously handled during the last rx interrupt of a
transaction, which was bad for timing. This does also fix malloc/free
while handling interrupts.

Change-Id: I055110720089e20e65db592eccc3ce4d618e8c63
diff --git a/ccid_common/ccid_device.h b/ccid_common/ccid_device.h
index 38a71db..f364f72 100644
--- a/ccid_common/ccid_device.h
+++ b/ccid_common/ccid_device.h
@@ -57,6 +57,8 @@
 	struct ccid_pars_decoded proposed_pars;
 	/* default parameters; applied on ResetParameters */
 	const struct ccid_pars_decoded *default_pars;
+	volatile uint32_t event;
+	volatile void* event_data;
 };
 
 /* CCID operations provided by USB transport layer */
@@ -86,6 +88,7 @@
 			  const struct ccid_pars_decoded *pars_dec);
 	int (*set_rate_and_clock)(struct ccid_slot *cs, uint32_t freq_hz, uint32_t rate_bps);
 	void (*icc_set_insertion_status)(struct ccid_slot *cs, bool present);
+	int (*handle_fsm_events)(struct ccid_slot *cs, bool enable);
 };
 
 /* An instance of CCID (i.e. a card reader device) */