blob: 412b1ce1ceea551b46453ab9079dabdd271550c9 [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"
Christina Quast32906bb2015-02-24 11:35:19 +010011
Harald Welte8ee15db2016-03-20 16:00:39 +010012uint32_t g_unique_id[4];
13
Christina Quast32906bb2015-02-24 11:35:19 +010014/*------------------------------------------------------------------------------
Christina Quast32906bb2015-02-24 11:35:19 +010015 * Internal variables
16 *------------------------------------------------------------------------------*/
Christina Quastfb524b92015-02-27 13:39:45 +010017typedef struct {
Harald Welte7dd3dfd2016-03-03 12:32:04 +010018 /* static initialization, called whether or not the usb config is active */
19 void (*configure) (void);
20 /* initialization function after the config was selected */
21 void (*init) (void);
22 /* de-initialization before selecting new config */
23 void (*exit) (void);
24 /* main loop content for given configuration */
25 void (*run) (void);
Harald Welte3bafe432016-03-20 16:43:12 +010026 /* Interrupt handler for USART1 */
27 void (*usart0_irq) (void);
28 /* Interrupt handler for USART1 */
29 void (*usart1_irq) (void);
Christina Quastfb524b92015-02-27 13:39:45 +010030} conf_func;
31
Harald Welted4c14212015-11-07 18:25:46 +010032static const conf_func config_func_ptrs[] = {
Harald Weltefefd5712015-11-07 18:19:11 +010033 /* array slot 0 is empty, usb configs start at 1 */
Harald Welte2fb59962016-02-28 12:34:26 +010034#ifdef HAVE_SNIFFER
Harald Weltefefd5712015-11-07 18:19:11 +010035 [CFG_NUM_SNIFF] = {
36 .configure = Sniffer_configure,
37 .init = Sniffer_init,
38 .exit = Sniffer_exit,
39 .run = Sniffer_run,
40 },
Harald Welte2fb59962016-02-28 12:34:26 +010041#endif
42#ifdef HAVE_CCID
Harald Weltefefd5712015-11-07 18:19:11 +010043 [CFG_NUM_CCID] = {
44 .configure = CCID_configure,
45 .init = CCID_init,
46 .exit = CCID_exit,
47 .run = CCID_run,
48 },
Harald Welte2fb59962016-02-28 12:34:26 +010049#endif
50#ifdef HAVE_CARDEM
Harald Weltefefd5712015-11-07 18:19:11 +010051 [CFG_NUM_PHONE] = {
Harald Welte2a6d3af2016-02-28 19:29:14 +010052 .configure = mode_cardemu_configure,
53 .init = mode_cardemu_init,
54 .exit = mode_cardemu_exit,
55 .run = mode_cardemu_run,
Harald Welte3bafe432016-03-20 16:43:12 +010056 .usart0_irq = mode_cardemu_usart0_irq,
57 .usart1_irq = mode_cardemu_usart1_irq,
Harald Weltefefd5712015-11-07 18:19:11 +010058 },
Harald Welte2fb59962016-02-28 12:34:26 +010059#endif
60#ifdef HAVE_MITM
Harald Weltefefd5712015-11-07 18:19:11 +010061 [CFG_NUM_MITM] = {
62 .configure = MITM_configure,
63 .init = MITM_init,
64 .exit = MITM_exit,
Harald Welte7dd3dfd2016-03-03 12:32:04 +010065 .run = MITM_run,
Harald Weltefefd5712015-11-07 18:19:11 +010066 },
Harald Welte2fb59962016-02-28 12:34:26 +010067#endif
Christina Quastfb524b92015-02-27 13:39:45 +010068};
69
Christina Quastfb524b92015-02-27 13:39:45 +010070/*------------------------------------------------------------------------------
71 * Internal variables
72 *------------------------------------------------------------------------------*/
Harald Welte2fb59962016-02-28 12:34:26 +010073#if defined(HAVE_SNIFFER)
Harald Welte8d6a5d82015-11-07 18:27:05 +010074static volatile enum confNum simtrace_config = CFG_NUM_SNIFF;
Harald Welte2fb59962016-02-28 12:34:26 +010075#elif defined(HAVE_CARDEM)
76static volatile enum confNum simtrace_config = CFG_NUM_PHONE;
77#elif defined(HAVE_CCID)
78static volatile enum confNum simtrace_config = CFG_NUM_CCID;
79#endif
80
Harald Welte006b16d2016-12-22 21:29:10 +010081static const Pin pin_hubpwr_override = PIN_PRTPWR_OVERRIDE;
Harald Welte6dfcf702017-01-11 22:23:13 +010082static const Pin pin_hub_rst = {PIO_PA13, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT};
Harald Welte006b16d2016-12-22 21:29:10 +010083static const Pin pin_1234_detect = {PIO_PA14, PIOA, ID_PIOA, PIO_INPUT, PIO_PULLUP};
84static const Pin pin_peer_rst = {PIO_PA0, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT};
85static const Pin pin_peer_erase = {PIO_PA11, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT};
86
87
Harald Welte8d6a5d82015-11-07 18:27:05 +010088/*----------------------------------------------------------------------------
89 * Callbacks
90 *----------------------------------------------------------------------------*/
91
92void USBDDriverCallbacks_ConfigurationChanged(uint8_t cfgnum)
93{
Harald Welte7dd3dfd2016-03-03 12:32:04 +010094 TRACE_INFO_WP("cfgChanged%d ", cfgnum);
95 simtrace_config = cfgnum;
Harald Welte8d6a5d82015-11-07 18:27:05 +010096}
Christina Quast32906bb2015-02-24 11:35:19 +010097
Harald Welte3bafe432016-03-20 16:43:12 +010098void USART1_IrqHandler(void)
99{
100 config_func_ptrs[simtrace_config].usart1_irq();
101}
102
103void USART0_IrqHandler(void)
104{
105 config_func_ptrs[simtrace_config].usart0_irq();
106}
107
Harald Welte006b16d2016-12-22 21:29:10 +0100108static int qmod_sam3_is_12(void)
109{
110 if (PIO_Get(&pin_1234_detect) == 0)
111 return 1;
112 else
113 return 0;
114}
Harald Weltee974fbb2016-10-19 19:36:07 +0200115
Harald Welteb8713632017-01-11 23:08:35 +0100116const unsigned char __eeprom_bin[256] = {
117 0x23, 0x42, 0x17, 0x25, 0x00, 0x00, 0x9b, 0x20, 0x01, 0x00, 0x00, 0x00, 0x32, 0x32, 0x32, 0x32, /* 0x00 - 0x0f */
118 0x32, 0x04, 0x09, 0x18, 0x0d, 0x00, 0x73, 0x00, 0x79, 0x00, 0x73, 0x00, 0x6d, 0x00, 0x6f, 0x00, /* 0x10 - 0x1f */
119 0x63, 0x00, 0x6f, 0x00, 0x6d, 0x00, 0x20, 0x00, 0x2d, 0x00, 0x20, 0x00, 0x73, 0x00, 0x2e, 0x00, /* 0x20 - 0x2f */
120 0x66, 0x00, 0x2e, 0x00, 0x6d, 0x00, 0x2e, 0x00, 0x63, 0x00, 0x2e, 0x00, 0x20, 0x00, 0x47, 0x00, /* 0x30 - 0x3f */
121 0x6d, 0x00, 0x62, 0x00, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40 - 0x4f */
122 0x00, 0x00, 0x00, 0x00, 0x71, 0x00, 0x75, 0x00, 0x61, 0x00, 0x64, 0x00, 0x20, 0x00, 0x6d, 0x00, /* 0x50 - 0x5f */
123 0x6f, 0x00, 0x64, 0x00, 0x65, 0x00, 0x6d, 0x00, 0x20, 0x00, 0x76, 0x00, 0x32, 0x00, 0x00, 0x00, /* 0x60 - 0x6f */
124 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70 - 0x7f */
125 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80 - 0x8f */
126 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90 - 0x9f */
127 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0 - 0xaf */
128 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0 - 0xbf */
129 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0 - 0xcf */
130 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0 - 0xdf */
131 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0 - 0xef */
132 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA0, 0x56, 0x23, 0x71, 0x04, 0x00, /* 0xf0 - 0xff */
133};
134
Harald Welte006b16d2016-12-22 21:29:10 +0100135#include "i2c.h"
Harald Weltee974fbb2016-10-19 19:36:07 +0200136static int write_hub_eeprom(void)
137{
Harald Weltee974fbb2016-10-19 19:36:07 +0200138 const unsigned int __eeprom_bin_len = 256;
139
Harald Weltee974fbb2016-10-19 19:36:07 +0200140 int i;
141
Harald Weltee974fbb2016-10-19 19:36:07 +0200142 /* wait */
143 volatile int v;
144 /* 440ns per cycle here */
145 for (i = 0; i < 1000000; i++) {
146 v = 0;
147 }
148
Harald Welte006b16d2016-12-22 21:29:10 +0100149 TRACE_INFO("Writing EEPROM...\r\n");
Harald Weltee974fbb2016-10-19 19:36:07 +0200150 /* write the EEPROM once */
151 for (i = 0; i < 256; i++) {
152 int rc = eeprom_write_byte(0x50, i, __eeprom_bin[i]);
153 /* if the result was negative, repeat that write */
154 if (rc < 0)
155 i--;
156 }
157
158 /* then pursue re-reading it again and again */
Harald Welte006b16d2016-12-22 21:29:10 +0100159 TRACE_INFO("Verifying EEPROM...\r\n");
Harald Weltee974fbb2016-10-19 19:36:07 +0200160 for (i = 0; i < 256; i++) {
161 int byte = eeprom_read_byte(0x50, i);
162 TRACE_INFO("0x%02x: %02x\r\n", i, byte);
163 if (byte != __eeprom_bin[i])
164 TRACE_ERROR("Byte %u is wrong, expected 0x%02x, found 0x%02x\r\n",
165 i, __eeprom_bin[i], byte);
166 }
Harald Weltee974fbb2016-10-19 19:36:07 +0200167
168 /* FIXME: Release PIN_PRTPWR_OVERRIDE after we know the hub is
169 * again powering us up */
170
171 return 0;
172}
173
Harald Weltef9a182d2017-01-11 22:22:16 +0100174/* returns '1' in case we should break any endless loop */
Harald Welteaf614792017-01-12 18:59:41 +0100175static void check_exec_dbg_cmd(void)
Harald Welte006b16d2016-12-22 21:29:10 +0100176{
177 uint32_t addr, val;
178
179 if (!UART_IsRxReady())
180 return;
181
182 int ch = UART_GetChar();
183 switch (ch) {
184 case '?':
185 printf("\t?\thelp\r\n");
186 printf("\tE\tprogram EEPROM\r\n");
187 printf("\tR\treset SAM3\r\n");
188 printf("\tO\tEnable PRTPWR_OVERRIDE\r\n");
189 printf("\to\tDisable PRTPWR_OVERRIDE\r\n");
190 printf("\tH\tRelease HUB RESET (high)\r\n");
191 printf("\th\tAssert HUB RESET (low)\r\n");
192 printf("\tw\tWrite single byte in EEPROM\r\n");
193 printf("\tr\tRead single byte from EEPROM\r\n");
194 printf("\tX\tRelease peer SAM3 from reset\r\n");
195 printf("\tx\tAssert peer SAM3 reset\r\n");
Harald Welte396354c2016-12-22 22:28:26 +0100196 printf("\tY\tRelease peer SAM3 ERASE signal\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100197 printf("\ty\tAssert peer SAM3 ERASE signal\r\n");
Harald Weltee07aed62016-12-22 22:32:15 +0100198 printf("\tU\tProceed to USB Initialization\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100199 break;
200 case 'E':
201 write_hub_eeprom();
202 break;
203 case 'R':
Harald Welte396354c2016-12-22 22:28:26 +0100204 printf("Asking NVIC to reset us\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100205 NVIC_SystemReset();
206 break;
207 case 'O':
Harald Welte396354c2016-12-22 22:28:26 +0100208 printf("Setting PRTPWR_OVERRIDE\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100209 PIO_Set(&pin_hubpwr_override);
210 break;
211 case 'o':
Harald Welte396354c2016-12-22 22:28:26 +0100212 printf("Clearing PRTPWR_OVERRIDE\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100213 PIO_Clear(&pin_hubpwr_override);
214 break;
215 case 'H':
Harald Welte396354c2016-12-22 22:28:26 +0100216 printf("Clearing _HUB_RESET -> HUB_RESET high (inactive)\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100217 PIO_Clear(&pin_hub_rst);
218 break;
219 case 'h':
220 /* high level drives transistor -> HUB_RESET low */
Harald Welte396354c2016-12-22 22:28:26 +0100221 printf("Asserting _HUB_RESET -> HUB_RESET low (active)\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100222 PIO_Set(&pin_hub_rst);
223 break;
224 case 'w':
225 if (PIO_GetOutputDataStatus(&pin_hub_rst) == 0)
226 printf("WARNING: attempting EEPROM access while HUB not in reset\r\n");
Harald Welte396354c2016-12-22 22:28:26 +0100227 printf("Please enter EEPROM offset:\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100228 UART_GetIntegerMinMax(&addr, 0, 255);
Harald Welte396354c2016-12-22 22:28:26 +0100229 printf("Please enter EEPROM value:\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100230 UART_GetIntegerMinMax(&val, 0, 255);
231 printf("Writing value 0x%02x to EEPROM offset 0x%02x\r\n", val, addr);
232 eeprom_write_byte(0x50, addr, val);
233 break;
234 case 'r':
Harald Welte396354c2016-12-22 22:28:26 +0100235 printf("Please enter EEPROM offset:\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100236 UART_GetIntegerMinMax(&addr, 0, 255);
237 printf("EEPROM[0x%02x] = 0x%02x\r\n", addr, eeprom_read_byte(0x50, addr));
238 break;
239 case 'X':
Harald Welte396354c2016-12-22 22:28:26 +0100240 printf("Clearing _SIMTRACExx_RST -> SIMTRACExx_RST high (inactive)\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100241 PIO_Clear(&pin_peer_rst);
242 break;
243 case 'x':
Harald Welte396354c2016-12-22 22:28:26 +0100244 printf("Setting _SIMTRACExx_RST -> SIMTRACExx_RST low (active)\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100245 PIO_Set(&pin_peer_rst);
246 break;
247 case 'Y':
Harald Welte396354c2016-12-22 22:28:26 +0100248 printf("Clearing SIMTRACExx_ERASE (inactive)\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100249 PIO_Clear(&pin_peer_erase);
250 break;
251 case 'y':
Harald Welte396354c2016-12-22 22:28:26 +0100252 printf("Seetting SIMTRACExx_ERASE (active)\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100253 PIO_Set(&pin_peer_erase);
254 break;
Harald Welte396354c2016-12-22 22:28:26 +0100255 default:
256 printf("Unknown command '%c'\r\n", ch);
257 break;
Harald Welte006b16d2016-12-22 21:29:10 +0100258 }
259}
Harald Weltee974fbb2016-10-19 19:36:07 +0200260
Christina Quast32906bb2015-02-24 11:35:19 +0100261/*------------------------------------------------------------------------------
Christina Quast95d66162015-04-09 22:38:47 +0200262 * Main
Christina Quast32906bb2015-02-24 11:35:19 +0100263 *------------------------------------------------------------------------------*/
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100264#define MAX_USB_ITER BOARD_MCK/72 // This should be around a second
265extern int main(void)
Christina Quast32906bb2015-02-24 11:35:19 +0100266{
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100267 uint8_t isUsbConnected = 0;
268 enum confNum last_simtrace_config = simtrace_config;
269 unsigned int i = 0;
Christina Quast1161b272015-02-25 14:15:57 +0100270
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100271 LED_Configure(LED_NUM_RED);
272 LED_Configure(LED_NUM_GREEN);
273 LED_Set(LED_NUM_RED);
Christina Quast32906bb2015-02-24 11:35:19 +0100274
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100275 /* Disable watchdog */
276 WDT_Disable(WDT);
Christina Quast32906bb2015-02-24 11:35:19 +0100277
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100278 req_ctx_init();
Harald Welteebbb6452016-02-29 17:57:51 +0100279
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100280 PIO_InitializeInterrupts(0);
Christina Quast32906bb2015-02-24 11:35:19 +0100281
Harald Welte2819e9c2017-02-03 07:46:01 +0100282 wwan_led_init();
283
Harald Welte8ee15db2016-03-20 16:00:39 +0100284 EEFC_ReadUniqueID(g_unique_id);
285
Harald Welte2315e6b2016-03-19 21:37:55 +0100286 printf("\r\n\r\n"
287 "=============================================================================\r\n"
288 "SIMtrace2 firmware " GIT_VERSION " (C) 2010-2016 by Harald Welte\r\n"
289 "=============================================================================\r\n");
290
Harald Welte8ee15db2016-03-20 16:00:39 +0100291 TRACE_INFO("Serial Nr. %08x-%08x-%08x-%08x\r\n",
292 g_unique_id[0], g_unique_id[1],
293 g_unique_id[2], g_unique_id[3]);
294
Harald Welte006b16d2016-12-22 21:29:10 +0100295 /* set PIN_PRTPWR_OVERRIDE to output-low to avoid the internal
296 * pull-up on the input to keep SIMTRACE12 alive */
297 PIO_Configure(&pin_hubpwr_override, 1);
298 PIO_Configure(&pin_hub_rst, 1);
299 PIO_Configure(&pin_1234_detect, 1);
300 PIO_Configure(&pin_peer_rst, 1);
301 PIO_Configure(&pin_peer_erase, 1);
302 i2c_pin_init();
303
304 if (qmod_sam3_is_12()) {
305 TRACE_INFO("Detected Quad-Modem ST12\r\n");
306 } else {
307 TRACE_INFO("Detected Quad-Modem ST34\r\n");
308 }
309
Harald Weltecf1c19a2016-03-20 15:18:18 +0100310 TRACE_INFO("USB init...\r\n");
Harald Weltee07aed62016-12-22 22:32:15 +0100311 SIMtrace_USB_Initialize();
312
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100313 while (USBD_GetState() < USBD_STATE_CONFIGURED) {
Harald Welte006b16d2016-12-22 21:29:10 +0100314 check_exec_dbg_cmd();
Harald Welte67415e32016-09-01 20:57:56 +0200315#if 0
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100316 if (i >= MAX_USB_ITER * 3) {
317 TRACE_ERROR("Resetting board (USB could "
Harald Weltecf1c19a2016-03-20 15:18:18 +0100318 "not be configured)\r\n");
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100319 NVIC_SystemReset();
320 }
Harald Welte67415e32016-09-01 20:57:56 +0200321#endif
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100322 i++;
323 }
Christina Quastde688672015-04-12 15:20:57 +0200324
Harald Welte006b16d2016-12-22 21:29:10 +0100325 TRACE_INFO("Releasing ST12_PRTPWR_OVERRIDE\r\n");
326 PIO_Clear(&pin_hubpwr_override);
327
Harald Weltecf1c19a2016-03-20 15:18:18 +0100328 TRACE_INFO("calling configure of all configurations...\r\n");
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100329 for (i = 1; i < sizeof(config_func_ptrs) / sizeof(config_func_ptrs[0]);
330 ++i) {
331 if (config_func_ptrs[i].configure)
332 config_func_ptrs[i].configure();
333 }
Christina Quast95d66162015-04-09 22:38:47 +0200334
Harald Weltecf1c19a2016-03-20 15:18:18 +0100335 TRACE_INFO("calling init of config %u...\r\n", simtrace_config);
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100336 config_func_ptrs[simtrace_config].init();
337 last_simtrace_config = simtrace_config;
Christina Quast95d66162015-04-09 22:38:47 +0200338
Harald Weltecf1c19a2016-03-20 15:18:18 +0100339 TRACE_INFO("entering main loop...\r\n");
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100340 while (1) {
Harald Welte04e37a82016-03-20 15:15:34 +0100341#if TRACE_LEVEL >= TRACE_LEVEL_DEBUG
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100342 const char rotor[] = { '-', '\\', '|', '/' };
343 putchar('\b');
344 putchar(rotor[i++ % ARRAY_SIZE(rotor)]);
Harald Welte04e37a82016-03-20 15:15:34 +0100345#endif
Harald Welte006b16d2016-12-22 21:29:10 +0100346 check_exec_dbg_cmd();
Christina Quast1161b272015-02-25 14:15:57 +0100347
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100348 if (USBD_GetState() < USBD_STATE_CONFIGURED) {
Christina Quast1161b272015-02-25 14:15:57 +0100349
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100350 if (isUsbConnected) {
351 isUsbConnected = 0;
352 }
353 } else if (isUsbConnected == 0) {
Harald Weltecf1c19a2016-03-20 15:18:18 +0100354 TRACE_INFO("USB is now configured\r\n");
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100355 LED_Set(LED_NUM_GREEN);
356 LED_Clear(LED_NUM_RED);
Christina Quast1161b272015-02-25 14:15:57 +0100357
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100358 isUsbConnected = 1;
359 }
360 if (last_simtrace_config != simtrace_config) {
361 TRACE_INFO("USB config chg %u -> %u\r\n",
362 last_simtrace_config, simtrace_config);
363 config_func_ptrs[last_simtrace_config].exit();
364 config_func_ptrs[simtrace_config].init();
365 last_simtrace_config = simtrace_config;
366 } else {
367 config_func_ptrs[simtrace_config].run();
368 }
369 }
Christina Quast32906bb2015-02-24 11:35:19 +0100370}