mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-10-29 17:54:14 +08:00
Merge pull request #496 from DrDoof/fix/sfp-nonblocking-wake
sfp: do not block the main loop while a module wakes up
This commit is contained in:
2 files changed
+12
-1
No files matched your search
@@ -20,6 +20,8 @@ extern __code const struct machine machine;
|
|||||||
|
|
||||||
// SFP1 b0 = 1 => module missing, b1 = 1 => LOS;
|
// SFP1 b0 = 1 => module missing, b1 = 1 => LOS;
|
||||||
// SFP2 b4 = 1 => module missing, b5 = 1 => LOS;
|
// SFP2 b4 = 1 => module missing, b5 = 1 => LOS;
|
||||||
|
extern volatile __xdata uint32_t ticks;
|
||||||
|
|
||||||
__xdata uint8_t sfp_pins_last;
|
__xdata uint8_t sfp_pins_last;
|
||||||
__xdata char sfp_module_vendor[2][17];
|
__xdata char sfp_module_vendor[2][17];
|
||||||
__xdata char sfp_module_model[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_buf[16]; /* scratch for one I2C transaction, the controller reads at most 16 bytes */
|
||||||
__xdata uint8_t sfp_speed[2];
|
__xdata uint8_t sfp_speed[2];
|
||||||
__xdata uint8_t sfp_quirks[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 {
|
__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 11: Encoding, see SFF-8472 and SFF-8024
|
||||||
// Read Reg 12: Signalling rate (including overhead) in 100Mbit: 0xd: 1Gbit, 0x67:10Gbit
|
// 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))
|
if (!sfp_read_block(sfp, 11, 2))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -199,6 +202,11 @@ void handle_sfp(void) __banked
|
|||||||
if (sfp_pins_last & (0x1 << (sfp << 2))) {
|
if (sfp_pins_last & (0x1 << (sfp << 2))) {
|
||||||
sfp_pins_last &= ~(0x01 << (sfp << 2));
|
sfp_pins_last &= ~(0x01 << (sfp << 2));
|
||||||
print_string("\n<MODULE INSERTED> Slot: "); write_char('1' + sfp);
|
print_string("\n<MODULE INSERTED> 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)) {
|
if (!sfp_module_read(sfp)) {
|
||||||
print_string("SFP: an I2C read failed, retrying on the next poll\n");
|
print_string("SFP: an I2C read failed, retrying on the next poll\n");
|
||||||
sfp_pins_last |= 0x01 << (sfp << 2);
|
sfp_pins_last |= 0x01 << (sfp << 2);
|
||||||
@@ -207,6 +215,7 @@ void handle_sfp(void) __banked
|
|||||||
} else {
|
} else {
|
||||||
if (!(sfp_pins_last & (0x1 << (sfp << 2)))) {
|
if (!(sfp_pins_last & (0x1 << (sfp << 2)))) {
|
||||||
sfp_pins_last |= 0x01 << (sfp << 2);
|
sfp_pins_last |= 0x01 << (sfp << 2);
|
||||||
|
sfp_wake_pending[sfp] = 0;
|
||||||
print_string("\n<MODULE REMOVED> Slot: "); write_char('1' + sfp); write_char('\n');
|
print_string("\n<MODULE REMOVED> Slot: "); write_char('1' + sfp); write_char('\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#ifndef SFP_H
|
#ifndef SFP_H
|
||||||
#define SFP_H
|
#define SFP_H
|
||||||
|
|
||||||
|
#define SFP_WAKE_TICKS 100
|
||||||
|
|
||||||
extern __xdata uint8_t sfp_pins_last;
|
extern __xdata uint8_t sfp_pins_last;
|
||||||
extern __xdata char sfp_module_vendor[2][17];
|
extern __xdata char sfp_module_vendor[2][17];
|
||||||
extern __xdata char sfp_module_model[2][17];
|
extern __xdata char sfp_module_model[2][17];
|
||||||
|
|||||||
Reference in new issue
Block a user