2015-02-24 10:35:19 +00:00
|
|
|
// FIXME: Copyright license here
|
|
|
|
/*------------------------------------------------------------------------------
|
|
|
|
* Headers
|
|
|
|
*------------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#include "board.h"
|
2016-03-03 10:02:45 +00:00
|
|
|
#include "simtrace.h"
|
2016-02-29 16:57:51 +00:00
|
|
|
#include "utils.h"
|
|
|
|
#include "req_ctx.h"
|
2017-02-03 06:46:01 +00:00
|
|
|
#include "wwan_led.h"
|
2017-02-03 21:59:04 +00:00
|
|
|
#include "wwan_perst.h"
|
2017-02-04 13:43:41 +00:00
|
|
|
#include "boardver_adc.h"
|
2017-02-04 11:15:58 +00:00
|
|
|
#include "osmocom/core/timer.h"
|
2015-02-24 10:35:19 +00:00
|
|
|
|
2016-03-20 15:00:39 +00:00
|
|
|
uint32_t g_unique_id[4];
|
|
|
|
|
2015-02-27 12:39:45 +00:00
|
|
|
/*------------------------------------------------------------------------------
|
|
|
|
* Internal variables
|
|
|
|
*------------------------------------------------------------------------------*/
|
|
|
|
typedef struct {
|
2016-03-03 11:32:04 +00:00
|
|
|
/* static initialization, called whether or not the usb config is active */
|
|
|
|
void (*configure) (void);
|
|
|
|
/* initialization function after the config was selected */
|
|
|
|
void (*init) (void);
|
|
|
|
/* de-initialization before selecting new config */
|
|
|
|
void (*exit) (void);
|
|
|
|
/* main loop content for given configuration */
|
|
|
|
void (*run) (void);
|
2016-03-20 15:43:12 +00:00
|
|
|
/* Interrupt handler for USART1 */
|
|
|
|
void (*usart0_irq) (void);
|
|
|
|
/* Interrupt handler for USART1 */
|
|
|
|
void (*usart1_irq) (void);
|
2015-02-27 12:39:45 +00:00
|
|
|
} conf_func;
|
|
|
|
|
2015-11-07 17:25:46 +00:00
|
|
|
static const conf_func config_func_ptrs[] = {
|
2015-11-07 17:19:11 +00:00
|
|
|
/* array slot 0 is empty, usb configs start at 1 */
|
2016-02-28 11:34:26 +00:00
|
|
|
#ifdef HAVE_SNIFFER
|
2015-11-07 17:19:11 +00:00
|
|
|
[CFG_NUM_SNIFF] = {
|
|
|
|
.configure = Sniffer_configure,
|
|
|
|
.init = Sniffer_init,
|
|
|
|
.exit = Sniffer_exit,
|
|
|
|
.run = Sniffer_run,
|
|
|
|
},
|
2016-02-28 11:34:26 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_CCID
|
2015-11-07 17:19:11 +00:00
|
|
|
[CFG_NUM_CCID] = {
|
|
|
|
.configure = CCID_configure,
|
|
|
|
.init = CCID_init,
|
|
|
|
.exit = CCID_exit,
|
|
|
|
.run = CCID_run,
|
|
|
|
},
|
2016-02-28 11:34:26 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_CARDEM
|
2015-11-07 17:19:11 +00:00
|
|
|
[CFG_NUM_PHONE] = {
|
2016-02-28 18:29:14 +00:00
|
|
|
.configure = mode_cardemu_configure,
|
|
|
|
.init = mode_cardemu_init,
|
|
|
|
.exit = mode_cardemu_exit,
|
|
|
|
.run = mode_cardemu_run,
|
2016-03-20 15:43:12 +00:00
|
|
|
.usart0_irq = mode_cardemu_usart0_irq,
|
|
|
|
.usart1_irq = mode_cardemu_usart1_irq,
|
2015-11-07 17:19:11 +00:00
|
|
|
},
|
2016-02-28 11:34:26 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_MITM
|
2015-11-07 17:19:11 +00:00
|
|
|
[CFG_NUM_MITM] = {
|
|
|
|
.configure = MITM_configure,
|
|
|
|
.init = MITM_init,
|
|
|
|
.exit = MITM_exit,
|
2016-03-03 11:32:04 +00:00
|
|
|
.run = MITM_run,
|
2015-11-07 17:19:11 +00:00
|
|
|
},
|
2016-02-28 11:34:26 +00:00
|
|
|
#endif
|
2015-02-27 12:39:45 +00:00
|
|
|
};
|
|
|
|
|
2015-02-24 10:35:19 +00:00
|
|
|
/*------------------------------------------------------------------------------
|
|
|
|
* Internal variables
|
|
|
|
*------------------------------------------------------------------------------*/
|
2016-02-28 11:34:26 +00:00
|
|
|
#if defined(HAVE_SNIFFER)
|
2015-11-07 17:27:05 +00:00
|
|
|
static volatile enum confNum simtrace_config = CFG_NUM_SNIFF;
|
2016-02-28 11:34:26 +00:00
|
|
|
#elif defined(HAVE_CARDEM)
|
|
|
|
static volatile enum confNum simtrace_config = CFG_NUM_PHONE;
|
|
|
|
#elif defined(HAVE_CCID)
|
|
|
|
static volatile enum confNum simtrace_config = CFG_NUM_CCID;
|
|
|
|
#endif
|
|
|
|
|
2016-12-22 20:29:10 +00:00
|
|
|
static const Pin pin_hubpwr_override = PIN_PRTPWR_OVERRIDE;
|
2017-01-11 21:23:13 +00:00
|
|
|
static const Pin pin_hub_rst = {PIO_PA13, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT};
|
2016-12-22 20:29:10 +00:00
|
|
|
static const Pin pin_1234_detect = {PIO_PA14, PIOA, ID_PIOA, PIO_INPUT, PIO_PULLUP};
|
|
|
|
static const Pin pin_peer_rst = {PIO_PA0, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT};
|
|
|
|
static const Pin pin_peer_erase = {PIO_PA11, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT};
|
|
|
|
|
|
|
|
|
2015-11-07 17:27:05 +00:00
|
|
|
/*----------------------------------------------------------------------------
|
|
|
|
* Callbacks
|
|
|
|
*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
void USBDDriverCallbacks_ConfigurationChanged(uint8_t cfgnum)
|
|
|
|
{
|
2016-03-03 11:32:04 +00:00
|
|
|
TRACE_INFO_WP("cfgChanged%d ", cfgnum);
|
|
|
|
simtrace_config = cfgnum;
|
2015-11-07 17:27:05 +00:00
|
|
|
}
|
2015-02-24 10:35:19 +00:00
|
|
|
|
2016-03-20 15:43:12 +00:00
|
|
|
void USART1_IrqHandler(void)
|
|
|
|
{
|
|
|
|
config_func_ptrs[simtrace_config].usart1_irq();
|
|
|
|
}
|
|
|
|
|
|
|
|
void USART0_IrqHandler(void)
|
|
|
|
{
|
|
|
|
config_func_ptrs[simtrace_config].usart0_irq();
|
|
|
|
}
|
|
|
|
|
2016-12-22 20:29:10 +00:00
|
|
|
static int qmod_sam3_is_12(void)
|
|
|
|
{
|
|
|
|
if (PIO_Get(&pin_1234_detect) == 0)
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
2016-03-03 11:32:04 +00:00
|
|
|
|
2017-01-11 22:08:35 +00:00
|
|
|
const unsigned char __eeprom_bin[256] = {
|
|
|
|
0x23, 0x42, 0x17, 0x25, 0x00, 0x00, 0x9b, 0x20, 0x01, 0x00, 0x00, 0x00, 0x32, 0x32, 0x32, 0x32, /* 0x00 - 0x0f */
|
|
|
|
0x32, 0x04, 0x09, 0x18, 0x0d, 0x00, 0x73, 0x00, 0x79, 0x00, 0x73, 0x00, 0x6d, 0x00, 0x6f, 0x00, /* 0x10 - 0x1f */
|
|
|
|
0x63, 0x00, 0x6f, 0x00, 0x6d, 0x00, 0x20, 0x00, 0x2d, 0x00, 0x20, 0x00, 0x73, 0x00, 0x2e, 0x00, /* 0x20 - 0x2f */
|
|
|
|
0x66, 0x00, 0x2e, 0x00, 0x6d, 0x00, 0x2e, 0x00, 0x63, 0x00, 0x2e, 0x00, 0x20, 0x00, 0x47, 0x00, /* 0x30 - 0x3f */
|
|
|
|
0x6d, 0x00, 0x62, 0x00, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40 - 0x4f */
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x71, 0x00, 0x75, 0x00, 0x61, 0x00, 0x64, 0x00, 0x20, 0x00, 0x6d, 0x00, /* 0x50 - 0x5f */
|
|
|
|
0x6f, 0x00, 0x64, 0x00, 0x65, 0x00, 0x6d, 0x00, 0x20, 0x00, 0x76, 0x00, 0x32, 0x00, 0x00, 0x00, /* 0x60 - 0x6f */
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70 - 0x7f */
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80 - 0x8f */
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90 - 0x9f */
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0 - 0xaf */
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0 - 0xbf */
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0 - 0xcf */
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0 - 0xdf */
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0 - 0xef */
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA0, 0x56, 0x23, 0x71, 0x04, 0x00, /* 0xf0 - 0xff */
|
|
|
|
};
|
|
|
|
|
2016-12-22 20:29:10 +00:00
|
|
|
#include "i2c.h"
|
2016-10-19 17:36:07 +00:00
|
|
|
static int write_hub_eeprom(void)
|
|
|
|
{
|
|
|
|
const unsigned int __eeprom_bin_len = 256;
|
2016-09-01 18:57:56 +00:00
|
|
|
|
2016-10-19 17:36:07 +00:00
|
|
|
int i;
|
2016-09-01 18:57:56 +00:00
|
|
|
|
|
|
|
/* wait */
|
|
|
|
volatile int v;
|
|
|
|
/* 440ns per cycle here */
|
|
|
|
for (i = 0; i < 1000000; i++) {
|
|
|
|
v = 0;
|
2016-08-21 17:33:24 +00:00
|
|
|
}
|
2016-09-01 18:57:56 +00:00
|
|
|
|
2016-12-22 20:29:10 +00:00
|
|
|
TRACE_INFO("Writing EEPROM...\r\n");
|
2016-09-01 18:57:56 +00:00
|
|
|
/* write the EEPROM once */
|
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
int rc = eeprom_write_byte(0x50, i, __eeprom_bin[i]);
|
|
|
|
/* if the result was negative, repeat that write */
|
|
|
|
if (rc < 0)
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* then pursue re-reading it again and again */
|
2016-12-22 20:29:10 +00:00
|
|
|
TRACE_INFO("Verifying EEPROM...\r\n");
|
2016-09-01 18:57:56 +00:00
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
int byte = eeprom_read_byte(0x50, i);
|
|
|
|
TRACE_INFO("0x%02x: %02x\r\n", i, byte);
|
|
|
|
if (byte != __eeprom_bin[i])
|
|
|
|
TRACE_ERROR("Byte %u is wrong, expected 0x%02x, found 0x%02x\r\n",
|
|
|
|
i, __eeprom_bin[i], byte);
|
|
|
|
}
|
2016-10-19 17:36:07 +00:00
|
|
|
|
|
|
|
/* FIXME: Release PIN_PRTPWR_OVERRIDE after we know the hub is
|
|
|
|
* again powering us up */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-01-11 21:22:16 +00:00
|
|
|
/* returns '1' in case we should break any endless loop */
|
2017-01-12 17:59:41 +00:00
|
|
|
static void check_exec_dbg_cmd(void)
|
2016-12-22 20:29:10 +00:00
|
|
|
{
|
|
|
|
uint32_t addr, val;
|
|
|
|
|
|
|
|
if (!UART_IsRxReady())
|
|
|
|
return;
|
|
|
|
|
|
|
|
int ch = UART_GetChar();
|
|
|
|
switch (ch) {
|
|
|
|
case '?':
|
|
|
|
printf("\t?\thelp\r\n");
|
|
|
|
printf("\tE\tprogram EEPROM\r\n");
|
|
|
|
printf("\tR\treset SAM3\r\n");
|
|
|
|
printf("\tO\tEnable PRTPWR_OVERRIDE\r\n");
|
|
|
|
printf("\to\tDisable PRTPWR_OVERRIDE\r\n");
|
|
|
|
printf("\tH\tRelease HUB RESET (high)\r\n");
|
|
|
|
printf("\th\tAssert HUB RESET (low)\r\n");
|
|
|
|
printf("\tw\tWrite single byte in EEPROM\r\n");
|
|
|
|
printf("\tr\tRead single byte from EEPROM\r\n");
|
|
|
|
printf("\tX\tRelease peer SAM3 from reset\r\n");
|
|
|
|
printf("\tx\tAssert peer SAM3 reset\r\n");
|
2016-12-22 21:28:26 +00:00
|
|
|
printf("\tY\tRelease peer SAM3 ERASE signal\r\n");
|
2016-12-22 20:29:10 +00:00
|
|
|
printf("\ty\tAssert peer SAM3 ERASE signal\r\n");
|
2016-12-22 21:32:15 +00:00
|
|
|
printf("\tU\tProceed to USB Initialization\r\n");
|
2017-02-03 21:59:04 +00:00
|
|
|
printf("\t1\tGenerate 1ms reset pulse on WWAN1\r\n");
|
|
|
|
printf("\t2\tGenerate 1ms reset pulse on WWAN2\r\n");
|
2016-12-22 20:29:10 +00:00
|
|
|
break;
|
|
|
|
case 'E':
|
|
|
|
write_hub_eeprom();
|
|
|
|
break;
|
|
|
|
case 'R':
|
2016-12-22 21:28:26 +00:00
|
|
|
printf("Asking NVIC to reset us\r\n");
|
2016-12-22 20:29:10 +00:00
|
|
|
NVIC_SystemReset();
|
|
|
|
break;
|
|
|
|
case 'O':
|
2016-12-22 21:28:26 +00:00
|
|
|
printf("Setting PRTPWR_OVERRIDE\r\n");
|
2016-12-22 20:29:10 +00:00
|
|
|
PIO_Set(&pin_hubpwr_override);
|
|
|
|
break;
|
|
|
|
case 'o':
|
2016-12-22 21:28:26 +00:00
|
|
|
printf("Clearing PRTPWR_OVERRIDE\r\n");
|
2016-12-22 20:29:10 +00:00
|
|
|
PIO_Clear(&pin_hubpwr_override);
|
|
|
|
break;
|
|
|
|
case 'H':
|
2016-12-22 21:28:26 +00:00
|
|
|
printf("Clearing _HUB_RESET -> HUB_RESET high (inactive)\r\n");
|
2016-12-22 20:29:10 +00:00
|
|
|
PIO_Clear(&pin_hub_rst);
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
/* high level drives transistor -> HUB_RESET low */
|
2016-12-22 21:28:26 +00:00
|
|
|
printf("Asserting _HUB_RESET -> HUB_RESET low (active)\r\n");
|
2016-12-22 20:29:10 +00:00
|
|
|
PIO_Set(&pin_hub_rst);
|
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
if (PIO_GetOutputDataStatus(&pin_hub_rst) == 0)
|
|
|
|
printf("WARNING: attempting EEPROM access while HUB not in reset\r\n");
|
2016-12-22 21:28:26 +00:00
|
|
|
printf("Please enter EEPROM offset:\r\n");
|
2016-12-22 20:29:10 +00:00
|
|
|
UART_GetIntegerMinMax(&addr, 0, 255);
|
2016-12-22 21:28:26 +00:00
|
|
|
printf("Please enter EEPROM value:\r\n");
|
2016-12-22 20:29:10 +00:00
|
|
|
UART_GetIntegerMinMax(&val, 0, 255);
|
|
|
|
printf("Writing value 0x%02x to EEPROM offset 0x%02x\r\n", val, addr);
|
|
|
|
eeprom_write_byte(0x50, addr, val);
|
|
|
|
break;
|
|
|
|
case 'r':
|
2016-12-22 21:28:26 +00:00
|
|
|
printf("Please enter EEPROM offset:\r\n");
|
2016-12-22 20:29:10 +00:00
|
|
|
UART_GetIntegerMinMax(&addr, 0, 255);
|
|
|
|
printf("EEPROM[0x%02x] = 0x%02x\r\n", addr, eeprom_read_byte(0x50, addr));
|
|
|
|
break;
|
|
|
|
case 'X':
|
2016-12-22 21:28:26 +00:00
|
|
|
printf("Clearing _SIMTRACExx_RST -> SIMTRACExx_RST high (inactive)\r\n");
|
2016-12-22 20:29:10 +00:00
|
|
|
PIO_Clear(&pin_peer_rst);
|
|
|
|
break;
|
|
|
|
case 'x':
|
2016-12-22 21:28:26 +00:00
|
|
|
printf("Setting _SIMTRACExx_RST -> SIMTRACExx_RST low (active)\r\n");
|
2016-12-22 20:29:10 +00:00
|
|
|
PIO_Set(&pin_peer_rst);
|
|
|
|
break;
|
|
|
|
case 'Y':
|
2016-12-22 21:28:26 +00:00
|
|
|
printf("Clearing SIMTRACExx_ERASE (inactive)\r\n");
|
2016-12-22 20:29:10 +00:00
|
|
|
PIO_Clear(&pin_peer_erase);
|
|
|
|
break;
|
|
|
|
case 'y':
|
2016-12-22 21:28:26 +00:00
|
|
|
printf("Seetting SIMTRACExx_ERASE (active)\r\n");
|
2016-12-22 20:29:10 +00:00
|
|
|
PIO_Set(&pin_peer_erase);
|
|
|
|
break;
|
2017-02-03 21:59:04 +00:00
|
|
|
case '1':
|
|
|
|
printf("Resetting Modem 1 (of this SAM3)\r\n");
|
|
|
|
wwan_perst_do_reset(1);
|
|
|
|
break;
|
|
|
|
case '2':
|
|
|
|
printf("Resetting Modem 2 (of this SAM3)\r\n");
|
|
|
|
wwan_perst_do_reset(2);
|
|
|
|
break;
|
2016-12-22 21:28:26 +00:00
|
|
|
default:
|
|
|
|
printf("Unknown command '%c'\r\n", ch);
|
|
|
|
break;
|
2016-12-22 20:29:10 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-19 17:36:07 +00:00
|
|
|
|
|
|
|
/*------------------------------------------------------------------------------
|
|
|
|
* Main
|
|
|
|
*------------------------------------------------------------------------------*/
|
|
|
|
#define MAX_USB_ITER BOARD_MCK/72 // This should be around a second
|
|
|
|
extern int main(void)
|
|
|
|
{
|
|
|
|
uint8_t isUsbConnected = 0;
|
|
|
|
enum confNum last_simtrace_config = simtrace_config;
|
|
|
|
unsigned int i = 0;
|
|
|
|
|
|
|
|
LED_Configure(LED_NUM_RED);
|
|
|
|
LED_Configure(LED_NUM_GREEN);
|
|
|
|
LED_Set(LED_NUM_RED);
|
|
|
|
|
|
|
|
/* Disable watchdog */
|
|
|
|
WDT_Disable(WDT);
|
|
|
|
|
|
|
|
req_ctx_init();
|
|
|
|
|
|
|
|
PIO_InitializeInterrupts(0);
|
|
|
|
|
2017-02-03 06:46:01 +00:00
|
|
|
wwan_led_init();
|
2017-02-03 21:59:04 +00:00
|
|
|
wwan_perst_init();
|
2017-02-03 06:46:01 +00:00
|
|
|
|
2016-10-19 17:36:07 +00:00
|
|
|
EEFC_ReadUniqueID(g_unique_id);
|
|
|
|
|
|
|
|
printf("\r\n\r\n"
|
|
|
|
"=============================================================================\r\n"
|
|
|
|
"SIMtrace2 firmware " GIT_VERSION " (C) 2010-2016 by Harald Welte\r\n"
|
|
|
|
"=============================================================================\r\n");
|
|
|
|
|
|
|
|
TRACE_INFO("Serial Nr. %08x-%08x-%08x-%08x\r\n",
|
|
|
|
g_unique_id[0], g_unique_id[1],
|
|
|
|
g_unique_id[2], g_unique_id[3]);
|
|
|
|
|
2016-12-22 20:29:10 +00:00
|
|
|
/* set PIN_PRTPWR_OVERRIDE to output-low to avoid the internal
|
|
|
|
* pull-up on the input to keep SIMTRACE12 alive */
|
|
|
|
PIO_Configure(&pin_hubpwr_override, 1);
|
|
|
|
PIO_Configure(&pin_hub_rst, 1);
|
|
|
|
PIO_Configure(&pin_1234_detect, 1);
|
|
|
|
PIO_Configure(&pin_peer_rst, 1);
|
|
|
|
PIO_Configure(&pin_peer_erase, 1);
|
|
|
|
i2c_pin_init();
|
|
|
|
|
|
|
|
if (qmod_sam3_is_12()) {
|
|
|
|
TRACE_INFO("Detected Quad-Modem ST12\r\n");
|
|
|
|
} else {
|
|
|
|
TRACE_INFO("Detected Quad-Modem ST34\r\n");
|
|
|
|
}
|
|
|
|
|
2017-02-04 13:43:41 +00:00
|
|
|
/* Obtain the circuit board version (currently just prints voltage */
|
|
|
|
get_board_version_adc();
|
|
|
|
|
2016-03-20 14:18:18 +00:00
|
|
|
TRACE_INFO("USB init...\r\n");
|
2016-12-22 21:32:15 +00:00
|
|
|
SIMtrace_USB_Initialize();
|
|
|
|
|
2016-03-03 11:32:04 +00:00
|
|
|
while (USBD_GetState() < USBD_STATE_CONFIGURED) {
|
2016-12-22 20:29:10 +00:00
|
|
|
check_exec_dbg_cmd();
|
2016-09-01 18:57:56 +00:00
|
|
|
#if 0
|
2016-03-03 11:32:04 +00:00
|
|
|
if (i >= MAX_USB_ITER * 3) {
|
|
|
|
TRACE_ERROR("Resetting board (USB could "
|
2016-03-20 14:18:18 +00:00
|
|
|
"not be configured)\r\n");
|
2016-03-03 11:32:04 +00:00
|
|
|
NVIC_SystemReset();
|
|
|
|
}
|
2016-09-01 18:57:56 +00:00
|
|
|
#endif
|
2016-03-03 11:32:04 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2016-12-22 20:29:10 +00:00
|
|
|
TRACE_INFO("Releasing ST12_PRTPWR_OVERRIDE\r\n");
|
|
|
|
PIO_Clear(&pin_hubpwr_override);
|
|
|
|
|
2016-03-20 14:18:18 +00:00
|
|
|
TRACE_INFO("calling configure of all configurations...\r\n");
|
2016-03-03 11:32:04 +00:00
|
|
|
for (i = 1; i < sizeof(config_func_ptrs) / sizeof(config_func_ptrs[0]);
|
|
|
|
++i) {
|
|
|
|
if (config_func_ptrs[i].configure)
|
|
|
|
config_func_ptrs[i].configure();
|
|
|
|
}
|
|
|
|
|
2016-03-20 14:18:18 +00:00
|
|
|
TRACE_INFO("calling init of config %u...\r\n", simtrace_config);
|
2016-03-03 11:32:04 +00:00
|
|
|
config_func_ptrs[simtrace_config].init();
|
|
|
|
last_simtrace_config = simtrace_config;
|
|
|
|
|
2016-03-20 14:18:18 +00:00
|
|
|
TRACE_INFO("entering main loop...\r\n");
|
2016-03-03 11:32:04 +00:00
|
|
|
while (1) {
|
2016-03-20 14:15:34 +00:00
|
|
|
#if TRACE_LEVEL >= TRACE_LEVEL_DEBUG
|
2016-03-03 11:32:04 +00:00
|
|
|
const char rotor[] = { '-', '\\', '|', '/' };
|
|
|
|
putchar('\b');
|
|
|
|
putchar(rotor[i++ % ARRAY_SIZE(rotor)]);
|
2016-03-20 14:15:34 +00:00
|
|
|
#endif
|
2016-12-22 20:29:10 +00:00
|
|
|
check_exec_dbg_cmd();
|
2017-02-04 11:34:35 +00:00
|
|
|
osmo_timers_prepare();
|
|
|
|
osmo_timers_update();
|
2016-03-03 11:32:04 +00:00
|
|
|
|
|
|
|
if (USBD_GetState() < USBD_STATE_CONFIGURED) {
|
|
|
|
|
|
|
|
if (isUsbConnected) {
|
|
|
|
isUsbConnected = 0;
|
|
|
|
}
|
|
|
|
} else if (isUsbConnected == 0) {
|
2016-03-20 14:18:18 +00:00
|
|
|
TRACE_INFO("USB is now configured\r\n");
|
2016-03-03 11:32:04 +00:00
|
|
|
LED_Set(LED_NUM_GREEN);
|
|
|
|
LED_Clear(LED_NUM_RED);
|
|
|
|
|
|
|
|
isUsbConnected = 1;
|
|
|
|
}
|
|
|
|
if (last_simtrace_config != simtrace_config) {
|
|
|
|
TRACE_INFO("USB config chg %u -> %u\r\n",
|
|
|
|
last_simtrace_config, simtrace_config);
|
|
|
|
config_func_ptrs[last_simtrace_config].exit();
|
|
|
|
config_func_ptrs[simtrace_config].init();
|
|
|
|
last_simtrace_config = simtrace_config;
|
|
|
|
} else {
|
|
|
|
config_func_ptrs[simtrace_config].run();
|
|
|
|
}
|
|
|
|
}
|
2015-02-24 10:35:19 +00:00
|
|
|
}
|