Changeset be47df9 in rtems


Ignore:
Timestamp:
May 17, 1999, 11:10:36 PM (22 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
842db5f3
Parents:
cc2bc302
Message:

Split Timer Manager into one routine per file.

Files:
14 added
4 edited

Legend:

Unmodified
Added
Removed
  • c/src/exec/rtems/src/Makefile.in

    rcc2bc302 rbe47df9  
    2525  taskstart tasksuspend taskwakeafter taskwakewhen
    2626
    27 CLOCK_PIECES=
     27CLOCK_PIECES=\
    2828  clock clockget clockset clocktick
     29
     30TIMER_PIECES=\
     31  timer timercancel timercreate timerdelete timerfireafter \
     32  timerfirewhere timerident timerreset
    2933
    3034REGION_PIECES=\
     
    5155   $(MESSAGE_QUEUE_PIECES) \
    5256   part $(RATEMON_PIECES)  $(REGION_PIECES) $(SEMAPHORE_PIECES) signal \
    53    $(TASK_PIECES) timer $(MP_PIECES)
     57   $(TASK_PIECES) $(TIMER_PIECES) $(MP_PIECES)
    5458C_FILES=$(C_PIECES:%=%.c)
    5559C_O_FILES=$(C_PIECES:%=${ARCH}/%.o)
  • c/src/exec/rtems/src/rtemstimer.c

    rcc2bc302 rbe47df9  
    5050  );
    5151}
    52 
    53 /*PAGE
    54  *
    55  *  rtems_timer_create
    56  *
    57  *  This directive creates a timer and performs some initialization.
    58  *
    59  *  Input parameters:
    60  *    name - timer name
    61  *    id   - pointer to timer id
    62  *
    63  *  Output parameters:
    64  *    id                - timer id
    65  *    RTEMS_SUCCESSFUL - if successful
    66  *    error code        - if unsuccessful
    67  */
    68 
    69 rtems_status_code rtems_timer_create(
    70   rtems_name    name,
    71   Objects_Id   *id
    72 )
    73 {
    74   Timer_Control *the_timer;
    75 
    76   if ( !rtems_is_name_valid( name ) )
    77     return RTEMS_INVALID_NAME;
    78 
    79   _Thread_Disable_dispatch();         /* to prevent deletion */
    80 
    81   the_timer = _Timer_Allocate();
    82 
    83   if ( !the_timer ) {
    84     _Thread_Enable_dispatch();
    85     return RTEMS_TOO_MANY;
    86   }
    87 
    88   the_timer->the_class = TIMER_DORMANT;
    89 
    90   _Objects_Open( &_Timer_Information, &the_timer->Object, &name );
    91 
    92   *id = the_timer->Object.id;
    93   _Thread_Enable_dispatch();
    94   return RTEMS_SUCCESSFUL;
    95 }
    96 
    97 /*PAGE
    98  *
    99  *  rtems_timer_ident
    100  *
    101  *  This directive returns the system ID associated with
    102  *  the timer name.
    103  *
    104  *  Input parameters:
    105  *    name - user defined message queue name
    106  *    id   - pointer to timer id
    107  *
    108  *  Output parameters:
    109  *    *id               - message queue id
    110  *    RTEMS_SUCCESSFUL - if successful
    111  *    error code        - if unsuccessful
    112  */
    113 
    114 rtems_status_code rtems_timer_ident(
    115   rtems_name    name,
    116   Objects_Id   *id
    117 )
    118 {
    119   Objects_Name_to_id_errors  status;
    120 
    121   status = _Objects_Name_to_id(
    122     &_Timer_Information,
    123     &name,
    124     OBJECTS_SEARCH_LOCAL_NODE,
    125     id
    126   );
    127 
    128   return _Status_Object_name_errors_to_status[ status ];
    129 }
    130 
    131 /*PAGE
    132  *
    133  *  rtems_timer_cancel
    134  *
    135  *  This directive allows a thread to cancel a timer.
    136  *
    137  *  Input parameters:
    138  *    id - timer id
    139  *
    140  *  Output parameters:
    141  *    RTEMS_SUCCESSFUL - if successful
    142  *    error code - if unsuccessful
    143  */
    144 
    145 rtems_status_code rtems_timer_cancel(
    146   Objects_Id id
    147 )
    148 {
    149   Timer_Control   *the_timer;
    150   Objects_Locations       location;
    151 
    152   the_timer = _Timer_Get( id, &location );
    153   switch ( location ) {
    154     case OBJECTS_REMOTE:            /* should never return this */
    155       return RTEMS_INTERNAL_ERROR;
    156 
    157     case OBJECTS_ERROR:
    158       return RTEMS_INVALID_ID;
    159 
    160     case OBJECTS_LOCAL:
    161       if ( !_Timer_Is_dormant_class( the_timer->the_class ) )
    162         (void) _Watchdog_Remove( &the_timer->Ticker );
    163       _Thread_Enable_dispatch();
    164       return RTEMS_SUCCESSFUL;
    165   }
    166 
    167   return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
    168 }
    169 
    170 /*PAGE
    171  *
    172  *  rtems_timer_delete
    173  *
    174  *  This directive allows a thread to delete a timer.
    175  *
    176  *  Input parameters:
    177  *    id - timer id
    178  *
    179  *  Output parameters:
    180  *    RTEMS_SUCCESSFUL - if successful
    181  *    error code - if unsuccessful
    182  */
    183 
    184 rtems_status_code rtems_timer_delete(
    185   Objects_Id id
    186 )
    187 {
    188   Timer_Control   *the_timer;
    189   Objects_Locations       location;
    190 
    191   the_timer = _Timer_Get( id, &location );
    192   switch ( location ) {
    193     case OBJECTS_REMOTE:            /* should never return this */
    194       return RTEMS_INTERNAL_ERROR;
    195 
    196     case OBJECTS_ERROR:
    197       return RTEMS_INVALID_ID;
    198 
    199     case OBJECTS_LOCAL:
    200       _Objects_Close( &_Timer_Information, &the_timer->Object );
    201       (void) _Watchdog_Remove( &the_timer->Ticker );
    202       _Timer_Free( the_timer );
    203       _Thread_Enable_dispatch();
    204       return RTEMS_SUCCESSFUL;
    205   }
    206 
    207   return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
    208 }
    209 
    210 /*PAGE
    211  *
    212  *  rtems_timer_fire_after
    213  *
    214  *  This directive allows a thread to start a timer.
    215  *
    216  *  Input parameters:
    217  *    id      - timer id
    218  *    ticks   - interval until routine is fired
    219  *    routine - routine to schedule
    220  *
    221  *  Output parameters:
    222  *    RTEMS_SUCCESSFUL - if successful
    223  *    error code        - if unsuccessful
    224  */
    225 
    226 rtems_status_code rtems_timer_fire_after(
    227   Objects_Id                         id,
    228   rtems_interval                     ticks,
    229   rtems_timer_service_routine_entry  routine,
    230   void                              *user_data
    231 )
    232 {
    233   Timer_Control      *the_timer;
    234   Objects_Locations   location;
    235 
    236   if ( ticks == 0 )
    237     return RTEMS_INVALID_NUMBER;
    238 
    239   the_timer = _Timer_Get( id, &location );
    240   switch ( location ) {
    241     case OBJECTS_REMOTE:            /* should never return this */
    242       return RTEMS_INTERNAL_ERROR;
    243 
    244     case OBJECTS_ERROR:
    245       return RTEMS_INVALID_ID;
    246 
    247     case OBJECTS_LOCAL:
    248       (void) _Watchdog_Remove( &the_timer->Ticker );
    249       the_timer->the_class = TIMER_INTERVAL;
    250       _Watchdog_Initialize( &the_timer->Ticker, routine, id, user_data );
    251       _Watchdog_Insert_ticks( &the_timer->Ticker, ticks );
    252       _Thread_Enable_dispatch();
    253       return RTEMS_SUCCESSFUL;
    254   }
    255 
    256   return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
    257 }
    258 
    259 /*PAGE
    260  *
    261  *  rtems_timer_fire_when
    262  *
    263  *  This directive allows a thread to start a timer.
    264  *
    265  *  Input parameters:
    266  *    id        - timer id
    267  *    wall_time - time of day to fire timer
    268  *    routine   - routine to schedule
    269  *
    270  *  Output parameters:
    271  *    RTEMS_SUCCESSFUL - if successful
    272  *    error code        - if unsuccessful
    273  */
    274 
    275 rtems_status_code rtems_timer_fire_when(
    276   Objects_Id                          id,
    277   rtems_time_of_day                  *wall_time,
    278   rtems_timer_service_routine_entry   routine,
    279   void                               *user_data
    280 )
    281 {
    282   Timer_Control       *the_timer;
    283   Objects_Locations    location;
    284   rtems_interval       seconds;
    285 
    286   if ( !_TOD_Is_set )
    287     return RTEMS_NOT_DEFINED;
    288 
    289   if ( !_TOD_Validate( wall_time ) )
    290     return RTEMS_INVALID_CLOCK;
    291 
    292   seconds = _TOD_To_seconds( wall_time );
    293   if ( seconds <= _TOD_Seconds_since_epoch )
    294     return RTEMS_INVALID_CLOCK;
    295 
    296   the_timer = _Timer_Get( id, &location );
    297   switch ( location ) {
    298     case OBJECTS_REMOTE:            /* should never return this */
    299       return RTEMS_INTERNAL_ERROR;
    300 
    301     case OBJECTS_ERROR:
    302       return RTEMS_INVALID_ID;
    303 
    304     case OBJECTS_LOCAL:
    305       (void) _Watchdog_Remove( &the_timer->Ticker );
    306       the_timer->the_class = TIMER_TIME_OF_DAY;
    307       _Watchdog_Initialize( &the_timer->Ticker, routine, id, user_data );
    308       _Watchdog_Insert_seconds(
    309          &the_timer->Ticker,
    310          seconds - _TOD_Seconds_since_epoch
    311        );
    312       _Thread_Enable_dispatch();
    313       return RTEMS_SUCCESSFUL;
    314   }
    315 
    316   return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
    317 }
    318 
    319 /*PAGE
    320  *
    321  *  rtems_timer_reset
    322  *
    323  *  This directive allows a thread to reset a timer.
    324  *
    325  *  Input parameters:
    326  *    id - timer id
    327  *
    328  *  Output parameters:
    329  *    RTEMS_SUCCESSFUL - if successful
    330  *    error code        - if unsuccessful
    331  */
    332 
    333 rtems_status_code rtems_timer_reset(
    334   Objects_Id id
    335 )
    336 {
    337   Timer_Control     *the_timer;
    338   Objects_Locations  location;
    339 
    340   the_timer = _Timer_Get( id, &location );
    341   switch ( location ) {
    342     case OBJECTS_REMOTE:            /* should never return this */
    343       return RTEMS_INTERNAL_ERROR;
    344 
    345     case OBJECTS_ERROR:
    346       return RTEMS_INVALID_ID;
    347 
    348     case OBJECTS_LOCAL:
    349       if ( _Timer_Is_interval_class( the_timer->the_class ) ) {
    350         _Watchdog_Reset( &the_timer->Ticker );
    351         _Thread_Enable_dispatch();
    352         return RTEMS_SUCCESSFUL;
    353       }
    354       _Thread_Enable_dispatch();
    355       return RTEMS_NOT_DEFINED;
    356   }
    357 
    358   return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
    359 }
  • c/src/exec/rtems/src/timer.c

    rcc2bc302 rbe47df9  
    5050  );
    5151}
    52 
    53 /*PAGE
    54  *
    55  *  rtems_timer_create
    56  *
    57  *  This directive creates a timer and performs some initialization.
    58  *
    59  *  Input parameters:
    60  *    name - timer name
    61  *    id   - pointer to timer id
    62  *
    63  *  Output parameters:
    64  *    id                - timer id
    65  *    RTEMS_SUCCESSFUL - if successful
    66  *    error code        - if unsuccessful
    67  */
    68 
    69 rtems_status_code rtems_timer_create(
    70   rtems_name    name,
    71   Objects_Id   *id
    72 )
    73 {
    74   Timer_Control *the_timer;
    75 
    76   if ( !rtems_is_name_valid( name ) )
    77     return RTEMS_INVALID_NAME;
    78 
    79   _Thread_Disable_dispatch();         /* to prevent deletion */
    80 
    81   the_timer = _Timer_Allocate();
    82 
    83   if ( !the_timer ) {
    84     _Thread_Enable_dispatch();
    85     return RTEMS_TOO_MANY;
    86   }
    87 
    88   the_timer->the_class = TIMER_DORMANT;
    89 
    90   _Objects_Open( &_Timer_Information, &the_timer->Object, &name );
    91 
    92   *id = the_timer->Object.id;
    93   _Thread_Enable_dispatch();
    94   return RTEMS_SUCCESSFUL;
    95 }
    96 
    97 /*PAGE
    98  *
    99  *  rtems_timer_ident
    100  *
    101  *  This directive returns the system ID associated with
    102  *  the timer name.
    103  *
    104  *  Input parameters:
    105  *    name - user defined message queue name
    106  *    id   - pointer to timer id
    107  *
    108  *  Output parameters:
    109  *    *id               - message queue id
    110  *    RTEMS_SUCCESSFUL - if successful
    111  *    error code        - if unsuccessful
    112  */
    113 
    114 rtems_status_code rtems_timer_ident(
    115   rtems_name    name,
    116   Objects_Id   *id
    117 )
    118 {
    119   Objects_Name_to_id_errors  status;
    120 
    121   status = _Objects_Name_to_id(
    122     &_Timer_Information,
    123     &name,
    124     OBJECTS_SEARCH_LOCAL_NODE,
    125     id
    126   );
    127 
    128   return _Status_Object_name_errors_to_status[ status ];
    129 }
    130 
    131 /*PAGE
    132  *
    133  *  rtems_timer_cancel
    134  *
    135  *  This directive allows a thread to cancel a timer.
    136  *
    137  *  Input parameters:
    138  *    id - timer id
    139  *
    140  *  Output parameters:
    141  *    RTEMS_SUCCESSFUL - if successful
    142  *    error code - if unsuccessful
    143  */
    144 
    145 rtems_status_code rtems_timer_cancel(
    146   Objects_Id id
    147 )
    148 {
    149   Timer_Control   *the_timer;
    150   Objects_Locations       location;
    151 
    152   the_timer = _Timer_Get( id, &location );
    153   switch ( location ) {
    154     case OBJECTS_REMOTE:            /* should never return this */
    155       return RTEMS_INTERNAL_ERROR;
    156 
    157     case OBJECTS_ERROR:
    158       return RTEMS_INVALID_ID;
    159 
    160     case OBJECTS_LOCAL:
    161       if ( !_Timer_Is_dormant_class( the_timer->the_class ) )
    162         (void) _Watchdog_Remove( &the_timer->Ticker );
    163       _Thread_Enable_dispatch();
    164       return RTEMS_SUCCESSFUL;
    165   }
    166 
    167   return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
    168 }
    169 
    170 /*PAGE
    171  *
    172  *  rtems_timer_delete
    173  *
    174  *  This directive allows a thread to delete a timer.
    175  *
    176  *  Input parameters:
    177  *    id - timer id
    178  *
    179  *  Output parameters:
    180  *    RTEMS_SUCCESSFUL - if successful
    181  *    error code - if unsuccessful
    182  */
    183 
    184 rtems_status_code rtems_timer_delete(
    185   Objects_Id id
    186 )
    187 {
    188   Timer_Control   *the_timer;
    189   Objects_Locations       location;
    190 
    191   the_timer = _Timer_Get( id, &location );
    192   switch ( location ) {
    193     case OBJECTS_REMOTE:            /* should never return this */
    194       return RTEMS_INTERNAL_ERROR;
    195 
    196     case OBJECTS_ERROR:
    197       return RTEMS_INVALID_ID;
    198 
    199     case OBJECTS_LOCAL:
    200       _Objects_Close( &_Timer_Information, &the_timer->Object );
    201       (void) _Watchdog_Remove( &the_timer->Ticker );
    202       _Timer_Free( the_timer );
    203       _Thread_Enable_dispatch();
    204       return RTEMS_SUCCESSFUL;
    205   }
    206 
    207   return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
    208 }
    209 
    210 /*PAGE
    211  *
    212  *  rtems_timer_fire_after
    213  *
    214  *  This directive allows a thread to start a timer.
    215  *
    216  *  Input parameters:
    217  *    id      - timer id
    218  *    ticks   - interval until routine is fired
    219  *    routine - routine to schedule
    220  *
    221  *  Output parameters:
    222  *    RTEMS_SUCCESSFUL - if successful
    223  *    error code        - if unsuccessful
    224  */
    225 
    226 rtems_status_code rtems_timer_fire_after(
    227   Objects_Id                         id,
    228   rtems_interval                     ticks,
    229   rtems_timer_service_routine_entry  routine,
    230   void                              *user_data
    231 )
    232 {
    233   Timer_Control      *the_timer;
    234   Objects_Locations   location;
    235 
    236   if ( ticks == 0 )
    237     return RTEMS_INVALID_NUMBER;
    238 
    239   the_timer = _Timer_Get( id, &location );
    240   switch ( location ) {
    241     case OBJECTS_REMOTE:            /* should never return this */
    242       return RTEMS_INTERNAL_ERROR;
    243 
    244     case OBJECTS_ERROR:
    245       return RTEMS_INVALID_ID;
    246 
    247     case OBJECTS_LOCAL:
    248       (void) _Watchdog_Remove( &the_timer->Ticker );
    249       the_timer->the_class = TIMER_INTERVAL;
    250       _Watchdog_Initialize( &the_timer->Ticker, routine, id, user_data );
    251       _Watchdog_Insert_ticks( &the_timer->Ticker, ticks );
    252       _Thread_Enable_dispatch();
    253       return RTEMS_SUCCESSFUL;
    254   }
    255 
    256   return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
    257 }
    258 
    259 /*PAGE
    260  *
    261  *  rtems_timer_fire_when
    262  *
    263  *  This directive allows a thread to start a timer.
    264  *
    265  *  Input parameters:
    266  *    id        - timer id
    267  *    wall_time - time of day to fire timer
    268  *    routine   - routine to schedule
    269  *
    270  *  Output parameters:
    271  *    RTEMS_SUCCESSFUL - if successful
    272  *    error code        - if unsuccessful
    273  */
    274 
    275 rtems_status_code rtems_timer_fire_when(
    276   Objects_Id                          id,
    277   rtems_time_of_day                  *wall_time,
    278   rtems_timer_service_routine_entry   routine,
    279   void                               *user_data
    280 )
    281 {
    282   Timer_Control       *the_timer;
    283   Objects_Locations    location;
    284   rtems_interval       seconds;
    285 
    286   if ( !_TOD_Is_set )
    287     return RTEMS_NOT_DEFINED;
    288 
    289   if ( !_TOD_Validate( wall_time ) )
    290     return RTEMS_INVALID_CLOCK;
    291 
    292   seconds = _TOD_To_seconds( wall_time );
    293   if ( seconds <= _TOD_Seconds_since_epoch )
    294     return RTEMS_INVALID_CLOCK;
    295 
    296   the_timer = _Timer_Get( id, &location );
    297   switch ( location ) {
    298     case OBJECTS_REMOTE:            /* should never return this */
    299       return RTEMS_INTERNAL_ERROR;
    300 
    301     case OBJECTS_ERROR:
    302       return RTEMS_INVALID_ID;
    303 
    304     case OBJECTS_LOCAL:
    305       (void) _Watchdog_Remove( &the_timer->Ticker );
    306       the_timer->the_class = TIMER_TIME_OF_DAY;
    307       _Watchdog_Initialize( &the_timer->Ticker, routine, id, user_data );
    308       _Watchdog_Insert_seconds(
    309          &the_timer->Ticker,
    310          seconds - _TOD_Seconds_since_epoch
    311        );
    312       _Thread_Enable_dispatch();
    313       return RTEMS_SUCCESSFUL;
    314   }
    315 
    316   return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
    317 }
    318 
    319 /*PAGE
    320  *
    321  *  rtems_timer_reset
    322  *
    323  *  This directive allows a thread to reset a timer.
    324  *
    325  *  Input parameters:
    326  *    id - timer id
    327  *
    328  *  Output parameters:
    329  *    RTEMS_SUCCESSFUL - if successful
    330  *    error code        - if unsuccessful
    331  */
    332 
    333 rtems_status_code rtems_timer_reset(
    334   Objects_Id id
    335 )
    336 {
    337   Timer_Control     *the_timer;
    338   Objects_Locations  location;
    339 
    340   the_timer = _Timer_Get( id, &location );
    341   switch ( location ) {
    342     case OBJECTS_REMOTE:            /* should never return this */
    343       return RTEMS_INTERNAL_ERROR;
    344 
    345     case OBJECTS_ERROR:
    346       return RTEMS_INVALID_ID;
    347 
    348     case OBJECTS_LOCAL:
    349       if ( _Timer_Is_interval_class( the_timer->the_class ) ) {
    350         _Watchdog_Reset( &the_timer->Ticker );
    351         _Thread_Enable_dispatch();
    352         return RTEMS_SUCCESSFUL;
    353       }
    354       _Thread_Enable_dispatch();
    355       return RTEMS_NOT_DEFINED;
    356   }
    357 
    358   return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
    359 }
  • cpukit/rtems/src/rtemstimer.c

    rcc2bc302 rbe47df9  
    5050  );
    5151}
    52 
    53 /*PAGE
    54  *
    55  *  rtems_timer_create
    56  *
    57  *  This directive creates a timer and performs some initialization.
    58  *
    59  *  Input parameters:
    60  *    name - timer name
    61  *    id   - pointer to timer id
    62  *
    63  *  Output parameters:
    64  *    id                - timer id
    65  *    RTEMS_SUCCESSFUL - if successful
    66  *    error code        - if unsuccessful
    67  */
    68 
    69 rtems_status_code rtems_timer_create(
    70   rtems_name    name,
    71   Objects_Id   *id
    72 )
    73 {
    74   Timer_Control *the_timer;
    75 
    76   if ( !rtems_is_name_valid( name ) )
    77     return RTEMS_INVALID_NAME;
    78 
    79   _Thread_Disable_dispatch();         /* to prevent deletion */
    80 
    81   the_timer = _Timer_Allocate();
    82 
    83   if ( !the_timer ) {
    84     _Thread_Enable_dispatch();
    85     return RTEMS_TOO_MANY;
    86   }
    87 
    88   the_timer->the_class = TIMER_DORMANT;
    89 
    90   _Objects_Open( &_Timer_Information, &the_timer->Object, &name );
    91 
    92   *id = the_timer->Object.id;
    93   _Thread_Enable_dispatch();
    94   return RTEMS_SUCCESSFUL;
    95 }
    96 
    97 /*PAGE
    98  *
    99  *  rtems_timer_ident
    100  *
    101  *  This directive returns the system ID associated with
    102  *  the timer name.
    103  *
    104  *  Input parameters:
    105  *    name - user defined message queue name
    106  *    id   - pointer to timer id
    107  *
    108  *  Output parameters:
    109  *    *id               - message queue id
    110  *    RTEMS_SUCCESSFUL - if successful
    111  *    error code        - if unsuccessful
    112  */
    113 
    114 rtems_status_code rtems_timer_ident(
    115   rtems_name    name,
    116   Objects_Id   *id
    117 )
    118 {
    119   Objects_Name_to_id_errors  status;
    120 
    121   status = _Objects_Name_to_id(
    122     &_Timer_Information,
    123     &name,
    124     OBJECTS_SEARCH_LOCAL_NODE,
    125     id
    126   );
    127 
    128   return _Status_Object_name_errors_to_status[ status ];
    129 }
    130 
    131 /*PAGE
    132  *
    133  *  rtems_timer_cancel
    134  *
    135  *  This directive allows a thread to cancel a timer.
    136  *
    137  *  Input parameters:
    138  *    id - timer id
    139  *
    140  *  Output parameters:
    141  *    RTEMS_SUCCESSFUL - if successful
    142  *    error code - if unsuccessful
    143  */
    144 
    145 rtems_status_code rtems_timer_cancel(
    146   Objects_Id id
    147 )
    148 {
    149   Timer_Control   *the_timer;
    150   Objects_Locations       location;
    151 
    152   the_timer = _Timer_Get( id, &location );
    153   switch ( location ) {
    154     case OBJECTS_REMOTE:            /* should never return this */
    155       return RTEMS_INTERNAL_ERROR;
    156 
    157     case OBJECTS_ERROR:
    158       return RTEMS_INVALID_ID;
    159 
    160     case OBJECTS_LOCAL:
    161       if ( !_Timer_Is_dormant_class( the_timer->the_class ) )
    162         (void) _Watchdog_Remove( &the_timer->Ticker );
    163       _Thread_Enable_dispatch();
    164       return RTEMS_SUCCESSFUL;
    165   }
    166 
    167   return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
    168 }
    169 
    170 /*PAGE
    171  *
    172  *  rtems_timer_delete
    173  *
    174  *  This directive allows a thread to delete a timer.
    175  *
    176  *  Input parameters:
    177  *    id - timer id
    178  *
    179  *  Output parameters:
    180  *    RTEMS_SUCCESSFUL - if successful
    181  *    error code - if unsuccessful
    182  */
    183 
    184 rtems_status_code rtems_timer_delete(
    185   Objects_Id id
    186 )
    187 {
    188   Timer_Control   *the_timer;
    189   Objects_Locations       location;
    190 
    191   the_timer = _Timer_Get( id, &location );
    192   switch ( location ) {
    193     case OBJECTS_REMOTE:            /* should never return this */
    194       return RTEMS_INTERNAL_ERROR;
    195 
    196     case OBJECTS_ERROR:
    197       return RTEMS_INVALID_ID;
    198 
    199     case OBJECTS_LOCAL:
    200       _Objects_Close( &_Timer_Information, &the_timer->Object );
    201       (void) _Watchdog_Remove( &the_timer->Ticker );
    202       _Timer_Free( the_timer );
    203       _Thread_Enable_dispatch();
    204       return RTEMS_SUCCESSFUL;
    205   }
    206 
    207   return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
    208 }
    209 
    210 /*PAGE
    211  *
    212  *  rtems_timer_fire_after
    213  *
    214  *  This directive allows a thread to start a timer.
    215  *
    216  *  Input parameters:
    217  *    id      - timer id
    218  *    ticks   - interval until routine is fired
    219  *    routine - routine to schedule
    220  *
    221  *  Output parameters:
    222  *    RTEMS_SUCCESSFUL - if successful
    223  *    error code        - if unsuccessful
    224  */
    225 
    226 rtems_status_code rtems_timer_fire_after(
    227   Objects_Id                         id,
    228   rtems_interval                     ticks,
    229   rtems_timer_service_routine_entry  routine,
    230   void                              *user_data
    231 )
    232 {
    233   Timer_Control      *the_timer;
    234   Objects_Locations   location;
    235 
    236   if ( ticks == 0 )
    237     return RTEMS_INVALID_NUMBER;
    238 
    239   the_timer = _Timer_Get( id, &location );
    240   switch ( location ) {
    241     case OBJECTS_REMOTE:            /* should never return this */
    242       return RTEMS_INTERNAL_ERROR;
    243 
    244     case OBJECTS_ERROR:
    245       return RTEMS_INVALID_ID;
    246 
    247     case OBJECTS_LOCAL:
    248       (void) _Watchdog_Remove( &the_timer->Ticker );
    249       the_timer->the_class = TIMER_INTERVAL;
    250       _Watchdog_Initialize( &the_timer->Ticker, routine, id, user_data );
    251       _Watchdog_Insert_ticks( &the_timer->Ticker, ticks );
    252       _Thread_Enable_dispatch();
    253       return RTEMS_SUCCESSFUL;
    254   }
    255 
    256   return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
    257 }
    258 
    259 /*PAGE
    260  *
    261  *  rtems_timer_fire_when
    262  *
    263  *  This directive allows a thread to start a timer.
    264  *
    265  *  Input parameters:
    266  *    id        - timer id
    267  *    wall_time - time of day to fire timer
    268  *    routine   - routine to schedule
    269  *
    270  *  Output parameters:
    271  *    RTEMS_SUCCESSFUL - if successful
    272  *    error code        - if unsuccessful
    273  */
    274 
    275 rtems_status_code rtems_timer_fire_when(
    276   Objects_Id                          id,
    277   rtems_time_of_day                  *wall_time,
    278   rtems_timer_service_routine_entry   routine,
    279   void                               *user_data
    280 )
    281 {
    282   Timer_Control       *the_timer;
    283   Objects_Locations    location;
    284   rtems_interval       seconds;
    285 
    286   if ( !_TOD_Is_set )
    287     return RTEMS_NOT_DEFINED;
    288 
    289   if ( !_TOD_Validate( wall_time ) )
    290     return RTEMS_INVALID_CLOCK;
    291 
    292   seconds = _TOD_To_seconds( wall_time );
    293   if ( seconds <= _TOD_Seconds_since_epoch )
    294     return RTEMS_INVALID_CLOCK;
    295 
    296   the_timer = _Timer_Get( id, &location );
    297   switch ( location ) {
    298     case OBJECTS_REMOTE:            /* should never return this */
    299       return RTEMS_INTERNAL_ERROR;
    300 
    301     case OBJECTS_ERROR:
    302       return RTEMS_INVALID_ID;
    303 
    304     case OBJECTS_LOCAL:
    305       (void) _Watchdog_Remove( &the_timer->Ticker );
    306       the_timer->the_class = TIMER_TIME_OF_DAY;
    307       _Watchdog_Initialize( &the_timer->Ticker, routine, id, user_data );
    308       _Watchdog_Insert_seconds(
    309          &the_timer->Ticker,
    310          seconds - _TOD_Seconds_since_epoch
    311        );
    312       _Thread_Enable_dispatch();
    313       return RTEMS_SUCCESSFUL;
    314   }
    315 
    316   return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
    317 }
    318 
    319 /*PAGE
    320  *
    321  *  rtems_timer_reset
    322  *
    323  *  This directive allows a thread to reset a timer.
    324  *
    325  *  Input parameters:
    326  *    id - timer id
    327  *
    328  *  Output parameters:
    329  *    RTEMS_SUCCESSFUL - if successful
    330  *    error code        - if unsuccessful
    331  */
    332 
    333 rtems_status_code rtems_timer_reset(
    334   Objects_Id id
    335 )
    336 {
    337   Timer_Control     *the_timer;
    338   Objects_Locations  location;
    339 
    340   the_timer = _Timer_Get( id, &location );
    341   switch ( location ) {
    342     case OBJECTS_REMOTE:            /* should never return this */
    343       return RTEMS_INTERNAL_ERROR;
    344 
    345     case OBJECTS_ERROR:
    346       return RTEMS_INVALID_ID;
    347 
    348     case OBJECTS_LOCAL:
    349       if ( _Timer_Is_interval_class( the_timer->the_class ) ) {
    350         _Watchdog_Reset( &the_timer->Ticker );
    351         _Thread_Enable_dispatch();
    352         return RTEMS_SUCCESSFUL;
    353       }
    354       _Thread_Enable_dispatch();
    355       return RTEMS_NOT_DEFINED;
    356   }
    357 
    358   return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
    359 }
Note: See TracChangeset for help on using the changeset viewer.