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 { |
| 12 | void (* init) ( void ); |
| 13 | void (* run) ( void ); |
| 14 | } conf_func; |
| 15 | |
| 16 | conf_func config_func_ptrs[] = { |
| 17 | {Sniffer_Init, Sniffer_run}, /* CFG_NUM_SNIFF */ |
Christina Quast | 541656c | 2015-03-05 15:42:40 +0100 | [diff] [blame] | 18 | {CCID_init, CCID_run}, /* CFG_NUM_CCID */ |
Christina Quast | fb524b9 | 2015-02-27 13:39:45 +0100 | [diff] [blame] | 19 | {Phone_Master_Init, Phone_run}, /* CFG_NUM_PHONE */ |
| 20 | {MITM_init, MITM_run}, /* CFG_NUM_MITM */ |
| 21 | }; |
| 22 | |
| 23 | |
| 24 | /*------------------------------------------------------------------------------ |
| 25 | * Internal variables |
| 26 | *------------------------------------------------------------------------------*/ |
Christina Quast | cafde00 | 2015-03-02 16:12:16 +0100 | [diff] [blame] | 27 | uint8_t simtrace_config = CFG_NUM_SNIFF; |
Christina Quast | c02571e | 2015-02-24 19:09:55 +0100 | [diff] [blame] | 28 | uint8_t conf_changed = 1; |
| 29 | |
| 30 | uint8_t rcvdChar = 0; |
Christina Quast | 1161b27 | 2015-02-25 14:15:57 +0100 | [diff] [blame] | 31 | uint32_t char_stat = 0; |
Christina Quast | 32906bb | 2015-02-24 11:35:19 +0100 | [diff] [blame] | 32 | |
| 33 | /*------------------------------------------------------------------------------ |
| 34 | * Main |
| 35 | *------------------------------------------------------------------------------*/ |
| 36 | |
| 37 | extern int main( void ) |
| 38 | { |
Christina Quast | 1161b27 | 2015-02-25 14:15:57 +0100 | [diff] [blame] | 39 | uint8_t isUsbConnected = 0; |
| 40 | |
Christina Quast | b5ebebe | 2015-03-05 15:43:01 +0100 | [diff] [blame] | 41 | LED_Configure(LED_NUM_RED); |
Christina Quast | 32906bb | 2015-02-24 11:35:19 +0100 | [diff] [blame] | 42 | LED_Configure(LED_NUM_GREEN); |
| 43 | LED_Set(LED_NUM_GREEN); |
| 44 | |
| 45 | /* Disable watchdog*/ |
| 46 | WDT_Disable( WDT ) ; |
| 47 | |
| 48 | PIO_InitializeInterrupts(0); |
| 49 | |
Christina Quast | 1161b27 | 2015-02-25 14:15:57 +0100 | [diff] [blame] | 50 | SIMtrace_USB_Initialize(); |
| 51 | |
| 52 | printf("%s", "USB init\n\r"); |
| 53 | |
Christina Quast | cafde00 | 2015-03-02 16:12:16 +0100 | [diff] [blame] | 54 | // FIXME: why don't we get any interrupts with this line?: |
Christina Quast | c5a78d7 | 2015-03-10 15:35:33 +0100 | [diff] [blame] | 55 | while(USBD_GetState() < USBD_STATE_CONFIGURED); |
Christina Quast | 32906bb | 2015-02-24 11:35:19 +0100 | [diff] [blame] | 56 | |
| 57 | TRACE_DEBUG("%s", "Start\n\r"); |
Christina Quast | cafde00 | 2015-03-02 16:12:16 +0100 | [diff] [blame] | 58 | |
Christina Quast | 1161b27 | 2015-02-25 14:15:57 +0100 | [diff] [blame] | 59 | printf("%s", "Start\n\r"); |
Christina Quast | 32906bb | 2015-02-24 11:35:19 +0100 | [diff] [blame] | 60 | while(1) { |
Christina Quast | 1161b27 | 2015-02-25 14:15:57 +0100 | [diff] [blame] | 61 | |
| 62 | /* Device is not configured */ |
| 63 | if (USBD_GetState() < USBD_STATE_CONFIGURED) { |
| 64 | |
| 65 | if (isUsbConnected) { |
| 66 | isUsbConnected = 0; |
| 67 | // TC_Stop(TC0, 0); |
| 68 | } |
| 69 | } |
| 70 | else if (isUsbConnected == 0) { |
| 71 | printf("USB is now configured\n\r"); |
| 72 | |
| 73 | isUsbConnected = 1; |
| 74 | // TC_Start(TC0, 0); |
| 75 | } |
Christina Quast | cafde00 | 2015-03-02 16:12:16 +0100 | [diff] [blame] | 76 | |
| 77 | // for (int i=0; i <10000; i++); |
| 78 | |
Christina Quast | 32906bb | 2015-02-24 11:35:19 +0100 | [diff] [blame] | 79 | /* FIXME: Or should we move the while loop into every case, and break out |
| 80 | in case the config changes? */ |
Christina Quast | fb524b9 | 2015-02-27 13:39:45 +0100 | [diff] [blame] | 81 | if (conf_changed) { |
| 82 | config_func_ptrs[simtrace_config-1].init(); |
| 83 | conf_changed = 0; |
| 84 | } else { |
| 85 | config_func_ptrs[simtrace_config-1].run(); |
Christina Quast | 32906bb | 2015-02-24 11:35:19 +0100 | [diff] [blame] | 86 | } |
| 87 | } |
| 88 | } |