score: Fix _TOD_Set_with_timestamp()

Update the current time before the watchdog adjust so that timer
routines observe the new time.
This commit is contained in:
Sebastian Huber
2015-04-16 22:24:59 +02:00
parent c77e3cb1b0
commit a211a732fd
2 changed files with 25 additions and 19 deletions

View File

@@ -36,6 +36,11 @@ void _TOD_Set_with_timestamp(
_Thread_Disable_dispatch(); _Thread_Disable_dispatch();
seconds_now = _TOD_Seconds_since_epoch(); seconds_now = _TOD_Seconds_since_epoch();
_TOD_Acquire( tod, &lock_context );
tod->now = *tod_as_timestamp;
_TOD_Release( tod, &lock_context );
header = &_Watchdog_Seconds_header; header = &_Watchdog_Seconds_header;
if ( seconds_next < seconds_now ) if ( seconds_next < seconds_now )
@@ -43,10 +48,6 @@ void _TOD_Set_with_timestamp(
else else
_Watchdog_Adjust_forward( header, seconds_next - seconds_now ); _Watchdog_Adjust_forward( header, seconds_next - seconds_now );
_TOD_Acquire( tod, &lock_context );
tod->now = *tod_as_timestamp;
_TOD_Release( tod, &lock_context );
tod->seconds_trigger = nanoseconds; tod->seconds_trigger = nanoseconds;
tod->is_set = true; tod->is_set = true;

View File

@@ -26,29 +26,35 @@
#endif #endif
#include <tmacros.h> #include <tmacros.h>
#include <string.h>
const char rtems_test_name[] = "SP " TEST_NUMBER; const char rtems_test_name[] = "SP " TEST_NUMBER;
/* forward declarations to avoid warnings */ #define INITIAL_YEAR 2009
rtems_task Init(rtems_task_argument argument);
rtems_timer_service_routine TIMER_service_routine(
rtems_id ignored_id,
void *user_data
);
#define INITIAL_SECOND 10 static bool _timer_passage;
volatile bool _timer_passage = FALSE;
static rtems_time_of_day time_to_fire;
/*timer Routine*/ /*timer Routine*/
rtems_timer_service_routine TIMER_service_routine( static rtems_timer_service_routine TIMER_service_routine(
rtems_id ignored_id, rtems_id ignored_id,
void *user_data void *user_data
) )
{ {
_timer_passage = TRUE; rtems_status_code status;
rtems_time_of_day now;
_timer_passage = true;
memset( &now, 0, sizeof( now ) );
status = rtems_clock_get_tod( &now );
rtems_test_assert( status == RTEMS_SUCCESSFUL );
rtems_test_assert( memcmp( &now, &time_to_fire, sizeof( now ) ) == 0 );
} }
rtems_task Init( static rtems_task Init(
rtems_task_argument argument rtems_task_argument argument
) )
{ {
@@ -57,7 +63,6 @@ rtems_task Init(
rtems_name timer_name; rtems_name timer_name;
rtems_time_of_day global_time; rtems_time_of_day global_time;
rtems_time_of_day time_to_fire;
TEST_BEGIN(); TEST_BEGIN();
@@ -79,7 +84,7 @@ rtems_task Init(
#endif #endif
/* Set system clock */ /* Set system clock */
build_time(&global_time, 6, 8, 2009, 16, 5, INITIAL_SECOND, 0); build_time(&global_time, 6, 8, INITIAL_YEAR, 16, 5, 13, 0);
status = rtems_clock_set(&global_time); status = rtems_clock_set(&global_time);
directive_failed( status, "rtems_clock_set" ); directive_failed( status, "rtems_clock_set" );
@@ -88,7 +93,7 @@ rtems_task Init(
time_to_fire = global_time; time_to_fire = global_time;
/* only diferent second */ /* only diferent second */
time_to_fire.second = INITIAL_SECOND + 5; time_to_fire.year = INITIAL_YEAR + 5;
status = FIRE_WHEN( status = FIRE_WHEN(
timer_id, timer_id,
@@ -99,7 +104,7 @@ rtems_task Init(
directive_failed( status, FIRE_WHEN_STRING ); directive_failed( status, FIRE_WHEN_STRING );
/* Set system clock FORWARD */ /* Set system clock FORWARD */
global_time.second = INITIAL_SECOND + 10; global_time.year = time_to_fire.year;
status = rtems_clock_set(&global_time); status = rtems_clock_set(&global_time);
if (!_timer_passage) { if (!_timer_passage) {