tsunami_io.cc (3932:62e915bb6704) tsunami_io.cc (3943:68e673d2db04)
1/*
2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 51 unchanged lines hidden (view full) ---

60TsunamiIO::RTC::RTC(const string &n, Tsunami* tsunami, const vector<int> &t,
61 bool bcd, Tick i)
62 : _name(n), event(tsunami, i), addr(0), year_is_bcd(bcd)
63{
64 memset(clock_data, 0, sizeof(clock_data));
65 stat_regA = RTCA_32768HZ | RTCA_1024HZ;
66 stat_regB = RTCB_PRDC_IE |RTCB_BIN | RTCB_24HR;
67
1/*
2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 51 unchanged lines hidden (view full) ---

60TsunamiIO::RTC::RTC(const string &n, Tsunami* tsunami, const vector<int> &t,
61 bool bcd, Tick i)
62 : _name(n), event(tsunami, i), addr(0), year_is_bcd(bcd)
63{
64 memset(clock_data, 0, sizeof(clock_data));
65 stat_regA = RTCA_32768HZ | RTCA_1024HZ;
66 stat_regB = RTCB_PRDC_IE |RTCB_BIN | RTCB_24HR;
67
68 if (year_is_bcd) {
69 // The RTC uses BCD for the last two digits in the year.
70 // They python year is a full year.
71 int _year = t[0] % 100;
72 int tens = _year / 10;
73 int ones = _year % 10;
74
75 year = (tens << 4) + ones;
76 } else {
77 // Even though the datasheet says that the year field should be
78 // interpreted as BCD, we just enter the number of years since
79 // 1900 since linux seems to be happy with that (and I believe
80 // that Tru64 was as well)
81 year = t[0] - 1900;
82 }
83
84 mon = t[1];
85 mday = t[2];
86 hour = t[3];
87 min = t[4];
88 sec = t[5];
89
90 // wday is defined to be in the range from 1 - 7 with 1 being Sunday.
91 // the value coming from python is in the range from 0 - 6 with 0 being
92 // Monday. Fix that here.
93 wday = t[6] + 2;
94 if (wday > 7)
95 wday -= 7;
96
97 DPRINTFN("Real-time clock set to %s", getDateString());
98}
99
100std::string
101TsunamiIO::RTC::getDateString()
102{
103 struct tm tm;
68 struct tm tm;
69 parseTime(t, &tm);
104
70
105 memset(&tm, 0, sizeof(tm));
71 year = tm.tm_year;
106
107 if (year_is_bcd) {
72
73 if (year_is_bcd) {
108 // undo the BCD and conver to years since 1900 guessing that
109 // anything before 1970 is actually after 2000
110 int _year = (year >> 4) * 10 + (year & 0xf);
111 if (_year < 70)
112 _year += 100;
113
114 tm.tm_year = _year;
115 } else {
116 // number of years since 1900
117 tm.tm_year = year;
74 // The datasheet says that the year field can be either BCD or
75 // years since 1900. Linux seems to be happy with years since
76 // 1900.
77 year = year % 100;
78 int tens = year / 10;
79 int ones = year % 10;
80 year = (tens << 4) + ones;
118 }
119
81 }
82
120 // unix is 0-11 for month
121 tm.tm_mon = mon - 1;
122 tm.tm_mday = mday;
123 tm.tm_hour = hour;
124 tm.tm_min = min;
125 tm.tm_sec = sec;
83 // Unix is 0-11 for month, data seet says start at 1
84 mon = tm.tm_mon + 1;
85 mday = tm.tm_mday;
86 hour = tm.tm_hour;
87 min = tm.tm_min;
88 sec = tm.tm_sec;
126
89
127 // to add more annoyance unix is 0 - 6 with 0 as sunday
128 tm.tm_wday = wday - 1;
90 // Datasheet says 1 is sunday
91 wday = tm.tm_wday + 1;
129
92
130 return asctime(&tm);
93 DPRINTFN("Real-time clock set to %s", asctime(&tm));
131}
132
133void
134TsunamiIO::RTC::writeAddr(const uint8_t data)
135{
136 if (data <= RTC_STAT_REGD)
137 addr = data;
138 else

--- 601 unchanged lines hidden ---
94}
95
96void
97TsunamiIO::RTC::writeAddr(const uint8_t data)
98{
99 if (data <= RTC_STAT_REGD)
100 addr = data;
101 else

--- 601 unchanged lines hidden ---