mc146818.hh revision 5392
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;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Ali Saidi
29 *          Andrew Schultz
30 *          Miguel Serrano
31 */
32
33#ifndef __DEV_MC146818_HH__
34#define __DEV_MC146818_HH__
35
36#include "base/range.hh"
37#include "sim/eventq.hh"
38
39/** Real-Time Clock (MC146818) */
40class MC146818
41{
42  protected:
43    virtual void handleEvent()
44    {
45        warn("No RTC event handler defined.\n");
46    }
47
48  private:
49    /** Event for RTC periodic interrupt */
50    struct RTCEvent : public Event
51    {
52        MC146818 * parent;
53        Tick interval;
54
55        RTCEvent(MC146818 * _parent, Tick i);
56
57        /** Schedule the RTC periodic interrupt */
58        void scheduleIntr();
59
60        /** Event process to occur at interrupt*/
61        virtual void process();
62
63        /** Event description */
64        virtual const char *description() const;
65    };
66
67  private:
68    std::string _name;
69    const std::string &name() const { return _name; }
70
71    /** RTC periodic interrupt event */
72    RTCEvent event;
73
74    /** Data for real-time clock function */
75    union {
76        uint8_t clock_data[10];
77
78        struct {
79            uint8_t sec;
80            uint8_t sec_alrm;
81            uint8_t min;
82            uint8_t min_alrm;
83            uint8_t hour;
84            uint8_t hour_alrm;
85            uint8_t wday;
86            uint8_t mday;
87            uint8_t mon;
88            uint8_t year;
89        };
90    };
91
92    /** RTC status register A */
93    uint8_t stat_regA;
94
95    /** RTC status register B */
96    uint8_t stat_regB;
97
98  public:
99    virtual ~MC146818()
100    {}
101
102    MC146818(const std::string &name, const struct tm time,
103            bool bcd, Tick frequency);
104
105    /** RTC write data */
106    void writeData(const uint8_t addr, const uint8_t data);
107
108    /** RTC read data */
109    uint8_t readData(const uint8_t addr);
110
111    /**
112      * Serialize this object to the given output stream.
113      * @param base The base name of the counter object.
114      * @param os The stream to serialize to.
115      */
116    void serialize(const std::string &base, std::ostream &os);
117
118    /**
119     * Reconstruct the state of this object from a checkpoint.
120     * @param base The base name of the counter object.
121     * @param cp The checkpoint use.
122     * @param section The section name of this object
123     */
124    void unserialize(const std::string &base, Checkpoint *cp,
125                     const std::string &section);
126};
127
128#endif // __DEV_MC146818_HH__
129