Эх сурвалжийг харах

F1 Plus: Support testmode

Keir Fraser 3 жил өмнө
parent
commit
5b79e9e79b

+ 1 - 3
src/Makefile

@@ -9,9 +9,7 @@ OBJS += time.o
 OBJS += timer.o
 OBJS += util.o
 OBJS += floppy.o
-
-OBJS-$(stm32f7)  += testmode.o
-OBJS-$(at32f4) += testmode.o
+OBJS += testmode.o
 
 OBJS-$(debug) += console.o
 

+ 0 - 4
src/floppy.c

@@ -1536,7 +1536,6 @@ static void process_command(void)
         }
         break;
     }
-#if MCU != STM32F1
     case CMD_TEST_MODE: {
         uint32_t sig1 = *(uint32_t *)&u_buf[2];
         uint32_t sig2 = *(uint32_t *)&u_buf[6];
@@ -1548,7 +1547,6 @@ static void process_command(void)
             floppy_state = ST_testmode;
         goto out;
     }
-#endif
     case CMD_NOCLICK_STEP: {
         if (len != 2)
             goto bad_command;
@@ -1647,12 +1645,10 @@ void floppy_process(void)
         update_continue();
         break;
 
-#if MCU != STM32F1
     case ST_testmode:
         watchdog.armed = FALSE;
         testmode_process();
         break;
-#endif
 
     default:
         break;

+ 28 - 0
src/mcu/at32f4/testmode.c

@@ -31,6 +31,34 @@ void testmode_get_option_bytes(void *buf)
     memcpy(buf, (void *)0x1ffff800, 32);
 }
 
+#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)
+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);
+}
+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;
+}
+
 uint8_t testmode_init(void)
 {
     return ACK_OKAY;

+ 1 - 0
src/mcu/stm32f1/Makefile

@@ -1,2 +1,3 @@
 OBJS += stm32.o
 OBJS += fpec.o
+OBJS += testmode.o

+ 0 - 6
src/mcu/stm32f1/floppy.c

@@ -29,12 +29,6 @@ static unsigned int GPI_bus;
 #define pin_wrprot  8 /* PB8 */
 
 /* Output pins. */
-#define gpio_densel gpiob
-#define pin_densel  9 /* PB9 */
-#define gpio_sel   gpiob
-#define pin_sel    10 /* PB10 */
-#define gpio_mot   gpiob
-#define pin_mot    11 /* PB11 */
 #define gpio_dir   gpiob
 #define pin_dir    12 /* PB12 */
 #define gpio_step  gpiob

+ 79 - 0
src/mcu/stm32f1/testmode.c

@@ -0,0 +1,79 @@
+/*
+ * f1/testmode.c
+ * 
+ * Written & released by Keir Fraser <keir.xen@gmail.com>
+ * 
+ * This is free and unencumbered software released into the public domain.
+ * See the file COPYING for more details, or visit <http://unlicense.org>.
+ */
+
+const struct pin_mapping testmode_in_pins[] = {
+    {  8, _B,  6 },
+    { 26, _B,  7 },
+    { 28, _B,  8 },
+    { 30, _B,  3 },
+    { 34, _A,  8 },
+    {  0,  0,  0 }
+};
+
+const struct pin_mapping testmode_out_pins[] = {
+    { 18, _B, 12 },
+    { 20, _B, 13 },
+    { 22, _B,  4 },
+    { 24, _B, 14 },
+    { 32, _B, 15 },
+    { 33, _A,  2 },
+    {  0,  0,  0 }
+};
+
+void testmode_get_option_bytes(void *buf)
+{
+    memset(buf, 0, 32);
+    memcpy(buf, (void *)0x1ffff800, 16);
+}
+
+#define gpio_wdata  gpiob
+#define pin_wdata   4
+#define tim_wdata   (tim3)
+void testmode_wdat_osc_on(void)
+{
+    tim_wdata->psc = SYSCLK_MHZ/TIME_MHZ-1;
+    tim_wdata->ccmr1 = (TIM_CCMR1_CC1S(TIM_CCS_OUTPUT) |
+                        TIM_CCMR1_OC1M(TIM_OCM_PWM1));
+    tim_wdata->ccer = TIM_CCER_CC1E;
+    tim_wdata->ccr1 = 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_wdata->crl = gpio_wdata->crl | (8 << (pin_wdata<<2)); /* AFO */
+}
+void testmode_wdat_osc_off(void)
+{
+    gpio_wdata->crl = gpio_wdata->crl & ~(8 << (pin_wdata<<2)); /* GPO */
+    tim_wdata->ccer = 0;
+    tim_wdata->cr1 = 0;
+    tim_wdata->sr = 0;
+}
+
+uint8_t testmode_init(void)
+{
+    switch (gw_info.hw_submodel) {
+    case F1SM_plus:
+    case F1SM_plus_unbuffered:
+        return ACK_OKAY;
+    }
+    return ACK_BAD_COMMAND;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "Linux"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */

+ 28 - 0
src/mcu/stm32f7/testmode.c

@@ -31,6 +31,34 @@ void testmode_get_option_bytes(void *buf)
     memcpy(buf, (void *)0x1fff0000, 32);
 }
 
+#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)
+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);
+}
+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;
+}
+
 uint8_t testmode_init(void)
 {
     switch (gw_info.hw_submodel) {

+ 2 - 31
src/testmode.c

@@ -15,6 +15,8 @@
 extern struct pin_mapping testmode_in_pins[];
 extern struct pin_mapping testmode_out_pins[];
 void testmode_get_option_bytes(void *buf);
+void testmode_wdat_osc_on(void);
+void testmode_wdat_osc_off(void);
 
 static void testmode_set_pin(unsigned int pin, bool_t level)
 {
@@ -107,37 +109,6 @@ out:
     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);