Skip to content

Commit 6de7cc7

Browse files
committed
amiga: Motor signal must be respected even while a disk is ejected.
Since the motor signal selects between ID and RDY signals on pin 34. Refs #354
1 parent fc161f4 commit 6de7cc7

File tree

5 files changed

+36
-26
lines changed

5 files changed

+36
-26
lines changed

inc/floppy.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@ static inline bool_t in_da_mode(struct image *im, unsigned int cyl)
298298
return cyl >= max_t(unsigned int, DA_FIRST_CYL, im_nphys_cyls(im));
299299
}
300300

301+
extern uint32_t motor_chgrst_exti_mask;
302+
void motor_chgrst_setup_exti(void);
303+
301304
/*
302305
* Local variables:
303306
* mode: C

src/floppy.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ static void update_amiga_id(struct drive *drv, bool_t amiga_hd_id)
165165
drive_change_pin(&drive, pin_34, TRUE);
166166
} else {
167167
/* Do nothing here. Pin 34 will be updated by IRQ_MOTOR() via
168-
* motor_chgrst_{insert,eject}(). */
168+
* motor_chgrst_update_status(). */
169169
IRQ_global_enable();
170170
}
171171
}
@@ -204,7 +204,7 @@ void floppy_cancel(void)
204204
index.fake_fired = FALSE;
205205
barrier(); /* /then/ cancel index.timer_deassert */
206206
timer_cancel(&index.timer_deassert);
207-
motor_chgrst_eject(drv);
207+
motor_chgrst_update_status(drv);
208208

209209
/* Set outputs for empty drive. */
210210
barrier();
@@ -329,7 +329,7 @@ void floppy_init(void)
329329
timer_init(&index.timer, index_assert, NULL);
330330
timer_init(&index.timer_deassert, index_deassert, NULL);
331331

332-
motor_chgrst_eject(drv);
332+
motor_chgrst_setup_exti();
333333
}
334334

335335
void floppy_insert(unsigned int unit, struct slot *slot)
@@ -354,7 +354,7 @@ void floppy_insert(unsigned int unit, struct slot *slot)
354354
drive_change_output(drv, outp_wrprot, FALSE);
355355
barrier();
356356
drv->inserted = TRUE;
357-
motor_chgrst_insert(drv); /* update RDY + motor state */
357+
motor_chgrst_update_status(drv); /* update RDY + motor state */
358358
if (ff_cfg.chgrst <= CHGRST_delay(15))
359359
timer_set(&drv->chgrst_timer, time_now() + ff_cfg.chgrst*time_ms(500));
360360
}

src/gotek/floppy.c

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -460,36 +460,25 @@ static void motor_chgrst_update_status(struct drive *drv)
460460
IRQx_set_pending(MOTOR_CHGRST_IRQ);
461461
}
462462

463-
static void motor_chgrst_insert(struct drive *drv)
463+
uint32_t motor_chgrst_exti_mask;
464+
void motor_chgrst_setup_exti(void)
464465
{
465-
uint32_t imr = exti->imr;
466+
uint32_t m = 0;
466467

467468
if (ff_cfg.motor_delay != MOTOR_ignore) {
468469
_exti_route(gotek_enhanced()?0/*PA*/:1/*PB*/, pin_motor);
469-
imr |= m(pin_motor);
470+
m |= m(pin_motor);
470471
}
471472

472473
if (ff_cfg.chgrst == CHGRST_pa14) {
473474
exti_route_pa(pin_chgrst);
474-
imr |= m(pin_chgrst);
475+
m |= m(pin_chgrst);
475476
}
476477

477-
exti->imr = imr;
478-
motor_chgrst_update_status(drv);
479-
}
480-
481-
static void motor_chgrst_eject(struct drive *drv)
482-
{
483-
uint32_t imr = exti->imr;
484-
485-
if (ff_cfg.motor_delay != MOTOR_ignore)
486-
imr &= ~m(pin_motor);
487-
488-
if (ff_cfg.chgrst == CHGRST_pa14)
489-
imr &= ~m(pin_chgrst);
478+
motor_chgrst_exti_mask = m;
479+
exti->imr |= m;
490480

491-
exti->imr = imr;
492-
motor_chgrst_update_status(drv);
481+
motor_chgrst_update_status(&drive);
493482
}
494483

495484
/*

src/gotek/quickdisk.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,12 @@ static void IRQ_rotary_changed(void)
243243
IRQ_rotary();
244244
}
245245

246+
uint32_t motor_chgrst_exti_mask;
247+
void motor_chgrst_setup_exti(void)
248+
{
249+
/* Quick Disk does not have configurable MOTOR and CHGRST. */
250+
}
251+
246252
/*
247253
* Local variables:
248254
* mode: C

src/main.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,15 +1300,27 @@ static void read_ff_cfg(void)
13001300

13011301
static void process_ff_cfg_opts(const struct ff_cfg *old)
13021302
{
1303+
/* chgrst, motor-delay: Reset EXTI handlers. */
1304+
if ((ff_cfg.motor_delay != old->motor_delay)
1305+
|| (ff_cfg.chgrst != old->chgrst)) {
1306+
exti->imr &= ~motor_chgrst_exti_mask;
1307+
motor_chgrst_exti_mask = 0;
1308+
}
1309+
13031310
/* rotary, chgrst, motor-delay: Inform the rotary-encoder subsystem.
1304-
* It is harmless to notify unconditionally. */
1311+
* It is harmless to reset rotary EXTI handlers unconditionally. */
13051312
set_rotary_exti();
13061313

1307-
/* interface, pin02, pin34: Inform the floppy subsystem. */
1314+
/* interface, pin02, pin34, chgrst, motor-delay: Inform the floppy
1315+
* subsystem. */
13081316
if ((ff_cfg.interface != old->interface)
13091317
|| (ff_cfg.pin02 != old->pin02)
1310-
|| (ff_cfg.pin34 != old->pin34))
1318+
|| (ff_cfg.pin34 != old->pin34)
1319+
|| (ff_cfg.motor_delay != old->motor_delay)
1320+
|| (ff_cfg.chgrst != old->chgrst)) {
13111321
floppy_set_fintf_mode();
1322+
motor_chgrst_setup_exti();
1323+
}
13121324

13131325
/* max-cyl: Inform the floppy subsystem. */
13141326
if (ff_cfg.max_cyl != old->max_cyl)

0 commit comments

Comments
 (0)