μHAL (v2.6.5)
Part of the IPbus software repository
ProtocolPCIe.hxx
Go to the documentation of this file.
1 /*
2 ---------------------------------------------------------------------------
3 
4  This file is part of uHAL.
5 
6  uHAL is a hardware access library and programming framework
7  originally developed for upgrades of the Level-1 trigger of the CMS
8  experiment at CERN.
9 
10  uHAL is free software: you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  uHAL is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with uHAL. If not, see <http://www.gnu.org/licenses/>.
22 
23 
24  Andrew Rose, Imperial College, London
25  email: awr01 <AT> imperial.ac.uk
26 
27  Marc Magrans de Abril, CERN
28  email: marc.magrans.de.abril <AT> cern.ch
29 
30 ---------------------------------------------------------------------------
31 */
32 
33 #include "uhal/grammars/URI.hpp"
34 
35 
36 //#include "uhal/IPbusInspector.hpp"
37 // #include "uhal/logo.hpp"
38 
39 #include <sys/time.h>
40 #include <iostream>
41 
42 namespace uhal
43 {
44 
45  //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
46  //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
47 
48  template < typename InnerProtocol >
49  PCIe< InnerProtocol >::PCIe ( const std::string& aId, const URI& aUri ) :
50  InnerProtocol ( aId , aUri )
51  {
52  std::string lPCIePath( '/' + aUri.mPath );
53 
54  std::cout << "Id: " << aId << ", Path: " << lPCIePath << std::endl;
55  }
56 
57 
58 
59  template < typename InnerProtocol >
60  PCIe< InnerProtocol >::PCIe ( const PCIe< InnerProtocol >& aPCIe )
61  {}
62 
63 
64  template < typename InnerProtocol >
66  {}
67 
68  template < typename InnerProtocol >
70  {}
71 
72 
73 
74  template < typename InnerProtocol >
76  {
77 
78  // I split the write and read processes into separate functions for clarity only here,
79  // For multi-threaded code it becomes more important (and far more confusing)
80 
81  mDispatchBuffers = aBuffers;
82  write ( );
83  }
84 
85 
86  template < typename InnerProtocol >
88  {
89 
90  if ( !mDispatchBuffers )
91  {
92  log ( Error() , __PRETTY_FUNCTION__ , " called when 'mDispatchBuffers' was NULL" );
93  return;
94  }
95 
96  // DO WRITE OPERATION HERE
97  // mDispatchBuffers->getSendBuffer()
98  // mDispatchBuffers->sendCounter()
99 
100  mReplyBuffers = mDispatchBuffers;
101  mDispatchBuffers.reset();
102  read ( );
103  }
104 
105 
106  template < typename InnerProtocol >
108  {
109  if ( !mReplyBuffers )
110  {
111  log ( Error() , __PRETTY_FUNCTION__ , " called when 'mReplyBuffers' was NULL" );
112  return;
113  }
114 
115  // DO READ OPERATION HERE
116  // mReplyBuffers->getReplyBuffer()
117 
118  if ( uhal::exception::exception* lExc = ClientInterface::validate ( mReplyBuffers ) ) //Control of the pointer has been passed back to the client interface
119  {
120  throw lExc;
121  }
122  mReplyBuffers.reset();
123  }
124 
125 
126  template < typename InnerProtocol >
128  {
129  }
130 
131  template < typename InnerProtocol >
133  {
134  InnerProtocol::dispatchExceptionHandler();
135  }
136 
137 }
138 
PCIe & operator=(const PCIe &aPCIe)
void read()
Read next pending reply packet from appropriate page of FPGA-to-host device file, and validate conten...
An abstract base exception class providing an interface to a throw/ThrowAsDerivedType mechanism which...
Definition: exception.hpp:89
virtual void dispatchExceptionHandler()
Function which tidies up this protocol layer in the event of an exception.
ErrorLevel Error
Definition: LogLevels.cpp:61
virtual void Flush()
Concrete implementation of the synchronization function to block until all buffers have been sent...
ValHeader write(const uint32_t &aValue) const
Write a single, unmasked word to a register.
Definition: Node.cpp:494
void write(const boost::shared_ptr< Buffers > &aBuffers)
Write request packet to next page in host-to-FPGA device file.
void implementDispatch(boost::shared_ptr< Buffers > aBuffers)
Send the IPbus buffer to the target, read back the response and call the packing-protocol&#39;s validate ...
virtual exception::exception * validate(boost::shared_ptr< Buffers > aBuffers)
Function which dispatch calls when the reply is received to check that the headers are as expected...
Transport protocol to transfer an IPbus buffer via PCIe.
ValWord< uint32_t > read() const
Read a single, unmasked, unsigned word.
Definition: Node.cpp:589
PCIe(const PCIe &aPCIe)
virtual ~PCIe()
Destructor.