AFHBA404
AFHBA404 connects ACQ2106 to PCI-Express
RTM_T_Device.h
Go to the documentation of this file.
1 /*
2  * RTM_T_Device.h
3  *
4  * Created on: Apr 28, 2011
5  * Author: pgm
6  */
7 
8 #ifndef RTM_T_DEVICE_H_
9 #define RTM_T_DEVICE_H_
10 
11 #include <map>
12 #include <string>
13 
14 #include <fcntl.h>
15 #include <unistd.h>
16 
17 class RTM_T_Device {
18  enum { CTRL_ROOT=-1, MINOR_REGREAD=253, MINOR_DMAREAD=254 };
19 
20  std::map<int, std::string> names;
21  std::map<int, void*> host_buffers;
22  std::map<int, int> handles;
23 
24  void _open(int id, int mode = O_RDWR){
25  int fp = open(names[id].c_str(), mode);
26 
27  if (fp == -1){
28  perror(names[id].c_str());
29  _exit(errno);
30  }else{
31  handles[id] = fp;
32  }
33  }
34 
35  void _close(void){
36  std::map<int, int>::const_iterator iter;
37 
38  for (iter = handles.begin(); iter != handles.end(); ++iter){
39  close(iter->second);
40  }
41  }
42 
43 public:
44  const unsigned devnum;
45  const unsigned nbuffers;
46  const unsigned maxlen;
47  const unsigned transfer_buffers;
48 
49  RTM_T_Device(int _devnum);
50  virtual ~RTM_T_Device() {
51  _close();
52  }
53  const char *getDevice(void) {
54  return names[MINOR_DMAREAD].c_str();
55  }
56  const int getDeviceHandle(void) {
57  return handles[MINOR_DMAREAD];
58  }
59  const char *getRegsDevice(void) {
60  return names[MINOR_REGREAD].c_str();
61  }
62  const void *getHostBufferMapping(int ibuf = 0) {
63  return host_buffers[ibuf];
64  }
65  void *getHostBufferMappingW(int ibuf = 0) {
66  return host_buffers[ibuf];
67  }
68 
69  const char *getControlRoot(void) {
70  return names[CTRL_ROOT].c_str();
71  }
72  int getDevnum(void) const {
73  return devnum;
74  }
75  int next(int ibuf){
76  return ++ibuf == nbuffers? 0: ibuf;
77  }
78 
79  enum {
80  MAXBUF = 32 // maximum buffers per read
81  };
82 
83 };
84 
85 #endif /* RTM_T_DEVICE_H_ */
RTM_T_Device::nbuffers
const unsigned nbuffers
Definition: RTM_T_Device.h:45
RTM_T_Device::getHostBufferMapping
const void * getHostBufferMapping(int ibuf=0)
Definition: RTM_T_Device.h:62
RTM_T_Device::next
int next(int ibuf)
Definition: RTM_T_Device.h:75
RTM_T_Device::RTM_T_Device
RTM_T_Device(int _devnum)
Definition: RTM_T_Device.cpp:30
RTM_T_Device::getHostBufferMappingW
void * getHostBufferMappingW(int ibuf=0)
Definition: RTM_T_Device.h:65
RTM_T_Device::~RTM_T_Device
virtual ~RTM_T_Device()
Definition: RTM_T_Device.h:50
RTM_T_Device::getDevnum
int getDevnum(void) const
Definition: RTM_T_Device.h:72
RTM_T_Device::maxlen
const unsigned maxlen
Definition: RTM_T_Device.h:46
RTM_T_Device::getDeviceHandle
const int getDeviceHandle(void)
Definition: RTM_T_Device.h:56
RTM_T_Device::getControlRoot
const char * getControlRoot(void)
Definition: RTM_T_Device.h:69
RTM_T_Device::getRegsDevice
const char * getRegsDevice(void)
Definition: RTM_T_Device.h:59
RTM_T_Device::MAXBUF
@ MAXBUF
Definition: RTM_T_Device.h:80
RTM_T_Device::transfer_buffers
const unsigned transfer_buffers
Definition: RTM_T_Device.h:47
RTM_T_Device::devnum
const unsigned devnum
Definition: RTM_T_Device.h:44
RTM_T_Device
Definition: RTM_T_Device.h:17
RTM_T_Device::getDevice
const char * getDevice(void)
Definition: RTM_T_Device.h:53