1 |
/* bebob_dl_codes.h |
---|
2 |
* Copyright (C) 2006 by Daniel Wagner |
---|
3 |
* |
---|
4 |
* This file is part of FreeBoB. |
---|
5 |
* |
---|
6 |
* FreeBoB 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 of the License, or |
---|
9 |
* (at your option) any later version. |
---|
10 |
* FreeBoB is distributed in the hope that it will be useful, |
---|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
13 |
* GNU General Public License for more details. |
---|
14 |
* |
---|
15 |
* You should have received a copy of the GNU General Public License |
---|
16 |
* along with FreeBoB; if not, write to the Free Software |
---|
17 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
---|
18 |
* MA 02111-1307 USA. |
---|
19 |
*/ |
---|
20 |
|
---|
21 |
#ifndef BEBOB_DL_CODES_H |
---|
22 |
#define BEBOB_DL_CODES_H |
---|
23 |
|
---|
24 |
#include "fbtypes.h" |
---|
25 |
|
---|
26 |
#include "libfreebobavc/serialize.h" |
---|
27 |
|
---|
28 |
namespace BeBoB { |
---|
29 |
enum EBootloaderProtocolVersion { |
---|
30 |
eBPV_Unknown = 0, |
---|
31 |
eBPV_V1 = 1, |
---|
32 |
eBPV_V2 = 2, |
---|
33 |
eBPV_V3 = 3, |
---|
34 |
}; |
---|
35 |
|
---|
36 |
enum EBootloaderCommandCodes { |
---|
37 |
eCmdC_Halt = 0x01, |
---|
38 |
eCmdC_Reset = 0x02, |
---|
39 |
eCmdC_ReadImageCRC = 0x03, |
---|
40 |
eCmdC_DownloadStart = 0x04, |
---|
41 |
eCmdC_DownloadBlock = 0x05, |
---|
42 |
eCmdC_DownloadEnd = 0x06, |
---|
43 |
eCmdC_SwitchTo1394Shell = 0x07, |
---|
44 |
eCmdC_ReadShellChars = 0x08, |
---|
45 |
eCmdC_WriteShellChars = 0x09, |
---|
46 |
eCmdC_ProgramGUID = 0x0a, |
---|
47 |
eCmdC_ProgramMAC = 0x0b, |
---|
48 |
eCmdC_InitPersParams = 0x0c, |
---|
49 |
eCmdC_InitConfigToFactorySetting = 0x0d, |
---|
50 |
eCmdC_SetDebugGUID = 0x0f, |
---|
51 |
eCmdC_ProgramHWIdVersion = 0x10, |
---|
52 |
eCmdC_Go = 0x11, |
---|
53 |
}; |
---|
54 |
|
---|
55 |
///////////////////////// |
---|
56 |
|
---|
57 |
class CommandCodes { |
---|
58 |
public: |
---|
59 |
CommandCodes( fb_quadlet_t protocolVersion, |
---|
60 |
fb_byte_t commandCode, |
---|
61 |
size_t msgSize, |
---|
62 |
fb_byte_t operandSizeRequestField, |
---|
63 |
fb_byte_t operandSizeResponseField ); |
---|
64 |
virtual ~CommandCodes(); |
---|
65 |
|
---|
66 |
virtual bool serialize( IOSSerialize& se ); |
---|
67 |
virtual bool deserialize( IISDeserialize& de ); |
---|
68 |
|
---|
69 |
virtual size_t getMaxSize(); |
---|
70 |
|
---|
71 |
EBootloaderCommandCodes getCommandCode() const |
---|
72 |
{ return static_cast<EBootloaderCommandCodes>( m_commandCode ); } |
---|
73 |
|
---|
74 |
fb_byte_t getProtocolVersion() const |
---|
75 |
{ return m_protocolVersion; } |
---|
76 |
size_t getMsgSize() const |
---|
77 |
{ return m_msgSize; } |
---|
78 |
fb_byte_t getOperandSizeRequest() const |
---|
79 |
{ return m_operandSizeRequest; } |
---|
80 |
fb_byte_t getOperandSizeResponse() const |
---|
81 |
{ return m_operandSizeResponse; } |
---|
82 |
unsigned short getCommandId() const |
---|
83 |
{ return m_commandId; } |
---|
84 |
|
---|
85 |
fb_quadlet_t getRespProtocolVersion() const |
---|
86 |
{ return m_resp_protocolVersion; } |
---|
87 |
unsigned short getRespCommandId() const |
---|
88 |
{ return m_resp_commandId; } |
---|
89 |
fb_byte_t getRespCommandCode() const |
---|
90 |
{ return m_resp_commandCode; } |
---|
91 |
fb_byte_t getRespOperandSize() const |
---|
92 |
{ return m_resp_operandSize; } |
---|
93 |
fb_byte_t getRespSizeInQuadlets() const |
---|
94 |
{ return 2 + m_operandSizeResponse; } |
---|
95 |
|
---|
96 |
protected: |
---|
97 |
static unsigned short m_gCommandId; |
---|
98 |
unsigned short m_commandId; |
---|
99 |
fb_quadlet_t m_protocolVersion; |
---|
100 |
fb_byte_t m_commandCode; |
---|
101 |
size_t m_msgSize; |
---|
102 |
fb_byte_t m_operandSizeRequest; |
---|
103 |
fb_byte_t m_operandSizeResponse; |
---|
104 |
|
---|
105 |
fb_quadlet_t m_resp_protocolVersion; |
---|
106 |
unsigned short m_resp_commandId; |
---|
107 |
fb_byte_t m_resp_commandCode; |
---|
108 |
fb_byte_t m_resp_operandSize; |
---|
109 |
}; |
---|
110 |
|
---|
111 |
///////////////////////// |
---|
112 |
|
---|
113 |
class CommandCodesReset : public CommandCodes { |
---|
114 |
public: |
---|
115 |
enum EStartMode { |
---|
116 |
eSM_Application = 0, |
---|
117 |
eSM_Bootloader, |
---|
118 |
eSM_Debugger, |
---|
119 |
}; |
---|
120 |
|
---|
121 |
CommandCodesReset( fb_quadlet_t protocolVersion, EStartMode startMode ); |
---|
122 |
virtual ~CommandCodesReset(); |
---|
123 |
|
---|
124 |
virtual bool serialize( IOSSerialize& se ); |
---|
125 |
virtual bool deserialize( IISDeserialize& de ); |
---|
126 |
|
---|
127 |
EStartMode getStartMode() const |
---|
128 |
{ return static_cast<EStartMode>( m_startMode ); } |
---|
129 |
bool setStartMode( EStartMode startMode ) |
---|
130 |
{ m_startMode = startMode; return true; } |
---|
131 |
|
---|
132 |
private: |
---|
133 |
fb_byte_t m_startMode; |
---|
134 |
}; |
---|
135 |
|
---|
136 |
///////////////////////// |
---|
137 |
|
---|
138 |
class CommandCodesProgramGUID : public CommandCodes { |
---|
139 |
public: |
---|
140 |
CommandCodesProgramGUID( fb_quadlet_t protocolVersion, |
---|
141 |
fb_octlet_t guid ); |
---|
142 |
virtual ~CommandCodesProgramGUID(); |
---|
143 |
|
---|
144 |
virtual bool serialize( IOSSerialize& se ); |
---|
145 |
virtual bool deserialize( IISDeserialize& de ); |
---|
146 |
|
---|
147 |
fb_octlet_t getGUID() const |
---|
148 |
{ return m_guid; } |
---|
149 |
bool setGUID( fb_octlet_t guid ) |
---|
150 |
{ m_guid = guid; return true; } |
---|
151 |
|
---|
152 |
private: |
---|
153 |
fb_octlet_t m_guid; |
---|
154 |
}; |
---|
155 |
|
---|
156 |
|
---|
157 |
///////////////////////// |
---|
158 |
|
---|
159 |
class CommandCodesDownloadStart : public CommandCodes { |
---|
160 |
public: |
---|
161 |
enum EObject { |
---|
162 |
eO_Application = 0, |
---|
163 |
eO_Config = 1, |
---|
164 |
eO_Debugger = 2, |
---|
165 |
eO_Bootloader = 3, |
---|
166 |
eO_WarpImage = 4, |
---|
167 |
eO_SerialBootCode = 5, |
---|
168 |
}; |
---|
169 |
|
---|
170 |
CommandCodesDownloadStart( fb_quadlet_t protocolVersion, |
---|
171 |
EObject object ); |
---|
172 |
virtual ~CommandCodesDownloadStart(); |
---|
173 |
|
---|
174 |
virtual bool serialize( IOSSerialize& se ); |
---|
175 |
virtual bool deserialize( IISDeserialize& de ); |
---|
176 |
|
---|
177 |
bool setDate( fb_octlet_t date ) |
---|
178 |
{ m_date = date; return true; } |
---|
179 |
bool setTime( fb_octlet_t time ) |
---|
180 |
{ m_time = time; return true; } |
---|
181 |
bool setId( fb_quadlet_t id ) |
---|
182 |
{ m_id = id; return true; } |
---|
183 |
bool setVersion( fb_quadlet_t version ) |
---|
184 |
{ m_version = version; return true; } |
---|
185 |
bool setBaseAddress( fb_quadlet_t address ) |
---|
186 |
{ m_address = address; return true; } |
---|
187 |
bool setLength( fb_quadlet_t length ) |
---|
188 |
{ m_length = length; return true; } |
---|
189 |
bool setCRC( fb_quadlet_t crc ) |
---|
190 |
{ m_crc = crc; return true; } |
---|
191 |
|
---|
192 |
int getMaxBlockSize() const |
---|
193 |
{ return m_resp_max_block_size; } |
---|
194 |
|
---|
195 |
private: |
---|
196 |
fb_quadlet_t m_object; |
---|
197 |
fb_octlet_t m_date; |
---|
198 |
fb_octlet_t m_time; |
---|
199 |
fb_quadlet_t m_id; |
---|
200 |
fb_quadlet_t m_version; |
---|
201 |
fb_quadlet_t m_address; |
---|
202 |
fb_quadlet_t m_length; |
---|
203 |
fb_quadlet_t m_crc; |
---|
204 |
|
---|
205 |
int m_resp_max_block_size; |
---|
206 |
}; |
---|
207 |
|
---|
208 |
///////////////////////// |
---|
209 |
|
---|
210 |
class CommandCodesDownloadBlock : public CommandCodes { |
---|
211 |
public: |
---|
212 |
CommandCodesDownloadBlock( fb_quadlet_t protocolVersion ); |
---|
213 |
virtual ~CommandCodesDownloadBlock(); |
---|
214 |
|
---|
215 |
virtual bool serialize( IOSSerialize& se ); |
---|
216 |
virtual bool deserialize( IISDeserialize& de ); |
---|
217 |
|
---|
218 |
bool setSeqNumber( fb_quadlet_t seqNumber ) |
---|
219 |
{ m_seqNumber = seqNumber; return true; } |
---|
220 |
bool setAddress( fb_quadlet_t address ) |
---|
221 |
{ m_address = address; return true; } |
---|
222 |
bool setNumberBytes( fb_quadlet_t numByte ) |
---|
223 |
{ m_numBytes = numByte; return true; } |
---|
224 |
fb_quadlet_t getRespSeqNumber() const |
---|
225 |
{ return m_resp_seqNumber; } |
---|
226 |
fb_quadlet_t getRespErrorCode() const |
---|
227 |
{ return m_resp_errorCode; } |
---|
228 |
private: |
---|
229 |
fb_quadlet_t m_seqNumber; |
---|
230 |
fb_quadlet_t m_address; |
---|
231 |
fb_quadlet_t m_numBytes; |
---|
232 |
|
---|
233 |
fb_quadlet_t m_resp_seqNumber; |
---|
234 |
fb_quadlet_t m_resp_errorCode; |
---|
235 |
}; |
---|
236 |
|
---|
237 |
///////////////////////// |
---|
238 |
|
---|
239 |
class CommandCodesDownloadEnd : public CommandCodes { |
---|
240 |
public: |
---|
241 |
CommandCodesDownloadEnd( fb_quadlet_t protocolVersion ); |
---|
242 |
virtual ~CommandCodesDownloadEnd(); |
---|
243 |
|
---|
244 |
virtual bool serialize( IOSSerialize& se ); |
---|
245 |
virtual bool deserialize( IISDeserialize& de ); |
---|
246 |
|
---|
247 |
fb_quadlet_t getRespCrc32() const |
---|
248 |
{ return m_resp_crc32; } |
---|
249 |
bool getRespIsValid() const |
---|
250 |
{ return m_resp_valid == 0; } |
---|
251 |
|
---|
252 |
private: |
---|
253 |
quadlet_t m_resp_crc32; |
---|
254 |
quadlet_t m_resp_valid; |
---|
255 |
}; |
---|
256 |
|
---|
257 |
|
---|
258 |
///////////////////////// |
---|
259 |
|
---|
260 |
class CommandCodesInitializePersParam : public CommandCodes { |
---|
261 |
public: |
---|
262 |
CommandCodesInitializePersParam( fb_quadlet_t protocolVersion ); |
---|
263 |
virtual ~CommandCodesInitializePersParam(); |
---|
264 |
|
---|
265 |
virtual bool serialize( IOSSerialize& se ); |
---|
266 |
virtual bool deserialize( IISDeserialize& de ); |
---|
267 |
}; |
---|
268 |
|
---|
269 |
///////////////////////// |
---|
270 |
|
---|
271 |
class CommandCodesInitializeConfigToFactorySetting : public CommandCodes { |
---|
272 |
public: |
---|
273 |
CommandCodesInitializeConfigToFactorySetting( |
---|
274 |
fb_quadlet_t protocolVersion ); |
---|
275 |
virtual ~CommandCodesInitializeConfigToFactorySetting(); |
---|
276 |
|
---|
277 |
virtual bool serialize( IOSSerialize& se ); |
---|
278 |
virtual bool deserialize( IISDeserialize& de ); |
---|
279 |
}; |
---|
280 |
|
---|
281 |
}; |
---|
282 |
#endif |
---|