mc146818.cc (6620:ade9a088bb14) mc146818.cc (6621:835a99bdab10)
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;

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

47bcdize(uint8_t val)
48{
49 uint8_t result;
50 result = val % 10;
51 result += (val / 10) << 4;
52 return result;
53}
54
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;

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

47bcdize(uint8_t val)
48{
49 uint8_t result;
50 result = val % 10;
51 result += (val / 10) << 4;
52 return result;
53}
54
55static uint8_t
56unbcdize(uint8_t val)
57{
58 uint8_t result;
59 result = val & 0xf;
60 result += (val >> 4) * 10;
61 return result;
62}
63
55void
56MC146818::setTime(const struct tm time)
57{
58 curTime = time;
59 year = time.tm_year;
60 // Unix is 0-11 for month, data seet says start at 1
61 mon = time.tm_mon + 1;
62 mday = time.tm_mday;

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

96
97MC146818::~MC146818()
98{
99}
100
101void
102MC146818::writeData(const uint8_t addr, const uint8_t data)
103{
64void
65MC146818::setTime(const struct tm time)
66{
67 curTime = time;
68 year = time.tm_year;
69 // Unix is 0-11 for month, data seet says start at 1
70 mon = time.tm_mon + 1;
71 mday = time.tm_mday;

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

105
106MC146818::~MC146818()
107{
108}
109
110void
111MC146818::writeData(const uint8_t addr, const uint8_t data)
112{
104 if (addr < RTC_STAT_REGA)
113 if (addr < RTC_STAT_REGA) {
105 clock_data[addr] = data;
114 clock_data[addr] = data;
106 else {
115 curTime.tm_sec = unbcdize(sec);
116 curTime.tm_min = unbcdize(min);
117 curTime.tm_hour = unbcdize(hour);
118 curTime.tm_mday = unbcdize(mday);
119 curTime.tm_mon = unbcdize(mon) - 1;
120 curTime.tm_year = ((unbcdize(year) + 50) % 100) + 1950;
121 curTime.tm_wday = unbcdize(wday) - 1;
122 } else {
107 switch (addr) {
108 case RTC_STAT_REGA:
109 // The "update in progress" bit is read only.
110 if ((data & ~RTCA_UIP) != (RTCA_32768HZ | RTCA_1024HZ))
111 panic("Unimplemented RTC register A value write!\n");
112 replaceBits(stat_regA, data, 6, 0);
113 break;
114 case RTC_STAT_REGB:

--- 136 unchanged lines hidden ---
123 switch (addr) {
124 case RTC_STAT_REGA:
125 // The "update in progress" bit is read only.
126 if ((data & ~RTCA_UIP) != (RTCA_32768HZ | RTCA_1024HZ))
127 panic("Unimplemented RTC register A value write!\n");
128 replaceBits(stat_regA, data, 6, 0);
129 break;
130 case RTC_STAT_REGB:

--- 136 unchanged lines hidden ---