OSDN Git Service

* public snapshot of sid simulator
[pf3gnuchains/pf3gnuchains3x.git] / sid / component / timers / arm7t / arm7t-timer.h
1 // arm7t-timer.h- An implementation of the timers from the ARM PID7T
2 // development board.  -*- C++ -*-
3
4 // Copyright (C) 1999, 2000 Red Hat.
5 // This file is part of SID and is licensed under the GPL.
6 // See the file COPYING.SID for conditions for redistribution.
7 // arm7t-timer.h
8
9 // A more thorough description of this component may be found at
10 // <http://www.arm.com/Documentation/UserMans/rps/#timer>
11
12 #ifndef _ARM7T_TIMER_H
13 #define _ARM7T_TIMER_H
14
15 #include <sidcomp.h>
16 #include <sidso.h>
17 #include <sidcomputil.h>
18 #include <sidattrutil.h>
19 #include <sidpinutil.h>
20 #include <sidpinattrutil.h>
21 #include <sidbusutil.h>
22 #include <sidschedutil.h>
23 #include <sidtypes.h>
24 #include <sidwatchutil.h>
25
26 #include <string>
27 #include <iostream>
28
29 using std::vector;
30 using std::string;
31 using std::ostream;
32 using std::istream;
33 using std::ios;
34 using std::cerr;
35 using std::endl;
36
37 using sid::component;
38 using sid::bus;
39 using sid::little_int_4;
40 using sid::host_int_2;
41 using sid::host_int_4;
42 using sid::component_library;
43 using sid::COMPONENT_LIBRARY_MAGIC;
44
45 using sidutil::fixed_attribute_map_component;
46 using sidutil::fixed_bus_map_component;
47 using sidutil::fixed_pin_map_component;
48 using sidutil::no_accessor_component;
49 using sidutil::no_relation_component;
50 using sidutil::callback_pin;
51 using sidutil::output_pin;
52 using sidutil::word_bus;
53 using sidutil::scheduler_event_subscription;
54 using sidutil::make_attribute;
55 using sidutil::parse_attribute;
56 using sidutil::self_watcher;
57
58 #include <vector>
59 #include <string>
60
61 class armTimer: public virtual component, 
62                 protected fixed_attribute_map_component,
63                 protected fixed_bus_map_component,
64                 protected fixed_pin_map_component,
65                 protected no_accessor_component,
66                 protected no_relation_component
67 {
68 public:
69   armTimer();
70
71 private:
72   class bus_interface: public word_bus<little_int_4>
73   {
74   public:
75     bus_interface(armTimer *h): host(h) {}
76     bus::status word_write(host_int_4 addr,
77                            little_int_4 mask,
78                            little_int_4 data);
79
80     bus::status word_read(host_int_4 addr,
81                           little_int_4 mask,
82                           little_int_4& data);
83   private:
84     armTimer *host;
85   };
86   friend class bus_interface;
87
88 protected:
89   virtual void tick();
90   virtual void reset_schedule() {}
91
92   host_int_2 counter;
93   bool enabled;
94   host_int_2 loadValue;
95
96   enum timer_mode { periodic, free_running };
97   timer_mode mode;
98   friend istream& operator >> (istream&, timer_mode&);
99   friend ostream& operator << (ostream&, const timer_mode&);
100
101   host_int_2 prescale;
102   output_pin interrupt_pin;
103   bus_interface bus;
104
105   callback_pin<armTimer> reset_pin;
106   void reset_pin_handler (host_int_4) { this->reset(); }
107   virtual void reset ();
108   
109   // State save and restore.
110   std::string save_state();
111   sid::component::status restore_state ( const string& state );
112   friend ostream& operator << (ostream& op, const armTimer& copy_obj);
113   friend istream& operator >> (istream& ip, armTimer& ovwrite_obj);
114   
115   // Triggerpoint manager
116   friend class self_watcher<armTimer>;
117   self_watcher<armTimer> triggerpoint_manager;
118   
119   sid::component::status
120   pin_factory(const string& name)
121     {
122       return triggerpoint_manager.create_virtual_pin(name);
123     }
124   
125   void
126   pin_junkyard(const string& name)
127     {
128       return triggerpoint_manager.destroy_virtual_pin(name);
129     }
130
131   // These are made virtual so that derived classes may stream out
132   // additional data.  Override these methods.
133
134   virtual void stream(ostream& op) const;
135   virtual void destream(istream& ip);
136 };
137
138
139 class armTimerNoSched: public armTimer
140 {
141 public:
142   armTimerNoSched();
143
144 private:
145   callback_pin<armTimerNoSched> clockpin;
146   unsigned ticks; // does not get larger than 0 .. divider
147   void tick(); // perform divisor calculations here
148   void tick(host_int_4) { this->tick(); } // indirection for callback_pin
149   void reset ();
150
151   void stream(ostream& op) const;
152   void destream(istream& ip);
153 };
154
155
156 class armTimerSched: public armTimer
157 {
158 public:
159   armTimerSched();
160
161 private:
162   friend class scheduler_event_subscription<armTimerSched>;
163   scheduler_event_subscription<armTimerSched> ticker;
164
165   void reset_schedule();
166 };
167
168 #endif // _ARM7T_TIMER_H
169