blob: 4f937850818c07e6ad6eb8491f06e365a6d41af4 [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"
Christina Quast32906bb2015-02-24 11:35:19 +010010
Harald Welte8ee15db2016-03-20 16:00:39 +010011uint32_t g_unique_id[4];
12
Christina Quast32906bb2015-02-24 11:35:19 +010013/*------------------------------------------------------------------------------
Christina Quast32906bb2015-02-24 11:35:19 +010014 * Internal variables
15 *------------------------------------------------------------------------------*/
Christina Quastfb524b92015-02-27 13:39:45 +010016typedef struct {
Harald Welte7dd3dfd2016-03-03 12:32:04 +010017 /* static initialization, called whether or not the usb config is active */
18 void (*configure) (void);
19 /* initialization function after the config was selected */
20 void (*init) (void);
21 /* de-initialization before selecting new config */
22 void (*exit) (void);
23 /* main loop content for given configuration */
24 void (*run) (void);
Harald Welte3bafe432016-03-20 16:43:12 +010025 /* Interrupt handler for USART1 */
26 void (*usart0_irq) (void);
27 /* Interrupt handler for USART1 */
28 void (*usart1_irq) (void);
Christina Quastfb524b92015-02-27 13:39:45 +010029} conf_func;
30
Harald Welted4c14212015-11-07 18:25:46 +010031static const conf_func config_func_ptrs[] = {
Harald Weltefefd5712015-11-07 18:19:11 +010032 /* array slot 0 is empty, usb configs start at 1 */
Harald Welte2fb59962016-02-28 12:34:26 +010033#ifdef HAVE_SNIFFER
Harald Weltefefd5712015-11-07 18:19:11 +010034 [CFG_NUM_SNIFF] = {
35 .configure = Sniffer_configure,
36 .init = Sniffer_init,
37 .exit = Sniffer_exit,
38 .run = Sniffer_run,
39 },
Harald Welte2fb59962016-02-28 12:34:26 +010040#endif
41#ifdef HAVE_CCID
Harald Weltefefd5712015-11-07 18:19:11 +010042 [CFG_NUM_CCID] = {
43 .configure = CCID_configure,
44 .init = CCID_init,
45 .exit = CCID_exit,
46 .run = CCID_run,
47 },
Harald Welte2fb59962016-02-28 12:34:26 +010048#endif
49#ifdef HAVE_CARDEM
Harald Weltefefd5712015-11-07 18:19:11 +010050 [CFG_NUM_PHONE] = {
Harald Welte2a6d3af2016-02-28 19:29:14 +010051 .configure = mode_cardemu_configure,
52 .init = mode_cardemu_init,
53 .exit = mode_cardemu_exit,
54 .run = mode_cardemu_run,
Harald Welte3bafe432016-03-20 16:43:12 +010055 .usart0_irq = mode_cardemu_usart0_irq,
56 .usart1_irq = mode_cardemu_usart1_irq,
Harald Weltefefd5712015-11-07 18:19:11 +010057 },
Harald Welte2fb59962016-02-28 12:34:26 +010058#endif
59#ifdef HAVE_MITM
Harald Weltefefd5712015-11-07 18:19:11 +010060 [CFG_NUM_MITM] = {
61 .configure = MITM_configure,
62 .init = MITM_init,
63 .exit = MITM_exit,
Harald Welte7dd3dfd2016-03-03 12:32:04 +010064 .run = MITM_run,
Harald Weltefefd5712015-11-07 18:19:11 +010065 },
Harald Welte2fb59962016-02-28 12:34:26 +010066#endif
Christina Quastfb524b92015-02-27 13:39:45 +010067};
68
Christina Quastfb524b92015-02-27 13:39:45 +010069/*------------------------------------------------------------------------------
70 * Internal variables
71 *------------------------------------------------------------------------------*/
Harald Welte2fb59962016-02-28 12:34:26 +010072#if defined(HAVE_SNIFFER)
Harald Welte8d6a5d82015-11-07 18:27:05 +010073static volatile enum confNum simtrace_config = CFG_NUM_SNIFF;
Harald Welte2fb59962016-02-28 12:34:26 +010074#elif defined(HAVE_CARDEM)
75static volatile enum confNum simtrace_config = CFG_NUM_PHONE;
76#elif defined(HAVE_CCID)
77static volatile enum confNum simtrace_config = CFG_NUM_CCID;
78#endif
79
Harald Welte006b16d2016-12-22 21:29:10 +010080static const Pin pin_hubpwr_override = PIN_PRTPWR_OVERRIDE;
Harald Welte6dfcf702017-01-11 22:23:13 +010081static const Pin pin_hub_rst = {PIO_PA13, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT};
Harald Welte006b16d2016-12-22 21:29:10 +010082static const Pin pin_1234_detect = {PIO_PA14, PIOA, ID_PIOA, PIO_INPUT, PIO_PULLUP};
83static const Pin pin_peer_rst = {PIO_PA0, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT};
84static const Pin pin_peer_erase = {PIO_PA11, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT};
85
86
Harald Welte8d6a5d82015-11-07 18:27:05 +010087/*----------------------------------------------------------------------------
88 * Callbacks
89 *----------------------------------------------------------------------------*/
90
91void USBDDriverCallbacks_ConfigurationChanged(uint8_t cfgnum)
92{
Harald Welte7dd3dfd2016-03-03 12:32:04 +010093 TRACE_INFO_WP("cfgChanged%d ", cfgnum);
94 simtrace_config = cfgnum;
Harald Welte8d6a5d82015-11-07 18:27:05 +010095}
Christina Quast32906bb2015-02-24 11:35:19 +010096
Harald Welte3bafe432016-03-20 16:43:12 +010097void USART1_IrqHandler(void)
98{
99 config_func_ptrs[simtrace_config].usart1_irq();
100}
101
102void USART0_IrqHandler(void)
103{
104 config_func_ptrs[simtrace_config].usart0_irq();
105}
106
Harald Welte006b16d2016-12-22 21:29:10 +0100107static int qmod_sam3_is_12(void)
108{
109 if (PIO_Get(&pin_1234_detect) == 0)
110 return 1;
111 else
112 return 0;
113}
Harald Weltee974fbb2016-10-19 19:36:07 +0200114
Harald Welte006b16d2016-12-22 21:29:10 +0100115#include "i2c.h"
Harald Weltee974fbb2016-10-19 19:36:07 +0200116static int write_hub_eeprom(void)
117{
118 const unsigned char __eeprom_bin[] = {
119 0x23, 0x42, 0x17, 0x25, 0x00, 0x00, 0x9b, 0x20, 0x01, 0xa0, 0x00, 0x5e,
Harald Welteae8a4652017-01-11 22:59:09 +0100120 0x32, 0x32, 0x32, 0x32, 0x32, 0x04, 0x09, 0x18, 0x0d, 0x00, 0x73, 0x00,
Harald Weltee974fbb2016-10-19 19:36:07 +0200121 0x79, 0x00, 0x73, 0x00, 0x6d, 0x00, 0x6f, 0x00, 0x63, 0x00, 0x6f, 0x00,
122 0x6d, 0x00, 0x20, 0x00, 0x2d, 0x00, 0x20, 0x00, 0x73, 0x00, 0x2e, 0x00,
123 0x66, 0x00, 0x2e, 0x00, 0x6d, 0x00, 0x2e, 0x00, 0x63, 0x00, 0x2e, 0x00,
124 0x20, 0x00, 0x47, 0x00, 0x6d, 0x00, 0x62, 0x00, 0x48, 0x00, 0x00, 0x00,
125 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
126 0x71, 0x00, 0x75, 0x00, 0x61, 0x00, 0x64, 0x00, 0x20, 0x00, 0x6d, 0x00,
127 0x6f, 0x00, 0x64, 0x00, 0x65, 0x00, 0x6d, 0x00, 0x20, 0x00, 0x76, 0x00,
Harald Welteae8a4652017-01-11 22:59:09 +0100128 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Harald Weltee974fbb2016-10-19 19:36:07 +0200129 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
130 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
131 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
132 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
133 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
134 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
135 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
136 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
137 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
138 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Harald Welteae8a4652017-01-11 22:59:09 +0100139 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA0, 0x56,
140 0x23, 0x71, 0x04, 0x00
Harald Weltee974fbb2016-10-19 19:36:07 +0200141 };
142 const unsigned int __eeprom_bin_len = 256;
143
Harald Weltee974fbb2016-10-19 19:36:07 +0200144 int i;
145
Harald Weltee974fbb2016-10-19 19:36:07 +0200146 /* wait */
147 volatile int v;
148 /* 440ns per cycle here */
149 for (i = 0; i < 1000000; i++) {
150 v = 0;
151 }
152
Harald Welte006b16d2016-12-22 21:29:10 +0100153 TRACE_INFO("Writing EEPROM...\r\n");
Harald Weltee974fbb2016-10-19 19:36:07 +0200154 /* write the EEPROM once */
155 for (i = 0; i < 256; i++) {
156 int rc = eeprom_write_byte(0x50, i, __eeprom_bin[i]);
157 /* if the result was negative, repeat that write */
158 if (rc < 0)
159 i--;
160 }
161
162 /* then pursue re-reading it again and again */
Harald Welte006b16d2016-12-22 21:29:10 +0100163 TRACE_INFO("Verifying EEPROM...\r\n");
Harald Weltee974fbb2016-10-19 19:36:07 +0200164 for (i = 0; i < 256; i++) {
165 int byte = eeprom_read_byte(0x50, i);
166 TRACE_INFO("0x%02x: %02x\r\n", i, byte);
167 if (byte != __eeprom_bin[i])
168 TRACE_ERROR("Byte %u is wrong, expected 0x%02x, found 0x%02x\r\n",
169 i, __eeprom_bin[i], byte);
170 }
Harald Weltee974fbb2016-10-19 19:36:07 +0200171
172 /* FIXME: Release PIN_PRTPWR_OVERRIDE after we know the hub is
173 * again powering us up */
174
175 return 0;
176}
177
Harald Weltef9a182d2017-01-11 22:22:16 +0100178/* returns '1' in case we should break any endless loop */
179static int check_exec_dbg_cmd(void)
Harald Welte006b16d2016-12-22 21:29:10 +0100180{
181 uint32_t addr, val;
182
183 if (!UART_IsRxReady())
184 return;
185
186 int ch = UART_GetChar();
187 switch (ch) {
188 case '?':
189 printf("\t?\thelp\r\n");
190 printf("\tE\tprogram EEPROM\r\n");
191 printf("\tR\treset SAM3\r\n");
192 printf("\tO\tEnable PRTPWR_OVERRIDE\r\n");
193 printf("\to\tDisable PRTPWR_OVERRIDE\r\n");
194 printf("\tH\tRelease HUB RESET (high)\r\n");
195 printf("\th\tAssert HUB RESET (low)\r\n");
196 printf("\tw\tWrite single byte in EEPROM\r\n");
197 printf("\tr\tRead single byte from EEPROM\r\n");
198 printf("\tX\tRelease peer SAM3 from reset\r\n");
199 printf("\tx\tAssert peer SAM3 reset\r\n");
Harald Welte396354c2016-12-22 22:28:26 +0100200 printf("\tY\tRelease peer SAM3 ERASE signal\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100201 printf("\ty\tAssert peer SAM3 ERASE signal\r\n");
Harald Weltee07aed62016-12-22 22:32:15 +0100202 printf("\tU\tProceed to USB Initialization\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100203 break;
204 case 'E':
205 write_hub_eeprom();
206 break;
207 case 'R':
Harald Welte396354c2016-12-22 22:28:26 +0100208 printf("Asking NVIC to reset us\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100209 NVIC_SystemReset();
210 break;
211 case 'O':
Harald Welte396354c2016-12-22 22:28:26 +0100212 printf("Setting PRTPWR_OVERRIDE\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100213 PIO_Set(&pin_hubpwr_override);
214 break;
215 case 'o':
Harald Welte396354c2016-12-22 22:28:26 +0100216 printf("Clearing PRTPWR_OVERRIDE\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100217 PIO_Clear(&pin_hubpwr_override);
218 break;
219 case 'H':
Harald Welte396354c2016-12-22 22:28:26 +0100220 printf("Clearing _HUB_RESET -> HUB_RESET high (inactive)\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100221 PIO_Clear(&pin_hub_rst);
222 break;
223 case 'h':
224 /* high level drives transistor -> HUB_RESET low */
Harald Welte396354c2016-12-22 22:28:26 +0100225 printf("Asserting _HUB_RESET -> HUB_RESET low (active)\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100226 PIO_Set(&pin_hub_rst);
227 break;
228 case 'w':
229 if (PIO_GetOutputDataStatus(&pin_hub_rst) == 0)
230 printf("WARNING: attempting EEPROM access while HUB not in reset\r\n");
Harald Welte396354c2016-12-22 22:28:26 +0100231 printf("Please enter EEPROM offset:\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100232 UART_GetIntegerMinMax(&addr, 0, 255);
Harald Welte396354c2016-12-22 22:28:26 +0100233 printf("Please enter EEPROM value:\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100234 UART_GetIntegerMinMax(&val, 0, 255);
235 printf("Writing value 0x%02x to EEPROM offset 0x%02x\r\n", val, addr);
236 eeprom_write_byte(0x50, addr, val);
237 break;
238 case 'r':
Harald Welte396354c2016-12-22 22:28:26 +0100239 printf("Please enter EEPROM offset:\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100240 UART_GetIntegerMinMax(&addr, 0, 255);
241 printf("EEPROM[0x%02x] = 0x%02x\r\n", addr, eeprom_read_byte(0x50, addr));
242 break;
243 case 'X':
Harald Welte396354c2016-12-22 22:28:26 +0100244 printf("Clearing _SIMTRACExx_RST -> SIMTRACExx_RST high (inactive)\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100245 PIO_Clear(&pin_peer_rst);
246 break;
247 case 'x':
Harald Welte396354c2016-12-22 22:28:26 +0100248 printf("Setting _SIMTRACExx_RST -> SIMTRACExx_RST low (active)\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100249 PIO_Set(&pin_peer_rst);
250 break;
251 case 'Y':
Harald Welte396354c2016-12-22 22:28:26 +0100252 printf("Clearing SIMTRACExx_ERASE (inactive)\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100253 PIO_Clear(&pin_peer_erase);
254 break;
255 case 'y':
Harald Welte396354c2016-12-22 22:28:26 +0100256 printf("Seetting SIMTRACExx_ERASE (active)\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100257 PIO_Set(&pin_peer_erase);
258 break;
Harald Weltee07aed62016-12-22 22:32:15 +0100259 case 'U':
260 printf("Proceeding to USB init\r\n");
Harald Weltef9a182d2017-01-11 22:22:16 +0100261 return 1;
Harald Welte396354c2016-12-22 22:28:26 +0100262 default:
263 printf("Unknown command '%c'\r\n", ch);
264 break;
Harald Welte006b16d2016-12-22 21:29:10 +0100265 }
Harald Weltef9a182d2017-01-11 22:22:16 +0100266 return 0;
Harald Welte006b16d2016-12-22 21:29:10 +0100267}
Harald Weltee974fbb2016-10-19 19:36:07 +0200268
Christina Quast32906bb2015-02-24 11:35:19 +0100269/*------------------------------------------------------------------------------
Christina Quast95d66162015-04-09 22:38:47 +0200270 * Main
Christina Quast32906bb2015-02-24 11:35:19 +0100271 *------------------------------------------------------------------------------*/
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100272#define MAX_USB_ITER BOARD_MCK/72 // This should be around a second
273extern int main(void)
Christina Quast32906bb2015-02-24 11:35:19 +0100274{
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100275 uint8_t isUsbConnected = 0;
276 enum confNum last_simtrace_config = simtrace_config;
277 unsigned int i = 0;
Christina Quast1161b272015-02-25 14:15:57 +0100278
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100279 LED_Configure(LED_NUM_RED);
280 LED_Configure(LED_NUM_GREEN);
281 LED_Set(LED_NUM_RED);
Christina Quast32906bb2015-02-24 11:35:19 +0100282
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100283 /* Disable watchdog */
284 WDT_Disable(WDT);
Christina Quast32906bb2015-02-24 11:35:19 +0100285
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100286 req_ctx_init();
Harald Welteebbb6452016-02-29 17:57:51 +0100287
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100288 PIO_InitializeInterrupts(0);
Christina Quast32906bb2015-02-24 11:35:19 +0100289
Harald Welte8ee15db2016-03-20 16:00:39 +0100290 EEFC_ReadUniqueID(g_unique_id);
291
Harald Welte2315e6b2016-03-19 21:37:55 +0100292 printf("\r\n\r\n"
293 "=============================================================================\r\n"
294 "SIMtrace2 firmware " GIT_VERSION " (C) 2010-2016 by Harald Welte\r\n"
295 "=============================================================================\r\n");
296
Harald Welte8ee15db2016-03-20 16:00:39 +0100297 TRACE_INFO("Serial Nr. %08x-%08x-%08x-%08x\r\n",
298 g_unique_id[0], g_unique_id[1],
299 g_unique_id[2], g_unique_id[3]);
300
Harald Welte006b16d2016-12-22 21:29:10 +0100301 /* set PIN_PRTPWR_OVERRIDE to output-low to avoid the internal
302 * pull-up on the input to keep SIMTRACE12 alive */
303 PIO_Configure(&pin_hubpwr_override, 1);
304 PIO_Configure(&pin_hub_rst, 1);
305 PIO_Configure(&pin_1234_detect, 1);
306 PIO_Configure(&pin_peer_rst, 1);
307 PIO_Configure(&pin_peer_erase, 1);
308 i2c_pin_init();
309
310 if (qmod_sam3_is_12()) {
311 TRACE_INFO("Detected Quad-Modem ST12\r\n");
312 } else {
313 TRACE_INFO("Detected Quad-Modem ST34\r\n");
314 }
315
316 while (1) {
Harald Weltef9a182d2017-01-11 22:22:16 +0100317 if (check_exec_dbg_cmd() == 1)
318 break;
Harald Welte006b16d2016-12-22 21:29:10 +0100319 }
Harald Welte226b40a2016-08-21 19:33:24 +0200320
Harald Weltecf1c19a2016-03-20 15:18:18 +0100321 TRACE_INFO("USB init...\r\n");
Harald Weltee07aed62016-12-22 22:32:15 +0100322 SIMtrace_USB_Initialize();
323
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100324 while (USBD_GetState() < USBD_STATE_CONFIGURED) {
Harald Welte006b16d2016-12-22 21:29:10 +0100325 check_exec_dbg_cmd();
Harald Welte67415e32016-09-01 20:57:56 +0200326#if 0
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100327 if (i >= MAX_USB_ITER * 3) {
328 TRACE_ERROR("Resetting board (USB could "
Harald Weltecf1c19a2016-03-20 15:18:18 +0100329 "not be configured)\r\n");
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100330 NVIC_SystemReset();
331 }
Harald Welte67415e32016-09-01 20:57:56 +0200332#endif
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100333 i++;
334 }
Christina Quastde688672015-04-12 15:20:57 +0200335
Harald Welte006b16d2016-12-22 21:29:10 +0100336 TRACE_INFO("Releasing ST12_PRTPWR_OVERRIDE\r\n");
337 PIO_Clear(&pin_hubpwr_override);
338
Harald Weltecf1c19a2016-03-20 15:18:18 +0100339 TRACE_INFO("calling configure of all configurations...\r\n");
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100340 for (i = 1; i < sizeof(config_func_ptrs) / sizeof(config_func_ptrs[0]);
341 ++i) {
342 if (config_func_ptrs[i].configure)
343 config_func_ptrs[i].configure();
344 }
Christina Quast95d66162015-04-09 22:38:47 +0200345
Harald Weltecf1c19a2016-03-20 15:18:18 +0100346 TRACE_INFO("calling init of config %u...\r\n", simtrace_config);
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100347 config_func_ptrs[simtrace_config].init();
348 last_simtrace_config = simtrace_config;
Christina Quast95d66162015-04-09 22:38:47 +0200349
Harald Weltecf1c19a2016-03-20 15:18:18 +0100350 TRACE_INFO("entering main loop...\r\n");
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100351 while (1) {
Harald Welte04e37a82016-03-20 15:15:34 +0100352#if TRACE_LEVEL >= TRACE_LEVEL_DEBUG
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100353 const char rotor[] = { '-', '\\', '|', '/' };
354 putchar('\b');
355 putchar(rotor[i++ % ARRAY_SIZE(rotor)]);
Harald Welte04e37a82016-03-20 15:15:34 +0100356#endif
Harald Welte006b16d2016-12-22 21:29:10 +0100357 check_exec_dbg_cmd();
Christina Quast1161b272015-02-25 14:15:57 +0100358
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100359 if (USBD_GetState() < USBD_STATE_CONFIGURED) {
Christina Quast1161b272015-02-25 14:15:57 +0100360
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100361 if (isUsbConnected) {
362 isUsbConnected = 0;
363 }
364 } else if (isUsbConnected == 0) {
Harald Weltecf1c19a2016-03-20 15:18:18 +0100365 TRACE_INFO("USB is now configured\r\n");
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100366 LED_Set(LED_NUM_GREEN);
367 LED_Clear(LED_NUM_RED);
Christina Quast1161b272015-02-25 14:15:57 +0100368
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100369 isUsbConnected = 1;
370 }
371 if (last_simtrace_config != simtrace_config) {
372 TRACE_INFO("USB config chg %u -> %u\r\n",
373 last_simtrace_config, simtrace_config);
374 config_func_ptrs[last_simtrace_config].exit();
375 config_func_ptrs[simtrace_config].init();
376 last_simtrace_config = simtrace_config;
377 } else {
378 config_func_ptrs[simtrace_config].run();
379 }
380 }
Christina Quast32906bb2015-02-24 11:35:19 +0100381}