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; --- 43 unchanged lines hidden (view full) --- 52#include "mem/port.hh" 53#include "sim/builder.hh" 54#include "sim/system.hh" 55 56using namespace std; 57//Should this be AlphaISA? 58using namespace TheISA; 59 |
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; |
104 |
105 memset(&tm, 0, sizeof(tm)); |
106 |
107 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; 118 } 119 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; 126 127 // to add more annoyance unix is 0 - 6 with 0 as sunday 128 tm.tm_wday = wday - 1; 129 130 return asctime(&tm); |
131} 132 133void 134TsunamiIO::RTC::writeAddr(const uint8_t data) 135{ 136 if (data <= RTC_STAT_REGD) 137 addr = data; 138 else --- 332 unchanged lines hidden (view full) --- 471const char * 472TsunamiIO::PITimer::Counter::CounterEvent::description() 473{ 474 return "tsunami 8254 Interval timer"; 475} 476 477TsunamiIO::TsunamiIO(Params *p) 478 : BasicPioDevice(p), tsunami(p->tsunami), pitimer(p->name + "pitimer"), |
479 rtc(p->name + ".rtc", p->tsunami, p->init_time, p->year_is_bcd, 480 p->frequency) |
481{ 482 pioSize = 0x100; 483 484 // set the back pointer from tsunami to myself 485 tsunami->io = this; 486 487 timerData = 0; 488 picr = 0; --- 208 unchanged lines hidden (view full) --- 697 698BEGIN_DECLARE_SIM_OBJECT_PARAMS(TsunamiIO) 699 700 Param<Addr> pio_addr; 701 Param<Tick> pio_latency; 702 Param<Tick> frequency; 703 SimObjectParam<Platform *> platform; 704 SimObjectParam<System *> system; |
705 VectorParam<int> time; 706 Param<bool> year_is_bcd; |
707 SimObjectParam<Tsunami *> tsunami; 708 709END_DECLARE_SIM_OBJECT_PARAMS(TsunamiIO) 710 711BEGIN_INIT_SIM_OBJECT_PARAMS(TsunamiIO) 712 713 INIT_PARAM(pio_addr, "Device Address"), 714 INIT_PARAM(pio_latency, "Programmed IO latency"), 715 INIT_PARAM(frequency, "clock interrupt frequency"), 716 INIT_PARAM(platform, "platform"), 717 INIT_PARAM(system, "system object"), 718 INIT_PARAM(time, "System time to use (0 for actual time"), |
719 INIT_PARAM(year_is_bcd, ""), |
720 INIT_PARAM(tsunami, "Tsunami") 721 722END_INIT_SIM_OBJECT_PARAMS(TsunamiIO) 723 724CREATE_SIM_OBJECT(TsunamiIO) 725{ 726 TsunamiIO::Params *p = new TsunamiIO::Params; 727 p->frequency = frequency; 728 p->name = getInstanceName(); 729 p->pio_addr = pio_addr; 730 p->pio_delay = pio_latency; 731 p->platform = platform; 732 p->system = system; 733 p->init_time = time; |
734 p->year_is_bcd = year_is_bcd; |
735 p->tsunami = tsunami; 736 return new TsunamiIO(p); 737} 738 739REGISTER_SIM_OBJECT("TsunamiIO", TsunamiIO) |