1 //####COPYRIGHTBEGIN####
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
6 // This program is part of the eCos host tools.
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)
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
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.
22 // ----------------------------------------------------------------------------
24 //####COPYRIGHTEND####
25 //=================================================================
27 // eCosTestSerialFilter.h
29 // Serial test filter class
31 //=================================================================
32 //=================================================================
33 //#####DESCRIPTIONBEGIN####
36 // Contributors: jskov
38 //####DESCRIPTIONEND####
39 #ifndef _CECOSSERIALFILTER_H
40 #define _CECOSSERIALFILTER_H
44 #include "eCosSocket.h"
45 #include "eCosSerial.h"
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 :)
51 #define INIT_VALUE(__args) \
53 char *__ptr1, *__ptr2 = (__args) \
55 #define SET_VALUE(__type, __slot) { \
56 __ptr1 = strchr(__ptr2, (int) ':'); \
57 if (*__ptr2 == '\0') \
58 (__slot) = (__type)-1; \
63 __ptr1 = strchr( __ptr2, 0) - 1; \
66 (__slot) = (__type) v; \
71 //----------------------------------------------------------------------------
72 // Structures used by the filter.
73 struct filter_abort_t {
74 const unsigned char* data_ptr;
93 typedef struct ser_cfg {
96 CeCosSerial::StopBitsType stop_bits;
110 //----------------------------------------------------------------------------
112 class CeCosTestSerialFilter;
114 class CeCosTestSerialFilter {
117 CeCosTestSerialFilter();
118 ~CeCosTestSerialFilter();
120 // Configuration methods
121 void SetConsoleOutput(bool bConsoleOutput)
122 { m_bOptConsoleOutput = bConsoleOutput; }
123 void SetSerialDebug(bool bSerialDebug)
124 { m_bOptSerDebug = bSerialDebug; }
125 void SetFilterTrace(bool bFilterTrace)
126 { m_bOptFilterTrace = bFilterTrace; }
129 bool FilterFunctionProper(void*& pBuf,
132 CeCosSocket& socket);
135 enum {MAX_CMD_LEN=128};
136 enum data_origin_t {SF_TARGET=0, SF_FILTER} ;
139 void GDBWrite(const char* pszStr);
140 void ConsoleWrite(const char* pszStr);
141 void Trace(const char* pszFormat, ...);
142 void Log(const char* pszFormat, ...);
144 void PrintHex(const unsigned char* d1, int len,
145 data_origin_t origin=SF_TARGET);
147 // Target read/write methods
148 void TargetWrite(CeCosSerial &pSer,
149 const unsigned char* buffer, int len);
150 void TargetASCIIWrite(CeCosSerial &pSer, const char* s);
151 bool TargetRead(CeCosSerial &pSer,
152 unsigned char* buffer, int len);
154 // Configuration CMD and helper methods
155 void ParseConfig(char* args, ser_cfg_t* new_cfg);
156 bool SetConfig(CeCosSerial &pSer, const ser_cfg_t* new_cfg,
158 bool VerifyConfig(CeCosSerial &pSer, ser_cfg_t* new_cfg);
159 void CMD_ChangeConfig(CeCosSerial &pSer, char* cfg_str);
160 void CMD_DefaultConfig(CeCosSerial &pSer);
162 // Other CMD methods.
163 void CMD_TestBinary(CeCosSerial &pSer, char* args);
164 void CMD_TestText(CeCosSerial &pSer, char* args);
165 void CMD_TestPing(CeCosSerial &pSer, char* args);
168 // Misc helper methods
169 int DoCRC(unsigned char* data, int size);
170 void SendChecksum(CeCosSerial &pSer, int crc);
171 void SendStatus(CeCosSerial &pSer, int state);
172 void ReceiveDone(CeCosSerial &pSer, unsigned char* data_in, int size);
173 void DispatchCommand(CeCosSerial &pSer, char* cmd);
175 // Options used for configuring behavior.
176 bool m_bOptConsoleOutput;
178 bool m_bOptFilterTrace;
180 // Buffer holding unread bytes.
181 unsigned char* m_xUnreadBuffer; // unread_buffer;
182 int m_nUnreadBufferIndex; // unread_buffer_ix;
183 int m_nUnreadBufferSize; // unread_buffer_size = 0;
185 unsigned char* m_xStoredTraceBuffer;// We need this to avoid outputting
186 // serial tracing when the target
187 // last sent an incomplete packet, so
188 // we store it here temporarily until
189 // the entire packet arrives
190 unsigned int m_nStoredTraceBufferSize; // size of above
196 char m_aCmd[MAX_CMD_LEN];
197 bool m_bFirstCommandSeen; // We need this to avoid outputting
198 // serial tracing while GDB is trying
199 // to connect, or it will get confused.
201 CeCosSocket* m_cGDBSocket; // gdb_socket
204 extern bool CALLBACK SerialFilterFunction(void*& pBuf,
210 #endif // _CECOSSERIALFILTER_H