| [3537] | 1 | #include "pciewrap.h"
 | 
|---|
| [3623] | 2 | #include "brpaqu.h"
 | 
|---|
| [3537] | 3 | 
 | 
|---|
| [3623] | 4 | #include "racqumem.h"
 | 
|---|
 | 5 | 
 | 
|---|
| [3537] | 6 | #include <stdlib.h>
 | 
|---|
 | 7 | #include <stdio.h>
 | 
|---|
| [3639] | 8 | #include <string.h>
 | 
|---|
| [3537] | 9 | #include <math.h>
 | 
|---|
 | 10 | #include <iostream>
 | 
|---|
 | 11 | 
 | 
|---|
| [3683] | 12 | using namespace SOPHYA;
 | 
|---|
 | 13 | 
 | 
|---|
| [3909] | 14 | //-----------------------------------------------------------------------
 | 
|---|
 | 15 | //  Classe PCIEWrapperInterface  ( virtuelle pure ) 
 | 
|---|
 | 16 | //-----------------------------------------------------------------------
 | 
|---|
| [4016] | 17 | /*!
 | 
|---|
 | 18 |    \class PCIEWrapperInterface
 | 
|---|
 | 19 |    \ingroup TAcq
 | 
|---|
| [3909] | 20 | 
 | 
|---|
| [4016] | 21 |    \brief Interface definition class for PCI-Express DMA controler 
 | 
|---|
 | 22 | */ 
 | 
|---|
 | 23 | 
 | 
|---|
| [3628] | 24 | /* --Methode-- */
 | 
|---|
| [3909] | 25 | PCIEWrapperInterface::PCIEWrapperInterface()
 | 
|---|
 | 26 | {
 | 
|---|
 | 27 |   SetMaxWaitEndDMA();
 | 
|---|
 | 28 | }
 | 
|---|
 | 29 | 
 | 
|---|
 | 30 | /* --Methode-- */
 | 
|---|
 | 31 | PCIEWrapperInterface::~PCIEWrapperInterface()
 | 
|---|
 | 32 | {
 | 
|---|
 | 33 | }
 | 
|---|
 | 34 | 
 | 
|---|
 | 35 | /* --Methode-- */
 | 
|---|
 | 36 | unsigned 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 | //------------------------------------------------------------------
 | 
|---|
| [4016] | 45 | /*!
 | 
|---|
 | 46 |    \class TestPCIWrapperNODMA
 | 
|---|
 | 47 |    \ingroup TAcq
 | 
|---|
 | 48 | 
 | 
|---|
 | 49 |    \brief PCIEWrapperInterface implementation WITHOUT DMA for tests. 
 | 
|---|
 | 50 | */ 
 | 
|---|
 | 51 | 
 | 
|---|
| [3909] | 52 | /* --Methode-- */
 | 
|---|
| [3645] | 53 | TestPCIWrapperNODMA::TestPCIWrapperNODMA(UInt32 sz, double lossrate) 
 | 
|---|
| [3628] | 54 |   : PCIEWrapperInterface() , size_(sz)
 | 
|---|
| [3537] | 55 | {
 | 
|---|
| [3623] | 56 |   data_ = new Byte[size_];
 | 
|---|
| [3631] | 57 |   srcdata_ = new Byte[10*size_];
 | 
|---|
 | 58 |   for(UInt32 kk=0; kk<10*size_; kk++)
 | 
|---|
 | 59 |     srcdata_[kk] = (Byte)(kk%200+20);
 | 
|---|
| [3623] | 60 |   frame_counter_ = 0;
 | 
|---|
 | 61 |   timetag_ = 0;
 | 
|---|
| [3645] | 62 |   tottransfer_ = 0;
 | 
|---|
| [3909] | 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;
 | 
|---|
| [3537] | 69 | }
 | 
|---|
 | 70 | 
 | 
|---|
| [3628] | 71 | /* --Methode-- */
 | 
|---|
| [3623] | 72 | TestPCIWrapperNODMA::~TestPCIWrapperNODMA()
 | 
|---|
| [3537] | 73 | {
 | 
|---|
| [3631] | 74 |   delete[] data_;
 | 
|---|
 | 75 |   delete[] srcdata_;    
 | 
|---|
| [3537] | 76 | }
 | 
|---|
 | 77 | 
 | 
|---|
| [3628] | 78 | /* --Methode-- */
 | 
|---|
| [3623] | 79 | UInt32 TestPCIWrapperNODMA::TransferSize()
 | 
|---|
 | 80 | {
 | 
|---|
 | 81 |   return size_; 
 | 
|---|
 | 82 | }
 | 
|---|
| [3537] | 83 | 
 | 
|---|
| [3628] | 84 | /* --Methode-- */
 | 
|---|
| [3623] | 85 | UInt64 TestPCIWrapperNODMA::TotTransferBytes()
 | 
|---|
 | 86 | {
 | 
|---|
 | 87 |   return tottransfer_;
 | 
|---|
 | 88 | }
 | 
|---|
| [3537] | 89 | 
 | 
|---|
| [3628] | 90 | /* --Methode-- */
 | 
|---|
| [3643] | 91 | Byte* TestPCIWrapperNODMA::GetData()
 | 
|---|
| [3537] | 92 | {
 | 
|---|
| [3911] | 93 |   if ((max_frcount_>0)&&(frame_counter_>max_frcount_))  return NULL;
 | 
|---|
| [3909] | 94 |   if (lossrate_ > 1.e-9) {
 | 
|---|
| [3645] | 95 |     UInt32 dfc = 1; 
 | 
|---|
 | 96 |     while (rg_.Flat01()<lossrate_)  dfc++;
 | 
|---|
 | 97 |     frame_counter_ += dfc;
 | 
|---|
 | 98 |   }
 | 
|---|
 | 99 |   else frame_counter_ ++;
 | 
|---|
| [3623] | 100 |   timetag_ = frame_counter_ * size_ / 2;
 | 
|---|
 | 101 |   BRPaquet paq(data_, size_);
 | 
|---|
 | 102 |   paq.SetHDRMarker64(pchk_.HDRTag());
 | 
|---|
 | 103 |   paq.SetTRLMarker64(pchk_.TRLTag());
 | 
|---|
| [3671] | 104 |   UInt16 cfc = (frame_counter_%65535);
 | 
|---|
 | 105 |   paq.SetFrameCounter(cfc);
 | 
|---|
| [3623] | 106 |   paq.SetTimeTag(timetag_);
 | 
|---|
 | 107 |   paq.SetPaqLen((UInt16)((size_ - BRHDRSIZE - BRTRLSIZE)/4));
 | 
|---|
 | 108 |   Byte* bp = paq.Data1();
 | 
|---|
| [3625] | 109 | /*
 | 
|---|
| [3623] | 110 |   for(UInt32 kk=0; kk<paq.DataSize(); kk++) 
 | 
|---|
 | 111 |     bp[kk] = (Byte)(sin(0.0345*kk)*78.+127.5);
 | 
|---|
| [3626] | 112 |   UInt32 kkmax = paq.DataSize();
 | 
|---|
 | 113 |   for(UInt32 kk=0; kk<kkmax; kk++)
 | 
|---|
| [3625] | 114 |     bp[kk] = (Byte)(kk%200+20);
 | 
|---|
| [3631] | 115 | */
 | 
|---|
 | 116 |   UInt32 off = (frame_counter_*size_/3)%(9*size_);
 | 
|---|
 | 117 |   memcpy(bp, srcdata_+off, paq.DataSize());
 | 
|---|
| [3623] | 118 |   tottransfer_ += size_;
 | 
|---|
 | 119 |   return data_;
 | 
|---|
| [3537] | 120 | }
 | 
|---|
 | 121 | 
 | 
|---|
| [3628] | 122 | /* --Methode-- */
 | 
|---|
| [3623] | 123 | void TestPCIWrapperNODMA::PrintStatus(ostream& os) 
 | 
|---|
| [3537] | 124 | {
 | 
|---|
| [3623] | 125 |   os << "TestPCIWrapperNODMA::Status, FrameCounter=" << frame_counter_ 
 | 
|---|
 | 126 |      << " TimeTag=" << timetag_ << endl;
 | 
|---|
| [3639] | 127 | }
 | 
|---|