blob: 347480803ae3082793bf1af5bc6258753046361f [file] [log] [blame]
Christina Quast32906bb2015-02-24 11:35:19 +01001// FIXME: Copyright license here
2/*------------------------------------------------------------------------------
3 * Headers
4 *------------------------------------------------------------------------------*/
5
6#include "board.h"
Christina Quast32906bb2015-02-24 11:35:19 +01007
8/*------------------------------------------------------------------------------
Christina Quast32906bb2015-02-24 11:35:19 +01009 * Internal variables
10 *------------------------------------------------------------------------------*/
Christina Quastfb524b92015-02-27 13:39:45 +010011typedef struct {
12 void (* init) ( void );
13 void (* run) ( void );
14} conf_func;
15
16conf_func config_func_ptrs[] = {
17 {Sniffer_Init, Sniffer_run}, /* CFG_NUM_SNIFF */
Christina Quast541656c2015-03-05 15:42:40 +010018 {CCID_init, CCID_run}, /* CFG_NUM_CCID */
Christina Quastfb524b92015-02-27 13:39:45 +010019 {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 Quastcafde002015-03-02 16:12:16 +010027uint8_t simtrace_config = CFG_NUM_SNIFF;
Christina Quastc02571e2015-02-24 19:09:55 +010028uint8_t conf_changed = 1;
29
30uint8_t rcvdChar = 0;
Christina Quast1161b272015-02-25 14:15:57 +010031uint32_t char_stat = 0;
Christina Quast32906bb2015-02-24 11:35:19 +010032
33/*------------------------------------------------------------------------------
34 * Main
35 *------------------------------------------------------------------------------*/
36
37extern int main( void )
38{
Christina Quast1161b272015-02-25 14:15:57 +010039 uint8_t isUsbConnected = 0;
40
Christina Quastb5ebebe2015-03-05 15:43:01 +010041 LED_Configure(LED_NUM_RED);
Christina Quast32906bb2015-02-24 11:35:19 +010042 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 Quast1161b272015-02-25 14:15:57 +010050 SIMtrace_USB_Initialize();
51
52 printf("%s", "USB init\n\r");
53
Christina Quastcafde002015-03-02 16:12:16 +010054// FIXME: why don't we get any interrupts with this line?:
Christina Quastc5a78d72015-03-10 15:35:33 +010055 while(USBD_GetState() < USBD_STATE_CONFIGURED);
Christina Quast32906bb2015-02-24 11:35:19 +010056
57 TRACE_DEBUG("%s", "Start\n\r");
Christina Quastcafde002015-03-02 16:12:16 +010058
Christina Quast1161b272015-02-25 14:15:57 +010059 printf("%s", "Start\n\r");
Christina Quast32906bb2015-02-24 11:35:19 +010060 while(1) {
Christina Quast1161b272015-02-25 14:15:57 +010061
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 Quastcafde002015-03-02 16:12:16 +010076
77// for (int i=0; i <10000; i++);
78
Christina Quast32906bb2015-02-24 11:35:19 +010079/* FIXME: Or should we move the while loop into every case, and break out
80 in case the config changes? */
Christina Quastfb524b92015-02-27 13:39:45 +010081 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 Quast32906bb2015-02-24 11:35:19 +010086 }
87 }
88}