summaryrefslogblamecommitdiffstats
path: root/cpukit/score/src/timespecaddto.c
blob: 363fac19eb1192aa27e46bf7f1cdd664b5232f60 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
   
        
  



                                                         


   
                            



                                                           
                                         

   
                    


                   
                                 
                                

                                 



















                                                         
/**
 * @file
 *
 * @ingroup RTEMSScoreTimespec
 *
 * @brief This source file contains the implementation of
 *   _Timespec_Add_to().
 */

/*
 *  COPYRIGHT (c) 1989-2008.
 *  On-Line Applications Research Corporation (OAR).
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.org/license/LICENSE.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <rtems/score/timespec.h>
#include <rtems/score/todimpl.h>
#include <rtems/score/watchdog.h>

uint32_t _Timespec_Add_to(
  struct timespec       *time,
  const struct timespec *add
)
{
  uint32_t seconds = add->tv_sec;

  /* Add the basics */
  time->tv_sec += add->tv_sec;
  time->tv_nsec += add->tv_nsec;

  /* Now adjust it so nanoseconds is in range */
  while ( time->tv_nsec >= TOD_NANOSECONDS_PER_SECOND ) {
    time->tv_nsec -= TOD_NANOSECONDS_PER_SECOND;
    time->tv_sec++;
    seconds++;
  }

  return seconds;
}