From c55df856aaba12355354374983fc1e69bb60373d Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Wed, 16 Jan 2002 22:09:50 +0000 Subject: 2001-01-16 Joel Sherrill * Added task-based timers to the Timer Manager. This added three new directives: - rtems_timer_initiate_server - rtems_timer_server_fire_after - rtems_timer_server_fire_when In the process of doing this, a number of cleanups were made. * src/timerserver.c, src/timerserverfireafter.c, src/timerserverfirewhen.c: New files. * include/timer/timer.h: Added new prototypes and supporting types. * inline/rtems/rtems/timer.h, macros/rtems/rtems/timer.h: Enhanced _Timer_Is_interval_class() to cover the class TIMER_INTERVAL_ON_TASK. * src/Makefile.am: Accounted for new files. * src/rtemstimer.c: Added initialization of _Timer_Server variable. * src/timercancel.c, src/timerreset.c: Account for addition of timer classes. Also corrected the headers. * src/timercreate.c, src/timerdelete.c, src/timerfireafter.c, src/timerfireafter.c, src/timerident.c: Corrected header. --- cpukit/rtems/ChangeLog | 20 +++++ cpukit/rtems/include/rtems/rtems/timer.h | 133 ++++++++++++++++++++++++++++-- cpukit/rtems/inline/rtems/rtems/timer.inl | 2 +- cpukit/rtems/macros/rtems/rtems/timer.inl | 3 +- cpukit/rtems/src/Makefile.am | 3 +- cpukit/rtems/src/rtemstimer.c | 9 +- cpukit/rtems/src/timercancel.c | 6 +- cpukit/rtems/src/timercreate.c | 8 +- cpukit/rtems/src/timerdelete.c | 6 +- cpukit/rtems/src/timerfireafter.c | 13 +-- cpukit/rtems/src/timerfirewhen.c | 7 +- cpukit/rtems/src/timerident.c | 8 +- cpukit/rtems/src/timerreset.c | 26 ++++-- 13 files changed, 203 insertions(+), 41 deletions(-) (limited to 'cpukit') diff --git a/cpukit/rtems/ChangeLog b/cpukit/rtems/ChangeLog index 416813a92b..94151de535 100644 --- a/cpukit/rtems/ChangeLog +++ b/cpukit/rtems/ChangeLog @@ -1,3 +1,23 @@ +2001-01-16 Joel Sherrill + + * Added task-based timers to the Timer Manager. This added three + new directives: + - rtems_timer_initiate_server + - rtems_timer_server_fire_after + - rtems_timer_server_fire_when + In the process of doing this, a number of cleanups were made. + * src/timerserver.c, src/timerserverfireafter.c, + src/timerserverfirewhen.c: New files. + * include/timer/timer.h: Added new prototypes and supporting types. + * inline/rtems/rtems/timer.h, macros/rtems/rtems/timer.h: Enhanced + _Timer_Is_interval_class() to cover the class TIMER_INTERVAL_ON_TASK. + * src/Makefile.am: Accounted for new files. + * src/rtemstimer.c: Added initialization of _Timer_Server variable. + * src/timercancel.c, src/timerreset.c: Account for addition + of timer classes. Also corrected the headers. + * src/timercreate.c, src/timerdelete.c, src/timerfireafter.c, + src/timerfireafter.c, src/timerident.c: Corrected header. + 2001-01-16 Joel Sherrill * src/taskmode.c: Ensure the this service does not dispatch before diff --git a/cpukit/rtems/include/rtems/rtems/timer.h b/cpukit/rtems/include/rtems/rtems/timer.h index 87e21d3228..8f9b765037 100644 --- a/cpukit/rtems/include/rtems/rtems/timer.h +++ b/cpukit/rtems/include/rtems/rtems/timer.h @@ -10,12 +10,17 @@ * + create a timer * + get an ID of a timer * + delete a timer - * + set a timer to fire after a number of ticks have passed - * + set a timer to fire when a specified date and time has been reached + * + set timer to fire in context of clock tick + * - after a number of ticks have passed + * - when a specified date and time has been reached + * + initiate the timer server task + * + set timer to fire in context of the timer server task + * - after a number of ticks have passed + * - when a specified date and time has been reached * + reset a timer * + cancel a time * - * COPYRIGHT (c) 1989-1999. + * COPYRIGHT (c) 1989-2002. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -35,6 +40,7 @@ extern "C" { #include #include #include +#include /* * The following enumerated type details the classes to which a timer @@ -43,7 +49,9 @@ extern "C" { typedef enum { TIMER_INTERVAL, + TIMER_INTERVAL_ON_TASK, TIMER_TIME_OF_DAY, + TIMER_TIME_OF_DAY_ON_TASK, TIMER_DORMANT } Timer_Classes; @@ -65,6 +73,29 @@ typedef rtems_timer_service_routine ( *rtems_timer_service_routine_entry )( RTEMS_EXTERN Objects_Information _Timer_Information; +/* + * Pointer to TCB of the Timer Server. This is NULL before the + * server is executing and task-based timers are not allowed to be + * initiated until the server is started. + */ + +RTEMS_EXTERN Thread_Control *_Timer_Server; + +/* + * The following chains contain the list of interval timers that are + * executed in the context of the Timer Server. + * + * NOTE: These are extern'ed because they do not have to be in the + * minimum footprint. They are only really required when + * task-based timers are used. Since task-based timers can + * not be started until the server is initiated, these structures + * do not have to be initialized until then. They are declared + * in the same file as _Timer_Server_body. + */ + +extern Chain_Control _Timer_Ticks_chain; +extern Chain_Control _Timer_Seconds_chain; + /* * The following records define the control block used to manage * each timer. @@ -88,6 +119,39 @@ void _Timer_Manager_initialization( unsigned32 maximum_timers ); +/* + * _Timer_Server_body + * + * DESCRIPTION: + * + * This is the server for task based timers. This task executes whenever + * a task-based timer should fire. It services both "after" and "when" + * timers. It is not created automatically but must be created explicitly + * by the application before task-based timers may be initiated. + */ + +Thread _Timer_Server_body( + unsigned32 ignored +); + +/* + * _Timer_Server_reset + * + * DESCRIPTION: + * + * This routine resets the timers which determine when the Timer Server + * will wake up next to service task-based timers. + */ + +typedef enum { + TIMER_SERVER_RESET_TICKS, + TIMER_SERVER_RESET_SECONDS +} Timer_Server_reset_mode; + +void _Timer_Server_reset( + Timer_Server_reset_mode reset_mode +); + /* * rtems_timer_create * @@ -151,8 +215,10 @@ rtems_status_code rtems_timer_delete( * DESCRIPTION: * * This routine implements the rtems_timer_fire_after directive. It - * initiates the timer associated with ID to fire in ticks clock - * ticks. When the timer fires, the routine will be invoked. + * initiates the timer associated with ID to fire in ticks clock ticks. + * When the timer fires, the routine will be invoked in the context + * of the rtems_clock_tick directive which is normally invoked as + * part of servicing a periodic interupt. */ rtems_status_code rtems_timer_fire_after( @@ -162,6 +228,25 @@ rtems_status_code rtems_timer_fire_after( void *user_data ); +/* + * rtems_timer_server_fire_after + * + * DESCRIPTION: + * + * This routine implements the rtems_timer_server_fire_after directive. It + * initiates the timer associated with ID to fire in ticks clock + * ticks. When the timer fires, the routine will be invoked by the + * Timer Server in the context of a task NOT IN THE CONTEXT of the + * clock tick interrupt. + */ + +rtems_status_code rtems_timer_server_fire_after( + Objects_Id id, + rtems_interval ticks, + rtems_timer_service_routine_entry routine, + void *user_data +); + /* * rtems_timer_fire_when * @@ -169,7 +254,9 @@ rtems_status_code rtems_timer_fire_after( * * This routine implements the rtems_timer_fire_when directive. It * initiates the timer associated with ID to fire at wall_time - * When the timer fires, the routine will be invoked. + * When the timer fires, the routine will be invoked in the context + * of the rtems_clock_tick directive which is normally invoked as + * part of servicing a periodic interupt. */ rtems_status_code rtems_timer_fire_when( @@ -179,6 +266,25 @@ rtems_status_code rtems_timer_fire_when( void *user_data ); +/* + * rtems_timer_server_fire_when + * + * DESCRIPTION: + * + * This routine implements the rtems_timer_server_fire_when directive. It + * initiates the timer associated with ID to fire at wall_time + * When the timer fires, the routine will be invoked by the + * Timer Server in the context of a task NOT IN THE CONTEXT of the + * clock tick interrupt. + */ + +rtems_status_code rtems_timer_server_fire_when( + Objects_Id id, + rtems_time_of_day *wall_time, + rtems_timer_service_routine_entry routine, + void *user_data +); + /* * rtems_timer_reset * @@ -194,6 +300,21 @@ rtems_status_code rtems_timer_reset( Objects_Id id ); +/* + * rtems_timer_initiate_server + * + * DESCRIPTION: + * + * This routine implements the rtems_timer_initiate_server directive. + * It creates and starts the server that executes task-based timers. + * It must be invoked before any task-based timers can be initiated. + */ + +rtems_status_code rtems_timer_initiate_server( + unsigned32 stack_size, + rtems_attribute attribute_set +); + #ifndef __RTEMS_APPLICATION__ #include #endif diff --git a/cpukit/rtems/inline/rtems/rtems/timer.inl b/cpukit/rtems/inline/rtems/rtems/timer.inl index a887553ce4..33bf5fc3c6 100644 --- a/cpukit/rtems/inline/rtems/rtems/timer.inl +++ b/cpukit/rtems/inline/rtems/rtems/timer.inl @@ -84,7 +84,7 @@ RTEMS_INLINE_ROUTINE boolean _Timer_Is_interval_class ( Timer_Classes the_class ) { - return ( the_class == TIMER_INTERVAL ); + return (the_class == TIMER_INTERVAL) || (the_class == TIMER_INTERVAL_ON_TASK); } /*PAGE diff --git a/cpukit/rtems/macros/rtems/rtems/timer.inl b/cpukit/rtems/macros/rtems/rtems/timer.inl index 36b0fdfe85..aa47189776 100644 --- a/cpukit/rtems/macros/rtems/rtems/timer.inl +++ b/cpukit/rtems/macros/rtems/rtems/timer.inl @@ -51,7 +51,8 @@ */ #define _Timer_Is_interval_class( _the_class ) \ - ( (_the_class) == TIMER_INTERVAL ) + ( ((_the_class) == TIMER_INTERVAL) || + ((_the_class) == TIMER_INTERVAL_ON_TASK) ) /*PAGE * diff --git a/cpukit/rtems/src/Makefile.am b/cpukit/rtems/src/Makefile.am index 8b8824876c..f1402ef9de 100644 --- a/cpukit/rtems/src/Makefile.am +++ b/cpukit/rtems/src/Makefile.am @@ -26,7 +26,8 @@ INTR_C_FILES = intr.c intrbody.c intrcatch.c CLOCK_C_FILES = rtclock.c clockget.c clockset.c clocktick.c TIMER_C_FILES = rtemstimer.c timercancel.c timercreate.c timerdelete.c \ - timerfireafter.c timerfirewhen.c timerident.c timerreset.c + timerfireafter.c timerfirewhen.c timerident.c timerreset.c timerserver.c \ + timerserverfireafter.c timerserverfirewhen.c MESSAGE_QUEUE_C_FILES = msg.c msgqallocate.c msgqbroadcast.c msgqcreate.c \ msgqdelete.c msgqflush.c msgqgetnumberpending.c msgqident.c \ diff --git a/cpukit/rtems/src/rtemstimer.c b/cpukit/rtems/src/rtemstimer.c index e413681549..6954f1dec6 100644 --- a/cpukit/rtems/src/rtemstimer.c +++ b/cpukit/rtems/src/rtemstimer.c @@ -2,7 +2,7 @@ * Timer Manager * * - * COPYRIGHT (c) 1989-1999. + * COPYRIGHT (c) 1989-2002. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -47,4 +47,11 @@ void _Timer_Manager_initialization( RTEMS_MAXIMUM_NAME_LENGTH, FALSE ); + + /* + * Initialize the pointer to the Timer Server TCB to NULL indicating + * that task-based timer support is not initialized. + */ + + _Timer_Server = NULL; } diff --git a/cpukit/rtems/src/timercancel.c b/cpukit/rtems/src/timercancel.c index 9db829d717..a4b2ea60d5 100644 --- a/cpukit/rtems/src/timercancel.c +++ b/cpukit/rtems/src/timercancel.c @@ -1,8 +1,8 @@ /* - * Timer Manager + * Timer Manager - rtems_timer_cancel directive * * - * COPYRIGHT (c) 1989-1999. + * COPYRIGHT (c) 1989-2002. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -32,7 +32,7 @@ * * Output parameters: * RTEMS_SUCCESSFUL - if successful - * error code - if unsuccessful + * error code - if unsuccessful */ rtems_status_code rtems_timer_cancel( diff --git a/cpukit/rtems/src/timercreate.c b/cpukit/rtems/src/timercreate.c index 33e7f00d79..a1734e980f 100644 --- a/cpukit/rtems/src/timercreate.c +++ b/cpukit/rtems/src/timercreate.c @@ -1,8 +1,8 @@ /* - * Timer Manager + * Timer Manager - rtems_timer_create directive * * - * COPYRIGHT (c) 1989-1999. + * COPYRIGHT (c) 1989-2002. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -32,9 +32,9 @@ * id - pointer to timer id * * Output parameters: - * id - timer id + * id - timer id * RTEMS_SUCCESSFUL - if successful - * error code - if unsuccessful + * error code - if unsuccessful */ rtems_status_code rtems_timer_create( diff --git a/cpukit/rtems/src/timerdelete.c b/cpukit/rtems/src/timerdelete.c index c207cb0ab7..87c61941d7 100644 --- a/cpukit/rtems/src/timerdelete.c +++ b/cpukit/rtems/src/timerdelete.c @@ -1,8 +1,8 @@ /* - * Timer Manager + * Timer Manager - rtems_timer_delete directive * * - * COPYRIGHT (c) 1989-1999. + * COPYRIGHT (c) 1989-2002. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -32,7 +32,7 @@ * * Output parameters: * RTEMS_SUCCESSFUL - if successful - * error code - if unsuccessful + * error code - if unsuccessful */ rtems_status_code rtems_timer_delete( diff --git a/cpukit/rtems/src/timerfireafter.c b/cpukit/rtems/src/timerfireafter.c index f31b63ae92..76a3e3a0e6 100644 --- a/cpukit/rtems/src/timerfireafter.c +++ b/cpukit/rtems/src/timerfireafter.c @@ -1,8 +1,8 @@ /* - * Timer Manager + * Timer Manager - rtems_timer_fire_after directive * * - * COPYRIGHT (c) 1989-1999. + * COPYRIGHT (c) 1989-2002. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -28,13 +28,14 @@ * This directive allows a thread to start a timer. * * Input parameters: - * id - timer id - * ticks - interval until routine is fired - * routine - routine to schedule + * id - timer id + * ticks - interval until routine is fired + * routine - routine to schedule + * user_data - passed as argument to routine when it is fired * * Output parameters: * RTEMS_SUCCESSFUL - if successful - * error code - if unsuccessful + * error code - if unsuccessful */ rtems_status_code rtems_timer_fire_after( diff --git a/cpukit/rtems/src/timerfirewhen.c b/cpukit/rtems/src/timerfirewhen.c index 309261351a..c2d9fdc222 100644 --- a/cpukit/rtems/src/timerfirewhen.c +++ b/cpukit/rtems/src/timerfirewhen.c @@ -1,8 +1,8 @@ /* - * Timer Manager + * Timer Manager - rtems_timer_fire_when directive * * - * COPYRIGHT (c) 1989-1999. + * COPYRIGHT (c) 1989-2002. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -31,10 +31,11 @@ * id - timer id * wall_time - time of day to fire timer * routine - routine to schedule + * user_data - passed as argument to routine when it is fired * * Output parameters: * RTEMS_SUCCESSFUL - if successful - * error code - if unsuccessful + * error code - if unsuccessful */ rtems_status_code rtems_timer_fire_when( diff --git a/cpukit/rtems/src/timerident.c b/cpukit/rtems/src/timerident.c index 492f55c6ac..f8cb36bdc6 100644 --- a/cpukit/rtems/src/timerident.c +++ b/cpukit/rtems/src/timerident.c @@ -1,8 +1,8 @@ /* - * Timer Manager + * Timer Manager - rtems_timer_ident directive * * - * COPYRIGHT (c) 1989-1999. + * COPYRIGHT (c) 1989-2002. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -33,9 +33,9 @@ * id - pointer to timer id * * Output parameters: - * *id - message queue id + * *id - message queue id * RTEMS_SUCCESSFUL - if successful - * error code - if unsuccessful + * error code - if unsuccessful */ rtems_status_code rtems_timer_ident( diff --git a/cpukit/rtems/src/timerreset.c b/cpukit/rtems/src/timerreset.c index f538098b1e..33a45e1fc3 100644 --- a/cpukit/rtems/src/timerreset.c +++ b/cpukit/rtems/src/timerreset.c @@ -1,8 +1,8 @@ /* - * Timer Manager + * Timer Manager - rtems_timer_reset directive * * - * COPYRIGHT (c) 1989-1999. + * COPYRIGHT (c) 1989-2002. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -32,7 +32,7 @@ * * Output parameters: * RTEMS_SUCCESSFUL - if successful - * error code - if unsuccessful + * error code - if unsuccessful */ rtems_status_code rtems_timer_reset( @@ -51,13 +51,23 @@ rtems_status_code rtems_timer_reset( return RTEMS_INVALID_ID; case OBJECTS_LOCAL: - if ( _Timer_Is_interval_class( the_timer->the_class ) ) { - _Watchdog_Reset( &the_timer->Ticker ); - _Thread_Enable_dispatch(); - return RTEMS_SUCCESSFUL; + switch ( the_timer->the_class ) { + case TIMER_INTERVAL: + _Watchdog_Remove( &the_timer->Ticker ); + _Watchdog_Insert( &_Watchdog_Ticks_chain, &the_timer->Ticker ); + break; + case TIMER_INTERVAL_ON_TASK: + _Watchdog_Remove( &the_timer->Ticker ); + _Watchdog_Insert( &_Timer_Ticks_chain, &the_timer->Ticker ); + break; + case TIMER_TIME_OF_DAY: + case TIMER_TIME_OF_DAY_ON_TASK: + case TIMER_DORMANT: + _Thread_Enable_dispatch(); + return RTEMS_NOT_DEFINED; } _Thread_Enable_dispatch(); - return RTEMS_NOT_DEFINED; + return RTEMS_SUCCESSFUL; } return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ -- cgit v1.2.3