Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | Related Pages

gNAT.py

00001 #!/usr/local/bin/python
00002 #
00003 #                               Copyright 2004
00004 #                                     by
00005 #                        The Board of Trustees of the
00006 #                     Leland Stanford Junior University.
00007 #                            All rights reserved.
00008 #
00009 
00010 
00011 __facility__ = "Online"
00012 __abstract__ = "GLAST COMM Card I/O node"
00013 __author__  = "Selim Tuvi <stuvi@slac.stanford.edu> SLAC - GLAST LAT I&T/Online"
00014 __date__     = ("$Date: 2004/08/24 23:09:08 $").split(' ')[1]
00015 __version__ = "$Revision: 2.4 $"
00016 __release__  = "$Name: R04-12-00 $"
00017 __credits__ = "SLAC"
00018 
00019 import LATTE.copyright_SLAC
00020 
00021 import gDb
00022 import gAttr
00023 
00024 class GNAT(gDb.Gdb):
00025   """\brief GNAT node Record
00026 
00027   This node contains COMM card related functions.
00028   Each GNAT node is associated with one COMM card.
00029   A GNAT node can either be instantiated through the
00030   createGNATinstance method of GTEM, GAEM or GGLT nodes or
00031   it can be instantiated as a standalone node by creating an
00032   instance of it and calling its initHandle method with the
00033   pysical address of the COMM card. The other parameter that it
00034   needs is a slot. A slot is a placeholder for a GNAT handle.
00035   There are currently 16 slots available. When calling the
00036   createGNATinstance or initHandle methods the desired slot is
00037   passed and this is where the handle is stored for the duration
00038   of the session.
00039   Currently the GNAT node serves to major purposes:
00040 
00041     (1) Statistics:
00042 
00043         Contains registers for retrieving TX/RX ctrl and data cells
00044         as well as RX header parity and TX busy assert flags.
00045 
00046     (2) Pattern generator functionality:
00047 
00048         It is possible to use the exposed methods and registers to
00049         write bit streams to the COMM card. This functionality is
00050         available mostly for internal testing and should not be of
00051         and particular use to the subsystems.
00052   """
00053   __attrs = [
00054       # Registers
00055       gAttr.GattrRaw('stats_rx_ctrl_cells',     0, 2),
00056       gAttr.GattrRaw('stats_rx_data_cells',     1, 2),
00057       gAttr.GattrRaw('stats_rx_header_parity',  2, 2),
00058       gAttr.GattrRaw('stats_rx_cell_parity',    3, 2),
00059       gAttr.GattrRaw('stats_tx_ctrl_cells',     4, 2),
00060       gAttr.GattrRaw('stats_tx_data_cells',     5, 2),
00061       gAttr.GattrRaw('stats_tx_busy_assert',    6, 2),
00062       gAttr.GattrRaw('stats_clear',             7, 2),
00063       gAttr.GattrRaw('output_mask',             8, 4)
00064       ]
00065 
00066   def __init__(self, client):
00067     """\brief Initialize valid registers as Gattrs.
00068 
00069     Assign default values to members
00070 
00071     Usage:
00072     \code
00073       gn = GNAT()
00074     \endcode
00075     """
00076     gDb.Gdb.__init__(self, client, None, 0, self.__attrs)
00077 
00078   def initHandle(self, slot, physAddr):
00079     """\brief Initializes a new GNAT handle given a physical VME address.
00080 
00081     \param slot     A number between 0 and 15 to hold the GNAT handle.
00082                     Each GNAT handle should be assigned a unique slot number.
00083                     The GNAT handle persists at that slot while the session is active.
00084     \param physAddr Physical VME address of the COMM card.
00085 
00086     \return Status
00087 
00088     Usage:
00089     \code
00090       gn = GNAT()
00091       gn.setCmd(lat.getCmd())
00092       gn.initHandle(0, 0x08000000)
00093     \endcode
00094     """
00095     if self.__cmdCli is not None:
00096       (userId, status, timestamp) = self.__cmdCli.gGNATgetGh(slot, physAddr)
00097       if status != 0:
00098         if self.__cmdCli.ignoreErrors():
00099           print "Error:", gutil.LATInterfaceStatus(status)
00100         else:
00101           raise gutil.LATInterfaceException(status)
00102       else:
00103         self._Gnode__id = slot
00104       return status
00105     else:
00106       raise RuntimeError, 'No command client. Use setCmd prior to calling this function'
00107 
00108   def clearBuffer(self):
00109     """\brief Zero out the contents of the bundle.
00110 
00111     Calls gBndlClear( gh);
00112 
00113     \return Status
00114     """
00115     if self.__cmdCli is not None:
00116       (userId, status, timestamp) = self.__cmdCli.gGNATclearBuffer(self._Gnode__id)
00117       if status != 0:
00118         if self.__cmdCli.ignoreErrors():
00119           print "Error:", gutil.LATInterfaceStatus(status)
00120         else:
00121           raise gutil.LATInterfaceException(status)
00122       return status
00123     else:
00124       raise RuntimeError, 'No command client. Use setCmd prior to calling this function'
00125 
00126   def addChannel(self, channelNo, itemList):
00127     """Inserts data into a channel
00128 
00129     \param  channelNo The channel number (0 - 15) to insert the chnlData into.
00130                       The maximum channel number is defined in GNAT/gnat.h as MAX_CHANNEL.
00131     \param  itemList  A sequence of 32-bit words.
00132                       The maximum number of words in the array is 5.
00133 
00134     \return           Status
00135 
00136     Usage:
00137     \code
00138       data = [0xdeadbeefL, 0xdeadbeefL, 0xdeadbeefL]
00139       gn.addChannel(channelNo=1, itemList=data)
00140     \endcode
00141     """
00142     if self.__cmdCli is not None:
00143       (userId, status, timestamp) = self.__cmdCli.gGNATaddChannel(self._Gnode__id, channelNo, itemList)
00144       if status != 0:
00145         if self.__cmdCli.ignoreErrors():
00146           print "Error:", gutil.LATInterfaceStatus(status)
00147         else:
00148           raise gutil.LATInterfaceException(status)
00149       return status
00150 
00151   def loadFIFO(self):
00152     """\brief This is a combination of gBndlGetBndl() and gWritePF16v().
00153 
00154     It transfers the data from the intermediate bundle buffer into the
00155     playback FIFO.
00156 
00157     \return  Status
00158     """
00159     if self.__cmdCli is not None:
00160       (userId, status, timestamp) = self.__cmdCli.gGNATloadFIFO(self._Gnode__id)
00161       if status != 0:
00162         if self.__cmdCli.ignoreErrors():
00163           print "Error:", gutil.LATInterfaceStatus(status)
00164         else:
00165           raise gutil.LATInterfaceException(status)
00166       return status
00167 
00168   def flushPlaybackFIFO(self):
00169     """\brief This is a combination of gFlushPF() and gEnablePF().
00170 
00171     Flushes the playback FIFO.
00172 
00173     \return Status
00174     """
00175     if self.__cmdCli is not None:
00176       (userId, status, timestamp) = self.__cmdCli.gGNATflushPlaybackFIFO(self._Gnode__id)
00177       if status != 0:
00178         if self.__cmdCli.ignoreErrors():
00179           print "Error:", gutil.LATInterfaceStatus(status)
00180         else:
00181           raise gutil.LATInterfaceException(status)
00182       return status
00183 
00184   def flushRecordFIFO(self):
00185     """\brief This is a combination of gFlushRF() and gEnableRF().
00186 
00187     Flushes the record FIFO.
00188 
00189     \return Status
00190     """
00191     if self.__cmdCli is not None:
00192       (userId, status, timestamp) = self.__cmdCli.gGNATflushRecordFIFO(self._Gnode__id)
00193       if status != 0:
00194         if self.__cmdCli.ignoreErrors():
00195           print "Error:", gutil.LATInterfaceStatus(status)
00196         else:
00197           raise gutil.LATInterfaceException(status)
00198       return status
00199 
00200   def writeFIFO(self, data):
00201     """\brief A wrapper around gWritePF().
00202 
00203     So user could write a single word to the
00204     FIFO or the user could prepare their own array of words,
00205     bypassing the bundle/channel interface.
00206 
00207     \param  data   A single or a sequence of 16-bit words
00208     \return        Status
00209 
00210     Usage:
00211     \code
00212       data = [0xa0a0, 0xb0b0, 0xc0c0]
00213       gn.writeFIFO(data)
00214       data = 0x1234
00215       gn.writeFIFO(data)
00216     \endcode
00217     """
00218     if self.__cmdCli is not None:
00219       if isNumberType(data):
00220         (userId, status, timestamp) = self.__cmdCli.gGNATwritePF16(self._Gnode__id, data)
00221       else:
00222         (userId, status, timestamp) = self.__cmdCli.gGNATwritePF16v(self._Gnode__id, data)
00223       if status != 0:
00224         if self.__cmdCli.ignoreErrors():
00225           print "Error:", gutil.LATInterfaceStatus(status)
00226         else:
00227           raise gutil.LATInterfaceException(status)
00228       return status
00229 
00230   def writeFIFO32(self, data):
00231     """\brief A wrapper around gWritePF()
00232 
00233     So user could write a single word to the
00234     FIFO or the user could prepare their own array of words,
00235     bypassing the bundle/channel interface.
00236 
00237     \param data A single or a sequence of 16-bit words
00238 
00239     \return     Status
00240 
00241     Usage:
00242     \code
00243       data = [0xa0a0a0a0L, 0xdeadbeefL, 0xc0c0c0c0L]
00244       gn.writeFIFO32(data)
00245       data = 0x12345678L
00246       gn.writeFIFO(data)
00247     \endcode
00248     """
00249     if self.__cmdCli is not None:
00250       if isNumberType(data):
00251         (userId, status, timestamp) = self.__cmdCli.gGNATwritePF32(self._Gnode__id, data)
00252       else:
00253         (userId, status, timestamp) = self.__cmdCli.gGNATwritePF32v(self._Gnode__id, data)
00254       if status != 0:
00255         if self.__cmdCli.ignoreErrors():
00256           print "Error:", gutil.LATInterfaceStatus(status)
00257         else:
00258           raise gutil.LATInterfaceException(status)
00259       return status
00260 
00261   def startPlayback(self):
00262     """\brief This is a wrapper around gStartPB().
00263 
00264     Starts the playback.
00265 
00266     \return Status
00267 
00268     Usage:
00269     \code
00270       gn.startPlayback()
00271     \endcode
00272     """
00273     if self.__cmdCli is not None:
00274       (userId, status, timestamp) = self.__cmdCli.gGNATstartPlayback(self._Gnode__id)
00275       if status != 0:
00276         if self.__cmdCli.ignoreErrors():
00277           print "Error:", gutil.LATInterfaceStatus(status)
00278         else:
00279           raise gutil.LATInterfaceException(status)
00280       return status
00281 
00282   def setLATpMode(self, mode):
00283     """\brief Sets the running mode of the COMM I/O board based on the boolean
00284     value of mode.
00285 
00286     When mode is non-zero the mode bit of the COMM I/O
00287     control register is set to 1, which puts the board in "LATp mode".
00288     When mode is zero the mode bit is cleared, which puts the board in
00289     "dumb record FIFO mode".
00290 
00291     \param mode The running mode of the COMM I/O board
00292 
00293     \return     Status
00294 
00295     Usage:
00296     \code
00297       gn.setLATpMode(0)
00298     \endcode
00299     """
00300     if self.__cmdCli is not None:
00301       (userId, status, timestamp) = self.__cmdCli.gGNATsetLATpMode(self._Gnode__id, mode)
00302       if status != 0:
00303         if self.__cmdCli.ignoreErrors():
00304           print "Error:", gutil.LATInterfaceStatus(status)
00305         else:
00306           raise gutil.LATInterfaceException(status)
00307       return status
00308 

Generated on Fri Jul 21 13:26:28 2006 for LATTE R04-12-00 by doxygen 1.4.3