motu: the 4pre channel layout within packets is now believed to be correct. Thanks...
[ffado.git] / libffado / src / fireworks / efc / efc_cmds_flash.cpp
blobec6725882ee205b80c676623dab921a47dc446de
1 /*
2 * Copyright (C) 2005-2008 by Pieter Palmers
4 * This file is part of FFADO
5 * FFADO = Free Firewire (pro-)audio drivers for linux
7 * FFADO is based upon FreeBoB
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.
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.
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/>.
24 #include "efc_cmd.h"
25 #include "efc_cmds_flash.h"
27 #include "libutil/ByteSwap.h"
28 #include <iostream>
30 using namespace std;
32 namespace FireWorks {
34 EfcFlashEraseCmd::EfcFlashEraseCmd()
35 : EfcCmd(EFC_CAT_FLASH, EFC_CMD_FLASH_ERASE)
36 , m_address ( 0xFFFFFFFF )
40 bool
41 EfcFlashEraseCmd::serialize( Util::Cmd::IOSSerialize& se )
43 bool result=true;
45 // the length should be specified before
46 // the header is serialized
47 m_length=EFC_HEADER_LENGTH_QUADLETS + 1;
49 result &= EfcCmd::serialize ( se );
50 result &= se.write(CondSwapToBus32(m_address), "Address" );
52 return result;
55 bool
56 EfcFlashEraseCmd::deserialize( Util::Cmd::IISDeserialize& de )
58 bool result=true;
60 result &= EfcCmd::deserialize ( de );
62 return result;
65 void
66 EfcFlashEraseCmd::showEfcCmd()
68 EfcCmd::showEfcCmd();
69 debugOutput(DEBUG_LEVEL_NORMAL, "EFC Flash Erase:\n");
70 debugOutput(DEBUG_LEVEL_NORMAL, " Address : %u\n", m_address);
73 // ----
74 EfcFlashReadCmd::EfcFlashReadCmd()
75 : EfcCmd(EFC_CAT_FLASH, EFC_CMD_FLASH_READ)
76 , m_address ( 0xFFFFFFFF )
77 , m_nb_quadlets ( 0 )
81 bool
82 EfcFlashReadCmd::serialize( Util::Cmd::IOSSerialize& se )
84 bool result=true;
86 // the length should be specified before
87 // the header is serialized
88 m_length=EFC_HEADER_LENGTH_QUADLETS+2;
90 result &= EfcCmd::serialize ( se );
92 result &= se.write(CondSwapToBus32(m_address), "Address" );
93 result &= se.write(CondSwapToBus32(m_nb_quadlets), "Length (quadlets)" );
95 return result;
98 bool
99 EfcFlashReadCmd::deserialize( Util::Cmd::IISDeserialize& de )
101 bool result=true;
103 result &= EfcCmd::deserialize ( de );
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;
111 for (unsigned int i=0; i < m_nb_quadlets; i++) {
112 EFC_DESERIALIZE_AND_SWAP(de, &m_data[i], result);
114 return result;
117 void
118 EfcFlashReadCmd::showEfcCmd()
120 EfcCmd::showEfcCmd();
121 debugOutput(DEBUG_LEVEL_NORMAL, "EFC Flash Read:\n");
122 debugOutput(DEBUG_LEVEL_NORMAL, " Address : %u\n", m_address);
123 debugOutput(DEBUG_LEVEL_NORMAL, " Length (quadlets) : %u\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]);
130 // ----
131 EfcFlashWriteCmd::EfcFlashWriteCmd()
132 : EfcCmd(EFC_CAT_FLASH, EFC_CMD_FLASH_WRITE)
133 , m_address ( 0xFFFFFFFF )
134 , m_nb_quadlets ( 0 )
138 bool
139 EfcFlashWriteCmd::serialize( Util::Cmd::IOSSerialize& se )
141 bool result=true;
143 if (m_nb_quadlets > EFC_FLASH_SIZE_QUADS) {
144 debugError("Too much quadlets to write: %u\n", m_nb_quadlets);
145 return false;
148 // the length should be specified before
149 // the header is serialized
150 m_length=EFC_HEADER_LENGTH_QUADLETS+2+m_nb_quadlets;
152 result &= EfcCmd::serialize ( se );
154 result &= se.write(CondSwapToBus32(m_address), "Address" );
155 result &= se.write(CondSwapToBus32(m_nb_quadlets), "Length (quadlets)" );
157 for (unsigned int i=0; i < m_nb_quadlets; i++) {
158 result &= se.write(CondSwapToBus32(m_data[i]), "Data");
160 return result;
163 bool
164 EfcFlashWriteCmd::deserialize( Util::Cmd::IISDeserialize& de )
166 bool result=true;
167 result &= EfcCmd::deserialize ( de );
168 return result;
171 void
172 EfcFlashWriteCmd::showEfcCmd()
174 EfcCmd::showEfcCmd();
175 debugOutput(DEBUG_LEVEL_NORMAL, "EFC Flash Write:\n");
176 debugOutput(DEBUG_LEVEL_NORMAL, " Address : %u\n", m_address);
177 debugOutput(DEBUG_LEVEL_NORMAL, " Length (quadlets) : %u\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]);
184 // ------------------
186 EfcFlashLockCmd::EfcFlashLockCmd()
187 : EfcCmd(EFC_CAT_FLASH, EFC_CMD_FLASH_LOCK)
188 , m_lock ( false )
192 bool
193 EfcFlashLockCmd::serialize( Util::Cmd::IOSSerialize& se )
195 bool result=true;
197 // the length should be specified before
198 // the header is serialized
199 m_length=EFC_HEADER_LENGTH_QUADLETS + 1;
201 result &= EfcCmd::serialize ( se );
202 result &= se.write(CondSwapToBus32(m_lock), "Locked" );
204 return result;
207 bool
208 EfcFlashLockCmd::deserialize( Util::Cmd::IISDeserialize& de )
210 bool result=true;
212 result &= EfcCmd::deserialize ( de );
213 //EFC_DESERIALIZE_AND_SWAP(de, &m_lock, result);
214 return result;
217 void
218 EfcFlashLockCmd::showEfcCmd()
220 EfcCmd::showEfcCmd();
221 debugOutput(DEBUG_LEVEL_NORMAL, "EFC Flash Lock:\n");
222 debugOutput(DEBUG_LEVEL_NORMAL, " Locked : %s\n", (m_lock?"Yes":"No"));
225 // ------------------
227 EfcFlashGetStatusCmd::EfcFlashGetStatusCmd()
228 : EfcCmd(EFC_CAT_FLASH, EFC_CMD_FLASH_GET_STATUS)
229 , m_ready ( false )
233 bool
234 EfcFlashGetStatusCmd::serialize( Util::Cmd::IOSSerialize& se )
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;
244 bool
245 EfcFlashGetStatusCmd::deserialize( Util::Cmd::IISDeserialize& de )
247 bool result=true;
248 result &= EfcCmd::deserialize ( de );
249 m_ready = !(m_header.retval == eERV_FlashBusy);
250 return result;
253 void
254 EfcFlashGetStatusCmd::showEfcCmd()
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"));
261 // ------------------
263 EfcFlashGetSessionBaseCmd::EfcFlashGetSessionBaseCmd()
264 : EfcCmd(EFC_CAT_FLASH, EFC_CMD_FLASH_GET_SESSION_BASE)
265 , m_address ( false )
269 bool
270 EfcFlashGetSessionBaseCmd::serialize( Util::Cmd::IOSSerialize& se )
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;
280 bool
281 EfcFlashGetSessionBaseCmd::deserialize( Util::Cmd::IISDeserialize& de )
283 bool result=true;
284 result &= EfcCmd::deserialize ( de );
285 EFC_DESERIALIZE_AND_SWAP(de, &m_address, result);
286 return result;
289 void
290 EfcFlashGetSessionBaseCmd::showEfcCmd()
292 EfcCmd::showEfcCmd();
293 debugOutput(DEBUG_LEVEL_NORMAL, "EFC Flash Get Session Base:\n");
294 debugOutput(DEBUG_LEVEL_NORMAL, " Address : %u\n", m_address);
297 } // namespace FireWorks