Skip to content

Commit

Permalink
Add Macro and remove redundant sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
AnoopKamath authored Sep 30, 2024
1 parent 6a2cfbe commit 6d57b46
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions sonic_platform_base/sonic_xcvr/api/public/cmis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1077,29 +1077,28 @@ def set_lpmode(self, lpmode):
if self.is_flat_memory() or not self.get_lpmode_support():
return False

DELAY_RETRY = 0.1
lpmode_val = self.xcvr_eeprom.read(consts.MODULE_LEVEL_CONTROL)
if lpmode_val is not None:
if lpmode is True:
# Force module transition to LowPwr under SW control
lpmode_val = lpmode_val | (1 << CmisApi.LowPwrRequestSW)
self.xcvr_eeprom.write(consts.MODULE_LEVEL_CONTROL, lpmode_val)
time.sleep(0.1)
start_time = time.time()
pwroff_duration = self.get_module_pwr_down_duration()/1000
# Loop until the power-off duration has elapsed
while (time.time() - start_time) < pwroff_duration:
if self.get_lpmode():
return self.get_lpmode()
# Sleep for a short interval before the next check
time.sleep(0.1)
time.sleep(DELAY_RETRY)
return self.get_lpmode()
else:
# Force transition from LowPwr to HighPower state under SW control.
# This will transition LowPwrS signal to False. (see Table 6-12 CMIS v5.0)
lpmode_val = lpmode_val & ~(1 << CmisApi.LowPwrRequestSW)
lpmode_val = lpmode_val & ~(1 << CmisApi.LowPwrAllowRequestHW)
self.xcvr_eeprom.write(consts.MODULE_LEVEL_CONTROL, lpmode_val)
time.sleep(1)
start_time = time.time()
# Loop until the power-on duration has elapsed
pwron_duration = self.get_module_pwr_up_duration()/1000
Expand All @@ -1108,7 +1107,7 @@ def set_lpmode(self, lpmode):
if mstate == 'ModuleReady':
return True
# Sleep for a short interval before the next check
time.sleep(0.1)
time.sleep(DELAY_RETRY)
return False

def get_loopback_capability(self):
Expand Down

0 comments on commit 6d57b46

Please sign in to comment.