root/trunk/libffado/src/fireworks/efc/efc_cmds_flash.cpp

Revision 742, 7.4 kB (checked in by ppalmers, 16 years ago)

- Remove some obsolete support files and dirs

- Clean up the license statements in the source files. Everything is

GPL version 3 now.

- Add license and copyright notices to scons scripts

- Clean up some other text files

Line 
1 /*
2  * Copyright (C) 2005-2007 by Pieter Palmers
3  *
4  * This file is part of FFADO
5  * FFADO = Free Firewire (pro-)audio drivers for linux
6  *
7  * FFADO is based upon FreeBoB
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23
24 #include "efc_cmd.h"
25 #include "efc_cmds_flash.h"
26
27 #include <netinet/in.h>
28 #include <iostream>
29
30 using namespace std;
31
32 namespace FireWorks {
33
34 EfcFlashEraseCmd::EfcFlashEraseCmd()
35     : EfcCmd(EFC_CAT_FLASH, EFC_CMD_FLASH_ERASE)
36     , m_address ( 0xFFFFFFFF )
37 {
38 }
39
40 bool
41 EfcFlashEraseCmd::serialize( Util::IOSSerialize& se )
42 {
43     bool result=true;
44
45     // the length should be specified before
46     // the header is serialized
47     m_length=EFC_HEADER_LENGTH_QUADLETS + 1;
48
49     result &= EfcCmd::serialize ( se );
50     result &= se.write(htonl(m_address), "Address" );
51
52     return result;
53 }
54
55 bool
56 EfcFlashEraseCmd::deserialize( Util::IISDeserialize& de )
57 {
58     bool result=true;
59
60     result &= EfcCmd::deserialize ( de );
61
62     EFC_DESERIALIZE_AND_SWAP(de, &m_address, result);
63
64     return result;
65 }
66
67 void
68 EfcFlashEraseCmd::showEfcCmd()
69 {
70     EfcCmd::showEfcCmd();
71     debugOutput(DEBUG_LEVEL_NORMAL, "EFC Flash Erase:\n");
72     debugOutput(DEBUG_LEVEL_NORMAL, " Address     : %lu\n", m_address);
73 }
74
75 // ----
76 EfcFlashReadCmd::EfcFlashReadCmd()
77     : EfcCmd(EFC_CAT_FLASH, EFC_CMD_FLASH_READ)
78     , m_address ( 0xFFFFFFFF )
79     , m_nb_quadlets ( 0 )
80 {
81 }
82
83 bool
84 EfcFlashReadCmd::serialize( Util::IOSSerialize& se )
85 {
86     bool result=true;
87
88     // the length should be specified before
89     // the header is serialized
90     m_length=EFC_HEADER_LENGTH_QUADLETS+2;
91
92     result &= EfcCmd::serialize ( se );
93
94     result &= se.write(htonl(m_address), "Address" );
95     result &= se.write(htonl(m_nb_quadlets), "Length (quadlets)" );
96
97     return result;
98 }
99
100 bool
101 EfcFlashReadCmd::deserialize( Util::IISDeserialize& de )
102 {
103     bool result=true;
104
105     result &= EfcCmd::deserialize ( de );
106
107     EFC_DESERIALIZE_AND_SWAP(de, &m_address, result);
108     EFC_DESERIALIZE_AND_SWAP(de, &m_nb_quadlets, result);
109     if (m_nb_quadlets > EFC_FLASH_SIZE_QUADS) {
110         debugError("Too much quadlets returned: %u\n", m_nb_quadlets);
111         return false;
112     }
113     for (unsigned int i=0; i < m_nb_quadlets; i++) {
114         // FIXME: do we have to swap?
115         //EFC_DESERIALIZE_AND_SWAP(de, &m_data[i], result);
116         // or not?
117         result &= de.read(&m_data[i]);
118     }
119     return result;
120 }
121
122 void
123 EfcFlashReadCmd::showEfcCmd()
124 {
125     EfcCmd::showEfcCmd();
126     debugOutput(DEBUG_LEVEL_NORMAL, "EFC Flash Read:\n");
127     debugOutput(DEBUG_LEVEL_NORMAL, " Address           : %lu\n", m_address);
128     debugOutput(DEBUG_LEVEL_NORMAL, " Length (quadlets) : %lu\n", m_nb_quadlets);
129     debugOutput(DEBUG_LEVEL_NORMAL, " Data              : \n");
130     for (unsigned int i=0; i < m_nb_quadlets; i++) {
131         debugOutput(DEBUG_LEVEL_NORMAL, "                     %08X \n", m_data[i]);
132     }
133 }
134
135 // ----
136 EfcFlashWriteCmd::EfcFlashWriteCmd()
137     : EfcCmd(EFC_CAT_FLASH, EFC_CMD_FLASH_WRITE)
138     , m_address ( 0xFFFFFFFF )
139     , m_nb_quadlets ( 0 )
140 {
141 }
142
143 bool
144 EfcFlashWriteCmd::serialize( Util::IOSSerialize& se )
145 {
146     bool result=true;
147
148     if (m_nb_quadlets > EFC_FLASH_SIZE_QUADS) {
149         debugError("Too much quadlets to write: %u\n", m_nb_quadlets);
150         return false;
151     }
152
153     // the length should be specified before
154     // the header is serialized
155     m_length=EFC_HEADER_LENGTH_QUADLETS+2+m_nb_quadlets;
156
157     result &= EfcCmd::serialize ( se );
158
159     result &= se.write(htonl(m_address), "Address" );
160     result &= se.write(htonl(m_nb_quadlets), "Length (quadlets)" );
161
162     for (unsigned int i=0; i < m_nb_quadlets; i++) {
163         // FIXME: do we have to swap?
164         // or not?
165         result &= se.write(m_data[i], "Data");
166     }
167     return result;
168 }
169
170 bool
171 EfcFlashWriteCmd::deserialize( Util::IISDeserialize& de )
172 {
173     bool result=true;
174     result &= EfcCmd::deserialize ( de );
175     return result;
176 }
177
178 void
179 EfcFlashWriteCmd::showEfcCmd()
180 {
181     EfcCmd::showEfcCmd();
182     debugOutput(DEBUG_LEVEL_NORMAL, "EFC Flash Write:\n");
183     debugOutput(DEBUG_LEVEL_NORMAL, " Address           : %lu\n", m_address);
184     debugOutput(DEBUG_LEVEL_NORMAL, " Length (quadlets) : %lu\n", m_nb_quadlets);
185     debugOutput(DEBUG_LEVEL_NORMAL, " Data              : \n");
186     for (unsigned int i=0; i < m_nb_quadlets; i++) {
187         debugOutput(DEBUG_LEVEL_NORMAL, "                     %08X \n", m_data[i]);
188     }
189 }
190
191 // ------------------
192
193 EfcFlashLockCmd::EfcFlashLockCmd()
194     : EfcCmd(EFC_CAT_FLASH, EFC_CMD_FLASH_LOCK)
195     , m_lock ( false )
196 {
197 }
198
199 bool
200 EfcFlashLockCmd::serialize( Util::IOSSerialize& se )
201 {
202     bool result=true;
203
204     // the length should be specified before
205     // the header is serialized
206     m_length=EFC_HEADER_LENGTH_QUADLETS + 1;
207
208     result &= EfcCmd::serialize ( se );
209     result &= se.write(htonl(m_lock), "Locked" );
210
211     return result;
212 }
213
214 bool
215 EfcFlashLockCmd::deserialize( Util::IISDeserialize& de )
216 {
217     bool result=true;
218
219     result &= EfcCmd::deserialize ( de );
220     //EFC_DESERIALIZE_AND_SWAP(de, &m_lock, result);
221     return result;
222 }
223
224 void
225 EfcFlashLockCmd::showEfcCmd()
226 {
227     EfcCmd::showEfcCmd();
228     debugOutput(DEBUG_LEVEL_NORMAL, "EFC Flash Lock:\n");
229     debugOutput(DEBUG_LEVEL_NORMAL, " Locked     : %s\n", (m_lock?"Yes":"No"));
230 }
231
232 // ------------------
233
234 EfcFlashGetStatusCmd::EfcFlashGetStatusCmd()
235     : EfcCmd(EFC_CAT_FLASH, EFC_CMD_FLASH_GET_STATUS)
236     , m_ready ( false )
237 {
238 }
239
240 bool
241 EfcFlashGetStatusCmd::serialize( Util::IOSSerialize& se )
242 {
243     bool result=true;
244     // the length should be specified before
245     // the header is serialized
246     m_length=EFC_HEADER_LENGTH_QUADLETS;
247     result &= EfcCmd::serialize ( se );
248     return result;
249 }
250
251 bool
252 EfcFlashGetStatusCmd::deserialize( Util::IISDeserialize& de )
253 {
254     bool result=true;
255     result &= EfcCmd::deserialize ( de );
256     m_ready = !(m_header.retval == eERV_FlashBusy);
257     return result;
258 }
259
260 void
261 EfcFlashGetStatusCmd::showEfcCmd()
262 {
263     EfcCmd::showEfcCmd();
264     debugOutput(DEBUG_LEVEL_NORMAL, "EFC Flash Get Status:\n");
265     debugOutput(DEBUG_LEVEL_NORMAL, " Ready?     : %s\n", (m_ready?"Yes":"No"));
266 }
267
268 // ------------------
269
270 EfcFlashGetSessionBaseCmd::EfcFlashGetSessionBaseCmd()
271     : EfcCmd(EFC_CAT_FLASH, EFC_CMD_FLASH_GET_SESSION_BASE)
272     , m_address ( false )
273 {
274 }
275
276 bool
277 EfcFlashGetSessionBaseCmd::serialize( Util::IOSSerialize& se )
278 {
279     bool result=true;
280     // the length should be specified before
281     // the header is serialized
282     m_length=EFC_HEADER_LENGTH_QUADLETS;
283     result &= EfcCmd::serialize ( se );
284     return result;
285 }
286
287 bool
288 EfcFlashGetSessionBaseCmd::deserialize( Util::IISDeserialize& de )
289 {
290     bool result=true;
291     result &= EfcCmd::deserialize ( de );
292     EFC_DESERIALIZE_AND_SWAP(de, &m_address, result);
293     return result;
294 }
295
296 void
297 EfcFlashGetSessionBaseCmd::showEfcCmd()
298 {
299     EfcCmd::showEfcCmd();
300     debugOutput(DEBUG_LEVEL_NORMAL, "EFC Flash Get Session Base:\n");
301     debugOutput(DEBUG_LEVEL_NORMAL, " Address           : %lu\n", m_address);
302 }
303
304 } // namespace FireWorks
Note: See TracBrowser for help on using the browser.