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 |
|
|
// eCosTestSerialFilter.h
|
25 |
|
|
//
|
26 |
|
|
// Serial test filter class
|
27 |
|
|
//
|
28 |
|
|
//=================================================================
|
29 |
|
|
//=================================================================
|
30 |
|
|
//#####DESCRIPTIONBEGIN####
|
31 |
|
|
//
|
32 |
|
|
// Author(s): jskov
|
33 |
|
|
// Contributors: jskov
|
34 |
|
|
// Date: 1999-03-01
|
35 |
|
|
//####DESCRIPTIONEND####
|
36 |
|
|
#ifndef _CECOSSERIALFILTER_H
|
37 |
|
|
#define _CECOSSERIALFILTER_H
|
38 |
|
|
|
39 |
|
|
#include "eCosStd.h"
|
40 |
|
|
#include "eCosTest.h"
|
41 |
|
|
#include "eCosSocket.h"
|
42 |
|
|
#include "eCosSerial.h"
|
43 |
|
|
|
44 |
|
|
//----------------------------------------------------------------------------
|
45 |
|
|
// Macros to help extract values from the argument string.
|
46 |
|
|
// Note: This is probably not an ideal solution, but it was easy to make :)
|
47 |
|
|
|
48 |
|
|
#define INIT_VALUE(__args) \
|
49 |
|
|
unsigned int v; \
|
50 |
|
|
char *__ptr1, *__ptr2 = (__args) \
|
51 |
|
|
|
52 |
|
|
#define SET_VALUE(__type, __slot) { \
|
53 |
|
|
__ptr1 = strchr(__ptr2, (int) ':'); \
|
54 |
|
|
if (*__ptr2 == '\0') \
|
55 |
|
|
(__slot) = (__type)-1; \
|
56 |
|
|
else { \
|
57 |
|
|
if (__ptr1) \
|
58 |
|
|
*__ptr1 = 0; \
|
59 |
|
|
else \
|
60 |
|
|
__ptr1 = strchr( __ptr2, 0) - 1; \
|
61 |
|
|
v = atoi(__ptr2); \
|
62 |
|
|
__ptr2 = __ptr1+1; \
|
63 |
|
|
(__slot) = (__type) v; \
|
64 |
|
|
} \
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
|
68 |
|
|
//----------------------------------------------------------------------------
|
69 |
|
|
// Structures used by the filter.
|
70 |
|
|
struct filter_abort_t {
|
71 |
|
|
const unsigned char* data_ptr;
|
72 |
|
|
int data_len;
|
73 |
|
|
|
74 |
|
|
filter_abort_t():
|
75 |
|
|
data_ptr(NULL),
|
76 |
|
|
data_len(0)
|
77 |
|
|
{}
|
78 |
|
|
};
|
79 |
|
|
|
80 |
|
|
typedef enum {
|
81 |
|
|
FLOW_NONE=0,
|
82 |
|
|
FLOW_XONXOFF_RX=1,
|
83 |
|
|
FLOW_XONXOFF_TX=2,
|
84 |
|
|
FLOW_RTSCTS_RX=4,
|
85 |
|
|
FLOW_RTSCTS_TX=8,
|
86 |
|
|
FLOW_DSRDTR_RX=16,
|
87 |
|
|
FLOW_DSRDTR_TX=32
|
88 |
|
|
} flow_cfg_t;
|
89 |
|
|
|
90 |
|
|
typedef struct ser_cfg {
|
91 |
|
|
int baud_rate;
|
92 |
|
|
int data_bits;
|
93 |
|
|
CeCosSerial::StopBitsType stop_bits;
|
94 |
|
|
bool parity;
|
95 |
|
|
|
96 |
|
|
unsigned int flags;
|
97 |
|
|
// etc...
|
98 |
|
|
} ser_cfg_t;
|
99 |
|
|
|
100 |
|
|
typedef enum {
|
101 |
|
|
MODE_NO_ECHO = 0,
|
102 |
|
|
MODE_EOP_ECHO,
|
103 |
|
|
MODE_DUPLEX_ECHO
|
104 |
|
|
} cyg_mode_t;
|
105 |
|
|
|
106 |
|
|
|
107 |
|
|
//----------------------------------------------------------------------------
|
108 |
|
|
// The filter class
|
109 |
|
|
class CeCosTestSerialFilter;
|
110 |
|
|
|
111 |
|
|
class CeCosTestSerialFilter {
|
112 |
|
|
public:
|
113 |
|
|
// Constructor
|
114 |
|
|
CeCosTestSerialFilter();
|
115 |
|
|
~CeCosTestSerialFilter();
|
116 |
|
|
|
117 |
|
|
// Configuration methods
|
118 |
|
|
void SetConsoleOutput(bool bConsoleOutput)
|
119 |
|
|
{ m_bOptConsoleOutput = bConsoleOutput; }
|
120 |
|
|
void SetSerialDebug(bool bSerialDebug)
|
121 |
|
|
{ m_bOptSerDebug = bSerialDebug; }
|
122 |
|
|
void SetFilterTrace(bool bFilterTrace)
|
123 |
|
|
{ m_bOptFilterTrace = bFilterTrace; }
|
124 |
|
|
|
125 |
|
|
|
126 |
|
|
bool FilterFunctionProper(void*& pBuf,
|
127 |
|
|
unsigned int& nRead,
|
128 |
|
|
CeCosSerial& serial,
|
129 |
|
|
CeCosSocket& socket);
|
130 |
|
|
|
131 |
|
|
private:
|
132 |
|
|
enum {MAX_CMD_LEN=128};
|
133 |
|
|
enum data_origin_t {SF_TARGET=0, SF_FILTER} ;
|
134 |
|
|
|
135 |
|
|
// Output methods
|
136 |
|
|
void GDBWrite(const char* pszStr);
|
137 |
|
|
void ConsoleWrite(const char* pszStr);
|
138 |
|
|
void Trace(const char* pszFormat, ...);
|
139 |
|
|
void Log(const char* pszFormat, ...);
|
140 |
|
|
|
141 |
|
|
void PrintHex(const unsigned char* d1, int len,
|
142 |
|
|
data_origin_t origin=SF_TARGET);
|
143 |
|
|
|
144 |
|
|
// Target read/write methods
|
145 |
|
|
void TargetWrite(CeCosSerial &pSer,
|
146 |
|
|
const unsigned char* buffer, int len);
|
147 |
|
|
void TargetASCIIWrite(CeCosSerial &pSer, const char* s);
|
148 |
|
|
bool TargetRead(CeCosSerial &pSer,
|
149 |
|
|
unsigned char* buffer, int len);
|
150 |
|
|
|
151 |
|
|
// Configuration CMD and helper methods
|
152 |
|
|
void ParseConfig(char* args, ser_cfg_t* new_cfg);
|
153 |
|
|
bool SetConfig(CeCosSerial &pSer, const ser_cfg_t* new_cfg,
|
154 |
|
|
ser_cfg_t* old_cfg);
|
155 |
|
|
bool VerifyConfig(CeCosSerial &pSer, ser_cfg_t* new_cfg);
|
156 |
|
|
void CMD_ChangeConfig(CeCosSerial &pSer, char* cfg_str);
|
157 |
|
|
void CMD_DefaultConfig(CeCosSerial &pSer);
|
158 |
|
|
|
159 |
|
|
// Other CMD methods.
|
160 |
|
|
void CMD_TestBinary(CeCosSerial &pSer, char* args);
|
161 |
|
|
void CMD_TestText(CeCosSerial &pSer, char* args);
|
162 |
|
|
void CMD_TestPing(CeCosSerial &pSer, char* args);
|
163 |
|
|
|
164 |
|
|
|
165 |
|
|
// Misc helper methods
|
166 |
|
|
int DoCRC(unsigned char* data, int size);
|
167 |
|
|
void SendChecksum(CeCosSerial &pSer, int crc);
|
168 |
|
|
void SendStatus(CeCosSerial &pSer, int state);
|
169 |
|
|
void ReceiveDone(CeCosSerial &pSer, unsigned char* data_in, int size);
|
170 |
|
|
void DispatchCommand(CeCosSerial &pSer, char* cmd);
|
171 |
|
|
|
172 |
|
|
// Options used for configuring behavior.
|
173 |
|
|
bool m_bOptConsoleOutput;
|
174 |
|
|
bool m_bOptSerDebug;
|
175 |
|
|
bool m_bOptFilterTrace;
|
176 |
|
|
|
177 |
|
|
// Buffer holding unread bytes.
|
178 |
|
|
unsigned char* m_xUnreadBuffer; // unread_buffer;
|
179 |
|
|
int m_nUnreadBufferIndex; // unread_buffer_ix;
|
180 |
|
|
int m_nUnreadBufferSize; // unread_buffer_size = 0;
|
181 |
|
|
|
182 |
|
|
unsigned char* m_xStoredTraceBuffer;// We need this to avoid outputting
|
183 |
|
|
// serial tracing when the target
|
184 |
|
|
// last sent an incomplete packet, so
|
185 |
|
|
// we store it here temporarily until
|
186 |
|
|
// the entire packet arrives
|
187 |
|
|
unsigned int m_nStoredTraceBufferSize; // size of above
|
188 |
|
|
|
189 |
|
|
// Filter state
|
190 |
|
|
bool m_bNullFilter;
|
191 |
|
|
int m_nCmdIndex;
|
192 |
|
|
bool m_bCmdFlag;
|
193 |
|
|
char m_aCmd[MAX_CMD_LEN];
|
194 |
|
|
bool m_bFirstCommandSeen; // We need this to avoid outputting
|
195 |
|
|
// serial tracing while GDB is trying
|
196 |
|
|
// to connect, or it will get confused.
|
197 |
|
|
|
198 |
|
|
CeCosSocket* m_cGDBSocket; // gdb_socket
|
199 |
|
|
};
|
200 |
|
|
|
201 |
|
|
extern bool CALLBACK SerialFilterFunction(void*& pBuf,
|
202 |
|
|
unsigned int& nRead,
|
203 |
|
|
CeCosSerial& serial,
|
204 |
|
|
CeCosSocket& socket,
|
205 |
|
|
void* pParem);
|
206 |
|
|
|
207 |
|
|
#endif // _CECOSSERIALFILTER_H
|