Christina Quast | 32906bb | 2015-02-24 11:35:19 +0100 | [diff] [blame] | 1 | // FIXME: Copyright license here |
| 2 | /*------------------------------------------------------------------------------ |
| 3 | * Headers |
| 4 | *------------------------------------------------------------------------------*/ |
| 5 | |
| 6 | #include "board.h" |
Christina Quast | 32906bb | 2015-02-24 11:35:19 +0100 | [diff] [blame] | 7 | |
| 8 | /*------------------------------------------------------------------------------ |
Christina Quast | 32906bb | 2015-02-24 11:35:19 +0100 | [diff] [blame] | 9 | * Internal variables |
| 10 | *------------------------------------------------------------------------------*/ |
Christina Quast | fb524b9 | 2015-02-27 13:39:45 +0100 | [diff] [blame] | 11 | typedef struct { |
Christina Quast | 95d6616 | 2015-04-09 22:38:47 +0200 | [diff] [blame^] | 12 | void (* configure) ( void ); |
Christina Quast | fb524b9 | 2015-02-27 13:39:45 +0100 | [diff] [blame] | 13 | void (* init) ( void ); |
Christina Quast | 95d6616 | 2015-04-09 22:38:47 +0200 | [diff] [blame^] | 14 | void (* exit) ( void ); |
Christina Quast | fb524b9 | 2015-02-27 13:39:45 +0100 | [diff] [blame] | 15 | void (* run) ( void ); |
| 16 | } conf_func; |
| 17 | |
| 18 | conf_func config_func_ptrs[] = { |
Christina Quast | 95d6616 | 2015-04-09 22:38:47 +0200 | [diff] [blame^] | 19 | {Sniffer_configure, Sniffer_init, Sniffer_exit, Sniffer_run}, /* CFG_NUM_SNIFF */ |
| 20 | {CCID_configure, CCID_init, CCID_exit, CCID_run}, /* CFG_NUM_CCID */ |
| 21 | {Phone_configure, Phone_init, Phone_exit, Phone_run}, /* CFG_NUM_PHONE */ |
| 22 | {MITM_configure, MITM_init, MITM_exit, MITM_run}, /* CFG_NUM_MITM */ |
Christina Quast | fb524b9 | 2015-02-27 13:39:45 +0100 | [diff] [blame] | 23 | }; |
| 24 | |
| 25 | |
| 26 | /*------------------------------------------------------------------------------ |
| 27 | * Internal variables |
| 28 | *------------------------------------------------------------------------------*/ |
Christina Quast | 95d6616 | 2015-04-09 22:38:47 +0200 | [diff] [blame^] | 29 | volatile enum confNum simtrace_config = CFG_NUM_SNIFF; |
Christina Quast | 32906bb | 2015-02-24 11:35:19 +0100 | [diff] [blame] | 30 | |
| 31 | /*------------------------------------------------------------------------------ |
Christina Quast | 95d6616 | 2015-04-09 22:38:47 +0200 | [diff] [blame^] | 32 | * Main |
Christina Quast | 32906bb | 2015-02-24 11:35:19 +0100 | [diff] [blame] | 33 | *------------------------------------------------------------------------------*/ |
| 34 | |
| 35 | extern int main( void ) |
| 36 | { |
Christina Quast | 1161b27 | 2015-02-25 14:15:57 +0100 | [diff] [blame] | 37 | uint8_t isUsbConnected = 0; |
Christina Quast | 95d6616 | 2015-04-09 22:38:47 +0200 | [diff] [blame^] | 38 | enum confNum last_simtrace_config = simtrace_config; |
Christina Quast | 1161b27 | 2015-02-25 14:15:57 +0100 | [diff] [blame] | 39 | |
Christina Quast | b5ebebe | 2015-03-05 15:43:01 +0100 | [diff] [blame] | 40 | LED_Configure(LED_NUM_RED); |
Christina Quast | 32906bb | 2015-02-24 11:35:19 +0100 | [diff] [blame] | 41 | LED_Configure(LED_NUM_GREEN); |
| 42 | LED_Set(LED_NUM_GREEN); |
| 43 | |
| 44 | /* Disable watchdog*/ |
| 45 | WDT_Disable( WDT ) ; |
| 46 | |
| 47 | PIO_InitializeInterrupts(0); |
| 48 | |
Christina Quast | 1161b27 | 2015-02-25 14:15:57 +0100 | [diff] [blame] | 49 | SIMtrace_USB_Initialize(); |
| 50 | |
| 51 | printf("%s", "USB init\n\r"); |
| 52 | |
Christina Quast | 95d6616 | 2015-04-09 22:38:47 +0200 | [diff] [blame^] | 53 | for (unsigned int i = 0; i < sizeof(config_func_ptrs)/sizeof(config_func_ptrs[0]); ++i) |
| 54 | { |
| 55 | config_func_ptrs[i].configure(); |
| 56 | } |
| 57 | |
| 58 | config_func_ptrs[simtrace_config-1].init(); |
| 59 | last_simtrace_config = simtrace_config; |
| 60 | |
Christina Quast | cafde00 | 2015-03-02 16:12:16 +0100 | [diff] [blame] | 61 | // FIXME: why don't we get any interrupts with this line?: |
Christina Quast | c5a78d7 | 2015-03-10 15:35:33 +0100 | [diff] [blame] | 62 | while(USBD_GetState() < USBD_STATE_CONFIGURED); |
Christina Quast | 32906bb | 2015-02-24 11:35:19 +0100 | [diff] [blame] | 63 | |
| 64 | TRACE_DEBUG("%s", "Start\n\r"); |
Christina Quast | cafde00 | 2015-03-02 16:12:16 +0100 | [diff] [blame] | 65 | |
Christina Quast | 1161b27 | 2015-02-25 14:15:57 +0100 | [diff] [blame] | 66 | printf("%s", "Start\n\r"); |
Christina Quast | 32906bb | 2015-02-24 11:35:19 +0100 | [diff] [blame] | 67 | while(1) { |
Christina Quast | 1161b27 | 2015-02-25 14:15:57 +0100 | [diff] [blame] | 68 | |
| 69 | /* Device is not configured */ |
| 70 | if (USBD_GetState() < USBD_STATE_CONFIGURED) { |
| 71 | |
| 72 | if (isUsbConnected) { |
| 73 | isUsbConnected = 0; |
| 74 | // TC_Stop(TC0, 0); |
| 75 | } |
| 76 | } |
| 77 | else if (isUsbConnected == 0) { |
| 78 | printf("USB is now configured\n\r"); |
| 79 | |
| 80 | isUsbConnected = 1; |
| 81 | // TC_Start(TC0, 0); |
Christina Quast | 95d6616 | 2015-04-09 22:38:47 +0200 | [diff] [blame^] | 82 | } |
Christina Quast | cafde00 | 2015-03-02 16:12:16 +0100 | [diff] [blame] | 83 | |
| 84 | // for (int i=0; i <10000; i++); |
| 85 | |
Christina Quast | 32906bb | 2015-02-24 11:35:19 +0100 | [diff] [blame] | 86 | /* FIXME: Or should we move the while loop into every case, and break out |
| 87 | in case the config changes? */ |
Christina Quast | 95d6616 | 2015-04-09 22:38:47 +0200 | [diff] [blame^] | 88 | if (last_simtrace_config != simtrace_config) { |
| 89 | config_func_ptrs[last_simtrace_config-1].exit(); |
Christina Quast | fb524b9 | 2015-02-27 13:39:45 +0100 | [diff] [blame] | 90 | config_func_ptrs[simtrace_config-1].init(); |
Christina Quast | 95d6616 | 2015-04-09 22:38:47 +0200 | [diff] [blame^] | 91 | last_simtrace_config = simtrace_config; |
Christina Quast | fb524b9 | 2015-02-27 13:39:45 +0100 | [diff] [blame] | 92 | } else { |
| 93 | config_func_ptrs[simtrace_config-1].run(); |
Christina Quast | 32906bb | 2015-02-24 11:35:19 +0100 | [diff] [blame] | 94 | } |
| 95 | } |
| 96 | } |