diff --git a/sfp.c b/sfp.c index 7edf9ce8..c3977795 100644 --- a/sfp.c +++ b/sfp.c @@ -20,6 +20,8 @@ extern __code const struct machine machine; // SFP1 b0 = 1 => module missing, b1 = 1 => LOS; // SFP2 b4 = 1 => module missing, b5 = 1 => LOS; +extern volatile __xdata uint32_t ticks; + __xdata uint8_t sfp_pins_last; __xdata char sfp_module_vendor[2][17]; __xdata char sfp_module_model[2][17]; @@ -28,6 +30,8 @@ __xdata uint8_t sfp_options[2]; __xdata uint8_t sfp_buf[16]; /* scratch for one I2C transaction, the controller reads at most 16 bytes */ __xdata uint8_t sfp_speed[2]; __xdata uint8_t sfp_quirks[2]; +__xdata uint8_t sfp_wake_at[2]; +__xdata uint8_t sfp_wake_pending[2]; __code enum sfp_quirk { @@ -157,7 +161,6 @@ static bool sfp_module_read(uint8_t sfp) // Read Reg 11: Encoding, see SFF-8472 and SFF-8024 // Read Reg 12: Signalling rate (including overhead) in 100Mbit: 0xd: 1Gbit, 0x67:10Gbit - delay(100); // Delay, because some modules need time to wake up if (!sfp_read_block(sfp, 11, 2)) return false; @@ -199,6 +202,11 @@ void handle_sfp(void) __banked if (sfp_pins_last & (0x1 << (sfp << 2))) { sfp_pins_last &= ~(0x01 << (sfp << 2)); print_string("\n Slot: "); write_char('1' + sfp); + sfp_wake_at[sfp] = ticks; + sfp_wake_pending[sfp] = 1; + } else if (sfp_wake_pending[sfp] + && (uint8_t)((uint8_t)ticks - sfp_wake_at[sfp]) >= SFP_WAKE_TICKS) { + sfp_wake_pending[sfp] = 0; if (!sfp_module_read(sfp)) { print_string("SFP: an I2C read failed, retrying on the next poll\n"); sfp_pins_last |= 0x01 << (sfp << 2); @@ -207,6 +215,7 @@ void handle_sfp(void) __banked } else { if (!(sfp_pins_last & (0x1 << (sfp << 2)))) { sfp_pins_last |= 0x01 << (sfp << 2); + sfp_wake_pending[sfp] = 0; print_string("\n Slot: "); write_char('1' + sfp); write_char('\n'); } } diff --git a/sfp.h b/sfp.h index 250ce4d6..6d1b57c5 100644 --- a/sfp.h +++ b/sfp.h @@ -1,6 +1,8 @@ #ifndef SFP_H #define SFP_H +#define SFP_WAKE_TICKS 100 + extern __xdata uint8_t sfp_pins_last; extern __xdata char sfp_module_vendor[2][17]; extern __xdata char sfp_module_model[2][17];