New delay parameter: index_mask

Allows configuration of post-trigger INDEX mask time in microseconds
(0-65535). Some drives may need much longer than the default, if
there is sensor-switch bounce on trailing edge of the INDEX pulse.

Fixes keirf/greaseweazle#7
This commit is contained in:
Keir Fraser
2024-09-24 17:59:48 +01:00
parent 1da90a030d
commit 5b0857791f
2 changed files with 20 additions and 18 deletions

View File

@@ -221,13 +221,14 @@ struct packed gw_sink_source_bytes {
/* CMD_{GET,SET}_PARAMS, index 0 */
#define PARAMS_DELAYS 0
struct packed gw_delay {
uint16_t select_delay; /* usec */
uint16_t step_delay; /* usec */
uint16_t seek_settle; /* msec */
uint16_t motor_delay; /* msec */
uint16_t watchdog; /* msec */
uint16_t pre_write; /* min. usec since previous head change */
uint16_t post_write; /* min. usec to next write/step/head-change */
uint16_t select_delay; /* (usec) delay after asserting a drive select */
uint16_t step_delay; /* (usec) delay after a head-step pulse */
uint16_t seek_settle; /* (msec) delay after completing a seek operation */
uint16_t motor_delay; /* (msec) delay after turning on a drive spindle */
uint16_t watchdog; /* (msec) timeout after last command */
uint16_t pre_write; /* (usec) min time since previous head change */
uint16_t post_write; /* (usec) min time to next write/step/head-change */
uint16_t index_mask; /* (usec) post-trigger index mask */
};
/* CMD_SWITCH_FW_MODE */

View File

@@ -53,7 +53,8 @@ static const struct gw_delay factory_delay_params = {
.motor_delay = 750,
.watchdog = 10000,
.pre_write = 100,
.post_write = 1000
.post_write = 1000,
.index_mask = 200
};
extern uint8_t u_buf[];
@@ -71,13 +72,13 @@ static struct index {
volatile unsigned int count;
/* For synchronising index pulse reporting to the RDATA flux stream. */
volatile unsigned int rdata_cnt;
/* Last time at which ISR fired. */
time_t isr_time;
/* Last time at which index was triggered. */
time_t trigger_time;
/* Timer structure for index_timer() calls. */
struct timer timer;
} index;
/* Timer to clean up stale index.isr_time. */
/* Timer to clean up stale index.trigger_time. */
#define INDEX_TIMER_PERIOD time_ms(5000)
static void index_timer(void *unused);
@@ -1825,15 +1826,15 @@ const struct usb_class_ops usb_cdc_acm_ops = {
static void IRQ_INDEX_changed(void)
{
unsigned int cnt = tim_rdata->cnt;
time_t now = time_now(), prev = index.isr_time;
time_t now = time_now();
/* Clear INDEX-changed flag. */
exti->pr = m(pin_index);
index.isr_time = now;
if (time_diff(prev, now) < time_us(50))
if (time_diff(index.trigger_time, now) < time_us(delay_params.index_mask))
return;
index.trigger_time = now;
index.count++;
index.rdata_cnt = cnt;
}
@@ -1842,13 +1843,13 @@ static void index_timer(void *unused)
{
time_t now = time_now();
IRQ_global_disable();
/* index.isr_time mustn't get so old that the time_diff() test in
/* index.trigger_time mustn't get so old that the time_diff() test in
* IRQ_INDEX_changed() overflows. To prevent this, we ensure that,
* at all times,
* time_diff(index.isr_time, time_now()) < 2*INDEX_TIMER_PERIOD + delta,
* time_diff(index.trigger_time, now) < 2*INDEX_TIMER_PERIOD + delta,
* where delta is small. */
if (time_diff(index.isr_time, now) > INDEX_TIMER_PERIOD)
index.isr_time = now - INDEX_TIMER_PERIOD;
if (time_diff(index.trigger_time, now) > INDEX_TIMER_PERIOD)
index.trigger_time = now - INDEX_TIMER_PERIOD;
IRQ_global_enable();
timer_set(&index.timer, now + INDEX_TIMER_PERIOD);
}