source: Sophya/trunk/AddOn/TAcq/pciewrap.cc@ 4016

Last change on this file since 4016 was 4016, checked in by ansari, 14 years ago

Ajout de commentaires d'autodocumentation Doxygen, Reza 12/08/2011

File size: 3.2 KB
Line 
1#include "pciewrap.h"
2#include "brpaqu.h"
3
4#include "racqumem.h"
5
6#include <stdlib.h>
7#include <stdio.h>
8#include <string.h>
9#include <math.h>
10#include <iostream>
11
12using namespace SOPHYA;
13
14//-----------------------------------------------------------------------
15// Classe PCIEWrapperInterface ( virtuelle pure )
16//-----------------------------------------------------------------------
17/*!
18 \class PCIEWrapperInterface
19 \ingroup TAcq
20
21 \brief Interface definition class for PCI-Express DMA controler
22*/
23
24/* --Methode-- */
25PCIEWrapperInterface::PCIEWrapperInterface()
26{
27 SetMaxWaitEndDMA();
28}
29
30/* --Methode-- */
31PCIEWrapperInterface::~PCIEWrapperInterface()
32{
33}
34
35/* --Methode-- */
36unsigned long PCIEWrapperInterface::SetMaxWaitEndDMA(unsigned int maxkwedma, unsigned int nretry)
37{
38 if (maxkwedma>1) { maxwaitenddmaloop_=maxkwedma*1000; maxretryenddma_=nretry; }
39 return maxwaitenddmaloop_;
40}
41
42//------------------------------------------------------------------
43// Classe TestPCIWrapperNODMA : genere des paquets sans appel au DMA
44//------------------------------------------------------------------
45/*!
46 \class TestPCIWrapperNODMA
47 \ingroup TAcq
48
49 \brief PCIEWrapperInterface implementation WITHOUT DMA for tests.
50*/
51
52/* --Methode-- */
53TestPCIWrapperNODMA::TestPCIWrapperNODMA(UInt32 sz, double lossrate)
54 : PCIEWrapperInterface() , size_(sz)
55{
56 data_ = new Byte[size_];
57 srcdata_ = new Byte[10*size_];
58 for(UInt32 kk=0; kk<10*size_; kk++)
59 srcdata_[kk] = (Byte)(kk%200+20);
60 frame_counter_ = 0;
61 timetag_ = 0;
62 tottransfer_ = 0;
63 if (lossrate<0.) lossrate=-lossrate;
64 max_frcount_=(UInt32)lossrate;
65 lossrate_ = lossrate-(double)max_frcount_;
66 if (lossrate_<1.e-9) lossrate_=0.;
67 cout << " TestPCIWrapperNODMA(PaqSz=" << sz << ",LossRate=" << lossrate
68 << " MaxFrameCount=" << max_frcount_ << ")" << endl;
69}
70
71/* --Methode-- */
72TestPCIWrapperNODMA::~TestPCIWrapperNODMA()
73{
74 delete[] data_;
75 delete[] srcdata_;
76}
77
78/* --Methode-- */
79UInt32 TestPCIWrapperNODMA::TransferSize()
80{
81 return size_;
82}
83
84/* --Methode-- */
85UInt64 TestPCIWrapperNODMA::TotTransferBytes()
86{
87 return tottransfer_;
88}
89
90/* --Methode-- */
91Byte* TestPCIWrapperNODMA::GetData()
92{
93 if ((max_frcount_>0)&&(frame_counter_>max_frcount_)) return NULL;
94 if (lossrate_ > 1.e-9) {
95 UInt32 dfc = 1;
96 while (rg_.Flat01()<lossrate_) dfc++;
97 frame_counter_ += dfc;
98 }
99 else frame_counter_ ++;
100 timetag_ = frame_counter_ * size_ / 2;
101 BRPaquet paq(data_, size_);
102 paq.SetHDRMarker64(pchk_.HDRTag());
103 paq.SetTRLMarker64(pchk_.TRLTag());
104 UInt16 cfc = (frame_counter_%65535);
105 paq.SetFrameCounter(cfc);
106 paq.SetTimeTag(timetag_);
107 paq.SetPaqLen((UInt16)((size_ - BRHDRSIZE - BRTRLSIZE)/4));
108 Byte* bp = paq.Data1();
109/*
110 for(UInt32 kk=0; kk<paq.DataSize(); kk++)
111 bp[kk] = (Byte)(sin(0.0345*kk)*78.+127.5);
112 UInt32 kkmax = paq.DataSize();
113 for(UInt32 kk=0; kk<kkmax; kk++)
114 bp[kk] = (Byte)(kk%200+20);
115*/
116 UInt32 off = (frame_counter_*size_/3)%(9*size_);
117 memcpy(bp, srcdata_+off, paq.DataSize());
118 tottransfer_ += size_;
119 return data_;
120}
121
122/* --Methode-- */
123void TestPCIWrapperNODMA::PrintStatus(ostream& os)
124{
125 os << "TestPCIWrapperNODMA::Status, FrameCounter=" << frame_counter_
126 << " TimeTag=" << timetag_ << endl;
127}
Note: See TracBrowser for help on using the repository browser.