17584SN/A/*
28869SAli.Saidi@ARM.com * Copyright (c) 2010-2012 ARM Limited
37584SN/A * All rights reserved
47584SN/A *
57584SN/A * The license below extends only to copyright in the software and shall
67584SN/A * not be construed as granting a license to any other intellectual
77584SN/A * property including but not limited to intellectual property relating
87584SN/A * to a hardware implementation of the functionality of the software
97584SN/A * licensed hereunder.  You may use the software subject to the license
107584SN/A * terms below provided that you ensure that this notice is replicated
117584SN/A * unmodified and in its entirety in all distributions of the software,
127584SN/A * modified or unmodified, in source code or in binary form.
137584SN/A *
147584SN/A * Redistribution and use in source and binary forms, with or without
157584SN/A * modification, are permitted provided that the following conditions are
167584SN/A * met: redistributions of source code must retain the above copyright
177584SN/A * notice, this list of conditions and the following disclaimer;
187584SN/A * redistributions in binary form must reproduce the above copyright
197584SN/A * notice, this list of conditions and the following disclaimer in the
207584SN/A * documentation and/or other materials provided with the distribution;
217584SN/A * neither the name of the copyright holders nor the names of its
227584SN/A * contributors may be used to endorse or promote products derived from
237584SN/A * this software without specific prior written permission.
247584SN/A *
257584SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
267584SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
277584SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
287584SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
297584SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
307584SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
317584SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
327584SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
337584SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
347584SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
357584SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
367584SN/A *
377584SN/A * Authors: Ali Saidi
387584SN/A */
397584SN/A
408869SAli.Saidi@ARM.com#ifndef __DEV_ARM_RTC_PL310_HH__
418869SAli.Saidi@ARM.com#define __DEV_ARM_RTC_PL310_HH__
427584SN/A
437584SN/A#include "dev/arm/amba_device.hh"
448869SAli.Saidi@ARM.com#include "params/PL031.hh"
457584SN/A
467584SN/A/** @file
478869SAli.Saidi@ARM.com * This implements the ARM Primecell 031 RTC
487584SN/A */
497584SN/A
508869SAli.Saidi@ARM.comclass PL031 : public AmbaIntDevice
517584SN/A{
527584SN/A  protected:
538869SAli.Saidi@ARM.com    enum {
548869SAli.Saidi@ARM.com        DataReg    = 0x00,
558869SAli.Saidi@ARM.com        MatchReg   = 0x04,
568869SAli.Saidi@ARM.com        LoadReg    = 0x08,
578869SAli.Saidi@ARM.com        ControlReg = 0x0C,
588869SAli.Saidi@ARM.com        IntMask    = 0x10,
598869SAli.Saidi@ARM.com        RawISR     = 0x14,
608869SAli.Saidi@ARM.com        MaskedISR  = 0x18,
618869SAli.Saidi@ARM.com        IntClear   = 0x1C,
627584SN/A    };
637584SN/A
648869SAli.Saidi@ARM.com    /* Seconds since epoch that correspond to time simulation was started at the
658869SAli.Saidi@ARM.com     * begining of simulation and is then updated if ever written. */
668869SAli.Saidi@ARM.com    uint32_t timeVal;
677584SN/A
688869SAli.Saidi@ARM.com    /* Time when the timeVal register was written */
698869SAli.Saidi@ARM.com    Tick lastWrittenTick;
708869SAli.Saidi@ARM.com
718869SAli.Saidi@ARM.com    /* Previous load value */
728869SAli.Saidi@ARM.com    uint32_t loadVal;
738869SAli.Saidi@ARM.com
748869SAli.Saidi@ARM.com    /* RTC Match Value
758869SAli.Saidi@ARM.com     * Cause an interrupt when this value hits counter
768869SAli.Saidi@ARM.com     */
778869SAli.Saidi@ARM.com    uint32_t matchVal;
788869SAli.Saidi@ARM.com
798869SAli.Saidi@ARM.com    /** If timer has caused an interrupt. This is irrespective of
808869SAli.Saidi@ARM.com     * interrupt enable */
818869SAli.Saidi@ARM.com    bool rawInt;
828869SAli.Saidi@ARM.com
838869SAli.Saidi@ARM.com    /** If the timer interrupt mask that is anded with the raw interrupt to
848869SAli.Saidi@ARM.com     * generate a pending interrupt
858869SAli.Saidi@ARM.com     */
868869SAli.Saidi@ARM.com    bool maskInt;
878869SAli.Saidi@ARM.com
888869SAli.Saidi@ARM.com    /** If an interrupt is currently pending. Logical and of CTRL.intEnable
898869SAli.Saidi@ARM.com     * and rawInt */
908869SAli.Saidi@ARM.com    bool pendingInt;
918869SAli.Saidi@ARM.com
928869SAli.Saidi@ARM.com    /** Called when the counter reaches matches */
938869SAli.Saidi@ARM.com    void counterMatch();
9412086Sspwilson2@wisc.edu    EventFunctionWrapper matchEvent;
958869SAli.Saidi@ARM.com
968869SAli.Saidi@ARM.com    /** Called to update the matchEvent when the load Value or match value are
978869SAli.Saidi@ARM.com     * written.
988869SAli.Saidi@ARM.com     */
998869SAli.Saidi@ARM.com    void resyncMatch();
1007584SN/A
1017584SN/A  public:
1028869SAli.Saidi@ARM.com    typedef PL031Params Params;
1037584SN/A    const Params *
1047584SN/A    params() const
1057584SN/A    {
1067584SN/A        return dynamic_cast<const Params *>(_params);
1077584SN/A    }
1087584SN/A    /**
1097584SN/A      * The constructor for RealView just registers itself with the MMU.
1107584SN/A      * @param p params structure
1117584SN/A      */
1128869SAli.Saidi@ARM.com    PL031(Params *p);
1137584SN/A
1147584SN/A    /**
1157584SN/A     * Handle a read to the device
1167584SN/A     * @param pkt The memory request.
1177584SN/A     * @param data Where to put the data.
1187584SN/A     */
11911174Sandreas.hansson@arm.com    Tick read(PacketPtr pkt) override;
1207584SN/A
1217584SN/A    /**
1228869SAli.Saidi@ARM.com     * Handle writes to the device
1237584SN/A     * @param pkt The memory request.
1247584SN/A     * @param data the data
1257584SN/A     */
12611174Sandreas.hansson@arm.com    Tick write(PacketPtr pkt) override;
1277584SN/A
12811168Sandreas.hansson@arm.com    void serialize(CheckpointOut &cp) const override;
12911168Sandreas.hansson@arm.com    void unserialize(CheckpointIn &cp) override;
1307584SN/A};
1317584SN/A
1327584SN/A
1338869SAli.Saidi@ARM.com#endif // __DEV_ARM_RTC_PL031_HH__
1347584SN/A
135