blob: d44cc44dd814bb1ee07b4c727780ce23391f5db2 [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"
Harald Welteb41598b2017-02-04 12:15:58 +010012#include "osmocom/core/timer.h"
Christina Quast32906bb2015-02-24 11:35:19 +010013
Harald Welte8ee15db2016-03-20 16:00:39 +010014uint32_t g_unique_id[4];
15
Christina Quast32906bb2015-02-24 11:35:19 +010016/*------------------------------------------------------------------------------
Christina Quast32906bb2015-02-24 11:35:19 +010017 * Internal variables
18 *------------------------------------------------------------------------------*/
Christina Quastfb524b92015-02-27 13:39:45 +010019typedef struct {
Harald Welte7dd3dfd2016-03-03 12:32:04 +010020 /* static initialization, called whether or not the usb config is active */
21 void (*configure) (void);
22 /* initialization function after the config was selected */
23 void (*init) (void);
24 /* de-initialization before selecting new config */
25 void (*exit) (void);
26 /* main loop content for given configuration */
27 void (*run) (void);
Harald Welte3bafe432016-03-20 16:43:12 +010028 /* Interrupt handler for USART1 */
29 void (*usart0_irq) (void);
30 /* Interrupt handler for USART1 */
31 void (*usart1_irq) (void);
Christina Quastfb524b92015-02-27 13:39:45 +010032} conf_func;
33
Harald Welted4c14212015-11-07 18:25:46 +010034static const conf_func config_func_ptrs[] = {
Harald Weltefefd5712015-11-07 18:19:11 +010035 /* array slot 0 is empty, usb configs start at 1 */
Harald Welte2fb59962016-02-28 12:34:26 +010036#ifdef HAVE_SNIFFER
Harald Weltefefd5712015-11-07 18:19:11 +010037 [CFG_NUM_SNIFF] = {
38 .configure = Sniffer_configure,
39 .init = Sniffer_init,
40 .exit = Sniffer_exit,
41 .run = Sniffer_run,
42 },
Harald Welte2fb59962016-02-28 12:34:26 +010043#endif
44#ifdef HAVE_CCID
Harald Weltefefd5712015-11-07 18:19:11 +010045 [CFG_NUM_CCID] = {
46 .configure = CCID_configure,
47 .init = CCID_init,
48 .exit = CCID_exit,
49 .run = CCID_run,
50 },
Harald Welte2fb59962016-02-28 12:34:26 +010051#endif
52#ifdef HAVE_CARDEM
Harald Weltefefd5712015-11-07 18:19:11 +010053 [CFG_NUM_PHONE] = {
Harald Welte2a6d3af2016-02-28 19:29:14 +010054 .configure = mode_cardemu_configure,
55 .init = mode_cardemu_init,
56 .exit = mode_cardemu_exit,
57 .run = mode_cardemu_run,
Harald Welte3bafe432016-03-20 16:43:12 +010058 .usart0_irq = mode_cardemu_usart0_irq,
59 .usart1_irq = mode_cardemu_usart1_irq,
Harald Weltefefd5712015-11-07 18:19:11 +010060 },
Harald Welte2fb59962016-02-28 12:34:26 +010061#endif
62#ifdef HAVE_MITM
Harald Weltefefd5712015-11-07 18:19:11 +010063 [CFG_NUM_MITM] = {
64 .configure = MITM_configure,
65 .init = MITM_init,
66 .exit = MITM_exit,
Harald Welte7dd3dfd2016-03-03 12:32:04 +010067 .run = MITM_run,
Harald Weltefefd5712015-11-07 18:19:11 +010068 },
Harald Welte2fb59962016-02-28 12:34:26 +010069#endif
Christina Quastfb524b92015-02-27 13:39:45 +010070};
71
Christina Quastfb524b92015-02-27 13:39:45 +010072/*------------------------------------------------------------------------------
73 * Internal variables
74 *------------------------------------------------------------------------------*/
Harald Welte2fb59962016-02-28 12:34:26 +010075#if defined(HAVE_SNIFFER)
Harald Welte8d6a5d82015-11-07 18:27:05 +010076static volatile enum confNum simtrace_config = CFG_NUM_SNIFF;
Harald Welte2fb59962016-02-28 12:34:26 +010077#elif defined(HAVE_CARDEM)
78static volatile enum confNum simtrace_config = CFG_NUM_PHONE;
79#elif defined(HAVE_CCID)
80static volatile enum confNum simtrace_config = CFG_NUM_CCID;
81#endif
82
Harald Welte006b16d2016-12-22 21:29:10 +010083static const Pin pin_hubpwr_override = PIN_PRTPWR_OVERRIDE;
Harald Welte6dfcf702017-01-11 22:23:13 +010084static const Pin pin_hub_rst = {PIO_PA13, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT};
Harald Welte006b16d2016-12-22 21:29:10 +010085static const Pin pin_1234_detect = {PIO_PA14, PIOA, ID_PIOA, PIO_INPUT, PIO_PULLUP};
86static const Pin pin_peer_rst = {PIO_PA0, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT};
87static const Pin pin_peer_erase = {PIO_PA11, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT};
88
89
Harald Welte8d6a5d82015-11-07 18:27:05 +010090/*----------------------------------------------------------------------------
91 * Callbacks
92 *----------------------------------------------------------------------------*/
93
94void USBDDriverCallbacks_ConfigurationChanged(uint8_t cfgnum)
95{
Harald Welte7dd3dfd2016-03-03 12:32:04 +010096 TRACE_INFO_WP("cfgChanged%d ", cfgnum);
97 simtrace_config = cfgnum;
Harald Welte8d6a5d82015-11-07 18:27:05 +010098}
Christina Quast32906bb2015-02-24 11:35:19 +010099
Harald Welte3bafe432016-03-20 16:43:12 +0100100void USART1_IrqHandler(void)
101{
102 config_func_ptrs[simtrace_config].usart1_irq();
103}
104
105void USART0_IrqHandler(void)
106{
107 config_func_ptrs[simtrace_config].usart0_irq();
108}
109
Harald Welte006b16d2016-12-22 21:29:10 +0100110static int qmod_sam3_is_12(void)
111{
112 if (PIO_Get(&pin_1234_detect) == 0)
113 return 1;
114 else
115 return 0;
116}
Harald Weltee974fbb2016-10-19 19:36:07 +0200117
Harald Welteb8713632017-01-11 23:08:35 +0100118const unsigned char __eeprom_bin[256] = {
119 0x23, 0x42, 0x17, 0x25, 0x00, 0x00, 0x9b, 0x20, 0x01, 0x00, 0x00, 0x00, 0x32, 0x32, 0x32, 0x32, /* 0x00 - 0x0f */
120 0x32, 0x04, 0x09, 0x18, 0x0d, 0x00, 0x73, 0x00, 0x79, 0x00, 0x73, 0x00, 0x6d, 0x00, 0x6f, 0x00, /* 0x10 - 0x1f */
121 0x63, 0x00, 0x6f, 0x00, 0x6d, 0x00, 0x20, 0x00, 0x2d, 0x00, 0x20, 0x00, 0x73, 0x00, 0x2e, 0x00, /* 0x20 - 0x2f */
122 0x66, 0x00, 0x2e, 0x00, 0x6d, 0x00, 0x2e, 0x00, 0x63, 0x00, 0x2e, 0x00, 0x20, 0x00, 0x47, 0x00, /* 0x30 - 0x3f */
123 0x6d, 0x00, 0x62, 0x00, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40 - 0x4f */
124 0x00, 0x00, 0x00, 0x00, 0x71, 0x00, 0x75, 0x00, 0x61, 0x00, 0x64, 0x00, 0x20, 0x00, 0x6d, 0x00, /* 0x50 - 0x5f */
125 0x6f, 0x00, 0x64, 0x00, 0x65, 0x00, 0x6d, 0x00, 0x20, 0x00, 0x76, 0x00, 0x32, 0x00, 0x00, 0x00, /* 0x60 - 0x6f */
126 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70 - 0x7f */
127 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80 - 0x8f */
128 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90 - 0x9f */
129 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0 - 0xaf */
130 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0 - 0xbf */
131 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0 - 0xcf */
132 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0 - 0xdf */
133 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0 - 0xef */
134 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA0, 0x56, 0x23, 0x71, 0x04, 0x00, /* 0xf0 - 0xff */
135};
136
Harald Welte006b16d2016-12-22 21:29:10 +0100137#include "i2c.h"
Harald Weltee974fbb2016-10-19 19:36:07 +0200138static int write_hub_eeprom(void)
139{
Harald Weltee974fbb2016-10-19 19:36:07 +0200140 const unsigned int __eeprom_bin_len = 256;
141
Harald Weltee974fbb2016-10-19 19:36:07 +0200142 int i;
143
Harald Weltee974fbb2016-10-19 19:36:07 +0200144 /* wait */
145 volatile int v;
146 /* 440ns per cycle here */
147 for (i = 0; i < 1000000; i++) {
148 v = 0;
149 }
150
Harald Welte006b16d2016-12-22 21:29:10 +0100151 TRACE_INFO("Writing EEPROM...\r\n");
Harald Weltee974fbb2016-10-19 19:36:07 +0200152 /* write the EEPROM once */
153 for (i = 0; i < 256; i++) {
154 int rc = eeprom_write_byte(0x50, i, __eeprom_bin[i]);
155 /* if the result was negative, repeat that write */
156 if (rc < 0)
157 i--;
158 }
159
160 /* then pursue re-reading it again and again */
Harald Welte006b16d2016-12-22 21:29:10 +0100161 TRACE_INFO("Verifying EEPROM...\r\n");
Harald Weltee974fbb2016-10-19 19:36:07 +0200162 for (i = 0; i < 256; i++) {
163 int byte = eeprom_read_byte(0x50, i);
164 TRACE_INFO("0x%02x: %02x\r\n", i, byte);
165 if (byte != __eeprom_bin[i])
166 TRACE_ERROR("Byte %u is wrong, expected 0x%02x, found 0x%02x\r\n",
167 i, __eeprom_bin[i], byte);
168 }
Harald Weltee974fbb2016-10-19 19:36:07 +0200169
170 /* FIXME: Release PIN_PRTPWR_OVERRIDE after we know the hub is
171 * again powering us up */
172
173 return 0;
174}
175
Harald Weltef9a182d2017-01-11 22:22:16 +0100176/* returns '1' in case we should break any endless loop */
Harald Welteaf614792017-01-12 18:59:41 +0100177static void check_exec_dbg_cmd(void)
Harald Welte006b16d2016-12-22 21:29:10 +0100178{
179 uint32_t addr, val;
180
181 if (!UART_IsRxReady())
182 return;
183
184 int ch = UART_GetChar();
185 switch (ch) {
186 case '?':
187 printf("\t?\thelp\r\n");
188 printf("\tE\tprogram EEPROM\r\n");
189 printf("\tR\treset SAM3\r\n");
190 printf("\tO\tEnable PRTPWR_OVERRIDE\r\n");
191 printf("\to\tDisable PRTPWR_OVERRIDE\r\n");
192 printf("\tH\tRelease HUB RESET (high)\r\n");
193 printf("\th\tAssert HUB RESET (low)\r\n");
194 printf("\tw\tWrite single byte in EEPROM\r\n");
195 printf("\tr\tRead single byte from EEPROM\r\n");
196 printf("\tX\tRelease peer SAM3 from reset\r\n");
197 printf("\tx\tAssert peer SAM3 reset\r\n");
Harald Welte396354c2016-12-22 22:28:26 +0100198 printf("\tY\tRelease peer SAM3 ERASE signal\r\n");
Harald Welte006b16d2016-12-22 21:29:10 +0100199 printf("\ty\tAssert peer SAM3 ERASE signal\r\n");
Harald Weltee07aed62016-12-22 22:32:15 +0100200 printf("\tU\tProceed to USB Initialization\r\n");
Harald Welte7e5c7d52017-02-03 22:59:04 +0100201 printf("\t1\tGenerate 1ms reset pulse on WWAN1\r\n");
202 printf("\t2\tGenerate 1ms reset pulse on WWAN2\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 Welte7e5c7d52017-02-03 22:59:04 +0100259 case '1':
260 printf("Resetting Modem 1 (of this SAM3)\r\n");
261 wwan_perst_do_reset(1);
262 break;
263 case '2':
264 printf("Resetting Modem 2 (of this SAM3)\r\n");
265 wwan_perst_do_reset(2);
266 break;
Harald Welte396354c2016-12-22 22:28:26 +0100267 default:
268 printf("Unknown command '%c'\r\n", ch);
269 break;
Harald Welte006b16d2016-12-22 21:29:10 +0100270 }
271}
Harald Weltee974fbb2016-10-19 19:36:07 +0200272
Christina Quast32906bb2015-02-24 11:35:19 +0100273/*------------------------------------------------------------------------------
Christina Quast95d66162015-04-09 22:38:47 +0200274 * Main
Christina Quast32906bb2015-02-24 11:35:19 +0100275 *------------------------------------------------------------------------------*/
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100276#define MAX_USB_ITER BOARD_MCK/72 // This should be around a second
277extern int main(void)
Christina Quast32906bb2015-02-24 11:35:19 +0100278{
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100279 uint8_t isUsbConnected = 0;
280 enum confNum last_simtrace_config = simtrace_config;
281 unsigned int i = 0;
Christina Quast1161b272015-02-25 14:15:57 +0100282
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100283 LED_Configure(LED_NUM_RED);
284 LED_Configure(LED_NUM_GREEN);
285 LED_Set(LED_NUM_RED);
Christina Quast32906bb2015-02-24 11:35:19 +0100286
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100287 /* Disable watchdog */
288 WDT_Disable(WDT);
Christina Quast32906bb2015-02-24 11:35:19 +0100289
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100290 req_ctx_init();
Harald Welteebbb6452016-02-29 17:57:51 +0100291
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100292 PIO_InitializeInterrupts(0);
Christina Quast32906bb2015-02-24 11:35:19 +0100293
Harald Welte2819e9c2017-02-03 07:46:01 +0100294 wwan_led_init();
Harald Welte7e5c7d52017-02-03 22:59:04 +0100295 wwan_perst_init();
Harald Welte2819e9c2017-02-03 07:46:01 +0100296
Harald Welte8ee15db2016-03-20 16:00:39 +0100297 EEFC_ReadUniqueID(g_unique_id);
298
Harald Welte2315e6b2016-03-19 21:37:55 +0100299 printf("\r\n\r\n"
300 "=============================================================================\r\n"
301 "SIMtrace2 firmware " GIT_VERSION " (C) 2010-2016 by Harald Welte\r\n"
302 "=============================================================================\r\n");
303
Harald Welte8ee15db2016-03-20 16:00:39 +0100304 TRACE_INFO("Serial Nr. %08x-%08x-%08x-%08x\r\n",
305 g_unique_id[0], g_unique_id[1],
306 g_unique_id[2], g_unique_id[3]);
307
Harald Welte006b16d2016-12-22 21:29:10 +0100308 /* set PIN_PRTPWR_OVERRIDE to output-low to avoid the internal
309 * pull-up on the input to keep SIMTRACE12 alive */
310 PIO_Configure(&pin_hubpwr_override, 1);
311 PIO_Configure(&pin_hub_rst, 1);
312 PIO_Configure(&pin_1234_detect, 1);
313 PIO_Configure(&pin_peer_rst, 1);
314 PIO_Configure(&pin_peer_erase, 1);
315 i2c_pin_init();
316
317 if (qmod_sam3_is_12()) {
318 TRACE_INFO("Detected Quad-Modem ST12\r\n");
319 } else {
320 TRACE_INFO("Detected Quad-Modem ST34\r\n");
321 }
322
Harald Weltecf1c19a2016-03-20 15:18:18 +0100323 TRACE_INFO("USB init...\r\n");
Harald Weltee07aed62016-12-22 22:32:15 +0100324 SIMtrace_USB_Initialize();
325
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100326 while (USBD_GetState() < USBD_STATE_CONFIGURED) {
Harald Welte006b16d2016-12-22 21:29:10 +0100327 check_exec_dbg_cmd();
Harald Welte67415e32016-09-01 20:57:56 +0200328#if 0
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100329 if (i >= MAX_USB_ITER * 3) {
330 TRACE_ERROR("Resetting board (USB could "
Harald Weltecf1c19a2016-03-20 15:18:18 +0100331 "not be configured)\r\n");
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100332 NVIC_SystemReset();
333 }
Harald Welte67415e32016-09-01 20:57:56 +0200334#endif
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100335 i++;
336 }
Christina Quastde688672015-04-12 15:20:57 +0200337
Harald Welte006b16d2016-12-22 21:29:10 +0100338 TRACE_INFO("Releasing ST12_PRTPWR_OVERRIDE\r\n");
339 PIO_Clear(&pin_hubpwr_override);
340
Harald Weltecf1c19a2016-03-20 15:18:18 +0100341 TRACE_INFO("calling configure of all configurations...\r\n");
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100342 for (i = 1; i < sizeof(config_func_ptrs) / sizeof(config_func_ptrs[0]);
343 ++i) {
344 if (config_func_ptrs[i].configure)
345 config_func_ptrs[i].configure();
346 }
Christina Quast95d66162015-04-09 22:38:47 +0200347
Harald Weltecf1c19a2016-03-20 15:18:18 +0100348 TRACE_INFO("calling init of config %u...\r\n", simtrace_config);
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100349 config_func_ptrs[simtrace_config].init();
350 last_simtrace_config = simtrace_config;
Christina Quast95d66162015-04-09 22:38:47 +0200351
Harald Weltecf1c19a2016-03-20 15:18:18 +0100352 TRACE_INFO("entering main loop...\r\n");
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100353 while (1) {
Harald Welte04e37a82016-03-20 15:15:34 +0100354#if TRACE_LEVEL >= TRACE_LEVEL_DEBUG
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100355 const char rotor[] = { '-', '\\', '|', '/' };
356 putchar('\b');
357 putchar(rotor[i++ % ARRAY_SIZE(rotor)]);
Harald Welte04e37a82016-03-20 15:15:34 +0100358#endif
Harald Welte006b16d2016-12-22 21:29:10 +0100359 check_exec_dbg_cmd();
Harald Welte987f59a2017-02-04 12:34:35 +0100360 osmo_timers_prepare();
361 osmo_timers_update();
Christina Quast1161b272015-02-25 14:15:57 +0100362
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100363 if (USBD_GetState() < USBD_STATE_CONFIGURED) {
Christina Quast1161b272015-02-25 14:15:57 +0100364
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100365 if (isUsbConnected) {
366 isUsbConnected = 0;
367 }
368 } else if (isUsbConnected == 0) {
Harald Weltecf1c19a2016-03-20 15:18:18 +0100369 TRACE_INFO("USB is now configured\r\n");
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100370 LED_Set(LED_NUM_GREEN);
371 LED_Clear(LED_NUM_RED);
Christina Quast1161b272015-02-25 14:15:57 +0100372
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100373 isUsbConnected = 1;
374 }
375 if (last_simtrace_config != simtrace_config) {
376 TRACE_INFO("USB config chg %u -> %u\r\n",
377 last_simtrace_config, simtrace_config);
378 config_func_ptrs[last_simtrace_config].exit();
379 config_func_ptrs[simtrace_config].init();
380 last_simtrace_config = simtrace_config;
381 } else {
382 config_func_ptrs[simtrace_config].run();
383 }
384 }
Christina Quast32906bb2015-02-24 11:35:19 +0100385}