blob: 02a3fb2bb79eb4461d9484661fdaf3704d418290 [file] [log] [blame]
Christina Quast32906bb2015-02-24 11:35:19 +01001// FIXME: Copyright license here
2/*------------------------------------------------------------------------------
3 * Headers
4 *------------------------------------------------------------------------------*/
5
6#include "board.h"
Harald Welte16055642016-03-03 11:02:45 +01007#include "simtrace.h"
Harald Welteebbb6452016-02-29 17:57:51 +01008#include "utils.h"
9#include "req_ctx.h"
Harald Welte2819e9c2017-02-03 07:46:01 +010010#include "wwan_led.h"
Harald Welte7e5c7d52017-02-03 22:59:04 +010011#include "wwan_perst.h"
Christina Quast32906bb2015-02-24 11:35:19 +010012
Harald Welte8ee15db2016-03-20 16:00:39 +010013uint32_t g_unique_id[4];
14
Christina Quast32906bb2015-02-24 11:35:19 +010015/*------------------------------------------------------------------------------
Christina Quast32906bb2015-02-24 11:35:19 +010016 * Internal variables
17 *------------------------------------------------------------------------------*/
Christina Quastfb524b92015-02-27 13:39:45 +010018typedef struct {
Harald Welte7dd3dfd2016-03-03 12:32:04 +010019 /* static initialization, called whether or not the usb config is active */
20 void (*configure) (void);
21 /* initialization function after the config was selected */
22 void (*init) (void);
23 /* de-initialization before selecting new config */
24 void (*exit) (void);
25 /* main loop content for given configuration */
26 void (*run) (void);
Harald Welte3bafe432016-03-20 16:43:12 +010027 /* Interrupt handler for USART1 */
28 void (*usart0_irq) (void);
29 /* Interrupt handler for USART1 */
30 void (*usart1_irq) (void);
Christina Quastfb524b92015-02-27 13:39:45 +010031} conf_func;
32
Harald Welted4c14212015-11-07 18:25:46 +010033static const conf_func config_func_ptrs[] = {
Harald Weltefefd5712015-11-07 18:19:11 +010034 /* array slot 0 is empty, usb configs start at 1 */
Harald Welte2fb59962016-02-28 12:34:26 +010035#ifdef HAVE_SNIFFER
Harald Weltefefd5712015-11-07 18:19:11 +010036 [CFG_NUM_SNIFF] = {
37 .configure = Sniffer_configure,
38 .init = Sniffer_init,
39 .exit = Sniffer_exit,
40 .run = Sniffer_run,
41 },
Harald Welte2fb59962016-02-28 12:34:26 +010042#endif
43#ifdef HAVE_CCID
Harald Weltefefd5712015-11-07 18:19:11 +010044 [CFG_NUM_CCID] = {
45 .configure = CCID_configure,
46 .init = CCID_init,
47 .exit = CCID_exit,
48 .run = CCID_run,
49 },
Harald Welte2fb59962016-02-28 12:34:26 +010050#endif
51#ifdef HAVE_CARDEM
Harald Weltefefd5712015-11-07 18:19:11 +010052 [CFG_NUM_PHONE] = {
Harald Welte2a6d3af2016-02-28 19:29:14 +010053 .configure = mode_cardemu_configure,
54 .init = mode_cardemu_init,
55 .exit = mode_cardemu_exit,
56 .run = mode_cardemu_run,
Harald Welte3bafe432016-03-20 16:43:12 +010057 .usart0_irq = mode_cardemu_usart0_irq,
58 .usart1_irq = mode_cardemu_usart1_irq,
Harald Weltefefd5712015-11-07 18:19:11 +010059 },
Harald Welte2fb59962016-02-28 12:34:26 +010060#endif
61#ifdef HAVE_MITM
Harald Weltefefd5712015-11-07 18:19:11 +010062 [CFG_NUM_MITM] = {
63 .configure = MITM_configure,
64 .init = MITM_init,
65 .exit = MITM_exit,
Harald Welte7dd3dfd2016-03-03 12:32:04 +010066 .run = MITM_run,
Harald Weltefefd5712015-11-07 18:19:11 +010067 },
Harald Welte2fb59962016-02-28 12:34:26 +010068#endif
Christina Quastfb524b92015-02-27 13:39:45 +010069};
70
Christina Quastfb524b92015-02-27 13:39:45 +010071/*------------------------------------------------------------------------------
72 * Internal variables
73 *------------------------------------------------------------------------------*/
Harald Welte2fb59962016-02-28 12:34:26 +010074#if defined(HAVE_SNIFFER)
Harald Welte8d6a5d82015-11-07 18:27:05 +010075static volatile enum confNum simtrace_config = CFG_NUM_SNIFF;
Harald Welte2fb59962016-02-28 12:34:26 +010076#elif defined(HAVE_CARDEM)
77static volatile enum confNum simtrace_config = CFG_NUM_PHONE;
78#elif defined(HAVE_CCID)
79static volatile enum confNum simtrace_config = CFG_NUM_CCID;
80#endif
81
Harald Welte006b16d2016-12-22 21:29:10 +010082static const Pin pin_hubpwr_override = PIN_PRTPWR_OVERRIDE;
Harald Welte6dfcf702017-01-11 22:23:13 +010083static const Pin pin_hub_rst = {PIO_PA13, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT};
Harald Welte006b16d2016-12-22 21:29:10 +010084static const Pin pin_1234_detect = {PIO_PA14, PIOA, ID_PIOA, PIO_INPUT, PIO_PULLUP};
85static const Pin pin_peer_rst = {PIO_PA0, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT};
86static const Pin pin_peer_erase = {PIO_PA11, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT};
87
88
Harald Welte8d6a5d82015-11-07 18:27:05 +010089/*----------------------------------------------------------------------------
90 * Callbacks
91 *----------------------------------------------------------------------------*/
92
93void USBDDriverCallbacks_ConfigurationChanged(uint8_t cfgnum)
94{
Harald Welte7dd3dfd2016-03-03 12:32:04 +010095 TRACE_INFO_WP("cfgChanged%d ", cfgnum);
96 simtrace_config = cfgnum;
Harald Welte8d6a5d82015-11-07 18:27:05 +010097}
Christina Quast32906bb2015-02-24 11:35:19 +010098
Harald Welte3bafe432016-03-20 16:43:12 +010099void USART1_IrqHandler(void)
100{
101 config_func_ptrs[simtrace_config].usart1_irq();
102}
103
104void USART0_IrqHandler(void)
105{
106 config_func_ptrs[simtrace_config].usart0_irq();
107}
108
Harald Welte006b16d2016-12-22 21:29:10 +0100109static int qmod_sam3_is_12(void)
110{
111 if (PIO_Get(&pin_1234_detect) == 0)
112 return 1;
113 else
114 return 0;
115}
Harald Weltee974fbb2016-10-19 19:36:07 +0200116
Harald Welteb8713632017-01-11 23:08:35 +0100117const unsigned char __eeprom_bin[256] = {
118 0x23, 0x42, 0x17, 0x25, 0x00, 0x00, 0x9b, 0x20, 0x01, 0x00, 0x00, 0x00, 0x32, 0x32, 0x32, 0x32, /* 0x00 - 0x0f */
119 0x32, 0x04, 0x09, 0x18, 0x0d, 0x00, 0x73, 0x00, 0x79, 0x00, 0x73, 0x00, 0x6d, 0x00, 0x6f, 0x00, /* 0x10 - 0x1f */
120 0x63, 0x00, 0x6f, 0x00, 0x6d, 0x00, 0x20, 0x00, 0x2d, 0x00, 0x20, 0x00, 0x73, 0x00, 0x2e, 0x00, /* 0x20 - 0x2f */
121 0x66, 0x00, 0x2e, 0x00, 0x6d, 0x00, 0x2e, 0x00, 0x63, 0x00, 0x2e, 0x00, 0x20, 0x00, 0x47, 0x00, /* 0x30 - 0x3f */
122 0x6d, 0x00, 0x62, 0x00, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40 - 0x4f */
123 0x00, 0x00, 0x00, 0x00, 0x71, 0x00, 0x75, 0x00, 0x61, 0x00, 0x64, 0x00, 0x20, 0x00, 0x6d, 0x00, /* 0x50 - 0x5f */
124 0x6f, 0x00, 0x64, 0x00, 0x65, 0x00, 0x6d, 0x00, 0x20, 0x00, 0x76, 0x00, 0x32, 0x00, 0x00, 0x00, /* 0x60 - 0x6f */
125 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70 - 0x7f */
126 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80 - 0x8f */
127 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90 - 0x9f */
128 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0 - 0xaf */
129 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0 - 0xbf */
130 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0 - 0xcf */
131 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0 - 0xdf */
132 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0 - 0xef */
133 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA0, 0x56, 0x23, 0x71, 0x04, 0x00, /* 0xf0 - 0xff */
134};
135
Harald Welte006b16d2016-12-22 21:29:10 +0100136#include "i2c.h"
Harald Weltee974fbb2016-10-19 19:36:07 +0200137static int write_hub_eeprom(void)
138{
Harald Weltee974fbb2016-10-19 19:36:07 +0200139 const unsigned int __eeprom_bin_len = 256;
140
Harald Weltee974fbb2016-10-19 19:36:07 +0200141 int i;
142
Harald Weltee974fbb2016-10-19 19:36:07 +0200143 /* wait */
144 volatile int v;
145 /* 440ns per cycle here */
146 for (i = 0; i < 1000000; i++) {
147 v = 0;
148 }
149
Harald Welte006b16d2016-12-22 21:29:10 +0100150 TRACE_INFO("Writing EEPROM...\r\n");
Harald Weltee974fbb2016-10-19 19:36:07 +0200151 /* write the EEPROM once */
152 for (i = 0; i < 256; i++) {
153 int rc = eeprom_write_byte(0x50, i, __eeprom_bin[i]);
154 /* if the result was negative, repeat that write */
155 if (rc < 0)
156 i--;
157 }
158
159 /* then pursue re-reading it again and again */
Harald Welte006b16d2016-12-22 21:29:10 +0100160 TRACE_INFO("Verifying EEPROM...\r\n");
Harald Weltee974fbb2016-10-19 19:36:07 +0200161 for (i = 0; i < 256; i++) {
162 int byte = eeprom_read_byte(0x50, i);
163 TRACE_INFO("0x%02x: %02x\r\n", i, byte);
164 if (byte != __eeprom_bin[i])
165 TRACE_ERROR("Byte %u is wrong, expected 0x%02x, found 0x%02x\r\n",
166 i, __eeprom_bin[i], byte);
167 }
Harald Weltee974fbb2016-10-19 19:36:07 +0200168
169 /* FIXME: Release PIN_PRTPWR_OVERRIDE after we know the hub is
170 * again powering us up */
171
172 return 0;
173}
174
Harald Weltef9a182d2017-01-11 22:22:16 +0100175/* returns '1' in case we should break any endless loop */
Harald Welteaf614792017-01-12 18:59:41 +0100176static void check_exec_dbg_cmd(void)
Harald Welte006b16d2016-12-22 21:29:10 +0100177{
178 uint32_t addr, val;
179
180 if (!UART_IsRxReady())
181 return;
182
183 int ch = UART_GetChar();
184 switch (ch) {
185 case '?':
186 printf("\t?\thelp\r\n");
187 printf("\tE\tprogram EEPROM\r\n");
188 printf("\tR\treset SAM3\r\n");
189 printf("\tO\tEnable PRTPWR_OVERRIDE\r\n");
190 printf("\to\tDisable PRTPWR_OVERRIDE\r\n");
191 printf("\tH\tRelease HUB RESET (high)\r\n");
192 printf("\th\tAssert HUB RESET (low)\r\n");
193 printf("\tw\tWrite single byte in EEPROM\r\n");
194 printf("\tr\tRead single byte from EEPROM\r\n");
195 printf("\tX\tRelease peer SAM3 from reset\r\n");
196 printf("\tx\tAssert peer SAM3 reset\r\n");
Harald Welte396354c2016-12-22 22:28:26 +0100197 printf("\tY\tRelease peer SAM3 ERASE signal\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100198 printf("\ty\tAssert peer SAM3 ERASE signal\r\n");
Harald Weltee07aed62016-12-22 22:32:15 +0100199 printf("\tU\tProceed to USB Initialization\r\n");
Harald Welte7e5c7d52017-02-03 22:59:04 +0100200 printf("\t1\tGenerate 1ms reset pulse on WWAN1\r\n");
201 printf("\t2\tGenerate 1ms reset pulse on WWAN2\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100202 break;
203 case 'E':
204 write_hub_eeprom();
205 break;
206 case 'R':
Harald Welte396354c2016-12-22 22:28:26 +0100207 printf("Asking NVIC to reset us\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100208 NVIC_SystemReset();
209 break;
210 case 'O':
Harald Welte396354c2016-12-22 22:28:26 +0100211 printf("Setting PRTPWR_OVERRIDE\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100212 PIO_Set(&pin_hubpwr_override);
213 break;
214 case 'o':
Harald Welte396354c2016-12-22 22:28:26 +0100215 printf("Clearing PRTPWR_OVERRIDE\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100216 PIO_Clear(&pin_hubpwr_override);
217 break;
218 case 'H':
Harald Welte396354c2016-12-22 22:28:26 +0100219 printf("Clearing _HUB_RESET -> HUB_RESET high (inactive)\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100220 PIO_Clear(&pin_hub_rst);
221 break;
222 case 'h':
223 /* high level drives transistor -> HUB_RESET low */
Harald Welte396354c2016-12-22 22:28:26 +0100224 printf("Asserting _HUB_RESET -> HUB_RESET low (active)\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100225 PIO_Set(&pin_hub_rst);
226 break;
227 case 'w':
228 if (PIO_GetOutputDataStatus(&pin_hub_rst) == 0)
229 printf("WARNING: attempting EEPROM access while HUB not in reset\r\n");
Harald Welte396354c2016-12-22 22:28:26 +0100230 printf("Please enter EEPROM offset:\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100231 UART_GetIntegerMinMax(&addr, 0, 255);
Harald Welte396354c2016-12-22 22:28:26 +0100232 printf("Please enter EEPROM value:\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100233 UART_GetIntegerMinMax(&val, 0, 255);
234 printf("Writing value 0x%02x to EEPROM offset 0x%02x\r\n", val, addr);
235 eeprom_write_byte(0x50, addr, val);
236 break;
237 case 'r':
Harald Welte396354c2016-12-22 22:28:26 +0100238 printf("Please enter EEPROM offset:\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100239 UART_GetIntegerMinMax(&addr, 0, 255);
240 printf("EEPROM[0x%02x] = 0x%02x\r\n", addr, eeprom_read_byte(0x50, addr));
241 break;
242 case 'X':
Harald Welte396354c2016-12-22 22:28:26 +0100243 printf("Clearing _SIMTRACExx_RST -> SIMTRACExx_RST high (inactive)\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100244 PIO_Clear(&pin_peer_rst);
245 break;
246 case 'x':
Harald Welte396354c2016-12-22 22:28:26 +0100247 printf("Setting _SIMTRACExx_RST -> SIMTRACExx_RST low (active)\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100248 PIO_Set(&pin_peer_rst);
249 break;
250 case 'Y':
Harald Welte396354c2016-12-22 22:28:26 +0100251 printf("Clearing SIMTRACExx_ERASE (inactive)\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100252 PIO_Clear(&pin_peer_erase);
253 break;
254 case 'y':
Harald Welte396354c2016-12-22 22:28:26 +0100255 printf("Seetting SIMTRACExx_ERASE (active)\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100256 PIO_Set(&pin_peer_erase);
257 break;
Harald Welte7e5c7d52017-02-03 22:59:04 +0100258 case '1':
259 printf("Resetting Modem 1 (of this SAM3)\r\n");
260 wwan_perst_do_reset(1);
261 break;
262 case '2':
263 printf("Resetting Modem 2 (of this SAM3)\r\n");
264 wwan_perst_do_reset(2);
265 break;
Harald Welte396354c2016-12-22 22:28:26 +0100266 default:
267 printf("Unknown command '%c'\r\n", ch);
268 break;
Harald Welte006b16d2016-12-22 21:29:10 +0100269 }
270}
Harald Weltee974fbb2016-10-19 19:36:07 +0200271
Christina Quast32906bb2015-02-24 11:35:19 +0100272/*------------------------------------------------------------------------------
Christina Quast95d66162015-04-09 22:38:47 +0200273 * Main
Christina Quast32906bb2015-02-24 11:35:19 +0100274 *------------------------------------------------------------------------------*/
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100275#define MAX_USB_ITER BOARD_MCK/72 // This should be around a second
276extern int main(void)
Christina Quast32906bb2015-02-24 11:35:19 +0100277{
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100278 uint8_t isUsbConnected = 0;
279 enum confNum last_simtrace_config = simtrace_config;
280 unsigned int i = 0;
Christina Quast1161b272015-02-25 14:15:57 +0100281
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100282 LED_Configure(LED_NUM_RED);
283 LED_Configure(LED_NUM_GREEN);
284 LED_Set(LED_NUM_RED);
Christina Quast32906bb2015-02-24 11:35:19 +0100285
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100286 /* Disable watchdog */
287 WDT_Disable(WDT);
Christina Quast32906bb2015-02-24 11:35:19 +0100288
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100289 req_ctx_init();
Harald Welteebbb6452016-02-29 17:57:51 +0100290
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100291 PIO_InitializeInterrupts(0);
Christina Quast32906bb2015-02-24 11:35:19 +0100292
Harald Welte2819e9c2017-02-03 07:46:01 +0100293 wwan_led_init();
Harald Welte7e5c7d52017-02-03 22:59:04 +0100294 wwan_perst_init();
Harald Welte2819e9c2017-02-03 07:46:01 +0100295
Harald Welte8ee15db2016-03-20 16:00:39 +0100296 EEFC_ReadUniqueID(g_unique_id);
297
Harald Welte2315e6b2016-03-19 21:37:55 +0100298 printf("\r\n\r\n"
299 "=============================================================================\r\n"
300 "SIMtrace2 firmware " GIT_VERSION " (C) 2010-2016 by Harald Welte\r\n"
301 "=============================================================================\r\n");
302
Harald Welte8ee15db2016-03-20 16:00:39 +0100303 TRACE_INFO("Serial Nr. %08x-%08x-%08x-%08x\r\n",
304 g_unique_id[0], g_unique_id[1],
305 g_unique_id[2], g_unique_id[3]);
306
Harald Welte006b16d2016-12-22 21:29:10 +0100307 /* set PIN_PRTPWR_OVERRIDE to output-low to avoid the internal
308 * pull-up on the input to keep SIMTRACE12 alive */
309 PIO_Configure(&pin_hubpwr_override, 1);
310 PIO_Configure(&pin_hub_rst, 1);
311 PIO_Configure(&pin_1234_detect, 1);
312 PIO_Configure(&pin_peer_rst, 1);
313 PIO_Configure(&pin_peer_erase, 1);
314 i2c_pin_init();
315
316 if (qmod_sam3_is_12()) {
317 TRACE_INFO("Detected Quad-Modem ST12\r\n");
318 } else {
319 TRACE_INFO("Detected Quad-Modem ST34\r\n");
320 }
321
Harald Weltecf1c19a2016-03-20 15:18:18 +0100322 TRACE_INFO("USB init...\r\n");
Harald Weltee07aed62016-12-22 22:32:15 +0100323 SIMtrace_USB_Initialize();
324
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100325 while (USBD_GetState() < USBD_STATE_CONFIGURED) {
Harald Welte006b16d2016-12-22 21:29:10 +0100326 check_exec_dbg_cmd();
Harald Welte67415e32016-09-01 20:57:56 +0200327#if 0
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100328 if (i >= MAX_USB_ITER * 3) {
329 TRACE_ERROR("Resetting board (USB could "
Harald Weltecf1c19a2016-03-20 15:18:18 +0100330 "not be configured)\r\n");
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100331 NVIC_SystemReset();
332 }
Harald Welte67415e32016-09-01 20:57:56 +0200333#endif
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100334 i++;
335 }
Christina Quastde688672015-04-12 15:20:57 +0200336
Harald Welte006b16d2016-12-22 21:29:10 +0100337 TRACE_INFO("Releasing ST12_PRTPWR_OVERRIDE\r\n");
338 PIO_Clear(&pin_hubpwr_override);
339
Harald Weltecf1c19a2016-03-20 15:18:18 +0100340 TRACE_INFO("calling configure of all configurations...\r\n");
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100341 for (i = 1; i < sizeof(config_func_ptrs) / sizeof(config_func_ptrs[0]);
342 ++i) {
343 if (config_func_ptrs[i].configure)
344 config_func_ptrs[i].configure();
345 }
Christina Quast95d66162015-04-09 22:38:47 +0200346
Harald Weltecf1c19a2016-03-20 15:18:18 +0100347 TRACE_INFO("calling init of config %u...\r\n", simtrace_config);
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100348 config_func_ptrs[simtrace_config].init();
349 last_simtrace_config = simtrace_config;
Christina Quast95d66162015-04-09 22:38:47 +0200350
Harald Weltecf1c19a2016-03-20 15:18:18 +0100351 TRACE_INFO("entering main loop...\r\n");
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100352 while (1) {
Harald Welte04e37a82016-03-20 15:15:34 +0100353#if TRACE_LEVEL >= TRACE_LEVEL_DEBUG
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100354 const char rotor[] = { '-', '\\', '|', '/' };
355 putchar('\b');
356 putchar(rotor[i++ % ARRAY_SIZE(rotor)]);
Harald Welte04e37a82016-03-20 15:15:34 +0100357#endif
Harald Welte006b16d2016-12-22 21:29:10 +0100358 check_exec_dbg_cmd();
Christina Quast1161b272015-02-25 14:15:57 +0100359
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100360 if (USBD_GetState() < USBD_STATE_CONFIGURED) {
Christina Quast1161b272015-02-25 14:15:57 +0100361
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100362 if (isUsbConnected) {
363 isUsbConnected = 0;
364 }
365 } else if (isUsbConnected == 0) {
Harald Weltecf1c19a2016-03-20 15:18:18 +0100366 TRACE_INFO("USB is now configured\r\n");
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100367 LED_Set(LED_NUM_GREEN);
368 LED_Clear(LED_NUM_RED);
Christina Quast1161b272015-02-25 14:15:57 +0100369
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100370 isUsbConnected = 1;
371 }
372 if (last_simtrace_config != simtrace_config) {
373 TRACE_INFO("USB config chg %u -> %u\r\n",
374 last_simtrace_config, simtrace_config);
375 config_func_ptrs[last_simtrace_config].exit();
376 config_func_ptrs[simtrace_config].init();
377 last_simtrace_config = simtrace_config;
378 } else {
379 config_func_ptrs[simtrace_config].run();
380 }
381 }
Christina Quast32906bb2015-02-24 11:35:19 +0100382}