| OLD | NEW |
| 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can |
| 3 # be # found in the LICENSE file. |
| 4 |
| 5 """Provides utility methods for the Real Time Clock device. |
| 6 """ |
| 7 |
| 1 import errno | 8 import errno |
| 2 | 9 |
| 10 |
| 3 def get_seconds(utc=True): | 11 def get_seconds(utc=True): |
| 4 """ | 12 """ |
| 5 Read the current time out of the RTC | 13 Read the current time out of the RTC |
| 6 """ | 14 """ |
| 7 return int(file('/sys/class/rtc/rtc0/since_epoch').readline()) | 15 return int(file('/sys/class/rtc/rtc0/since_epoch').readline()) |
| 8 | 16 |
| 9 | 17 |
| 10 def write_wake_alarm(alarm_time): | 18 def write_wake_alarm(alarm_time): |
| 11 """ | 19 """ |
| 12 Write a value to the wake alarm | 20 Write a value to the wake alarm |
| 13 """ | 21 """ |
| 14 f = file('/sys/class/rtc/rtc0/wakealarm', 'w') | 22 f = file('/sys/class/rtc/rtc0/wakealarm', 'w') |
| 15 f.write('%s\n' % str(alarm_time)) | 23 f.write('%s\n' % str(alarm_time)) |
| 16 f.close() | 24 f.close() |
| 17 | 25 |
| 18 def set_wake_alarm(alarm_time): | 26 def set_wake_alarm(alarm_time): |
| 19 """ | 27 """ |
| 20 Set the hardware RTC-based wake alarm to 'alarm_time'. | 28 Set the hardware RTC-based wake alarm to 'alarm_time'. |
| 21 """ | 29 """ |
| 22 try: | 30 try: |
| 23 write_wake_alarm(alarm_time) | 31 write_wake_alarm(alarm_time) |
| 24 except IOError as (errnum, strerror): | 32 except IOError as (errnum, strerror): |
| 25 if errnum != errno.EBUSY: | 33 if errnum != errno.EBUSY: |
| 26 raise | 34 raise |
| 27 write_wake_alarm('clear') | 35 write_wake_alarm('clear') |
| 28 write_wake_alarm(alarm_time) | 36 write_wake_alarm(alarm_time) |
| 29 | 37 |
| OLD | NEW |