summaryrefslogtreecommitdiffstats
path: root/cpukit/include/rtems/rtems/timerimpl.h
blob: f74d970e57c2fc398f69c4c882b5a0d856c16577 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/* SPDX-License-Identifier: BSD-2-Clause */

/**
 * @file
 *
 * @ingroup RTEMSImplClassicTimer
 *
 * @brief This header file provides the implementation interfaces of
 *   the @ref RTEMSImplClassicTimer.
 */

/*
 * COPYRIGHT (c) 1989-2011.
 * On-Line Applications Research Corporation (OAR).
 *
 * Copyright (c) 2016 embedded brains GmbH.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _RTEMS_RTEMS_TIMER_INL
#define _RTEMS_RTEMS_TIMER_INL

#include <rtems/rtems/timerdata.h>
#include <rtems/score/objectimpl.h>
#include <rtems/score/thread.h>
#include <rtems/score/watchdogimpl.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @defgroup RTEMSImplClassicTimer Timer Manager
 *
 * @ingroup RTEMSImplClassic
 *
 * @brief This group contains the Timer Manager implementation.
 *
 * @{
 */

typedef struct Timer_server_Control {
  ISR_LOCK_MEMBER( Lock )

  Chain_Control Pending;

  Objects_Id server_id;
} Timer_server_Control;

/**
 * @brief Pointer to default timer server control block.
 *
 * This value is @c NULL when the default timer server is not initialized.
 */
extern Timer_server_Control *volatile _Timer_server;

/**
 *  @brief Timer_Allocate
 *
 *  This function allocates a timer control block from
 *  the inactive chain of free timer control blocks.
 */
RTEMS_INLINE_ROUTINE Timer_Control *_Timer_Allocate( void )
{
  return (Timer_Control *) _Objects_Allocate( &_Timer_Information );
}

/**
 *  @brief Timer_Free
 *
 *  This routine frees a timer control block to the
 *  inactive chain of free timer control blocks.
 */
RTEMS_INLINE_ROUTINE void _Timer_Free (
  Timer_Control *the_timer
)
{
  _Objects_Free( &_Timer_Information, &the_timer->Object );
}

RTEMS_INLINE_ROUTINE Timer_Control *_Timer_Get(
  Objects_Id         id,
  ISR_lock_Context  *lock_context
)
{
  return (Timer_Control *) _Objects_Get(
    id,
    lock_context,
    &_Timer_Information
  );
}

RTEMS_INLINE_ROUTINE Per_CPU_Control *_Timer_Acquire_critical(
  Timer_Control    *the_timer,
  ISR_lock_Context *lock_context
)
{
  Per_CPU_Control *cpu;

  cpu = _Watchdog_Get_CPU( &the_timer->Ticker );
  _Watchdog_Per_CPU_acquire_critical( cpu, lock_context );

  return cpu;
}

RTEMS_INLINE_ROUTINE void _Timer_Release(
  Per_CPU_Control  *cpu,
  ISR_lock_Context *lock_context
)
{
  _Watchdog_Per_CPU_release_critical( cpu, lock_context );
  _ISR_lock_ISR_enable( lock_context );
}

RTEMS_INLINE_ROUTINE bool _Timer_Is_interval_class(
  Timer_Classes the_class
)
{
  int mask;

  mask = TIMER_CLASS_BIT_NOT_DORMANT | TIMER_CLASS_BIT_TIME_OF_DAY;
  return ( the_class & mask ) == TIMER_CLASS_BIT_NOT_DORMANT;
}

RTEMS_INLINE_ROUTINE bool _Timer_Is_on_task_class(
  Timer_Classes the_class
)
{
  int mask;

  mask = TIMER_CLASS_BIT_NOT_DORMANT | TIMER_CLASS_BIT_ON_TASK;
  return ( the_class & mask ) == mask;
}

RTEMS_INLINE_ROUTINE Per_CPU_Watchdog_index _Timer_Watchdog_header_index(
  Timer_Classes the_class
)
{
  return (Per_CPU_Watchdog_index) ( the_class & TIMER_CLASS_BIT_TIME_OF_DAY );
}

RTEMS_INLINE_ROUTINE Watchdog_Interval _Timer_Get_CPU_ticks(
  const Per_CPU_Control *cpu
)
{
  return (Watchdog_Interval) cpu->Watchdog.ticks;
}

rtems_status_code _Timer_Fire(
  rtems_id                           id,
  rtems_interval                     interval,
  rtems_timer_service_routine_entry  routine,
  void                              *user_data,
  Timer_Classes                      the_class,
  Watchdog_Service_routine_entry     adaptor
);

rtems_status_code _Timer_Fire_after(
  rtems_id                           id,
  rtems_interval                     ticks,
  rtems_timer_service_routine_entry  routine,
  void                              *user_data,
  Timer_Classes                      the_class,
  Watchdog_Service_routine_entry     adaptor
);

rtems_status_code _Timer_Fire_when(
  rtems_id                           id,
  const rtems_time_of_day           *wall_time,
  rtems_timer_service_routine_entry  routine,
  void                              *user_data,
  Timer_Classes                      the_class,
  Watchdog_Service_routine_entry     adaptor
);

void _Timer_Cancel( Per_CPU_Control *cpu, Timer_Control *the_timer );

void _Timer_Routine_adaptor( Watchdog_Control *the_watchdog );

void _Timer_server_Routine_adaptor( Watchdog_Control *the_watchdog );

RTEMS_INLINE_ROUTINE void _Timer_server_Acquire_critical(
  Timer_server_Control *timer_server,
  ISR_lock_Context     *lock_context
)
{
  _ISR_lock_Acquire( &timer_server->Lock, lock_context );
}

RTEMS_INLINE_ROUTINE void _Timer_server_Release_critical(
  Timer_server_Control *timer_server,
  ISR_lock_Context     *lock_context
)
{
  _ISR_lock_Release( &timer_server->Lock, lock_context );
}

/**@}*/

#ifdef __cplusplus
}
#endif

#endif
/* end of include file */