00001 /* 00002 * anvil 00003 * Copyright (C) 2007 Karl W. Pfalzer 00004 * 00005 * This program is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU General Public License 00007 * as published by the Free Software Foundation; either version 2 00008 * of the License, or (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the 00017 * Free Software Foundation, Inc. 00018 * 51 Franklin Street, Fifth Floor 00019 * Boston, MA 02110-1301, USA. 00020 */ 00021 #if !defined(_anvil_tbshm_hxx_) 00022 # define _anvil_tbshm_hxx_ 00023 00024 #include <map> 00025 #include "anvil/ipshm.hxx" 00026 #include "anvil/tbmgr.hxx" 00027 00028 namespace anvil 00029 { 00030 00031 namespace tb 00032 { 00033 00034 using namespace std; 00035 using namespace xyzzy; 00036 00037 class TShmManager; 00038 class TObject; 00039 class TInput; 00040 class TOutput; 00041 00042 typedef PTRcObjPtr<TShmManager> TRcShmManager; 00043 typedef PTRcObjPtr<TObject> TRcObject; 00044 00045 // Manager interface. 00046 class TShmManager : public IManager 00047 { 00048 public: 00049 explicit TShmManager(int port); 00050 00051 // Return an object which references dut. 00052 TRcIObject factory(const char *nm); 00053 00054 TShared* getShared() const {return m_stpShared;} 00055 00056 void assignAndRunDut(TUint32 assignDelay, TUint32 runFor); 00057 00058 void waitOnDut(); 00059 00060 void setExceptionOnX(bool v); 00061 00062 bool getExceptionOnX() const; 00063 00064 virtual ~TShmManager(); 00065 00066 private: 00067 typedef map<string, TRcObject> TMapOfIOsByName; 00068 00069 TMapOfIOsByName m_iosByName; 00070 00071 static TShared *m_stpShared; 00072 00073 static TShmManager *m_stpTheOne; 00074 00075 void init(int port); 00076 00077 friend class TObject; 00078 }; 00079 00080 // An implementation which uses shared memory. 00081 class TObject : public IObject 00082 { 00083 public: 00084 const char *getName() const {return m_shObj.getName();} 00085 00086 bool operator==(bool b) const; 00087 00088 bool operator==(TInt32 v) const; 00089 00090 bool operator==(const PTFixedPtBase<TInt32> &r) const; 00091 00092 int getNumBits() const {return m_shObj.getNumBits();} 00093 00094 virtual operator bool() const; 00095 00096 virtual operator TInt32() const; 00097 00098 virtual ~TObject(); 00099 00100 protected: 00101 explicit TObject(const char *nm); 00102 00103 explicit TObject(TShmObject &sref); 00104 00105 TShmObject &m_shObj; 00106 00107 private: 00108 static TShmObject& getShmObj(const char *nm); 00109 }; 00110 00111 // Input to (drives) dut. 00112 class TInput : public TObject 00113 { 00114 public: 00115 explicit TInput(const char *nm); 00116 00117 explicit TInput(TShmObject &sref); 00118 00119 virtual const TInput& operator=(bool b); 00120 00121 virtual const TInput& operator=(TInt32 v); 00122 00123 virtual const TInput& operator=(const PTFixedPtBase<TInt32> &r); 00124 00125 ~TInput(); 00126 00127 private: 00128 }; 00129 00130 // Output from dut. 00131 class TOutput : public TObject 00132 { 00133 public: 00134 explicit TOutput(const char *nm); 00135 00136 explicit TOutput(TShmObject &sref); 00137 00138 ~TOutput(); 00139 00140 private: 00141 }; 00142 00143 }; //namespace tb 00144 00145 }; //namespace anvil 00146 00147 #endif //_anvil_tbshm_hxx_