Subversion Repositories f9daq

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
86 f9daq 1
#ifndef __CPCICC32_H__
2
#define __CPCICC32_H__
3
 
4
//****************************************************************************
5
// Copyright (C) 2000-2004  ARW Elektronik Germany
6
//
7
// This program is free software; you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License as published by
9
// the Free Software Foundation; either version 2 of the License, or
10
// (at your option) any later version.
11
//
12
// This program is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
// GNU General Public License for more details.
16
//
17
// You should have received a copy of the GNU General Public License
18
// along with this program; if not, write to the Free Software
19
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
//
21
// This product is not authorized for use as critical component in 
22
// life support systems without the express written approval of 
23
// ARW Elektronik Germany.
24
//  
25
// Please announce changes and hints to ARW Elektronik
26
//
27
// Maintainer(s): Klaus Hitschler (klaus.hitschler@gmx.de)
28
//
29
//****************************************************************************
30
 
31
//****************************************************************************
32
//
33
// cpcicc32.h -- the header representing a CC32 module class
34
//
35
// $Log: cpcicc32.h,v $
36
// Revision 1.2  2005/03/11 13:23:58  klaus
37
// added _qx functions to get Q and X for every transfer. Release libcc32.so.2.
38
//
39
// Revision 1.1  2004/10/09 21:05:03  klaus
40
// Added C++ examples to test programs
41
//
42
//
43
//****************************************************************************
44
 
45
#include <libcc32.h>
46
 
47
class cpcicc32
48
{
49
  protected:
50
  int  m_nLastError;
51
  CC32_HANDLE m_handle;
52
  char *m_cszPath;
53
 
54
  public:
55
  cpcicc32() : m_nLastError(0), m_handle(0), m_cszPath(NULL)
56
  {
57
  }
58
 
59
  cpcicc32(char *szPath) : m_nLastError(0), m_handle(0), m_cszPath(szPath)
60
  {
61
  }
62
 
63
  ~cpcicc32()
64
  {
65
    cc32_close(m_handle);
66
  }
67
 
68
  /* gives the last error */
69
  inline int getLastError(void)
70
  {
71
    return m_nLastError;
72
  }
73
 
74
  /* open a path to a device. E.g. "/dev/pcicc32_1" */
75
  inline int open(void)
76
  {
77
    return m_nLastError = cc32_open(m_cszPath, &m_handle);
78
  }
79
 
80
  /* open a path to a device. E.g. "/dev/pcicc32_1" */
81
  inline int open(char *cszPath)
82
  {
83
    m_cszPath = cszPath;
84
    return m_nLastError = cc32_open(cszPath, &m_handle);
85
  }
86
 
87
  /* close the opened path */
88
  inline int close(void)
89
  {
90
    m_nLastError = cc32_close(m_handle);
91
 
92
    if (!m_nLastError)
93
      m_handle = NULL;
94
 
95
    return m_nLastError;
96
  }
97
 
98
  /* read only a word - 16 bits - from a address made out of N,A,F */
99
  inline void read(unsigned int N, unsigned int A, unsigned int F, __u16 &uwData)
100
  {
101
    uwData = cc32_read_word(m_handle, N, A, F);
102
  }
103
 
104
  /* read a long - 32 bits - without any interpretaion */
105
  inline void read(unsigned int N, unsigned int A, unsigned int F, __u32 &ulData)
106
  {
107
    ulData = cc32_read_long_all(m_handle, N, A, F);
108
  }
109
 
110
  /* read a long - 32 bits - from a address made out of N,A,F and get the result Q and X */
111
  inline void read(unsigned int N, unsigned int A, unsigned int F, __u32 &ulData, int &Q, int &X)
112
  {
113
    ulData = cc32_read_long_qx(m_handle, N, A,F, &Q, &X);
114
  }
115
 
116
  /* write a word - 16 bits - to a destination made out of N,A,F */
117
  inline void write(unsigned int N, unsigned int A, unsigned int F, __u16 uwData)
118
  {
119
    cc32_write_word(m_handle, N, A, F, uwData);
120
  }
121
 
122
  /* write a long - 32 bits - uninterpreted to a destination made out of N,A,F */
123
  inline void write(unsigned int N, unsigned int A, unsigned int F, __u32 ulData)
124
  {
125
    cc32_write_long(m_handle, N, A, F, ulData);
126
  }
127
 
128
  /* poll the state of the timeout line and the LAM state. The timeout line is cleared if it was set */
129
  inline int poll_event(int &nTimeout, int &nLam)
130
  {
131
    return m_nLastError = cc32_poll_event(m_handle, &nTimeout, &nLam);
132
  }
133
 
134
  /* control interrupts caused by timeouts or LAMs */
135
  inline int interrupt_disable(void)
136
  {
137
    return m_nLastError = cc32_interrupt_disable(m_handle);
138
  }
139
 
140
  inline int interrupt_enable(void)
141
  {
142
    return m_nLastError = cc32_interrupt_enable(m_handle);
143
  }
144
 
145
  /* same as cc32_poll_event(), but wait for a state change of timeout or LAMs. */
146
  inline int wait_event(int &nTimeout, int &nLam)
147
  {
148
    return m_nLastError = cc32_wait_event(m_handle, &nTimeout, &nLam);
149
  }
150
 
151
  /* switch cc32 autoread on or off - return the last switch state */
152
  inline int autoread_on(void)
153
  {
154
    return m_nLastError = cc32_autoread_on(m_handle);
155
  }
156
 
157
  inline int autoread_off(void)
158
  {
159
    return m_nLastError = cc32_autoread_off(m_handle);
160
  }  
161
};
162
 
163
#endif // __CPCICC32_H__