OpenCores
URL https://opencores.org/ocsvn/altor32/altor32/trunk

Subversion Repositories altor32

[/] [altor32/] [trunk/] [or1k-sim/] [periph_timer.h] - Blame information for rev 28

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 28 ultra_embe
//-----------------------------------------------------------------
2
//                           AltOR32 
3
//                Alternative Lightweight OpenRisc 
4
//                            V2.0
5
//                     Ultra-Embedded.com
6
//                   Copyright 2011 - 2013
7
//
8
//               Email: admin@ultra-embedded.com
9
//
10
//                       License: LGPL
11
//-----------------------------------------------------------------
12
//
13
// Copyright (C) 2011 - 2013 Ultra-Embedded.com
14
//
15
// This source file may be used and distributed without         
16
// restriction provided that this copyright statement is not    
17
// removed from the file and that any derivative work contains  
18
// the original copyright notice and the associated disclaimer. 
19
//
20
// This source file is free software; you can redistribute it   
21
// and/or modify it under the terms of the GNU Lesser General   
22
// Public License as published by the Free Software Foundation; 
23
// either version 2.1 of the License, or (at your option) any   
24
// later version.
25
//
26
// This source is distributed in the hope that it will be       
27
// useful, but WITHOUT ANY WARRANTY; without even the implied   
28
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      
29
// PURPOSE.  See the GNU Lesser General Public License for more 
30
// details.
31
//
32
// You should have received a copy of the GNU Lesser General    
33
// Public License along with this source; if not, write to the 
34
// Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
35
// Boston, MA  02111-1307  USA
36
//-----------------------------------------------------------------
37
#ifndef __PERIPH_TIMER_H__
38
#define __PERIPH_TIMER_H__
39
 
40
#include "peripheral.h"
41
 
42
//--------------------------------------------------------------------
43
// Defines:
44
//--------------------------------------------------------------------
45
#define TIMER_BASE          0x12000100
46
 
47
//--------------------------------------------------------------------
48
// Class
49
//--------------------------------------------------------------------
50
class TimerPeripheral: public Peripheral
51
{
52
    virtual void Reset(void)
53
    {
54
        tick_count = 0;
55
    }
56
 
57
    virtual void Clock(void)
58
    {
59
        static int ticks = 0;
60
 
61
        // 1ms tick, 1MHz clock rate...
62
        if (++ticks == 1000)
63
        {
64
            tick_count++;
65
            ticks = 0;
66
        }
67
    }
68
 
69
    virtual TRegister Access(TAddress addr, TRegister data_in, TRegister wr, TRegister rd)
70
    {
71
        switch (addr)
72
        {
73
            case TIMER_BASE:
74
                return tick_count;
75
        }
76
 
77
        return 0;
78
    }
79
 
80
    virtual bool Interrupt(void)
81
    {
82
        return false;
83
    }
84
 
85
    virtual TAddress GetStartAddress() { return TIMER_BASE; }
86
    virtual TAddress GetStopAddress()  { return TIMER_BASE; }
87
private:
88
 
89
    TRegister tick_count;
90
};
91
 
92
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.