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

Subversion Repositories adv_debug_sys

[/] [adv_debug_sys/] [trunk/] [Software/] [AdvancedWatchpointControl/] [src/] [advancedWatchpointControl/] [mainControl.java] - Blame information for rev 54

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 54 nyawn
////////////////////////////////////////////////////////////////
2
//
3
// mainControl.java
4
//
5
// Copyright (C) 2010 Nathan Yawn 
6
//                    (nyawn@opencores.org)
7
//
8
// This is the central control in the program.  It oversees
9
// the processes of reading and writing the target hardware.
10
//
11
////////////////////////////////////////////////////////////////
12
//
13
// This source file may be used and distributed without
14
// restriction provided that this copyright statement is not
15
// removed from the file and that any derivative work contains
16
// the original copyright notice and the associated disclaimer.
17
// 
18
// This source file is free software; you can redistribute it
19
// and/or modify it under the terms of the GNU General
20
// Public License as published by the Free Software Foundation;
21
// either version 3.0 of the License, or (at your option) any
22
// later version.
23
//
24
// This source is distributed in the hope that it will be
25
// useful, but WITHOUT ANY WARRANTY; without even the implied 
26
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
27
// PURPOSE.  See the GNU Lesser General Public License for more
28
// details.
29
// 
30
// You should have received a copy of the GNU General
31
// Public License along with this source; if not, download it 
32
// from http://www.gnu.org/licenses/gpl.html
33
//
34
////////////////////////////////////////////////////////////////
35 51 nyawn
package advancedWatchpointControl;
36
 
37
import java.io.IOException;
38
import java.util.LinkedList;
39
import java.util.List;
40
 
41
 
42
public class mainControl {
43
 
44
        public enum connectionStatus { NOT_CONNECTED, CONNECTING, CONNECTED, CONNECT_ERROR }
45
 
46
        private targetDebugRegisterSet regSet = null;
47
        private networkSystem netSys = null;
48
        private targetTransactor transactor = null;
49
        private rspCoder rsp = null;
50
        // Yes, there really need to have three different observer interfaces,
51
        // in case a single UI class wants to be more than one.
52
        private List<RegisterObserver> registerObserverList = null;
53
        private List<NetworkStatusObserver> networkStatusObserverList = null;
54
        private List<LogMessageObserver> logmsgObserverList = null;
55
        private String networkStatus = "";
56
        private String logMessage = "";
57
 
58
        public mainControl() {
59
                registerObserverList = new LinkedList<RegisterObserver>();
60
                networkStatusObserverList = new LinkedList<NetworkStatusObserver>();
61
                logmsgObserverList = new LinkedList<LogMessageObserver>();
62
                regSet = new targetDebugRegisterSet();  // Create the object to hold the debug registers
63
                netSys = new networkSystem(this);
64
                rsp = new rspCoder(netSys);
65
                transactor = new targetTransactor(rsp);
66
        }
67
 
68
        public void setNetworkSystem(networkSystem ns) {
69
                netSys = ns;
70
        }
71
 
72
        public void registerForRegsetUpdates(RegisterObserver obs) {
73
                registerObserverList.add(obs);
74
        }
75
 
76
        public void registerForNetworkStatusUpdates(NetworkStatusObserver obs) {
77
                networkStatusObserverList.add(obs);
78
        }
79
 
80
        public void registerForLogMessages(LogMessageObserver obs) {
81
                logmsgObserverList.add(obs);
82
        }
83
 
84
        public targetDebugRegisterSet getRegSet() {
85
                return regSet;
86
        }
87
 
88
        public void doNetworkConnect(String serverHostname, int port) {
89
                if(netSys != null) {
90
                        netSys.connect(serverHostname, port);
91
                }
92
        }
93
 
94
        public synchronized void doReadAllRegisters() {
95
                try {  // Any target interaction may throw an IOException.
96
 
97
                        if(transactor.isTargetRunning()) {
98
                                setLogMessage("Cannot read registers while target is running");
99
                                return;
100
                        }
101
 
102
                        // get all (debug) registers (we use) from the target
103
                        regSet.setDCR(0, transactor.readRegister(targetDebugRegisterSet.regType.DCR0));
104
                        regSet.setDCR(1, transactor.readRegister(targetDebugRegisterSet.regType.DCR1));
105
                        regSet.setDCR(2, transactor.readRegister(targetDebugRegisterSet.regType.DCR2));
106
                        regSet.setDCR(3, transactor.readRegister(targetDebugRegisterSet.regType.DCR3));
107
                        regSet.setDCR(4, transactor.readRegister(targetDebugRegisterSet.regType.DCR4));
108
                        regSet.setDCR(5, transactor.readRegister(targetDebugRegisterSet.regType.DCR5));
109
                        regSet.setDCR(6, transactor.readRegister(targetDebugRegisterSet.regType.DCR6));
110
                        regSet.setDCR(7, transactor.readRegister(targetDebugRegisterSet.regType.DCR7));
111
                        regSet.setDVR(0, transactor.readRegister(targetDebugRegisterSet.regType.DVR0));
112
                        regSet.setDVR(1, transactor.readRegister(targetDebugRegisterSet.regType.DVR1));
113
                        regSet.setDVR(2, transactor.readRegister(targetDebugRegisterSet.regType.DVR2));
114
                        regSet.setDVR(3, transactor.readRegister(targetDebugRegisterSet.regType.DVR3));
115
                        regSet.setDVR(4, transactor.readRegister(targetDebugRegisterSet.regType.DVR4));
116
                        regSet.setDVR(5, transactor.readRegister(targetDebugRegisterSet.regType.DVR5));
117
                        regSet.setDVR(6, transactor.readRegister(targetDebugRegisterSet.regType.DVR6));
118
                        regSet.setDVR(7, transactor.readRegister(targetDebugRegisterSet.regType.DVR7));
119
                        regSet.setDWCR0(transactor.readRegister(targetDebugRegisterSet.regType.DWCR0));
120
                        regSet.setDWCR1(transactor.readRegister(targetDebugRegisterSet.regType.DWCR1));
121
                        regSet.setDMR1(transactor.readRegister(targetDebugRegisterSet.regType.DMR1));
122
                        regSet.setDMR2(transactor.readRegister(targetDebugRegisterSet.regType.DMR2));
123
                } catch (IOException e) {
124
                        setLogMessage("Network error: " + e.getMessage());
125
                        // *** TODO Disconnect?? Retry?
126
                }
127
 
128
                // Notify observers to set GUI elements accordingly
129
                try {
130
                        for(RegisterObserver obs : registerObserverList) {
131
                                obs.notifyRegisterUpdate(RegisterObserver.updateDirection.REGS_TO_GUI);
132
                        }
133
                } catch(NumberFormatException e) {
134
                        // Since we're going long->String, this should never happen.
135
                        setLogMessage("Impossible exception while updating GUI!");
136
                }
137
        }
138
 
139
        public synchronized void doWriteAllRegisters() {
140
 
141
                try {
142
 
143
                        if(transactor.isTargetRunning()) {
144
                                setLogMessage("Cannot write registers while target is running");
145
                                return;
146
                        }
147
 
148
                        // Notify observers to set registers from GUI elements
149
                        try {
150
                                for(RegisterObserver obs : registerObserverList) {
151
                                        obs.notifyRegisterUpdate(RegisterObserver.updateDirection.GUI_TO_REGS);
152
                                }
153
                        } catch (NumberFormatException e) {
154
                                // DVRs must be converted from Strings.  This may fail and throw the exception.
155
                                setLogMessage("Illegal DVR value, registers not written");
156
                                return;
157
                        }
158
 
159
                        transactor.writeRegister(targetDebugRegisterSet.regType.DCR0, regSet.getDCR(0));
160
                        transactor.writeRegister(targetDebugRegisterSet.regType.DCR1, regSet.getDCR(1));
161
                        transactor.writeRegister(targetDebugRegisterSet.regType.DCR2, regSet.getDCR(2));
162
                        transactor.writeRegister(targetDebugRegisterSet.regType.DCR3, regSet.getDCR(3));
163
                        transactor.writeRegister(targetDebugRegisterSet.regType.DCR4, regSet.getDCR(4));
164
                        transactor.writeRegister(targetDebugRegisterSet.regType.DCR5, regSet.getDCR(5));
165
                        transactor.writeRegister(targetDebugRegisterSet.regType.DCR6, regSet.getDCR(6));
166
                        transactor.writeRegister(targetDebugRegisterSet.regType.DCR7, regSet.getDCR(7));
167
                        transactor.writeRegister(targetDebugRegisterSet.regType.DVR0, regSet.getDVR(0));
168
                        transactor.writeRegister(targetDebugRegisterSet.regType.DVR1, regSet.getDVR(1));
169
                        transactor.writeRegister(targetDebugRegisterSet.regType.DVR2, regSet.getDVR(2));
170
                        transactor.writeRegister(targetDebugRegisterSet.regType.DVR3, regSet.getDVR(3));
171
                        transactor.writeRegister(targetDebugRegisterSet.regType.DVR4, regSet.getDVR(4));
172
                        transactor.writeRegister(targetDebugRegisterSet.regType.DVR5, regSet.getDVR(5));
173
                        transactor.writeRegister(targetDebugRegisterSet.regType.DVR6, regSet.getDVR(6));
174
                        transactor.writeRegister(targetDebugRegisterSet.regType.DVR7, regSet.getDVR(7));
175
                        transactor.writeRegister(targetDebugRegisterSet.regType.DWCR0, regSet.getDWCR0());
176
                        transactor.writeRegister(targetDebugRegisterSet.regType.DWCR1, regSet.getDWCR1());
177
                        // Note that DMR2 must be written AFTER the DWCR registers.  If
178
                        // DMR2 is written first, then the trap condition will be cleared,
179
                        // but it will still exist because count still equals match val
180
                        // in the DWCR.
181
                        transactor.writeRegister(targetDebugRegisterSet.regType.DMR1, regSet.getDMR1());
182
                        transactor.writeRegister(targetDebugRegisterSet.regType.DMR2, regSet.getDMR2());
183
                } catch (IOException e) {
184
                        setLogMessage("Network error: " + e.getMessage());
185
                        // TODO *** Disconnect?  Retry??
186
                }
187
        }
188
 
189
 
190
        // This is thread-safe for the GUI.  It must be used by the network thread (receiveResponse()
191
        // and anything called from it) to log messages to the GUI.
192
        public void setLogMessage(final String msg) {
193
 
194
                logMessage = msg;
195
 
196
                // Tell the display(s) to fetch and show the status
197
                for(LogMessageObserver obs : logmsgObserverList) {
198
                        obs.notifyLogMessage();
199
                }
200
        }
201
 
202
        public String getLogMessage() {
203
                return logMessage;
204
        }
205
 
206
        // This just puts the status into a member variable,
207
        // for the network status observers to retrieve.
208
        public void setNetworkStatus(connectionStatus cStatus) {
209
                switch(cStatus) {
210
                case NOT_CONNECTED:
211
                        networkStatus = "Not Connected";
212
                        break;
213
                case CONNECTING:
214
                        networkStatus = "Connecting...";
215
                        break;
216
                case CONNECTED:
217
                        networkStatus = "Connected";
218
                        break;
219
                case CONNECT_ERROR:
220
                        networkStatus = "Error Connecting";
221
                        break;
222
                default:
223
                        networkStatus = "Unknown Error";
224
                }
225
 
226
                // Tell the display(s) to fetch and show the status
227
                for(NetworkStatusObserver obs : networkStatusObserverList) {
228
                        obs.notifyNetworkStatus();
229
                }
230
        }
231
 
232
        public String getNetworkStatus() {
233
                return networkStatus;
234
        }
235
}

powered by: WebSVN 2.1.0

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