1 // arm7t-timer.h- An implementation of the timers from the ARM PID7T
2 // development board. -*- C++ -*-
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.
9 // A more thorough description of this component may be found at
10 // <http://www.arm.com/Documentation/UserMans/rps/#timer>
12 #ifndef _ARM7T_TIMER_H
13 #define _ARM7T_TIMER_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>
24 #include <sidwatchutil.h>
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;
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;
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
72 class bus_interface: public word_bus<little_int_4>
75 bus_interface(armTimer *h): host(h) {}
76 bus::status word_write(host_int_4 addr,
80 bus::status word_read(host_int_4 addr,
86 friend class bus_interface;
90 virtual void reset_schedule() {}
96 enum timer_mode { periodic, free_running };
98 friend istream& operator >> (istream&, timer_mode&);
99 friend ostream& operator << (ostream&, const timer_mode&);
102 output_pin interrupt_pin;
105 callback_pin<armTimer> reset_pin;
106 void reset_pin_handler (host_int_4) { this->reset(); }
107 virtual void reset ();
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);
115 // Triggerpoint manager
116 friend class self_watcher<armTimer>;
117 self_watcher<armTimer> triggerpoint_manager;
119 sid::component::status
120 pin_factory(const string& name)
122 return triggerpoint_manager.create_virtual_pin(name);
126 pin_junkyard(const string& name)
128 return triggerpoint_manager.destroy_virtual_pin(name);
131 // These are made virtual so that derived classes may stream out
132 // additional data. Override these methods.
134 virtual void stream(ostream& op) const;
135 virtual void destream(istream& ip);
139 class armTimerNoSched: public armTimer
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
151 void stream(ostream& op) const;
152 void destream(istream& ip);
156 class armTimerSched: public armTimer
162 friend class scheduler_event_subscription<armTimerSched>;
163 scheduler_event_subscription<armTimerSched> ticker;
165 void reset_schedule();
168 #endif // _ARM7T_TIMER_H