<div dir="ltr"><div>The code i wrote is  not based on  my previous patch. I ran the same commands in the guide as well as my first patch:</div><div><br></div><div>git add <br></div><div>git commit <br></div><div> git send-email --to=<a href="mailto:devel@rtems.org" target="_blank">devel@rtems.org</a> -1      <br></div><div><br></div><div>is there a  way to only submit the second patch? I tried to delete the patch file before sending the first patch <br></div><div>Also, I have made changes to reduce code duplication. The structure of the code has changed so I had to format things. <br></div><div><br></div><div><br></div><div>Thanks <br></div><font style="--darkreader-inline-color:#9d9488;" color="#888888"><div>Zack <br></div><div><br><br></div></font></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, 15 Jul 2021 at 15:29, Gedare Bloom <<a href="mailto:gedare@rtems.org">gedare@rtems.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">The first line of the commit should be shorter. Use a blank line, and<br>
then close the ticket with the Closes #nnnn command.<br>
<br>
<a href="https://devel.rtems.org/wiki/Developer/Git#GitCommits" rel="noreferrer" target="_blank">https://devel.rtems.org/wiki/Developer/Git#GitCommits</a><br>
<br>
We need to move this information into<br>
<a href="https://docs.rtems.org/branches/master/eng/management.html" rel="noreferrer" target="_blank">https://docs.rtems.org/branches/master/eng/management.html</a><br>
<br>
<br>
On Thu, Jul 8, 2021 at 1:50 PM Zacchaeus Leung <<a href="mailto:zakthertemsdev@gmail.com" target="_blank">zakthertemsdev@gmail.com</a>> wrote:<br>
><br>
> ---<br>
>  ...or-timer_create-with-clock_monotonic.patch | 234 ++++++++++++++++++<br>
>  cpukit/include/rtems/posix/timer.h            |   2 +-<br>
>  cpukit/posix/src/psxtimercreate.c             |  86 +++----<br>
>  cpukit/posix/src/timergettime.c               |  76 ++----<br>
>  4 files changed, 300 insertions(+), 98 deletions(-)<br>
>  create mode 100644 0001-Addded-test-for-timer_create-with-clock_monotonic.patch<br>
><br>
> diff --git a/0001-Addded-test-for-timer_create-with-clock_monotonic.patch b/0001-Addded-test-for-timer_create-with-clock_monotonic.patch<br>
> new file mode 100644<br>
> index 0000000000..33be528411<br>
> --- /dev/null<br>
> +++ b/0001-Addded-test-for-timer_create-with-clock_monotonic.patch<br>
> @@ -0,0 +1,234 @@<br>
> +From f1cac2a4b64e5076f0ceff014b78be41e5f00389 Mon Sep 17 00:00:00 2001<br>
> +From: Zack <<a href="mailto:zakthertemsdev@outlook.com" target="_blank">zakthertemsdev@outlook.com</a>><br>
> +Date: Mon, 28 Jun 2021 14:23:42 -0400<br>
> +Subject: [PATCH] Addded test for timer_create with clock_monotonic<br>
> +<br>
<br>
It seems that you have included a patch within your patch. Please<br>
check your commit before you email it, to make sure only the changes<br>
you want included are there. Since I'm not sure what changes you are<br>
intending to send, I'm going to stop here.<br>
<br>
A few general comments:<br>
<br>
Avoid reformatting existing code. Keep your changes limited to<br>
functional changes only, and send reformatting/documentation changes<br>
separately. Make sure you write new code consistently to our style<br>
guide. (<a href="https://docs.rtems.org/branches/master/eng/coding.html" rel="noreferrer" target="_blank">https://docs.rtems.org/branches/master/eng/coding.html</a>) If in<br>
doubt, write your code consistent with code near it.<br>
<br>
Provide all the patches for your commits that go from the current HEAD<br>
(most recent commit on master). We can't review commits that are based<br>
on other commits on your local repo only, unless you include those<br>
commits also for review.<br>
<br>
> +---<br>
> + cpukit/include/rtems/posix/timer.h        |  1 +<br>
> + cpukit/posix/src/psxtimercreate.c         |  5 +-<br>
> + cpukit/posix/src/timergettime.c           | 79 ++++++++++++++++-------<br>
> + testsuites/psxtests/psxtimer02/psxtimer.c | 38 ++++++++++-<br>
> + 4 files changed, 98 insertions(+), 25 deletions(-)<br>
> +<br>
> +diff --git a/cpukit/include/rtems/posix/timer.h b/cpukit/include/rtems/posix/timer.h<br>
> +index bcbf07a65a..839fe3293c 100644<br>
> +--- a/cpukit/include/rtems/posix/timer.h<br>
> ++++ b/cpukit/include/rtems/posix/timer.h<br>
> +@@ -48,6 +48,7 @@ typedef struct {<br>
> +   uint32_t          ticks;      /* Number of ticks of the initialization */<br>
> +   uint32_t          overrun;    /* Number of expirations of the timer    */<br>
> +   struct timespec   time;       /* Time at which the timer was started   */<br>
> ++    clockid_t     clock_type;<br>
> + } POSIX_Timer_Control;<br>
> +<br>
> + /**<br>
> +diff --git a/cpukit/posix/src/psxtimercreate.c b/cpukit/posix/src/psxtimercreate.c<br>
> +index a63cf1d100..b60be3f229 100644<br>
> +--- a/cpukit/posix/src/psxtimercreate.c<br>
> ++++ b/cpukit/posix/src/psxtimercreate.c<br>
> +@@ -40,7 +40,7 @@ int timer_create(<br>
> + {<br>
> +   POSIX_Timer_Control *ptimer;<br>
> +<br>
> +-  if ( clock_id != CLOCK_REALTIME )<br>
> ++  if ( clock_id != CLOCK_REALTIME && clock_id != CLOCK_MONOTONIC  )<br>
> +     rtems_set_errno_and_return_minus_one( EINVAL );<br>
> +<br>
> +   if ( !timerid )<br>
> +@@ -91,7 +91,8 @@ int timer_create(<br>
> +   ptimer->timer_data.it_value.tv_nsec    = 0;<br>
> +   ptimer->timer_data.it_interval.tv_sec  = 0;<br>
> +   ptimer->timer_data.it_interval.tv_nsec = 0;<br>
> +-<br>
> ++  ptimer->clock_type=clock_id;<br>
> ++<br>
> +   _Watchdog_Preinitialize( &ptimer->Timer, _Per_CPU_Get_snapshot() );<br>
> +   _Watchdog_Initialize( &ptimer->Timer, _POSIX_Timer_TSR );<br>
> +   _Objects_Open_u32(&_POSIX_Timer_Information, &ptimer->Object, 0);<br>
> +diff --git a/cpukit/posix/src/timergettime.c b/cpukit/posix/src/timergettime.c<br>
> +index ee2a566f0e..57b0ab4918 100644<br>
> +--- a/cpukit/posix/src/timergettime.c<br>
> ++++ b/cpukit/posix/src/timergettime.c<br>
> +@@ -6,6 +6,14 @@<br>
> +  * @brief Function Fetches State of POSIX Per-Process Timers<br>
> +  */<br>
> +<br>
> ++/**<br>
> ++ * @file<br>
> ++ *<br>
> ++ * @ingroup POSIXAPI<br>
> ++ *<br>
> ++ * @brief Function Fetches State of POSIX Per-Process Timers<br>
> ++ */<br>
> ++<br>
> + /*<br>
> +  *  14.2.4 Per-Process Timers, P1003.1b-1993, p. 267<br>
> +  *<br>
> +@@ -21,13 +29,13 @@<br>
> + #include "config.h"<br>
> + #endif<br>
> +<br>
> +-#include <time.h><br>
> + #include <errno.h><br>
> +-<br>
> + #include <rtems/posix/timerimpl.h><br>
> + #include <rtems/score/todimpl.h><br>
> + #include <rtems/score/watchdogimpl.h><br>
> + #include <rtems/seterr.h><br>
> ++#include <rtems/timespec.h><br>
> ++#include <time.h><br>
> +<br>
> + /*<br>
> +  *          - When a timer is initialized, the value of the time in<br>
> +@@ -36,38 +44,65 @@<br>
> +  *            between the current time and the initialization time.<br>
> +  */<br>
> +<br>
> +-int timer_gettime(<br>
> +-  timer_t            timerid,<br>
> +-  struct itimerspec *value<br>
> +-)<br>
> +-{<br>
> ++int timer_gettime(timer_t timerid, struct itimerspec *value) {<br>
> +   POSIX_Timer_Control *ptimer;<br>
> +-  ISR_lock_Context     lock_context;<br>
> +-  uint64_t             now;<br>
> +-  uint32_t             remaining;<br>
> ++  ISR_lock_Context lock_context;<br>
> ++  uint32_t remaining;<br>
> ++  Per_CPU_Control *cpu;<br>
> ++  struct timespec *now;    // get time now either with<br>
> ++  struct timespec *expire; // expire<br>
> ++<br>
> ++  struct timespec *result;<br>
> ++<br>
> ++  if (!value)<br>
> ++    rtems_set_errno_and_return_minus_one(EINVAL);<br>
> +<br>
> +-  if ( !value )<br>
> +-    rtems_set_errno_and_return_minus_one( EINVAL );<br>
> ++  ptimer = _POSIX_Timer_Get(timerid, &lock_context);<br>
> ++  if (ptimer == NULL) {<br>
> ++    rtems_set_errno_and_return_minus_one(EINVAL);<br>
> ++  }<br>
> ++<br>
> ++  if (ptimer->clock_type == CLOCK_REALTIME) {<br>
> +<br>
> +-  ptimer = _POSIX_Timer_Get( timerid, &lock_context );<br>
> +-  if ( ptimer != NULL ) {<br>
> +-    Per_CPU_Control *cpu;<br>
> ++    cpu = _POSIX_Timer_Acquire_critical(ptimer, &lock_context);<br>
> +<br>
> +-    cpu = _POSIX_Timer_Acquire_critical( ptimer, &lock_context );<br>
> +-    now = cpu->Watchdog.ticks;<br>
> ++    _TOD_Get(now); // get current time<br>
> ++    rtems_timespec_from_ticks(ptimer->Timer.expire,<br>
> ++                              expire);<br>
> +<br>
> +-    if ( now < ptimer->Timer.expire ) {<br>
> +-      remaining = (uint32_t) ( ptimer->Timer.expire - now );<br>
> ++    if (now->tv_nsec + now->tv_sec ><br>
> ++        expire->tv_nsec + expire->tv_sec) {<br>
> ++      rtems_timespec_subtract(now, expire, result);<br>
> ++<br>
> ++      remaining = (uint32_t)result->tv_nsec + result->tv_sec;<br>
> +     } else {<br>
> +       remaining = 0;<br>
> +     }<br>
> +<br>
> +-    _Timespec_From_ticks( remaining, &value->it_value );<br>
> ++    _Timespec_From_ticks(remaining, &value->it_value);<br>
> +     value->it_interval = ptimer->timer_data.it_interval;<br>
> ++     _POSIX_Timer_Release(cpu, &lock_context);<br>
> ++    return 0;<br>
> ++  }<br>
> ++<br>
> ++  if (ptimer->clock_type == CLOCK_MONOTONIC) {<br>
> ++<br>
> ++    cpu = _POSIX_Timer_Acquire_critical(ptimer, &lock_context);<br>
> ++    rtems_timespec_from_ticks(ptimer->Timer.expire, expire);<br>
> +<br>
> +-    _POSIX_Timer_Release( cpu, &lock_context );<br>
> ++    if (now->tv_nsec + now->tv_sec > expire->tv_nsec + expire->tv_sec) {<br>
> ++<br>
> ++      rtems_timespec_subtract(now, expire, result);<br>
> ++      remaining = (uint32_t)result->tv_nsec + result->tv_sec;<br>
> ++    } else {<br>
> ++      remaining = 0;<br>
> ++    }<br>
> ++<br>
> ++    _Timespec_From_ticks(remaining, &value->it_value);<br>
> ++    value->it_interval = ptimer->timer_data.it_interval;<br>
> ++    _POSIX_Timer_Release(cpu, &lock_context);<br>
> +     return 0;<br>
> +   }<br>
> +<br>
> +-  rtems_set_errno_and_return_minus_one( EINVAL );<br>
> ++  rtems_set_errno_and_return_minus_one(EINVAL);<br>
> + }<br>
> +diff --git a/testsuites/psxtests/psxtimer02/psxtimer.c b/testsuites/psxtests/psxtimer02/psxtimer.c<br>
> +index 9f79d33c42..6aea61c498 100644<br>
> +--- a/testsuites/psxtests/psxtimer02/psxtimer.c<br>
> ++++ b/testsuites/psxtests/psxtimer02/psxtimer.c<br>
> +@@ -20,6 +20,7 @@<br>
> +  *  <a href="http://www.rtems.org/license/LICENSE" rel="noreferrer" target="_blank">http://www.rtems.org/license/LICENSE</a>.<br>
> +  */<br>
> +<br>
> ++<br>
> + #ifdef HAVE_CONFIG_H<br>
> + #include "config.h"<br>
> + #endif<br>
> +@@ -63,7 +64,7 @@ void *POSIX_Init (<br>
> +   fatal_posix_service_status_errno( status, EINVAL, "bad timer id" );<br>
> +<br>
> +   puts( "timer_create - OK" );<br>
> +-  status = timer_create( CLOCK_REALTIME, NULL, &timer );<br>
> ++  status = timer_create( CLOCK_REALTIME , NULL, &timer );<br>
> +   posix_service_failed( status, "timer_create OK" );<br>
> +<br>
> +   puts( "timer_create - too many - EAGAIN" );<br>
> +@@ -127,6 +128,41 @@ void *POSIX_Init (<br>
> +   status = timer_delete( timer );<br>
> +   fatal_posix_service_status_errno( status, EINVAL, "bad id" );<br>
> +<br>
> ++<br>
> ++  /*<br>
> ++   *  If these are not filled in correctly, we don't pass its error checking.<br>
> ++   */<br>
> ++<br>
> ++<br>
> ++puts( "timer_create - bad timer id pointer - EINVAL" );<br>
> ++  status = timer_create( CLOCK_MONOTONIC, &event, NULL );<br>
> ++  fatal_posix_service_status_errno( status, EINVAL, "bad timer id" );<br>
> ++<br>
> ++  puts( "timer_create - OK" );<br>
> ++  status = timer_create( CLOCK_MONOTONIC, NULL, &timer );<br>
> ++  posix_service_failed( status, "timer_create OK" );<br>
> ++<br>
> ++  puts( "timer_create - too many - EAGAIN" );<br>
> ++  status = timer_create( CLOCK_MONOTONIC, NULL, &timer1 );<br>
> ++  fatal_posix_service_status_errno( status, EAGAIN, "too many" );<br>
> ++<br>
> ++  clock_gettime( CLOCK_MONOTONIC, &now );<br>
> ++  itimer.it_value = now;<br>
> ++  itimer.it_value.tv_sec = itimer.it_value.tv_sec - 1;<br>
> ++  puts( "timer_settime - bad itimer value - previous time - EINVAL" );<br>
> ++  status = timer_settime( timer, TIMER_ABSTIME, &itimer, NULL );<br>
> ++  fatal_posix_service_status_errno( status, EINVAL, "bad itimer value #3" );<br>
> ++<br>
> ++ clock_gettime( CLOCK_MONOTONIC, &now );<br>
> ++  itimer.it_value = now;<br>
> ++  itimer.it_value.tv_sec = itimer.it_value.tv_sec + 1;<br>
> ++  puts( "timer_settime - bad id - EINVAL" );<br>
> ++  status = timer_settime( timer1, TIMER_ABSTIME, &itimer, NULL );<br>
> ++  fatal_posix_service_status_errno( status, EINVAL, "bad id" );<br>
> ++<br>
> ++<br>
> ++<br>
> ++<br>
> +   TEST_END();<br>
> +   rtems_test_exit (0);<br>
> + }<br>
> +--<br>
> +2.31.1<br>
> +<br>
> diff --git a/cpukit/include/rtems/posix/timer.h b/cpukit/include/rtems/posix/timer.h<br>
> index 839fe3293c..fdfa1e0b2f 100644<br>
> --- a/cpukit/include/rtems/posix/timer.h<br>
> +++ b/cpukit/include/rtems/posix/timer.h<br>
> @@ -48,7 +48,7 @@ typedef struct {<br>
>    uint32_t          ticks;      /* Number of ticks of the initialization */<br>
>    uint32_t          overrun;    /* Number of expirations of the timer    */<br>
>    struct timespec   time;       /* Time at which the timer was started   */<br>
> -    clockid_t     clock_type;<br>
> +  clockid_t     clock_type;  /* The type of timer */<br>
>  } POSIX_Timer_Control;<br>
><br>
>  /**<br>
> diff --git a/cpukit/posix/src/psxtimercreate.c b/cpukit/posix/src/psxtimercreate.c<br>
> index b60be3f229..18af8a6582 100644<br>
> --- a/cpukit/posix/src/psxtimercreate.c<br>
> +++ b/cpukit/posix/src/psxtimercreate.c<br>
> @@ -21,9 +21,9 @@<br>
>  #include "config.h"<br>
>  #endif<br>
><br>
> -#include <time.h><br>
>  #include <errno.h><br>
>  #include <signal.h><br>
> +#include <time.h><br>
><br>
>  #include <rtems/posix/sigset.h><br>
>  #include <rtems/posix/timerimpl.h><br>
> @@ -32,83 +32,73 @@<br>
>  #include <rtems/seterr.h><br>
>  #include <rtems/sysinit.h><br>
><br>
> -int timer_create(<br>
> -  clockid_t        clock_id,<br>
> -  struct sigevent *__restrict evp,<br>
> -  timer_t         *__restrict timerid<br>
> -)<br>
> -{<br>
> +int timer_create(clockid_t clock_id, struct sigevent *__restrict evp,<br>
> +                 timer_t *__restrict timerid) {<br>
>    POSIX_Timer_Control *ptimer;<br>
><br>
> -  if ( clock_id != CLOCK_REALTIME && clock_id != CLOCK_MONOTONIC  )<br>
> -    rtems_set_errno_and_return_minus_one( EINVAL );<br>
> +  if (clock_id != CLOCK_REALTIME && clock_id != CLOCK_MONOTONIC)<br>
> +    rtems_set_errno_and_return_minus_one(EINVAL);<br>
><br>
> -  if ( !timerid )<br>
> -    rtems_set_errno_and_return_minus_one( EINVAL );<br>
> +  if (!timerid)<br>
> +    rtems_set_errno_and_return_minus_one(EINVAL);<br>
><br>
> - /*<br>
> -  *  The data of the structure evp are checked in order to verify if they<br>
> -  *  are coherent.<br>
> -  */<br>
> +  /*<br>
> +   *  The data of the structure evp are checked in order to verify if they<br>
> +   *  are coherent.<br>
> +   */<br>
><br>
>    if (evp != NULL) {<br>
>      /* The structure has data */<br>
> -    if ( ( evp->sigev_notify != SIGEV_NONE ) &&<br>
> -         ( evp->sigev_notify != SIGEV_SIGNAL ) ) {<br>
> -       /* The value of the field sigev_notify is not valid */<br>
> -       rtems_set_errno_and_return_minus_one( EINVAL );<br>
> -     }<br>
> +    if ((evp->sigev_notify != SIGEV_NONE) &&<br>
> +        (evp->sigev_notify != SIGEV_SIGNAL)) {<br>
> +      /* The value of the field sigev_notify is not valid */<br>
> +      rtems_set_errno_and_return_minus_one(EINVAL);<br>
> +    }<br>
><br>
> -     if ( !evp->sigev_signo )<br>
> -       rtems_set_errno_and_return_minus_one( EINVAL );<br>
> +    if (!evp->sigev_signo)<br>
> +      rtems_set_errno_and_return_minus_one(EINVAL);<br>
><br>
> -     if ( !is_valid_signo(evp->sigev_signo) )<br>
> -       rtems_set_errno_and_return_minus_one( EINVAL );<br>
> +    if (!is_valid_signo(evp->sigev_signo))<br>
> +      rtems_set_errno_and_return_minus_one(EINVAL);<br>
>    }<br>
><br>
>    /*<br>
>     *  Allocate a timer<br>
>     */<br>
>    ptimer = _POSIX_Timer_Allocate();<br>
> -  if ( !ptimer ) {<br>
> +  if (!ptimer) {<br>
>      _Objects_Allocator_unlock();<br>
> -    rtems_set_errno_and_return_minus_one( EAGAIN );<br>
> +    rtems_set_errno_and_return_minus_one(EAGAIN);<br>
>    }<br>
><br>
>    /* The data of the created timer are stored to use them later */<br>
><br>
> -  ptimer->state     = POSIX_TIMER_STATE_CREATE_NEW;<br>
> +  ptimer->state = POSIX_TIMER_STATE_CREATE_NEW;<br>
>    ptimer->thread_id = _Thread_Get_executing()->Object.id;<br>
><br>
> -  if ( evp != NULL ) {<br>
> +  if (evp != NULL) {<br>
>      ptimer->inf.sigev_notify = evp->sigev_notify;<br>
> -    ptimer->inf.sigev_signo  = evp->sigev_signo;<br>
> -    ptimer->inf.sigev_value  = evp->sigev_value;<br>
> +    ptimer->inf.sigev_signo = evp->sigev_signo;<br>
> +    ptimer->inf.sigev_value = evp->sigev_value;<br>
>    }<br>
><br>
> -  ptimer->overrun  = 0;<br>
> -  ptimer->timer_data.it_value.tv_sec     = 0;<br>
> -  ptimer->timer_data.it_value.tv_nsec    = 0;<br>
> -  ptimer->timer_data.it_interval.tv_sec  = 0;<br>
> +  ptimer->overrun = 0;<br>
> +  ptimer->timer_data.it_value.tv_sec = 0;<br>
> +  ptimer->timer_data.it_value.tv_nsec = 0;<br>
> +  ptimer->timer_data.it_interval.tv_sec = 0;<br>
>    ptimer->timer_data.it_interval.tv_nsec = 0;<br>
> -  ptimer->clock_type=clock_id;<br>
> -<br>
> -  _Watchdog_Preinitialize( &ptimer->Timer, _Per_CPU_Get_snapshot() );<br>
> -  _Watchdog_Initialize( &ptimer->Timer, _POSIX_Timer_TSR );<br>
> +  ptimer->clock_type = clock_id;<br>
> +  _Watchdog_Preinitialize(&ptimer->Timer, _Per_CPU_Get_snapshot());<br>
> +  _Watchdog_Initialize(&ptimer->Timer, _POSIX_Timer_TSR);<br>
>    _Objects_Open_u32(&_POSIX_Timer_Information, &ptimer->Object, 0);<br>
> -<br>
> -  *timerid  = ptimer->Object.id;<br>
> +  *timerid = ptimer->Object.id;<br>
>    _Objects_Allocator_unlock();<br>
>    return 0;<br>
>  }<br>
><br>
> -static void _POSIX_Timer_Manager_initialization( void )<br>
> -{<br>
> -  _Objects_Initialize_information( &_POSIX_Timer_Information );<br>
> +static void _POSIX_Timer_Manager_initialization(void) {<br>
> +  _Objects_Initialize_information(&_POSIX_Timer_Information);<br>
>  }<br>
><br>
> -RTEMS_SYSINIT_ITEM(<br>
> -  _POSIX_Timer_Manager_initialization,<br>
> -  RTEMS_SYSINIT_POSIX_TIMER,<br>
> -  RTEMS_SYSINIT_ORDER_MIDDLE<br>
> -);<br>
> +RTEMS_SYSINIT_ITEM(_POSIX_Timer_Manager_initialization,<br>
> +                   RTEMS_SYSINIT_POSIX_TIMER, RTEMS_SYSINIT_ORDER_MIDDLE);<br>
> diff --git a/cpukit/posix/src/timergettime.c b/cpukit/posix/src/timergettime.c<br>
> index 57b0ab4918..ee9d37ccdd 100644<br>
> --- a/cpukit/posix/src/timergettime.c<br>
> +++ b/cpukit/posix/src/timergettime.c<br>
> @@ -1,10 +1,3 @@<br>
> -/**<br>
> - * @file<br>
> - *<br>
> - * @ingroup POSIXAPI<br>
> - *<br>
> - * @brief Function Fetches State of POSIX Per-Process Timers<br>
> - */<br>
><br>
>  /**<br>
>   * @file<br>
> @@ -30,12 +23,13 @@<br>
>  #endif<br>
><br>
>  #include <errno.h><br>
> +#include <time.h><br>
> +<br>
>  #include <rtems/posix/timerimpl.h><br>
>  #include <rtems/score/todimpl.h><br>
>  #include <rtems/score/watchdogimpl.h><br>
>  #include <rtems/seterr.h><br>
>  #include <rtems/timespec.h><br>
> -#include <time.h><br>
><br>
>  /*<br>
>   *          - When a timer is initialized, the value of the time in<br>
> @@ -44,15 +38,18 @@<br>
>   *            between the current time and the initialization time.<br>
>   */<br>
><br>
> -int timer_gettime(timer_t timerid, struct itimerspec *value) {<br>
> +int timer_gettime(<br>
> +  timer_t            timerid,<br>
> +  struct itimerspec *value<br>
> +)<br>
> +{<br>
>    POSIX_Timer_Control *ptimer;<br>
>    ISR_lock_Context lock_context;<br>
>    uint32_t remaining;<br>
>    Per_CPU_Control *cpu;<br>
> -  struct timespec *now;    // get time now either with<br>
> -  struct timespec *expire; // expire<br>
> -<br>
> -  struct timespec *result;<br>
> +  struct timespec *now;<br>
> +  struct timespec *expire;<br>
> +  struct timespec *result;<br>
><br>
>    if (!value)<br>
>      rtems_set_errno_and_return_minus_one(EINVAL);<br>
> @@ -62,47 +59,28 @@ int timer_gettime(timer_t timerid, struct itimerspec *value) {<br>
>      rtems_set_errno_and_return_minus_one(EINVAL);<br>
>    }<br>
><br>
> -  if (ptimer->clock_type == CLOCK_REALTIME) {<br>
> -<br>
> -    cpu = _POSIX_Timer_Acquire_critical(ptimer, &lock_context);<br>
> -<br>
> -    _TOD_Get(now); // get current time<br>
> -    rtems_timespec_from_ticks(ptimer->Timer.expire,<br>
> -                              expire);<br>
> -<br>
> -    if (now->tv_nsec + now->tv_sec ><br>
> -        expire->tv_nsec + expire->tv_sec) {<br>
> -      rtems_timespec_subtract(now, expire, result);<br>
> -<br>
> -      remaining = (uint32_t)result->tv_nsec + result->tv_sec;<br>
> -    } else {<br>
> -      remaining = 0;<br>
> -    }<br>
> -<br>
> -    _Timespec_From_ticks(remaining, &value->it_value);<br>
> -    value->it_interval = ptimer->timer_data.it_interval;<br>
> -     _POSIX_Timer_Release(cpu, &lock_context);<br>
> -    return 0;<br>
> -  }<br>
> +  cpu = _POSIX_Timer_Acquire_critical(ptimer, &lock_context);<br>
> +  rtems_timespec_from_ticks(ptimer->Timer.expire, expire);<br>
><br>
>    if (ptimer->clock_type == CLOCK_MONOTONIC) {<br>
> +  _Timecounter_Nanouptime(now);<br>
> +<br>
> +  }<br>
> +  if (ptimer->clock_type == CLOCK_REALTIME) {<br>
> +    _TOD_Get(now);<br>
> +  }<br>
><br>
> -    cpu = _POSIX_Timer_Acquire_critical(ptimer, &lock_context);<br>
> -    rtems_timespec_from_ticks(ptimer->Timer.expire, expire);<br>
> -<br>
> -    if (now->tv_nsec + now->tv_sec > expire->tv_nsec + expire->tv_sec) {<br>
><br>
> + if( rtems_timespec_less_than( now, expire )) {<br>
>        rtems_timespec_subtract(now, expire, result);<br>
> -      remaining = (uint32_t)result->tv_nsec + result->tv_sec;<br>
>      } else {<br>
> -      remaining = 0;<br>
> +      result->tv_nsec=0;<br>
> +      result->tv_sec=0;<br>
>      }<br>
> -<br>
> -    _Timespec_From_ticks(remaining, &value->it_value);<br>
> -    value->it_interval = ptimer->timer_data.it_interval;<br>
> -    _POSIX_Timer_Release(cpu, &lock_context);<br>
> -    return 0;<br>
> -  }<br>
> -<br>
> -  rtems_set_errno_and_return_minus_one(EINVAL);<br>
> +<br>
> +  (*value).it_value=*result;<br>
> +  value->it_interval = ptimer->timer_data.it_interval;<br>
> +<br>
> +  _POSIX_Timer_Release(cpu, &lock_context);<br>
> +  return 0;<br>
>  }<br>
> --<br>
> 2.32.0<br>
><br>
> _______________________________________________<br>
> devel mailing list<br>
> <a href="mailto:devel@rtems.org" target="_blank">devel@rtems.org</a><br>
> <a href="http://lists.rtems.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.rtems.org/mailman/listinfo/devel</a><br>
</blockquote></div>