comparison host/tools/ecostest/common/eCosTestSerialFilter.h @ 76:435cced73e2f ecos-v1_3_1-release

eCos v1.3.1 merged from eCos master repository on 2000-03-27-23:22:51-BST
author jlarmour
date Tue, 28 Mar 2000 14:10:45 +0000
parents
children 6736c52df507
comparison
equal deleted inserted replaced
75:41bf073c0c32 76:435cced73e2f
1 //####COPYRIGHTBEGIN####
2 //
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
5 //
6 // This program is part of the eCos host tools.
7 //
8 // This program is free software; you can redistribute it and/or modify it
9 // under the terms of the GNU General Public License as published by the Free
10 // Software Foundation; either version 2 of the License, or (at your option)
11 // any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but WITHOUT
14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 // more details.
17 //
18 // You should have received a copy of the GNU General Public License along with
19 // this program; if not, write to the Free Software Foundation, Inc.,
20 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 //
22 // ----------------------------------------------------------------------------
23 //
24 //####COPYRIGHTEND####
25 //=================================================================
26 //
27 // eCosTestSerialFilter.h
28 //
29 // Serial test filter class
30 //
31 //=================================================================
32 //=================================================================
33 //#####DESCRIPTIONBEGIN####
34 //
35 // Author(s): jskov
36 // Contributors: jskov
37 // Date: 1999-03-01
38 //####DESCRIPTIONEND####
39 #ifndef _CECOSSERIALFILTER_H
40 #define _CECOSSERIALFILTER_H
41
42 #include "eCosStd.h"
43 #include "eCosTest.h"
44 #include "eCosTestSocket.h"
45 #include "eCosTestSerial.h"
46
47 //----------------------------------------------------------------------------
48 // Macros to help extract values from the argument string.
49 // Note: This is probably not an ideal solution, but it was easy to make :)
50
51 #define INIT_VALUE(__args) unsigned int v; char *__ptr1, *__ptr2 = (__args)
52
53 #define SET_VALUE(__type, __slot) { __ptr1 = strchr(__ptr2, (int) ':'); if (__ptr1) *__ptr1 = 0; v = atoi(__ptr2); __ptr2 = __ptr1+1; (__slot) = (__type) v; }
54
55
56 //----------------------------------------------------------------------------
57 // Structures used by the filter.
58 struct filter_abort_t {
59 const unsigned char* data_ptr;
60 int data_len;
61
62 filter_abort_t():
63 data_ptr(NULL),
64 data_len(0)
65 {}
66 };
67
68 typedef struct ser_cfg {
69 int baud_rate;
70 int data_bits;
71 CeCosTestSerial::StopBitsType stop_bits;
72 bool parity;
73 // etc...
74 } ser_cfg_t;
75
76 typedef enum {
77 MODE_NO_ECHO = 0,
78 MODE_EOP_ECHO,
79 MODE_DUPLEX_ECHO
80 } cyg_mode_t;
81
82
83 //----------------------------------------------------------------------------
84 // The filter class
85 class CeCosTestSerialFilter;
86
87 class CeCosTestSerialFilter {
88 public:
89 // Constructor
90 CeCosTestSerialFilter();
91 ~CeCosTestSerialFilter();
92
93 // Configuration methods
94 void SetConsoleOutput(bool bConsoleOutput)
95 { m_bOptConsoleOutput = bConsoleOutput; }
96 void SetSerialDebug(bool bSerialDebug)
97 { m_bOptSerDebug = bSerialDebug; }
98 void SetFilterTrace(bool bFilterTrace)
99 { m_bOptFilterTrace = bFilterTrace; }
100
101
102 bool FilterFunctionProper(void*& pBuf,
103 unsigned int& nRead,
104 CeCosTestSerial& serial,
105 CeCosTestSocket& socket);
106
107 private:
108 enum {MAX_CMD_LEN=128};
109 enum data_origin_t {SF_TARGET=0, SF_FILTER} ;
110
111 // Output methods
112 void GDBWrite(const char* pszStr);
113 void ConsoleWrite(const char* pszStr);
114 void Trace(const char* pszFormat, ...);
115 void Log(const char* pszFormat, ...);
116
117 void PrintHex(const unsigned char* d1, int len,
118 data_origin_t origin=SF_TARGET);
119
120 // Target read/write methods
121 void TargetWrite(CeCosTestSerial &pSer,
122 const unsigned char* buffer, int len);
123 void TargetASCIIWrite(CeCosTestSerial &pSer, const char* s);
124 bool TargetRead(CeCosTestSerial &pSer,
125 unsigned char* buffer, int len);
126
127 // Configuration CMD and helper methods
128 void ParseConfig(char* args, ser_cfg_t* new_cfg);
129 bool SetConfig(CeCosTestSerial &pSer, const ser_cfg_t* new_cfg,
130 ser_cfg_t* old_cfg);
131 bool VerifyConfig(CeCosTestSerial &pSer, ser_cfg_t* new_cfg);
132 void CMD_ChangeConfig(CeCosTestSerial &pSer, char* cfg_str);
133 void CMD_DefaultConfig(CeCosTestSerial &pSer);
134
135 // Other CMD methods.
136 void CMD_TestBinary(CeCosTestSerial &pSer, char* args);
137 void CMD_TestText(CeCosTestSerial &pSer, char* args);
138 void CMD_TestPing(CeCosTestSerial &pSer, char* args);
139
140
141 // Misc helper methods
142 int DoCRC(unsigned char* data, int size);
143 void SendChecksum(CeCosTestSerial &pSer, int crc);
144 void SendStatus(CeCosTestSerial &pSer, int state);
145 void ReceiveDone(CeCosTestSerial &pSer, unsigned char* data_in, int size);
146 void DispatchCommand(CeCosTestSerial &pSer, char* cmd);
147
148 // Options used for configuring behavior.
149 bool m_bOptConsoleOutput;
150 bool m_bOptSerDebug;
151 bool m_bOptFilterTrace;
152
153 // Buffer holding unread bytes.
154 unsigned char* m_xUnreadBuffer; // unread_buffer;
155 int m_nUnreadBufferIndex; // unread_buffer_ix;
156 int m_nUnreadBufferSize; // unread_buffer_size = 0;
157
158 // Filter state
159 bool m_bNullFilter;
160 int m_nCmdIndex;
161 bool m_bCmdFlag;
162 char m_aCmd[MAX_CMD_LEN];
163 bool m_bFirstCommandSeen; // We need this to avoid outputting
164 // serial tracing while GDB is trying
165 // to connect, or it will get confused.
166
167 CeCosTestSocket* m_cGDBSocket; // gdb_socket
168 };
169
170 extern bool CALLBACK SerialFilterFunction(void*& pBuf,
171 unsigned int& nRead,
172 CeCosTestSerial& serial,
173 CeCosTestSocket& socket,
174 void* pParem);
175
176 #endif // _CECOSSERIALFILTER_H