Subversion Repositories f9daq

Rev

Blame | Last modification | View Log | RSS feed

#ifndef __CPCICC32_H__
#define __CPCICC32_H__

//****************************************************************************
// Copyright (C) 2000-2004  ARW Elektronik Germany
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// This product is not authorized for use as critical component in
// life support systems without the express written approval of
// ARW Elektronik Germany.
//  
// Please announce changes and hints to ARW Elektronik
//
// Maintainer(s): Klaus Hitschler (klaus.hitschler@gmx.de)
//
//****************************************************************************

//****************************************************************************
//
// cpcicc32.h -- the header representing a CC32 module class
//
// $Log: cpcicc32.h,v $
// Revision 1.2  2005/03/11 13:23:58  klaus
// added _qx functions to get Q and X for every transfer. Release libcc32.so.2.
//
// Revision 1.1  2004/10/09 21:05:03  klaus
// Added C++ examples to test programs
//
//
//****************************************************************************

#include <libcc32.h>

class cpcicc32
{
  protected:
  int  m_nLastError;
  CC32_HANDLE m_handle;
  char *m_cszPath;

  public:
  cpcicc32() : m_nLastError(0), m_handle(0), m_cszPath(NULL)
  {
  }

  cpcicc32(char *szPath) : m_nLastError(0), m_handle(0), m_cszPath(szPath)
  {
  }

  ~cpcicc32()
  {
    cc32_close(m_handle);
  }
 
  /* gives the last error */
  inline int getLastError(void)
  {
    return m_nLastError;
  }
 
  /* open a path to a device. E.g. "/dev/pcicc32_1" */
  inline int open(void)
  {
    return m_nLastError = cc32_open(m_cszPath, &m_handle);
  }
 
  /* open a path to a device. E.g. "/dev/pcicc32_1" */
  inline int open(char *cszPath)
  {
    m_cszPath = cszPath;
    return m_nLastError = cc32_open(cszPath, &m_handle);
  }
 
  /* close the opened path */
  inline int close(void)
  {
    m_nLastError = cc32_close(m_handle);
   
    if (!m_nLastError)
      m_handle = NULL;
     
    return m_nLastError;
  }
 
  /* read only a word - 16 bits - from a address made out of N,A,F */
  inline void read(unsigned int N, unsigned int A, unsigned int F, __u16 &uwData)
  {
    uwData = cc32_read_word(m_handle, N, A, F);
  }

  /* read a long - 32 bits - without any interpretaion */
  inline void read(unsigned int N, unsigned int A, unsigned int F, __u32 &ulData)
  {
    ulData = cc32_read_long_all(m_handle, N, A, F);
  }
 
  /* read a long - 32 bits - from a address made out of N,A,F and get the result Q and X */
  inline void read(unsigned int N, unsigned int A, unsigned int F, __u32 &ulData, int &Q, int &X)
  {
    ulData = cc32_read_long_qx(m_handle, N, A,F, &Q, &X);
  }

  /* write a word - 16 bits - to a destination made out of N,A,F */
  inline void write(unsigned int N, unsigned int A, unsigned int F, __u16 uwData)
  {
    cc32_write_word(m_handle, N, A, F, uwData);
  }

  /* write a long - 32 bits - uninterpreted to a destination made out of N,A,F */
  inline void write(unsigned int N, unsigned int A, unsigned int F, __u32 ulData)
  {
    cc32_write_long(m_handle, N, A, F, ulData);
  }

  /* poll the state of the timeout line and the LAM state. The timeout line is cleared if it was set */
  inline int poll_event(int &nTimeout, int &nLam)
  {
    return m_nLastError = cc32_poll_event(m_handle, &nTimeout, &nLam);
  }

  /* control interrupts caused by timeouts or LAMs */
  inline int interrupt_disable(void)
  {
    return m_nLastError = cc32_interrupt_disable(m_handle);
  }
 
  inline int interrupt_enable(void)
  {
    return m_nLastError = cc32_interrupt_enable(m_handle);
  }

  /* same as cc32_poll_event(), but wait for a state change of timeout or LAMs. */
  inline int wait_event(int &nTimeout, int &nLam)
  {
    return m_nLastError = cc32_wait_event(m_handle, &nTimeout, &nLam);
  }

  /* switch cc32 autoread on or off - return the last switch state */
  inline int autoread_on(void)
  {
    return m_nLastError = cc32_autoread_on(m_handle);
  }
 
  inline int autoread_off(void)
  {
    return m_nLastError = cc32_autoread_off(m_handle);
  }  
};

#endif // __CPCICC32_H__