Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wake up the clock before loading rtc_ds1307 module #1020

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions Software/Source/src/pijuice_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
noPowCnt = 0 # 0 will trigger at boot without power, 3 will not trigger at boot without power
PowCnt = 3 # 0 will trigger at boot with power, 3 will not trigger at boot with power
dopoll = True
PID_FILE = '/tmp/pijuice_sys.pid'
HALT_FILE = '/tmp/pijuice_halt.flag'
PID_FILE = '/run/pijuice/pijuice_sys.pid'
HALT_FILE = '/run/pijuice/pijuice_halt.flag'
I2C_ADDRESS_DEFAULT = 0x14
I2C_BUS_DEFAULT = 1

Expand Down Expand Up @@ -284,6 +284,7 @@ def _LoadConfiguration():
bus = configData['board']['general']['i2c_bus']
pijuice = PiJuice(bus, addr)
except:
print("Failed to connect to PiJuice with: {}".format(configPath))
sys.exit(0)

try:
Expand Down Expand Up @@ -352,6 +353,7 @@ def main():
pijuice.power.SetPowerOff(powerOffDelay)
except ValueError:
pass
os.remove(PID_FILE)
sys.exit(0)

# First check if rtc is operational when the rtc_ds1307 module is loaded.
Expand Down Expand Up @@ -381,14 +383,30 @@ def main():
if ret != 0:
print('Remove rtc_ds1307 module failed', flush=True)
else:
print('Wake up RTC hardware', flush=True)
timeout, pause = 100, 0.1
while pijuice.rtcAlarm.GetTime()['error'] != 'NO_ERROR' and timeout > 0:
time.sleep(pause)
timeout -= pause
if timeout <= 0:
print('RTC hardware not responding, trying to load rtc_ds1307 anyway', flush=True)
else:
if pijuice.rtcAlarm.GetTime()['data']['year'] == 2000:
print('RTC clock was reset to 0. Possible battery loss.')
print('Setting RTC to current system time')
pijuice.rtcAlarm.SetTime(None)

ret = os.system('sudo modprobe rtc_ds1307')
if (ret != 0):
print('Reload rtc_ds1307 module failed', flush=True)
else:
time.sleep(1) # give udev time to create the device
if os.path.exists('/dev/rtc'):
print('rtc_ds1307 mdule reloaded and RTC os-support OK', flush=True)
print('rtc_ds1307 module reloaded and RTC os-support OK', flush=True)
else:
print('RTC os-support not available', flush=True)
else:
print('RTC os-support not available', flush=True)

if watchdogEn: _ConfigureWatchdog('ACTIVATE')

Expand Down