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

Revision 1131, 7.3 kB (checked in by ppalmers, 16 years ago)

implement endian fixes (thx Heikki Lindholm)
switch from network host order byteswap routines to size based swap routines to remove ambiguity in definition of "long"

Line 
1 /*
2  * Copyright (C) 2005-2008 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 2 of the License, or
12  * (at your option) version 3 of the License.
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 <byteswap.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::Cmd::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(bswap_32(m_address), "Address" );
51
52     return result;
53 }
54
55 bool
56 EfcFlashEraseCmd::deserialize( Util::Cmd::IISDeserialize& de )
57 {
58     bool result=true;
59
60     result &= EfcCmd::deserialize ( de );
61
62     return result;
63 }
64
65 void
66 EfcFlashEraseCmd::showEfcCmd()
67 {
68     EfcCmd::showEfcCmd();
69     debugOutput(DEBUG_LEVEL_NORMAL, "EFC Flash Erase:\n");
70     debugOutput(DEBUG_LEVEL_NORMAL, " Address     : %lu\n", m_address);
71 }
72
73 // ----
74 EfcFlashReadCmd::EfcFlashReadCmd()
75     : EfcCmd(EFC_CAT_FLASH, EFC_CMD_FLASH_READ)
76     , m_address ( 0xFFFFFFFF )
77     , m_nb_quadlets ( 0 )
78 {
79 }
80
81 bool
82 EfcFlashReadCmd::serialize( Util::Cmd::IOSSerialize& se )
83 {
84     bool result=true;
85
86     // the length should be specified before
87     // the header is serialized
88     m_length=EFC_HEADER_LENGTH_QUADLETS+2;
89
90     result &= EfcCmd::serialize ( se );
91
92     result &= se.write(bswap_32(m_address), "Address" );
93     result &= se.write(bswap_32(m_nb_quadlets), "Length (quadlets)" );
94
95     return result;
96 }
97
98 bool
99 EfcFlashReadCmd::deserialize( Util::Cmd::IISDeserialize& de )
100 {
101     bool result=true;
102
103     result &= EfcCmd::deserialize ( de );
104
105     EFC_DESERIALIZE_AND_SWAP(de, &m_address, result);
106     EFC_DESERIALIZE_AND_SWAP(de, &m_nb_quadlets, result);
107     if (m_nb_quadlets > EFC_FLASH_SIZE_QUADS) {
108         debugError("Too much quadlets returned: %u\n", m_nb_quadlets);
109         return false;
110     }
111     for (unsigned int i=0; i < m_nb_quadlets; i++) {
112         EFC_DESERIALIZE_AND_SWAP(de, &m_data[i], result);
113     }
114     return result;
115 }
116
117 void
118 EfcFlashReadCmd::showEfcCmd()
119 {
120     EfcCmd::showEfcCmd();
121     debugOutput(DEBUG_LEVEL_NORMAL, "EFC Flash Read:\n");
122     debugOutput(DEBUG_LEVEL_NORMAL, " Address           : %lu\n", m_address);
123     debugOutput(DEBUG_LEVEL_NORMAL, " Length (quadlets) : %lu\n", m_nb_quadlets);
124     debugOutput(DEBUG_LEVEL_NORMAL, " Data              : \n");
125     for (unsigned int i=0; i < m_nb_quadlets; i++) {
126         debugOutput(DEBUG_LEVEL_NORMAL, "                     %08X \n", m_data[i]);
127     }
128 }
129
130 // ----
131 EfcFlashWriteCmd::EfcFlashWriteCmd()
132     : EfcCmd(EFC_CAT_FLASH, EFC_CMD_FLASH_WRITE)
133     , m_address ( 0xFFFFFFFF )
134     , m_nb_quadlets ( 0 )
135 {
136 }
137
138 bool
139 EfcFlashWriteCmd::serialize( Util::Cmd::IOSSerialize& se )
140 {
141     bool result=true;
142
143     if (m_nb_quadlets > EFC_FLASH_SIZE_QUADS) {
144         debugError("Too much quadlets to write: %u\n", m_nb_quadlets);
145         return false;
146     }
147
148     // the length should be specified before
149     // the header is serialized
150     m_length=EFC_HEADER_LENGTH_QUADLETS+2+m_nb_quadlets;
151
152     result &= EfcCmd::serialize ( se );
153
154     result &= se.write(bswap_32(m_address), "Address" );
155     result &= se.write(bswap_32(m_nb_quadlets), "Length (quadlets)" );
156
157     for (unsigned int i=0; i < m_nb_quadlets; i++) {
158         result &= se.write(bswap_32(m_data[i]), "Data");
159     }
160     return result;
161 }
162
163 bool
164 EfcFlashWriteCmd::deserialize( Util::Cmd::IISDeserialize& de )
165 {
166     bool result=true;
167     result &= EfcCmd::deserialize ( de );
168     return result;
169 }
170
171 void
172 EfcFlashWriteCmd::showEfcCmd()
173 {
174     EfcCmd::showEfcCmd();
175     debugOutput(DEBUG_LEVEL_NORMAL, "EFC Flash Write:\n");
176     debugOutput(DEBUG_LEVEL_NORMAL, " Address           : %lu\n", m_address);
177     debugOutput(DEBUG_LEVEL_NORMAL, " Length (quadlets) : %lu\n", m_nb_quadlets);
178     debugOutput(DEBUG_LEVEL_NORMAL, " Data              : \n");
179     for (unsigned int i=0; i < m_nb_quadlets; i++) {
180         debugOutput(DEBUG_LEVEL_NORMAL, "                     %08X \n", m_data[i]);
181     }
182 }
183
184 // ------------------
185
186 EfcFlashLockCmd::EfcFlashLockCmd()
187     : EfcCmd(EFC_CAT_FLASH, EFC_CMD_FLASH_LOCK)
188     , m_lock ( false )
189 {
190 }
191
192 bool
193 EfcFlashLockCmd::serialize( Util::Cmd::IOSSerialize& se )
194 {
195     bool result=true;
196
197     // the length should be specified before
198     // the header is serialized
199     m_length=EFC_HEADER_LENGTH_QUADLETS + 1;
200
201     result &= EfcCmd::serialize ( se );
202     result &= se.write(bswap_32(m_lock), "Locked" );
203
204     return result;
205 }
206
207 bool
208 EfcFlashLockCmd::deserialize( Util::Cmd::IISDeserialize& de )
209 {
210     bool result=true;
211
212     result &= EfcCmd::deserialize ( de );
213     //EFC_DESERIALIZE_AND_SWAP(de, &m_lock, result);
214     return result;
215 }
216
217 void
218 EfcFlashLockCmd::showEfcCmd()
219 {
220     EfcCmd::showEfcCmd();
221     debugOutput(DEBUG_LEVEL_NORMAL, "EFC Flash Lock:\n");
222     debugOutput(DEBUG_LEVEL_NORMAL, " Locked     : %s\n", (m_lock?"Yes":"No"));
223 }
224
225 // ------------------
226
227 EfcFlashGetStatusCmd::EfcFlashGetStatusCmd()
228     : EfcCmd(EFC_CAT_FLASH, EFC_CMD_FLASH_GET_STATUS)
229     , m_ready ( false )
230 {
231 }
232
233 bool
234 EfcFlashGetStatusCmd::serialize( Util::Cmd::IOSSerialize& se )
235 {
236     bool result=true;
237     // the length should be specified before
238     // the header is serialized
239     m_length=EFC_HEADER_LENGTH_QUADLETS;
240     result &= EfcCmd::serialize ( se );
241     return result;
242 }
243
244 bool
245 EfcFlashGetStatusCmd::deserialize( Util::Cmd::IISDeserialize& de )
246 {
247     bool result=true;
248     result &= EfcCmd::deserialize ( de );
249     m_ready = !(m_header.retval == eERV_FlashBusy);
250     return result;
251 }
252
253 void
254 EfcFlashGetStatusCmd::showEfcCmd()
255 {
256     EfcCmd::showEfcCmd();
257     debugOutput(DEBUG_LEVEL_NORMAL, "EFC Flash Get Status:\n");
258     debugOutput(DEBUG_LEVEL_NORMAL, " Ready?     : %s\n", (m_ready?"Yes":"No"));
259 }
260
261 // ------------------
262
263 EfcFlashGetSessionBaseCmd::EfcFlashGetSessionBaseCmd()
264     : EfcCmd(EFC_CAT_FLASH, EFC_CMD_FLASH_GET_SESSION_BASE)
265     , m_address ( false )
266 {
267 }
268
269 bool
270 EfcFlashGetSessionBaseCmd::serialize( Util::Cmd::IOSSerialize& se )
271 {
272     bool result=true;
273     // the length should be specified before
274     // the header is serialized
275     m_length=EFC_HEADER_LENGTH_QUADLETS;
276     result &= EfcCmd::serialize ( se );
277     return result;
278 }
279
280 bool
281 EfcFlashGetSessionBaseCmd::deserialize( Util::Cmd::IISDeserialize& de )
282 {
283     bool result=true;
284     result &= EfcCmd::deserialize ( de );
285     EFC_DESERIALIZE_AND_SWAP(de, &m_address, result);
286     return result;
287 }
288
289 void
290 EfcFlashGetSessionBaseCmd::showEfcCmd()
291 {
292     EfcCmd::showEfcCmd();
293     debugOutput(DEBUG_LEVEL_NORMAL, "EFC Flash Get Session Base:\n");
294     debugOutput(DEBUG_LEVEL_NORMAL, " Address           : %lu\n", m_address);
295 }
296
297 } // namespace FireWorks
Note: See TracBrowser for help on using the browser.