OSDN Git Service

* public snapshot of sid simulator
[pf3gnuchains/pf3gnuchains3x.git] / sid / component / uart / testsuite / Devices.h
1 // Devices.h - description.  -*- C++ -*-
2
3 // Copyright (C) 1999, 2000 Red Hat.
4 // This file is part of SID and is licensed under the GPL.
5 // See the file COPYING.SID for conditions for redistribution.
6
7 #ifndef DEVICES_DEF_H
8 #define DEVICES_DEF_H   1
9
10 #include <sidcomp.h>
11 #include <sidso.h>
12 #include <sidpinutil.h>
13 #include <sidbusutil.h>
14 #include <sidattrutil.h>
15 #include <sidcomputil.h>
16
17 using namespace std;
18 using namespace sid;
19 using namespace sidutil;
20
21 class DeviceDriver : public virtual component,
22                      public fixed_attribute_map_component,
23                      public fixed_bus_map_component,
24                      public fixed_accessor_map_component,
25                      public no_relation_component,
26                      public fixed_pin_map_component
27 {
28 private:
29
30   int irq_cnt;
31
32   int wc;               // for writing strings
33   char *wstr;
34
35   int rc;               // for reading strings
36   char rstr[128];
37
38   sid::bus *bus;
39   output_pin scheduler_advance_pin;
40
41   class intr_pin : public binary_input_pin {
42     DeviceDriver *driver;
43
44   public:
45     intr_pin()                          { driver = 0; }
46
47     void init( DeviceDriver *me )       { driver = me; set_active_high(); }
48
49     void driven( host_int_4 val )  throw ( ) { 
50        try
51          {
52              driver->intrHandler( val ); 
53          }
54         catch (...)
55           { }
56     }
57
58
59     ~intr_pin()                 {}
60   };
61
62   friend class intr_pin;
63   intr_pin intr;
64
65   void intrHandler( int val );
66
67   class WriteTrigger : public input_pin {
68     DeviceDriver *driver;
69
70   public:
71     WriteTrigger()              { driver = 0; }
72
73     void init(DeviceDriver *owner) { driver = owner; }
74
75     void driven( host_int_4 val ) throw ( ) {
76         try 
77           {
78             // XXX oh me god
79             long str_addr = val;
80             driver->write( (char *) str_addr ); 
81           }
82         catch (...)
83           { }
84     }
85
86   };
87
88   friend class WriteTrigger;
89   WriteTrigger wtrigger;
90   
91 public: 
92
93   DeviceDriver() {
94     add_pin( "sched-advance", &scheduler_advance_pin );
95
96     add_pin( "INTR", &intr );
97     intr.init( this );
98
99     add_pin( "write-trigger", &wtrigger );
100     wtrigger.init( this );
101
102     add_accessor( "Bus", &bus );
103
104     irq_cnt = 0; 
105     add_attribute( "interrupt-count", &irq_cnt );
106
107     wstr = 0; 
108     rc = 0;
109     bus = 0;
110   }
111   
112   void write( char *s );
113   int read( char *buf );
114
115   ~DeviceDriver()       {}
116 };
117
118 class SerialSink : public virtual component,
119                    public fixed_attribute_map_component,
120                    public no_bus_component,
121                    public no_accessor_component,
122                    public no_relation_component,
123                    public fixed_pin_map_component
124 {
125 private:
126
127   callback_pin<SerialSink> sin;
128   friend class callback_pin<SerialSink>;
129
130   unsigned ldisc;                       // Line Control Reg
131
132   enum parity {
133     ODD_PARITY = 0,
134     EVEN_PARITY = 0x10          // Matches bit in LCR
135   };
136
137   int checkParity( unsigned val, int nbits, enum parity p ) const;
138
139   void echo( host_int_4 val );
140
141 public:
142
143   SerialSink() : sin( this, &SerialSink::echo ) {
144     add_pin( "Sin", &sin );
145
146     ldisc = 0;
147     add_attribute( "line-discipline", &ldisc );
148   }
149
150   ~SerialSink() {}
151 };
152
153 class Main : public virtual component,
154              public no_attribute_component,
155              public fixed_bus_map_component,
156              public fixed_accessor_map_component,
157              public no_relation_component,
158              public fixed_pin_map_component
159 {
160 private:
161   output_pin shutdown;
162   output_pin source;
163   output_pin wtrigger;
164
165   sid::bus *bus;
166
167   class activity_pin_t: public input_pin {
168     Main* host;
169
170   public:
171     activity_pin_t(Main* h): host(h) {}
172
173     void driven() throw ( ){
174       try 
175         {
176           host->run();
177           host->shutdown.drive( 1 );
178         }
179       catch (...)
180         { }
181     }
182
183   };
184
185   friend class activity_pin_t;
186   activity_pin_t activity_pin;
187
188   void run();
189
190 public:
191
192   Main() : activity_pin(this) {
193     add_pin( "perform-activity", &activity_pin );
194     add_pin( "shutdown-status", &shutdown );
195     add_pin( "source", &source );
196     add_pin( "driver-trigger", &wtrigger );
197
198     add_accessor( "Bus", &bus );
199   }
200
201   ~Main() {}
202 };
203
204 #endif // DEVICES_DEF_H