F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
LinuxTimerComponentImplTimerFd.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title LinuxTimerImpl.cpp
3 // \author tim
4 // \brief cpp file for LinuxTimer component implementation class
5 //
6 // \copyright
7 // Copyright 2009-2015, by the California Institute of Technology.
8 // ALL RIGHTS RESERVED. United States Government Sponsorship
9 // acknowledged.
10 //
11 // ======================================================================
12 
13 #include <Fw/Logger/Logger.hpp>
15 #include <FpConfig.hpp>
16 #include <sys/timerfd.h>
17 #include <unistd.h>
18 #include <cerrno>
19 #include <cstring>
20 
21 namespace Svc {
22 
24  int fd;
25  struct itimerspec itval;
26 
27  /* Create the timer */
28  fd = timerfd_create (CLOCK_MONOTONIC, 0);
29 
30  itval.it_interval.tv_sec = interval/1000;
31  itval.it_interval.tv_nsec = (interval*1000000)%1000000000;
32  itval.it_value.tv_sec = interval/1000;
33  itval.it_value.tv_nsec = (interval*1000000)%1000000000;
34 
35  timerfd_settime (fd, 0, &itval, nullptr);
36 
37  while (true) {
38  unsigned long long missed;
39  int ret = read (fd, &missed, sizeof (missed));
40  if (-1 == ret) {
41  Fw::Logger::logMsg("timer read error: %s\n", reinterpret_cast<POINTER_CAST>(strerror(errno)));
42  }
43  this->m_mutex.lock();
44  bool quit = this->m_quit;
45  this->m_mutex.unLock();
46  if (quit) {
47  itval.it_interval.tv_sec = 0;
48  itval.it_interval.tv_nsec = 0;
49  itval.it_value.tv_sec = 0;
50  itval.it_value.tv_nsec = 0;
51 
52  timerfd_settime (fd, 0, &itval, nullptr);
53  return;
54  }
55  this->m_timer.take();
56  this->CycleOut_out(0,this->m_timer);
57  }
58  }
59 
60 } // end namespace Svc
PlatformPointerCastType POINTER_CAST
Definition: BasicTypes.h:53
PlatformIntType NATIVE_INT_TYPE
Definition: BasicTypes.h:51
C++-compatible configuration header for fprime configuration.
static void logMsg(const char *fmt, POINTER_CAST a0=0, POINTER_CAST a1=0, POINTER_CAST a2=0, POINTER_CAST a3=0, POINTER_CAST a4=0, POINTER_CAST a5=0, POINTER_CAST a6=0, POINTER_CAST a7=0, POINTER_CAST a8=0, POINTER_CAST a9=0)
Definition: Logger.cpp:18
void unLock()
unlock the mutex
Definition: Mutex.cpp:13
void lock()
lock the mutex
Definition: Mutex.cpp:12
void CycleOut_out(NATIVE_INT_TYPE portNum, Svc::TimerVal &cycleStart)
Invoke output port CycleOut.
void startTimer(NATIVE_INT_TYPE interval)
Start timer.
void take()
Function to store a timer value.
Definition: TimerVal.cpp:38