source: rtems/cpukit/rtems/include/rtems/rtems/timerimpl.h @ 03b900d

5
Last change on this file since 03b900d was 03b900d, checked in by Sebastian Huber <sebastian.huber@…>, on 02/18/16 at 07:36:26

score: Replace watchdog handler implementation

Use a red-black tree instead of delta chains.

Close #2344.
Update #2554.
Update #2555.
Close #2606.

  • Property mode set to 100644
File size: 4.8 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup ClassicTimerImpl
5 *
6 * @brief Classic Timer Implementation
7 */
8
9/*
10 * COPYRIGHT (c) 1989-2011.
11 * On-Line Applications Research Corporation (OAR).
12 *
13 * Copyright (c) 2016 embedded brains GmbH.
14 *
15 * The license and distribution terms for this file may be
16 * found in the file LICENSE in this distribution or at
17 * http://www.rtems.org/license/LICENSE.
18 */
19
20#ifndef _RTEMS_RTEMS_TIMER_INL
21#define _RTEMS_RTEMS_TIMER_INL
22
23#include <rtems/rtems/timer.h>
24#include <rtems/score/objectimpl.h>
25#include <rtems/score/thread.h>
26#include <rtems/score/watchdogimpl.h>
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32/**
33 * @defgroup ClassicTimerImpl Classic Timer Implementation
34 *
35 * @ingroup ClassicTimer
36 *
37 * @{
38 */
39
40typedef struct Timer_server_Control {
41  ISR_LOCK_MEMBER( Lock )
42
43  Chain_Control Pending;
44
45  Objects_Id server_id;
46} Timer_server_Control;
47
48/**
49 * @brief Pointer to default timer server control block.
50 *
51 * This value is @c NULL when the default timer server is not initialized.
52 */
53extern Timer_server_Control *volatile _Timer_server;
54
55/**
56 *  The following defines the information control block used to manage
57 *  this class of objects.
58 */
59extern Objects_Information  _Timer_Information;
60
61/**
62 *  @brief Timer_Allocate
63 *
64 *  This function allocates a timer control block from
65 *  the inactive chain of free timer control blocks.
66 */
67RTEMS_INLINE_ROUTINE Timer_Control *_Timer_Allocate( void )
68{
69  return (Timer_Control *) _Objects_Allocate( &_Timer_Information );
70}
71
72/**
73 *  @brief Timer_Free
74 *
75 *  This routine frees a timer control block to the
76 *  inactive chain of free timer control blocks.
77 */
78RTEMS_INLINE_ROUTINE void _Timer_Free (
79  Timer_Control *the_timer
80)
81{
82  _Objects_Free( &_Timer_Information, &the_timer->Object );
83}
84
85RTEMS_INLINE_ROUTINE Timer_Control *_Timer_Get(
86  Objects_Id         id,
87  Objects_Locations *location,
88  ISR_lock_Context  *lock_context
89)
90{
91  return (Timer_Control *) _Objects_Get_isr_disable(
92    &_Timer_Information,
93    id,
94    location,
95    lock_context
96  );
97}
98
99RTEMS_INLINE_ROUTINE Per_CPU_Control *_Timer_Acquire_critical(
100  Timer_Control    *the_timer,
101  ISR_lock_Context *lock_context
102)
103{
104  Per_CPU_Control *cpu;
105
106  cpu = _Watchdog_Get_CPU( &the_timer->Ticker );
107  _Watchdog_Per_CPU_acquire_critical( cpu, lock_context );
108
109  return cpu;
110}
111
112RTEMS_INLINE_ROUTINE void _Timer_Release(
113  Per_CPU_Control  *cpu,
114  ISR_lock_Context *lock_context
115)
116{
117  _Watchdog_Per_CPU_release_critical( cpu, lock_context );
118  _ISR_lock_ISR_enable( lock_context );
119}
120
121RTEMS_INLINE_ROUTINE bool _Timer_Is_interval_class(
122  Timer_Classes the_class
123)
124{
125  Timer_Classes mask =
126    TIMER_CLASS_BIT_NOT_DORMANT | TIMER_CLASS_BIT_TIME_OF_DAY;
127
128  return ( the_class & mask ) == TIMER_CLASS_BIT_NOT_DORMANT;
129}
130
131RTEMS_INLINE_ROUTINE bool _Timer_Is_on_task_class(
132  Timer_Classes the_class
133)
134{
135  Timer_Classes mask =
136    TIMER_CLASS_BIT_NOT_DORMANT | TIMER_CLASS_BIT_ON_TASK;
137
138  return ( the_class & mask ) == mask;
139}
140
141RTEMS_INLINE_ROUTINE Per_CPU_Watchdog_index _Timer_Watchdog_header_index(
142  Timer_Classes the_class
143)
144{
145  return ( the_class & TIMER_CLASS_BIT_TIME_OF_DAY );
146}
147
148RTEMS_INLINE_ROUTINE Watchdog_Interval _Timer_Get_CPU_ticks(
149  const Per_CPU_Control *cpu
150)
151{
152  return (Watchdog_Interval) cpu->Watchdog.ticks;
153}
154
155rtems_status_code _Timer_Fire(
156  rtems_id                           id,
157  rtems_interval                     interval,
158  rtems_timer_service_routine_entry  routine,
159  void                              *user_data,
160  Timer_Classes                      the_class,
161  Watchdog_Service_routine_entry     adaptor
162);
163
164rtems_status_code _Timer_Fire_after(
165  rtems_id                           id,
166  rtems_interval                     ticks,
167  rtems_timer_service_routine_entry  routine,
168  void                              *user_data,
169  Timer_Classes                      the_class,
170  Watchdog_Service_routine_entry     adaptor
171);
172
173rtems_status_code _Timer_Fire_when(
174  rtems_id                           id,
175  const rtems_time_of_day           *wall_time,
176  rtems_timer_service_routine_entry  routine,
177  void                              *user_data,
178  Timer_Classes                      the_class,
179  Watchdog_Service_routine_entry     adaptor
180);
181
182void _Timer_Cancel( Per_CPU_Control *cpu, Timer_Control *the_timer );
183
184void _Timer_Routine_adaptor( Watchdog_Control *the_watchdog );
185
186void _Timer_server_Routine_adaptor( Watchdog_Control *the_watchdog );
187
188RTEMS_INLINE_ROUTINE void _Timer_server_Acquire_critical(
189  Timer_server_Control *timer_server,
190  ISR_lock_Context     *lock_context
191)
192{
193  _ISR_lock_Acquire( &timer_server->Lock, lock_context );
194}
195
196RTEMS_INLINE_ROUTINE void _Timer_server_Release_critical(
197  Timer_server_Control *timer_server,
198  ISR_lock_Context     *lock_context
199)
200{
201  _ISR_lock_Release( &timer_server->Lock, lock_context );
202}
203
204/**@}*/
205
206#ifdef __cplusplus
207}
208#endif
209
210#endif
211/* end of include file */
Note: See TracBrowser for help on using the repository browser.