Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:54

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup RTEMSTestSuitesValidation
0007  *
0008  * @brief This source file contains the definition of DeleteTimerServer().
0009  */
0010 
0011 /*
0012  * Copyright (C) 2021 embedded brains GmbH & Co. KG
0013  *
0014  * Redistribution and use in source and binary forms, with or without
0015  * modification, are permitted provided that the following conditions
0016  * are met:
0017  * 1. Redistributions of source code must retain the above copyright
0018  *    notice, this list of conditions and the following disclaimer.
0019  * 2. Redistributions in binary form must reproduce the above copyright
0020  *    notice, this list of conditions and the following disclaimer in the
0021  *    documentation and/or other materials provided with the distribution.
0022  *
0023  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0024  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0025  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0026  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0027  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0028  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0029  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0030  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0031  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0032  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0033  * POSSIBILITY OF SUCH DAMAGE.
0034  */
0035 
0036 #ifdef HAVE_CONFIG_H
0037 #include "config.h"
0038 #endif
0039 
0040 #include "tx-support.h"
0041 
0042 #include <rtems/test.h>
0043 #include <rtems/rtems/timerimpl.h>
0044 #include <rtems/score/todimpl.h>
0045 
0046 rtems_id GetTimerServerTaskId( void )
0047 {
0048   if ( _Timer_server == NULL ) {
0049     return RTEMS_INVALID_ID;
0050   }
0051   return _Timer_server->server_id;
0052 }
0053 
0054 bool DeleteTimerServer( void )
0055 {
0056   Timer_server_Control *server;
0057 
0058   server = _Timer_server;
0059 
0060   if ( server == NULL ) {
0061     return false;
0062   }
0063 
0064   DeleteTask( server->server_id );
0065   _ISR_lock_Destroy( &server->Lock );
0066   T_true( _Chain_Is_empty( &server->Pending ) );
0067   _Timer_server = NULL;
0068 
0069   return true;
0070 }
0071 
0072 Timer_Classes GetTimerClass( rtems_id id )
0073 {
0074   /* This code is derived from rtems_timer_get_information() */
0075   Timer_Classes result = TIMER_DORMANT;
0076   Timer_Control *the_timer;
0077   ISR_lock_Context lock_context;
0078   Per_CPU_Control *cpu;
0079 
0080   the_timer = _Timer_Get( id, &lock_context );
0081   if ( the_timer != NULL ) {
0082     cpu = _Timer_Acquire_critical( the_timer, &lock_context );
0083     result = the_timer->the_class;
0084     _Timer_Release( cpu, &lock_context );
0085   }
0086 
0087   return result;
0088 }
0089 
0090 void GetTimerSchedulingData(
0091   rtems_id id,
0092   Timer_Scheduling_Data *data
0093 )
0094 {
0095   /* This code is derived from rtems_timer_get_information() */
0096   Timer_Control *the_timer;
0097   ISR_lock_Context lock_context;
0098   Per_CPU_Control *cpu;
0099 
0100   if ( data == NULL ) {
0101     return;
0102   }
0103 
0104   the_timer = _Timer_Get( id, &lock_context );
0105   if ( the_timer != NULL ) {
0106     cpu = _Timer_Acquire_critical( the_timer, &lock_context );
0107     data->routine   = the_timer->routine;
0108     data->user_data = the_timer->user_data;
0109     data->interval  = the_timer->initial;
0110     _Timer_Release( cpu, &lock_context );
0111   }
0112 }
0113 
0114 Timer_States GetTimerState( rtems_id id )
0115 {
0116   /* This code is derived from rtems_timer_cancel() and _timer_cancel() */
0117   Timer_States          result = TIMER_INVALID;
0118   Timer_Control        *the_timer;
0119   ISR_lock_Context      lock_context;
0120   Per_CPU_Control      *cpu;
0121   Timer_Classes         the_class;
0122   Timer_server_Control *timer_server = _Timer_server;
0123   ISR_lock_Context      lock_context_server;
0124 
0125   the_timer = _Timer_Get( id, &lock_context );
0126   if ( the_timer != NULL ) {
0127     result = TIMER_INACTIVE;
0128     cpu = _Timer_Acquire_critical( the_timer, &lock_context );
0129     the_class = the_timer->the_class;
0130 
0131     if ( _Watchdog_Is_scheduled( &the_timer->Ticker ) ) {
0132       result = TIMER_SCHEDULED;
0133     } else if ( _Timer_Is_on_task_class( the_class ) ) {
0134       _Assert( timer_server != NULL );
0135       _Timer_server_Acquire_critical( timer_server, &lock_context_server );
0136       if ( _Watchdog_Get_state( &the_timer->Ticker ) == WATCHDOG_PENDING ) {
0137         result = TIMER_PENDING;
0138       }
0139     _Timer_server_Release_critical( timer_server, &lock_context_server );
0140     }
0141     _Timer_Release( cpu, &lock_context );
0142   }
0143 
0144   return result;
0145 }
0146 
0147 void UnsetClock( void )
0148 {
0149   _TOD.is_set = false;
0150 }