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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [host/] [tools/] [ecostest/] [common/] [ser_filter.cpp] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
// ####ECOSHOSTGPLCOPYRIGHTBEGIN####                                        
2
// -------------------------------------------                              
3
// This file is part of the eCos host tools.                                
4
// Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.            
5
//
6
// This program is free software; you can redistribute it and/or modify     
7
// it under the terms of the GNU General Public License as published by     
8
// the Free Software Foundation; either version 2 or (at your option) any   
9
// later version.                                                           
10
//
11
// This program is distributed in the hope that it will be useful, but      
12
// WITHOUT ANY WARRANTY; without even the implied warranty of               
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        
14
// General Public License for more details.                                 
15
//
16
// You should have received a copy of the GNU General Public License        
17
// along with this program; if not, write to the                            
18
// Free Software Foundation, Inc., 51 Franklin Street,                      
19
// Fifth Floor, Boston, MA  02110-1301, USA.                                
20
// -------------------------------------------                              
21
// ####ECOSHOSTGPLCOPYRIGHTEND####                                          
22
//=================================================================
23
//
24
//        ser_filter.cxx
25
//
26
//        Serial test filter
27
//
28
//=================================================================
29
//=================================================================
30
//#####DESCRIPTIONBEGIN####
31
//
32
// Author(s):     jskov
33
// Contributors:  jskov
34
// Date:          1999-03-01
35
// Description:   This program acts as a filter between GDB and the test
36
//                running on the target, allowing testing of the serial
37
//                driver without confusing GDB.
38
// Usage:         Run the program with one argument, the serial port
39
//                on with the target is connected.
40
//                Run serial test in GDB, connecting to the target with
41
//                'target remote localhost:5678'.
42
//
43
// To Do:
44
//  o Add timeout setup and handling for recovery, can rely on testing
45
//    agent to control global timeout.
46
//  o Saving chunks that caused transfer failure?
47
//     - In SEND with echo, do CRC on 32-byte sub-packets
48
//  o Additional To Do items under each sub-protocol function.
49
//  o Option to get all serial IO written (in hex, > and < prepends 
50
//    input/output lines) to a file.
51
//  o Clean up the mess in this file....
52
//  o Make main() listen on two ports - use one for ser filter, the other for
53
//    null filter connections.
54
//  o Maybe use environment variable to find X10 reset command.
55
//####DESCRIPTIONEND####
56
 
57
#include "eCosTestSerialFilter.h"
58
#include "eCosTestDownloadFilter.h"
59
#include "eCosTestMonitorFilter.h"
60
#include "eCosTestUtils.h"
61
#include "eCosThreadUtils.h"
62
#include "eCosTrace.h"
63
 
64
bool opt_ser_debug = false;
65
bool opt_null_filter = false;
66
bool opt_console_output = false;
67
bool opt_X10_reset = false;
68
bool opt_filter_trace = false;
69
char opt_X10_port[2];
70
bool opt_monitor = false;
71
 
72
void
73
no_gdb(const char* pszPort, int nBaud,
74
       CeCosSocket::FilterFunc *pSerialToSocketFilterFunc,
75
       void *pParam, bool *pbStop)
76
{
77
  fprintf(stderr, "no_gdb, listening on %s\n",pszPort);
78
 
79
  CeCosSocket dummy_socket;
80
  CeCosSerial serial;
81
  serial.SetBlockingReads(false);
82
  bool rc=false;
83
 
84
  // Open serial device.
85
  if (!serial.Open(pszPort,nBaud)){
86
    ERROR("Couldn't open port %s\n",pszPort);
87
  } else {
88
    // Flush the serial buffer.
89
    serial.Flush();
90
 
91
    serial.ClearError();
92
    enum {BUFSIZE=8192};
93
    void *pBuf=malloc(BUFSIZE);
94
    rc=true;
95
    while(rc && (0==pbStop || !(*pbStop))){
96
      unsigned int nRead=0;
97
 
98
      for(;;) {
99
        if(serial.Read(pBuf,BUFSIZE,nRead)){
100
          if(nRead>0){
101
            break;
102
          }
103
          CeCosThreadUtils::Sleep(1);
104
        } else {
105
          fprintf(stderr, "Serial read failed (%d)\n", errno);
106
        }
107
      }
108
 
109
      if(pSerialToSocketFilterFunc){
110
        rc=pSerialToSocketFilterFunc(pBuf,nRead,serial,dummy_socket,
111
          pParam);
112
      }
113
    }
114
    free(pBuf);
115
  }
116
}
117
 
118
int
119
main(int argc, char** argv)
120
{
121
  int nSock = 0;
122
  int baud_rate, nTcpPort;
123
 
124
  bool opt_no_gdb = false;
125
  char* ser_port;
126
  int i=1;
127
  if(!CeCosTestUtils::CommandLine(argc, argv, false)){
128
    goto Usage;
129
  }
130
 
131
  while(i<argc){
132
    if(argv[i][0]=='-'){
133
      switch(argv[i][1]){
134
      case 't':
135
        // redundant - -v does this
136
        CeCosTrace ::EnableTracing(CeCosTrace::TRACE_LEVEL_TRACE);
137
        break;
138
      case 'f':
139
        opt_filter_trace = true;
140
        break;
141
      case 'S':
142
        opt_ser_debug = true;
143
        break;
144
      case 'm':
145
        opt_monitor = true;
146
        break;
147
      case 'n':
148
        opt_no_gdb = true;
149
        // fall through! Output on console when no GDB.
150
      case 'c':
151
        opt_console_output = true;
152
        break;
153
      case '0':
154
        opt_null_filter = true;
155
        break;
156
      case 'X':
157
        // X-10 port to reset when connection drops
158
        opt_X10_reset = true;
159
        opt_X10_port[0] = argv[i][2];
160
        opt_X10_port[1] = argv[i][3];
161
        break;
162
      default:
163
        fprintf(stderr,"Unrecognized switch %s\n",argv[i]);
164
        goto Usage;
165
        break;
166
      }
167
      for(int j=i;j<argc;j++){
168
        argv[j]=argv[j+1];
169
      }
170
      argc--;
171
      argv[argc]=0;
172
    } else {
173
      i++;
174
    }
175
  }
176
 
177
  if(!((3==argc && opt_no_gdb) || (4==argc && !opt_no_gdb)))
178
  {
179
    goto Usage;
180
  }
181
 
182
  if (opt_no_gdb) {
183
    ser_port = argv[1];
184
    baud_rate=atoi(argv[2]);
185
  } else {
186
    nTcpPort=atoi(argv[1]);
187
    if(0==nTcpPort){
188
      fprintf(stderr,"Invalid port %s\n",argv[1]);
189
      return main(0,argv); // Provoke usage message
190
    }
191
 
192
    ser_port = argv[2];
193
    baud_rate=atoi(argv[3]);
194
 
195
    nSock = CeCosSocket::Listen(nTcpPort);
196
    if (-1 == nSock) {
197
      fprintf(stderr, "Couldn't access socket.\n");
198
      throw "listen failed";
199
    }
200
  }
201
 
202
 
203
  if (opt_monitor) {
204
      fprintf(stdout, "Monitor mode - will not interact with data streams...\n");
205
 
206
      for(;;) {
207
 
208
          CeCosTestMonitorFilter* host_filter =
209
              new CeCosTestMonitorFilter();
210
          CeCosTestMonitorFilter* target_filter =
211
              new CeCosTestMonitorFilter();
212
 
213
          // Set filter directions
214
          host_filter->SetOrigin(CeCosTestMonitorFilter::MF_HOST);
215
          target_filter->SetOrigin(CeCosTestMonitorFilter::MF_TARGET);
216
 
217
          // Enable filters
218
          host_filter->SetVerbose(true);
219
          target_filter->SetVerbose(true);
220
 
221
          // Set filter functions
222
          CeCosSocket::FilterFunc *host_filter_function =
223
              &SerialMonitorFunction;
224
          CeCosSocket::FilterFunc *target_filter_function =
225
              &SerialMonitorFunction;
226
 
227
          try {
228
              CeCosSocket::ConnectSocketToSerial(nSock, ser_port,
229
                                                     baud_rate,
230
                                                     target_filter_function,
231
                                                     (void*)target_filter,
232
                                                     host_filter_function,
233
                                                     (void*)host_filter,
234
                                                     NULL);
235
          }
236
          catch (const char* p) {
237
              fprintf(stderr, "Caught filter crash: %s\n", p);
238
          }
239
 
240
          delete target_filter;
241
          delete host_filter;
242
      }
243
  }
244
 
245
  for(;;) {
246
    CeCosTestSerialFilter* serial_filter =
247
      new CeCosTestSerialFilter();
248
    CeCosTestDownloadFilter* download_filter =
249
      new CeCosTestDownloadFilter();
250
 
251
    // Set filter configuration
252
    serial_filter->SetFilterTrace(opt_filter_trace);
253
    serial_filter->SetSerialDebug(opt_ser_debug);
254
    serial_filter->SetConsoleOutput(opt_console_output);
255
 
256
    // Set download filter configuration
257
    download_filter->SetFilterTrace(opt_filter_trace);
258
    download_filter->SetSerialDebug(opt_ser_debug);
259
 
260
    // Set serial side filter
261
    CeCosSocket::FilterFunc *ser_filter_function =
262
      &SerialFilterFunction;
263
    if (opt_null_filter)
264
      ser_filter_function = NULL;
265
 
266
    // Set socket side filter
267
    CeCosSocket::FilterFunc *sock_filter_function =
268
      &DownloadFilterFunction;
269
 
270
    try {
271
      if (opt_no_gdb)
272
        no_gdb(ser_port, baud_rate, ser_filter_function,
273
        (void*)serial_filter, NULL);
274
      else
275
        CeCosSocket::ConnectSocketToSerial(nSock, ser_port,
276
        baud_rate,
277
        ser_filter_function,
278
        (void*)serial_filter,
279
        sock_filter_function,
280
        (void*)download_filter,
281
        NULL);
282
    }
283
    catch (const char* p) {
284
      fprintf(stderr, "Caught filter crash: %s\n", p);
285
    }
286
 
287
    if (opt_X10_reset) {
288
      char X10_cmd[80];
289
      sprintf(X10_cmd, "/usr/unsupported/bin/x10cli x10 5000 %c %c",
290
        opt_X10_port[0], opt_X10_port[1]);
291
      system(X10_cmd);
292
    }
293
 
294
    delete serial_filter;
295
    delete download_filter;
296
  }
297
 
298
//  return 0;
299
 
300
Usage:
301
  const char *pszMe="ser_filter";
302
  fprintf(stderr,"Usage: %s [-c -S -0 -Xab] TcpIPport SerialPort BaudRate\n"
303
    " or:   %s -n [-c -S -0 -Xab] SerialPort BaudRate\n"
304
    " Switches:\n"
305
    " -f: Enable filter output tracing.\n"
306
    " -S: Output data read from serial line.\n"
307
    " -c: Output data on console instead of via GDB.\n"
308
    " -m: Work only as a monitor filter. Implies -c.\n"
309
    " -n: No GDB.\n"
310
    " -0: Use null filter.\n"
311
    " -Xab: Reset X-10 Port 'a b' when TCP connection breaks\n",pszMe,pszMe);
312
  CeCosTestUtils::UsageMessage();
313
 
314
  return 1;
315
}

powered by: WebSVN 2.1.0

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