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_ipshm_hxx_) 00022 # define _anvil_ipshm_hxx_ 00023 00024 extern "C" 00025 { 00026 #include "vpi_user.h" 00027 } 00028 #include <iostream> 00029 #include "xyzzy/shmalloc.hxx" 00030 #include "xyzzy/semaphore.hxx" 00031 #include "xyzzy/exception.hxx" 00032 #include "anvil/object.hxx" 00033 00034 namespace anvil 00035 { 00036 00037 using namespace xyzzy; 00038 using std::ostream; 00039 00040 class TShared; 00041 00042 class XValueException : public TException {}; 00043 00044 class TShmObject 00045 { 00046 public: 00047 const char* getName() const; 00048 00049 s_vpi_vecval& vectorAt(unsigned ix) {return m_value[ix];} 00050 00051 int getNumBits() const {return m_numBits;} 00052 00053 ostream& print(ostream &os); 00054 00055 bool isInput() const {return m_isInput;} 00056 00057 // Xfer to m_value through handle (i.e., dut -> shared mem) 00058 void xferToValue(); 00059 00060 // Xfer from m_value/shared throug handle to dut. 00061 // Set getTime 1st time through iteration (only). 00062 void xferFromValue(bool getTime = false); 00063 00064 private: 00065 explicit TShmObject(const TRcObject obj); 00066 00067 void* operator new(size_t sz); 00068 00069 PTShmObj<const char*> m_name; 00070 00071 bool m_isInput; 00072 int m_numBits; 00073 vpiHandle m_hnd; 00074 00075 // Cant have union w/ object w/ copy constructor, so we'll just 00076 // take the worst case and always use vectors. 00077 PTShmObjAr<s_vpi_vecval> m_value; 00078 00079 friend class TShared; 00080 }; 00081 00082 class TShared 00083 { 00084 public: 00085 explicit TShared(TRcObjectSet set); 00086 00087 static TShared* asShared(const char *keyAndSize); 00088 00089 void* operator new(size_t szThis, TRcObjectSet set); 00090 00091 TShmObject& objectAt(unsigned ix); 00092 00093 ostream& print(ostream &os); 00094 00095 public: 00096 PTShmObjAr<PTShmObj<TShmObject*> > m_objs; 00097 // wakeupX: wait on X side, post on non-X side (X is one of Dut|Tb) 00098 TSemaphore m_wakeupDut, m_wakeupTb; 00099 00100 // tb notify of time to run for (0 == stop). 00101 // dut uses for current sim time. 00102 s_vpi_time m_timeVal; 00103 00104 // tb signal delay; as in "lhs = #assignDelay rhs" 00105 s_vpi_time m_assignDelay; 00106 00107 // Throw exception on X values on (any) output. 00108 bool m_exceptionOnX; 00109 }; 00110 00111 }; 00112 00113 #endif //_anvil_ipshm_hxx_