summaryrefslogtreecommitdiff
path: root/src/python/m5
diff options
context:
space:
mode:
authorNathan Binkert <binkertn@umich.edu>2007-01-25 14:59:41 -0500
committerNathan Binkert <binkertn@umich.edu>2007-01-25 14:59:41 -0500
commit73dd0ea35716b90c8448d729273cc153888a223b (patch)
tree4b9e1477bcf945deb7268ddc9be2f150a8c29a6f /src/python/m5
parent4301e4cd08018eb56b4f196afcce9a8311f390b4 (diff)
downloadgem5-73dd0ea35716b90c8448d729273cc153888a223b.tar.xz
Instead of passing an int to represent time between python and C++
pass the tuple of python's struct_time and interpret that. Fixes a problem where the local timezone leaked into the time calculation. Also fix things so that the unix, python, and RTC data sheets all get the right time. Provide both years since 1900 and BCD two digit year. Put the date back at 1/1/2006 for now. --HG-- extra : convert_revision : 473244572f468de2cb579a3dd7ae296a6f81f5d7
Diffstat (limited to 'src/python/m5')
-rw-r--r--src/python/m5/objects/Tsunami.py4
-rw-r--r--src/python/m5/params.py70
2 files changed, 41 insertions, 33 deletions
diff --git a/src/python/m5/objects/Tsunami.py b/src/python/m5/objects/Tsunami.py
index 18a776a7f..3d8e6dd04 100644
--- a/src/python/m5/objects/Tsunami.py
+++ b/src/python/m5/objects/Tsunami.py
@@ -13,8 +13,10 @@ class TsunamiCChip(BasicPioDevice):
class TsunamiIO(BasicPioDevice):
type = 'TsunamiIO'
- time = Param.Time('01/01/2009',
+ time = Param.Time('01/01/2006',
"System time to use ('Now' for actual time)")
+ year_is_bcd = Param.Bool(False,
+ "The RTC should interpret the year as a BCD value")
tsunami = Param.Tsunami(Parent.any, "Tsunami")
frequency = Param.Frequency('1024Hz', "frequency of interrupts")
diff --git a/src/python/m5/params.py b/src/python/m5/params.py
index d570804d8..f8a9f9ddd 100644
--- a/src/python/m5/params.py
+++ b/src/python/m5/params.py
@@ -518,49 +518,55 @@ class EthernetAddr(ParamValue):
else:
return self.value
+time_formats = [ "%a %b %d %H:%M:%S %Z %Y",
+ "%a %b %d %H:%M:%S %Z %Y",
+ "%Y/%m/%d %H:%M:%S",
+ "%Y/%m/%d %H:%M",
+ "%Y/%m/%d",
+ "%m/%d/%Y %H:%M:%S",
+ "%m/%d/%Y %H:%M",
+ "%m/%d/%Y",
+ "%m/%d/%y %H:%M:%S",
+ "%m/%d/%y %H:%M",
+ "%m/%d/%y"]
+
+
def parse_time(value):
- strings = [ "%a %b %d %H:%M:%S %Z %Y",
- "%a %b %d %H:%M:%S %Z %Y",
- "%Y/%m/%d %H:%M:%S",
- "%Y/%m/%d %H:%M",
- "%Y/%m/%d",
- "%m/%d/%Y %H:%M:%S",
- "%m/%d/%Y %H:%M",
- "%m/%d/%Y",
- "%m/%d/%y %H:%M:%S",
- "%m/%d/%y %H:%M",
- "%m/%d/%y"]
-
- for string in strings:
- try:
- return time.strptime(value, string)
- except ValueError:
- pass
+ from time import gmtime, strptime, struct_time, time
+ from datetime import datetime, date
+
+ if isinstance(value, struct_time):
+ return value
+
+ if isinstance(value, (int, long)):
+ return gmtime(value)
+
+ if isinstance(value, (datetime, date)):
+ return value.timetuple()
+
+ if isinstance(value, str):
+ if value in ('Now', 'Today'):
+ return time.gmtime(time.time())
+
+ for format in time_formats:
+ try:
+ return strptime(value, format)
+ except ValueError:
+ pass
raise ValueError, "Could not parse '%s' as a time" % value
class Time(ParamValue):
cxx_type = 'time_t'
def __init__(self, value):
- if isinstance(value, time.struct_time):
- self.value = time.mktime(value)
- elif isinstance(value, int):
- self.value = value
- elif isinstance(value, str):
- if value in ('Now', 'Today'):
- self.value = time.time()
- else:
- self.value = time.mktime(parse_time(value))
- elif isinstance(value, (datetime.datetime, datetime.date)):
- self.value = time.mktime(value.timetuple())
- else:
- raise ValueError, "Could not parse '%s' as a time" % value
+ self.value = parse_time(value)
def __str__(self):
- return str(int(self.value))
+ tm = self.value
+ return ' '.join([ str(tm[i]) for i in xrange(8)])
def ini_str(self):
- return str(int(self.value))
+ return str(self)
# Enumerated types are a little more complex. The user specifies the
# type as Enum(foo) where foo is either a list or dictionary of