Skip to content

Commit

Permalink
testmode: Add a WDAT oscillation test
Browse files Browse the repository at this point in the history
  • Loading branch information
keirf committed May 12, 2021
1 parent 2f7b96f commit 9846c54
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 2 deletions.
2 changes: 2 additions & 0 deletions inc/testmode.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#define CMD_pins 1
#define CMD_led 2
#define CMD_test_headers 3
#define CMD_wdat_osc_on 4
#define CMD_wdat_osc_off 5

/* CMD_test_headers return code in rsp.u.x[0] */
#define TESTHEADER_success 100
Expand Down
1 change: 1 addition & 0 deletions inc/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ void floppy_init(void);
void floppy_process(void);

/* Test mode */
uint8_t testmode_init(void);
void testmode_process(void);

/* CRC-CCITT */
Expand Down
6 changes: 4 additions & 2 deletions src/floppy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1488,8 +1488,10 @@ static void process_command(void)
if (len != 10) goto bad_command;
if (sig1 != 0x6e504b4e) goto bad_command;
if (sig2 != 0x382910d3) goto bad_command;
floppy_state = ST_testmode;
break;
u_buf[1] = testmode_init();
if (u_buf[1] == ACK_OKAY)
floppy_state = ST_testmode;
goto out;
}
#endif
default:
Expand Down
5 changes: 5 additions & 0 deletions src/mcu/at32f4/testmode.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ void testmode_get_option_bytes(void *buf)
memcpy(buf, (void *)0x1ffff800, 32);
}

uint8_t testmode_init(void)
{
return ACK_OKAY;
}

/*
* Local variables:
* mode: C
Expand Down
10 changes: 10 additions & 0 deletions src/mcu/stm32f7/testmode.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ void testmode_get_option_bytes(void *buf)
memcpy(buf, (void *)0x1fff0000, 32);
}

uint8_t testmode_init(void)
{
switch (gw_info.hw_submodel) {
case F7SM_lightning_plus:
case F7SM_v3:
return ACK_OKAY;
}
return ACK_BAD_COMMAND;
}

/*
* Local variables:
* mode: C
Expand Down
39 changes: 39 additions & 0 deletions src/testmode.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,37 @@ static unsigned int testmode_test_headers(void)
return rc;
}

/* It so happens that all supported boards use the same pin and timer for
* WDAT, so we can share the code here. Future boards may require this to
* be made board-specific. */
#define gpio_wdata gpioa
#define pin_wdata 2
#define tim_wdata (tim2)
#define GPO_bus GPO_pushpull(IOSPD_LOW,HIGH)
#define AFO_bus AFO_pushpull(IOSPD_LOW)
static void testmode_wdat_osc_on(void)
{
tim_wdata->psc = SYSCLK_MHZ/TIME_MHZ-1;
tim_wdata->ccmr2 = (TIM_CCMR2_CC3S(TIM_CCS_OUTPUT) |
TIM_CCMR2_OC3M(TIM_OCM_PWM1));
tim_wdata->ccer = TIM_CCER_CC3E;
tim_wdata->ccr3 = time_us(1);
tim_wdata->arr = time_us(2)-1;
tim_wdata->dier = TIM_DIER_UDE;
tim_wdata->cr2 = 0;
tim_wdata->egr = TIM_EGR_UG;
tim_wdata->sr = 0;
tim_wdata->cr1 = TIM_CR1_CEN;
gpio_configure_pin(gpio_wdata, pin_wdata, AFO_bus);
}
static void testmode_wdat_osc_off(void)
{
gpio_configure_pin(gpio_wdata, pin_wdata, GPO_bus);
tim_wdata->ccer = 0;
tim_wdata->cr1 = 0;
tim_wdata->sr = 0;
}

void testmode_process(void)
{
int len = ep_rx_ready(EP_RX);
Expand Down Expand Up @@ -141,6 +172,14 @@ void testmode_process(void)
rsp.u.x[0] = testmode_test_headers();
break;
}
case CMD_wdat_osc_on: {
testmode_wdat_osc_on();
break;
}
case CMD_wdat_osc_off: {
testmode_wdat_osc_off();
break;
}
}

usb_write(EP_TX, &rsp, 32);
Expand Down

0 comments on commit 9846c54

Please sign in to comment.