@@ -172,101 +172,111 @@ void readFromDmaToStdOut(
172172 }
173173}
174174
175- int main (int argc, char * argv[])
176- {
177- // Command Line Parser
178- CLI::App app{" VILLASfpga data output" };
179-
180- try {
181- std::string configFile;
182- app.add_option (" -c,--config" , configFile, " Configuration file" )
183- ->check (CLI::ExistingFile);
184-
185- std::string fpgaName = " vc707" ;
186- app.add_option (" --fpga" , fpgaName, " Which FPGA to use" );
187- std::string connectStr = " " ;
188- app.add_option (" -x,--connect" , connectStr, " Connect a FPGA port with another or stdin/stdout" );
189- bool noDma = false ;
190- app.add_flag (" --no-dma" , noDma, " Do not setup DMA, only setup FPGA and Crossbar links" );
191- std::string outputFormat = " short" ;
192- app.add_option (" --output-format" , outputFormat, " Output format (short, long)" );
193- bool dumpGraph = false ;
194- app.add_flag (" --dump-graph" , dumpGraph, " Dumps the graph of memory regions into \" graph.dot\" " );
195- bool dumpAuroraChannels = true ;
196- app.add_flag (" --dump-aurora" , dumpAuroraChannels, " Dumps the detected Aurora channels." );
197- app.parse (argc, argv);
198-
199- // Logging setup
200-
201- logging.setLevel (spdlog::level::debug);
202- fpga::setupColorHandling ();
203-
204- if (configFile.empty ()) {
205- logger->error (" No configuration file provided/ Please use -c/--config argument" );
206- return 1 ;
207- }
208-
209- auto card = fpga::setupFpgaCard (configFile, fpgaName);
210-
211- std::vector<std::shared_ptr<fpga::ip::AuroraXilinx>> aurora_channels;
212- for (int i = 0 ; i < 4 ; i++) {
213- auto name = fmt::format (" aurora_8b10b_ch{}" , i);
214- auto id = fpga::ip::IpIdentifier (" xilinx.com:ip:aurora_8b10b:" , name);
215- auto aurora = std::dynamic_pointer_cast<fpga::ip::AuroraXilinx>(card->lookupIp (id));
216- if (aurora == nullptr ) {
217- logger->error (" No Aurora interface found on FPGA" );
218- return 1 ;
219- }
220-
221- aurora_channels.push_back (aurora);
222- }
223-
224- auto dma = std::dynamic_pointer_cast<fpga::ip::Dma>
225- (card->lookupIp (fpga::Vlnv (" xilinx.com:ip:axi_dma:" )));
226- if (dma == nullptr ) {
227- logger->error (" No DMA found on FPGA " );
228- return 1 ;
229- }
230-
231- if (dumpGraph) {
232- auto &mm = MemoryManager::get ();
233- mm.getGraph ().dump (" graph.dot" );
234- }
235-
236- if (dumpAuroraChannels) {
237- for (auto aurora : aurora_channels)
238- aurora->dump ();
239- }
240- // Configure Crossbar switch
241- const fpga::ConnectString parsedConnectString (connectStr);
242- parsedConnectString.configCrossBar (dma, aurora_channels);
243-
244- std::unique_ptr<std::thread> stdInThread = nullptr ;
245- if (!noDma && parsedConnectString.isDstStdout ()) {
246- auto formatter = fpga::getBufferedSampleFormatter (outputFormat, 16 );
247- // We copy the dma shared ptr but move the fomatter unqiue ptr as we don't need it
248- // in this thread anymore
249- stdInThread = std::make_unique<std::thread>(readFromDmaToStdOut, dma, std::move (formatter));
250- }
251- if (!noDma && parsedConnectString.isSrcStdin ()) {
252- writeToDmaFromStdIn (dma);
253- }
254-
255- if (stdInThread) {
256- stdInThread->join ();
257- }
258- } catch (const RuntimeError &e) {
259- logger->error (" Error: {}" , e.what ());
260- return -1 ;
261- } catch (const CLI::ParseError &e) {
262- return app.exit (e);
263- } catch (const std::exception &e) {
264- logger->error (" Error: {}" , e.what ());
265- return -1 ;
266- } catch (...) {
267- logger->error (" Unknown error" );
268- return -1 ;
269- }
270-
271- return 0 ;
272- }
175+ int main (int argc, char *argv[]) {
176+ // Command Line Parser
177+ CLI::App app{" VILLASfpga data output" };
178+
179+ try {
180+ std::string configFile;
181+ app.add_option (" -c,--config" , configFile, " Configuration file" )
182+ ->check (CLI::ExistingFile);
183+
184+ std::string fpgaName = " vc707" ;
185+ app.add_option (" --fpga" , fpgaName, " Which FPGA to use" );
186+ std::vector<std::string> connectStr;
187+ app.add_option (" -x,--connect" , connectStr,
188+ " Connect a FPGA port with another or stdin/stdout" );
189+ bool noDma = false ;
190+ app.add_flag (" --no-dma" , noDma,
191+ " Do not setup DMA, only setup FPGA and Crossbar links" );
192+ std::string outputFormat = " short" ;
193+ app.add_option (" --output-format" , outputFormat,
194+ " Output format (short, long)" );
195+ bool dumpGraph = false ;
196+ app.add_flag (" --dump-graph" , dumpGraph,
197+ " Dumps the graph of memory regions into \" graph.dot\" " );
198+ bool dumpAuroraChannels = true ;
199+ app.add_flag (" --dump-aurora" , dumpAuroraChannels,
200+ " Dumps the detected Aurora channels." );
201+ app.parse (argc, argv);
202+
203+ // Logging setup
204+
205+ logging.setLevel (spdlog::level::debug);
206+ fpga::setupColorHandling ();
207+
208+ if (configFile.empty ()) {
209+ logger->error (
210+ " No configuration file provided/ Please use -c/--config argument" );
211+ return 1 ;
212+ }
213+
214+ auto card = fpga::setupFpgaCard (configFile, fpgaName);
215+
216+ if (dumpGraph) {
217+ auto &mm = MemoryManager::get ();
218+ mm.getGraph ().dump (" graph.dot" );
219+ }
220+
221+ if (dumpAuroraChannels) {
222+ auto aurora_channels = getAuroraChannels (card);
223+ for (auto aurora : *aurora_channels)
224+ aurora->dump ();
225+ }
226+ bool writeToStdout = false ;
227+ bool readFromStdin = false ;
228+ // Configure Crossbar switch
229+ for (std::string str : connectStr) {
230+ const fpga::ConnectString parsedConnectString (str);
231+ parsedConnectString.configCrossBar (card);
232+ if (parsedConnectString.isSrcStdin ()) {
233+ readFromStdin = true ;
234+ if (parsedConnectString.isBidirectional ()) {
235+ writeToStdout = true ;
236+ }
237+ }
238+ if (parsedConnectString.isDstStdout ()) {
239+ writeToStdout = true ;
240+ if (parsedConnectString.isBidirectional ()) {
241+ readFromStdin = true ;
242+ }
243+ }
244+ }
245+ if (writeToStdout || readFromStdin) {
246+ auto dma = std::dynamic_pointer_cast<fpga::ip::Dma>(
247+ card->lookupIp (fpga::Vlnv (" xilinx.com:ip:axi_dma:" )));
248+ if (dma == nullptr ) {
249+ logger->error (" No DMA found on FPGA " );
250+ throw std::runtime_error (" No DMA found on FPGA" );
251+ }
252+ std::unique_ptr<std::thread> stdInThread = nullptr ;
253+ if (!noDma && writeToStdout) {
254+ auto formatter = fpga::getBufferedSampleFormatter (outputFormat, 16 );
255+ // We copy the dma shared ptr but move the fomatter unqiue ptr as we don't need it
256+ // in this thread anymore
257+ stdInThread = std::make_unique<std::thread>(readFromDmaToStdOut, dma,
258+ std::move (formatter));
259+ }
260+ if (!noDma && readFromStdin) {
261+ writeToDmaFromStdIn (dma);
262+ }
263+
264+ if (stdInThread) {
265+ stdInThread->join ();
266+ }
267+ }
268+ } catch (const RuntimeError &e) {
269+ logger->error (" Error: {}" , e.what ());
270+ return -1 ;
271+ } catch (const CLI::ParseError &e) {
272+ return app.exit (e);
273+ } catch (const std::exception &e) {
274+ logger->error (" Error: {}" , e.what ());
275+ return -1 ;
276+ } catch (...) {
277+ logger->error (" Unknown error" );
278+ return -1 ;
279+ }
280+
281+ return 0 ;
282+ }
0 commit comments