mirror of
https://gitea.osmocom.org/sim-card/simtrace2.git
synced 2026-03-23 16:58:33 +03:00
quad-modem: Add debug console commands for debugging
This commit is contained in:
@@ -77,6 +77,13 @@ static volatile enum confNum simtrace_config = CFG_NUM_PHONE;
|
|||||||
static volatile enum confNum simtrace_config = CFG_NUM_CCID;
|
static volatile enum confNum simtrace_config = CFG_NUM_CCID;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static const Pin pin_hubpwr_override = PIN_PRTPWR_OVERRIDE;
|
||||||
|
static const Pin pin_hub_rst = {PIO_PA13, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT};
|
||||||
|
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};
|
||||||
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------
|
/*----------------------------------------------------------------------------
|
||||||
* Callbacks
|
* Callbacks
|
||||||
*----------------------------------------------------------------------------*/
|
*----------------------------------------------------------------------------*/
|
||||||
@@ -97,8 +104,15 @@ void USART0_IrqHandler(void)
|
|||||||
config_func_ptrs[simtrace_config].usart0_irq();
|
config_func_ptrs[simtrace_config].usart0_irq();
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "i2c.h"
|
static int qmod_sam3_is_12(void)
|
||||||
|
{
|
||||||
|
if (PIO_Get(&pin_1234_detect) == 0)
|
||||||
|
return 1;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "i2c.h"
|
||||||
static int write_hub_eeprom(void)
|
static int write_hub_eeprom(void)
|
||||||
{
|
{
|
||||||
const unsigned char __eeprom_bin[] = {
|
const unsigned char __eeprom_bin[] = {
|
||||||
@@ -127,17 +141,8 @@ static int write_hub_eeprom(void)
|
|||||||
};
|
};
|
||||||
const unsigned int __eeprom_bin_len = 256;
|
const unsigned int __eeprom_bin_len = 256;
|
||||||
|
|
||||||
const Pin pin_hubpwr_override = PIN_PRTPWR_OVERRIDE;
|
|
||||||
const Pin pin_hub_rst = {PIO_PA13, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT};
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* 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);
|
|
||||||
i2c_pin_init();
|
|
||||||
|
|
||||||
/* wait */
|
/* wait */
|
||||||
volatile int v;
|
volatile int v;
|
||||||
/* 440ns per cycle here */
|
/* 440ns per cycle here */
|
||||||
@@ -145,6 +150,7 @@ static int write_hub_eeprom(void)
|
|||||||
v = 0;
|
v = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TRACE_INFO("Writing EEPROM...\r\n");
|
||||||
/* write the EEPROM once */
|
/* write the EEPROM once */
|
||||||
for (i = 0; i < 256; i++) {
|
for (i = 0; i < 256; i++) {
|
||||||
int rc = eeprom_write_byte(0x50, i, __eeprom_bin[i]);
|
int rc = eeprom_write_byte(0x50, i, __eeprom_bin[i]);
|
||||||
@@ -154,6 +160,7 @@ static int write_hub_eeprom(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* then pursue re-reading it again and again */
|
/* then pursue re-reading it again and again */
|
||||||
|
TRACE_INFO("Verifying EEPROM...\r\n");
|
||||||
for (i = 0; i < 256; i++) {
|
for (i = 0; i < 256; i++) {
|
||||||
int byte = eeprom_read_byte(0x50, i);
|
int byte = eeprom_read_byte(0x50, i);
|
||||||
TRACE_INFO("0x%02x: %02x\r\n", i, byte);
|
TRACE_INFO("0x%02x: %02x\r\n", i, byte);
|
||||||
@@ -169,6 +176,79 @@ static int write_hub_eeprom(void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void check_exec_dbg_cmd(void)
|
||||||
|
{
|
||||||
|
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");
|
||||||
|
printf("\tY\tRelease peer SAM3 ERASE signal\n");
|
||||||
|
printf("\ty\tAssert peer SAM3 ERASE signal\r\n");
|
||||||
|
break;
|
||||||
|
case 'E':
|
||||||
|
write_hub_eeprom();
|
||||||
|
break;
|
||||||
|
case 'R':
|
||||||
|
NVIC_SystemReset();
|
||||||
|
break;
|
||||||
|
case 'O':
|
||||||
|
PIO_Set(&pin_hubpwr_override);
|
||||||
|
break;
|
||||||
|
case 'o':
|
||||||
|
PIO_Clear(&pin_hubpwr_override);
|
||||||
|
break;
|
||||||
|
case 'H':
|
||||||
|
PIO_Clear(&pin_hub_rst);
|
||||||
|
break;
|
||||||
|
case 'h':
|
||||||
|
/* high level drives transistor -> HUB_RESET low */
|
||||||
|
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");
|
||||||
|
printf("Please enter EEPROM offset: ");
|
||||||
|
UART_GetIntegerMinMax(&addr, 0, 255);
|
||||||
|
printf("Please enter EEPROM value: ");
|
||||||
|
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':
|
||||||
|
printf("Please enter EEPROM offset: ");
|
||||||
|
UART_GetIntegerMinMax(&addr, 0, 255);
|
||||||
|
printf("EEPROM[0x%02x] = 0x%02x\r\n", addr, eeprom_read_byte(0x50, addr));
|
||||||
|
break;
|
||||||
|
case 'X':
|
||||||
|
PIO_Clear(&pin_peer_rst);
|
||||||
|
break;
|
||||||
|
case 'x':
|
||||||
|
PIO_Set(&pin_peer_rst);
|
||||||
|
break;
|
||||||
|
case 'Y':
|
||||||
|
PIO_Clear(&pin_peer_erase);
|
||||||
|
break;
|
||||||
|
case 'y':
|
||||||
|
PIO_Set(&pin_peer_erase);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------------------------
|
/*------------------------------------------------------------------------------
|
||||||
* Main
|
* Main
|
||||||
@@ -204,10 +284,28 @@ extern int main(void)
|
|||||||
g_unique_id[0], g_unique_id[1],
|
g_unique_id[0], g_unique_id[1],
|
||||||
g_unique_id[2], g_unique_id[3]);
|
g_unique_id[2], g_unique_id[3]);
|
||||||
|
|
||||||
write_hub_eeprom();
|
/* 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");
|
||||||
|
}
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
check_exec_dbg_cmd();
|
||||||
|
}
|
||||||
|
|
||||||
TRACE_INFO("USB init...\r\n");
|
TRACE_INFO("USB init...\r\n");
|
||||||
while (USBD_GetState() < USBD_STATE_CONFIGURED) {
|
while (USBD_GetState() < USBD_STATE_CONFIGURED) {
|
||||||
|
check_exec_dbg_cmd();
|
||||||
#if 0
|
#if 0
|
||||||
if (i >= MAX_USB_ITER * 3) {
|
if (i >= MAX_USB_ITER * 3) {
|
||||||
TRACE_ERROR("Resetting board (USB could "
|
TRACE_ERROR("Resetting board (USB could "
|
||||||
@@ -218,6 +316,9 @@ extern int main(void)
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TRACE_INFO("Releasing ST12_PRTPWR_OVERRIDE\r\n");
|
||||||
|
PIO_Clear(&pin_hubpwr_override);
|
||||||
|
|
||||||
TRACE_INFO("calling configure of all configurations...\r\n");
|
TRACE_INFO("calling configure of all configurations...\r\n");
|
||||||
for (i = 1; i < sizeof(config_func_ptrs) / sizeof(config_func_ptrs[0]);
|
for (i = 1; i < sizeof(config_func_ptrs) / sizeof(config_func_ptrs[0]);
|
||||||
++i) {
|
++i) {
|
||||||
@@ -236,6 +337,7 @@ extern int main(void)
|
|||||||
putchar('\b');
|
putchar('\b');
|
||||||
putchar(rotor[i++ % ARRAY_SIZE(rotor)]);
|
putchar(rotor[i++ % ARRAY_SIZE(rotor)]);
|
||||||
#endif
|
#endif
|
||||||
|
check_exec_dbg_cmd();
|
||||||
|
|
||||||
if (USBD_GetState() < USBD_STATE_CONFIGURED) {
|
if (USBD_GetState() < USBD_STATE_CONFIGURED) {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user