void _TOD_Set( const Timestamp_Control *tod_as_timestamp, ISR_lock_Context *lock_context ) { struct timespec tod_as_timespec; uint64_t tod_as_ticks; uint32_t cpu_count; uint32_t cpu_index; _Assert( _API_Mutex_Is_owner( _Once_Mutex ) ); _Timecounter_Set_clock( tod_as_timestamp, lock_context ); _Timestamp_To_timespec( tod_as_timestamp, &tod_as_timespec ); tod_as_ticks = _Watchdog_Ticks_from_timespec( &tod_as_timespec ); cpu_count = _SMP_Get_processor_count(); for ( cpu_index = 0 ; cpu_index < cpu_count ; ++cpu_index ) { Per_CPU_Control *cpu = _Per_CPU_Get_by_index( cpu_index ); _Watchdog_Per_CPU_tickle_absolute( cpu, tod_as_ticks ); } _TOD.is_set = true; }
time_t rtems_clock_get_uptime_seconds( void ) { Timestamp_Control snapshot_as_timestamp; struct timespec snapshot_as_timespec; ISR_Level level; _ISR_Disable( level ); snapshot_as_timestamp = _TOD.uptime; _ISR_Enable( level ); _Timestamp_To_timespec( &snapshot_as_timestamp, &snapshot_as_timespec ); return snapshot_as_timespec.tv_sec; }
void _TOD_Get( struct timespec *time ) { ISR_Level level; Timestamp_Control offset; Timestamp_Control now; long nanoseconds; /* assume time checked for NULL by caller */ /* _TOD_Now is the native current time */ nanoseconds = 0; _ISR_Disable( level ); now = _TOD_Now; if ( _Watchdog_Nanoseconds_since_tick_handler ) nanoseconds = (*_Watchdog_Nanoseconds_since_tick_handler)(); _ISR_Enable( level ); _Timestamp_Set( &offset, 0, nanoseconds ); _Timestamp_Add_to( &now, &offset ); _Timestamp_To_timespec( &now, time ); }
rtems_status_code rtems_rate_monotonic_get_status( rtems_id id, rtems_rate_monotonic_period_status *status ) { Timestamp_Control executed; Objects_Locations location; Rate_monotonic_Period_time_t since_last_period; Rate_monotonic_Control *the_period; bool valid_status; if ( !status ) return RTEMS_INVALID_ADDRESS; the_period = _Rate_monotonic_Get( id, &location ); switch ( location ) { case OBJECTS_LOCAL: status->owner = the_period->owner->Object.id; status->state = the_period->state; /* * If the period is inactive, there is no information. */ if ( status->state == RATE_MONOTONIC_INACTIVE ) { _Timespec_Set_to_zero( &status->since_last_period ); _Timespec_Set_to_zero( &status->executed_since_last_period ); } else { /* * Grab the current status. */ valid_status = _Rate_monotonic_Get_status( the_period, &since_last_period, &executed ); if (!valid_status) { _Objects_Put( &the_period->Object ); return RTEMS_NOT_DEFINED; } _Timestamp_To_timespec( &since_last_period, &status->since_last_period ); _Timestamp_To_timespec( &executed, &status->executed_since_last_period ); } _Objects_Put( &the_period->Object ); return RTEMS_SUCCESSFUL; #if defined(RTEMS_MULTIPROCESSING) case OBJECTS_REMOTE: /* should never return this */ #endif case OBJECTS_ERROR: break; } return RTEMS_INVALID_ID; }