OpenCores
URL https://opencores.org/ocsvn/w11/w11/trunk

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.74/] [tools/] [src/] [librlink/] [RtimerFd.cpp] - Blame information for rev 38

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 wfjm
// $Id: RtimerFd.cpp 488 2013-02-16 18:49:47Z mueller $
2
//
3
// Copyright 2013- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4
//
5
// This program is free software; you may redistribute and/or modify it under
6
// the terms of the GNU General Public License as published by the Free
7
// Software Foundation, either version 2, or at your option any later version.
8
//
9
// This program is distributed in the hope that it will be useful, but
10
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
11
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
// for complete details.
13
// 
14
// Revision History: 
15
// Date         Rev Version  Comment
16
// 2013-01-11   473   1.0    Initial version
17
// ---------------------------------------------------------------------------
18
 
19
/*!
20
  \file
21
  \version $Id: RtimerFd.cpp 488 2013-02-16 18:49:47Z mueller $
22
  \brief   Implemenation of class RtimerFd.
23
*/
24
 
25
#include <errno.h>
26
#include <unistd.h>
27
#include <sys/timerfd.h>
28
 
29
#include "RtimerFd.hpp"
30
 
31
#include "librtools/Rexception.hpp"
32
 
33
using namespace std;
34
 
35
/*!
36
  \class Retro::RtimerFd
37
  \brief FIXME_docs
38
*/
39
 
40
// all method definitions in namespace Retro
41
namespace Retro {
42
 
43
//------------------------------------------+-----------------------------------
44
//! FIXME_docs
45
 
46
RtimerFd::RtimerFd()
47
{
48
  fFd = timerfd_create(CLOCK_MONOTONIC,0);  // use MONOTONIC; no flags
49
  if (fFd < 0)
50
    throw Rexception("RtimerFd::<ctor>", "timerfd() failed: ", errno);
51
}
52
 
53
//------------------------------------------+-----------------------------------
54
//! FIXME_docs
55
 
56
RtimerFd::~RtimerFd()
57
{
58
  close(fFd);
59
}
60
 
61
//------------------------------------------+-----------------------------------
62
//! FIXME_docs
63
 
64
void RtimerFd::SetRelTimer(boost::posix_time::time_duration interval,
65
                           boost::posix_time::time_duration initial)
66
{
67
  itimerspec  its;
68
  itimerspec  old;
69
  long sf = 1000000000/interval.ticks_per_second();
70
  its.it_interval.tv_sec  = interval.total_seconds();
71
  its.it_interval.tv_nsec = interval.fractional_seconds() * sf;
72
  its.it_value.tv_sec     = initial.total_seconds();
73
  its.it_value.tv_nsec    = initial.fractional_seconds() * sf;
74
  int irc = timerfd_settime(fFd, 0, &its, &old);
75
  if (irc < 0)
76
    throw Rexception("RtimerFd::SetRelTimer()", "timerfd() failed: ", errno);
77
  return;
78
}
79
 
80
} // end namespace Retro

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.