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 //=================================================================
26 //#####DESCRIPTIONBEGIN####
31 // Description: Holds information related to target reset.
34 //####DESCRIPTIONEND####
36 #ifndef _RESETATTRIBUTES_H
37 #define _RESETATTRIBUTES_H
39 #include "Collections.h"
41 #include "eCosSerial.h"
42 #include "eCosSocket.h"
43 #include "Properties.h"
45 //=================================================================
46 // This class deals with resetting a target.
47 // The ctor accepts the "reset string" this is something like
48 // expect($T05,#) 3(off(ginga:5000,a1) delay(2000) on(,..com2,38400))
49 // and is parsed to generate the commands to reset the target.
51 // resetstring :== [directive | <integer>(resetstring)] *
52 // directive :== id(arg[,arg]*)
53 // directive :== port | action | delay | expect
55 // The <integer>(string) syntax repeats argument its until reset is achieved.
56 // Each directive is given by example below:
58 // Expected string(s). e.g. expect(str1,str2,...).
60 // The string(s) expected to be output by a target after reset.
61 // *all* supplied strings must be present *in order* in the reset string for a reset to be recognized as valid.
63 // Provide port information to apply to all subsequent off|on|on_off|off_on actions until overwritten.
64 // e.g. port(com1,38400,1000)
69 // These have the meanings described under off|on|on_off|off_on.
70 // off|on|on_off|off_on:
71 // Request a reset host to perform a "power cycle" (or its logical equivalent -
72 // the meanings of "off" and "on" may depend on the reset host)
73 // e.g. off_on(ginga:500,A4,com1,38400,10000,1000)
76 // 1. Control string (meaning known to the reset host)
77 // 2. Port (from which to read startup output)
78 // 3. Baud for the above
80 // 5. Delay (between off and on or vice versa)
82 // Delay for a given time right now.
86 //=================================================================
88 class CResetAttributes {
90 CResetAttributes(LPCTSTR psz=_T(""));
94 const LPCTSTR Image() const { return m_str; }
96 bool IsNull() const { return m_str.empty(); }
97 static const CResetAttributes NoReset;
99 enum ResetResult {INVALID_STRING=-1,RESET_OK=0,NOT_RESET=1,
100 RESET_ILLEGAL_DEVICE_CODE=30000,RESET_NO_REPLY, RESET_BAD_CHECKSUM, RESET_BAD_ACK, RESET_UNKNOWN_ERROR};
102 // Perform the reset, sending the output to the log function supplied as parameter.
103 ResetResult Reset (LogFunc *pfnLog=0, void *pfnLogparam=0,bool bCheckOnly=false);
105 enum Action {OFF=0,ON=1,OFF_ON=2,ON_OFF=3};
109 // This function determines whether the board startup has output all that is required
110 // All the strings of m_arValidResetStrings [arguments of expect() in the reset string] must be present
113 Time m_tResetOccurred;
117 void *m_pfnResetparam;
118 // Log some output to the reset log function.
119 void ResetLog(LPCTSTR psz);
121 CeCosSerial m_Serial;
122 CeCosSocket m_Socket;
124 const TCHAR *GetIdAndArg (LPCTSTR psz,String &strID,String &strArg);
125 ResetResult Parse (LPCTSTR psz,bool bCheckOnly=false);
126 bool Reset (Action action,bool bCheckOutput);
128 void SuckThreadFunc ();
129 static void CALLBACK SSuckThreadFunc (void *pParam) { ((CResetAttributes*)pParam)->SuckThreadFunc(); }
131 String m_str; // Here is the reset string. Could be const, but avoid the assignment operator warnings
133 // These members hold the information we extract by parsing the string:
135 StringArray m_arValidResetStrings;
136 String m_strHostPort; // host we talk to
137 String m_strControl; // Control string
138 int m_nDelay; // Delay between power off and power on
139 String m_strAuxPort; // Auxiliary port (serial port to listen on if primary port is TCP/IP)
140 int m_nReadTimeout; // mSec to wait for board to say something
141 int m_nBaud; // Baud rate
143 String m_strResetOutput; // The output we get