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

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.61/] [tools/] [src/] [librlink/] [RtimerFd.cpp] - Diff between revs 19 and 26

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 19 Rev 26
// $Id: RtimerFd.cpp 488 2013-02-16 18:49:47Z mueller $
// $Id: RtimerFd.cpp 488 2013-02-16 18:49:47Z mueller $
//
//
// Copyright 2013- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
// Copyright 2013- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
//
//
// This program is free software; you may redistribute and/or modify it under
// This program is free software; you may redistribute and/or modify it under
// the terms of the GNU General Public License as published by the Free
// the terms of the GNU General Public License as published by the Free
// Software Foundation, either version 2, or at your option any later version.
// Software Foundation, either version 2, or at your option any later version.
//
//
// This program is distributed in the hope that it will be useful, but
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for complete details.
// for complete details.
// 
// 
// Revision History: 
// Revision History: 
// Date         Rev Version  Comment
// Date         Rev Version  Comment
// 2013-01-11   473   1.0    Initial version
// 2013-01-11   473   1.0    Initial version
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
 
 
/*!
/*!
  \file
  \file
  \version $Id: RtimerFd.cpp 488 2013-02-16 18:49:47Z mueller $
  \version $Id: RtimerFd.cpp 488 2013-02-16 18:49:47Z mueller $
  \brief   Implemenation of class RtimerFd.
  \brief   Implemenation of class RtimerFd.
*/
*/
 
 
#include <errno.h>
#include <errno.h>
#include <unistd.h>
#include <unistd.h>
#include <sys/timerfd.h>
#include <sys/timerfd.h>
 
 
#include "RtimerFd.hpp"
#include "RtimerFd.hpp"
 
 
#include "librtools/Rexception.hpp"
#include "librtools/Rexception.hpp"
 
 
using namespace std;
using namespace std;
 
 
/*!
/*!
  \class Retro::RtimerFd
  \class Retro::RtimerFd
  \brief FIXME_docs
  \brief FIXME_docs
*/
*/
 
 
// all method definitions in namespace Retro
// all method definitions in namespace Retro
namespace Retro {
namespace Retro {
 
 
//------------------------------------------+-----------------------------------
//------------------------------------------+-----------------------------------
//! FIXME_docs
//! FIXME_docs
 
 
RtimerFd::RtimerFd()
RtimerFd::RtimerFd()
{
{
  fFd = timerfd_create(CLOCK_MONOTONIC,0);  // use MONOTONIC; no flags
  fFd = timerfd_create(CLOCK_MONOTONIC,0);  // use MONOTONIC; no flags
  if (fFd < 0)
  if (fFd < 0)
    throw Rexception("RtimerFd::<ctor>", "timerfd() failed: ", errno);
    throw Rexception("RtimerFd::<ctor>", "timerfd() failed: ", errno);
}
}
 
 
//------------------------------------------+-----------------------------------
//------------------------------------------+-----------------------------------
//! FIXME_docs
//! FIXME_docs
 
 
RtimerFd::~RtimerFd()
RtimerFd::~RtimerFd()
{
{
  close(fFd);
  close(fFd);
}
}
 
 
//------------------------------------------+-----------------------------------
//------------------------------------------+-----------------------------------
//! FIXME_docs
//! FIXME_docs
 
 
void RtimerFd::SetRelTimer(boost::posix_time::time_duration interval,
void RtimerFd::SetRelTimer(boost::posix_time::time_duration interval,
                           boost::posix_time::time_duration initial)
                           boost::posix_time::time_duration initial)
{
{
  itimerspec  its;
  itimerspec  its;
  itimerspec  old;
  itimerspec  old;
  long sf = 1000000000/interval.ticks_per_second();
  long sf = 1000000000/interval.ticks_per_second();
  its.it_interval.tv_sec  = interval.total_seconds();
  its.it_interval.tv_sec  = interval.total_seconds();
  its.it_interval.tv_nsec = interval.fractional_seconds() * sf;
  its.it_interval.tv_nsec = interval.fractional_seconds() * sf;
  its.it_value.tv_sec     = initial.total_seconds();
  its.it_value.tv_sec     = initial.total_seconds();
  its.it_value.tv_nsec    = initial.fractional_seconds() * sf;
  its.it_value.tv_nsec    = initial.fractional_seconds() * sf;
  int irc = timerfd_settime(fFd, 0, &its, &old);
  int irc = timerfd_settime(fFd, 0, &its, &old);
  if (irc < 0)
  if (irc < 0)
    throw Rexception("RtimerFd::SetRelTimer()", "timerfd() failed: ", errno);
    throw Rexception("RtimerFd::SetRelTimer()", "timerfd() failed: ", errno);
  return;
  return;
}
}
 
 
} // end namespace Retro
} // end namespace Retro
 
 

powered by: WebSVN 2.1.0

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