source: rtems/cpukit/rtems/include/rtems/rtems/timerimpl.h @ 88575577

5
Last change on this file since 88575577 was 88575577, checked in by Sebastian Huber <sebastian.huber@…>, on 04/19/16 at 12:14:31

score: Optimize _Objects_Get_local()

Make the id the first parameter since usual callers get the object
identifier as the first parameter themself.

  • Property mode set to 100644
File size: 4.7 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  ISR_lock_Context  *lock_context
88)
89{
90  return (Timer_Control *) _Objects_Get_local(
91    id,
92    &_Timer_Information,
93    lock_context
94  );
95}
96
97RTEMS_INLINE_ROUTINE Per_CPU_Control *_Timer_Acquire_critical(
98  Timer_Control    *the_timer,
99  ISR_lock_Context *lock_context
100)
101{
102  Per_CPU_Control *cpu;
103
104  cpu = _Watchdog_Get_CPU( &the_timer->Ticker );
105  _Watchdog_Per_CPU_acquire_critical( cpu, lock_context );
106
107  return cpu;
108}
109
110RTEMS_INLINE_ROUTINE void _Timer_Release(
111  Per_CPU_Control  *cpu,
112  ISR_lock_Context *lock_context
113)
114{
115  _Watchdog_Per_CPU_release_critical( cpu, lock_context );
116  _ISR_lock_ISR_enable( lock_context );
117}
118
119RTEMS_INLINE_ROUTINE bool _Timer_Is_interval_class(
120  Timer_Classes the_class
121)
122{
123  Timer_Classes mask =
124    TIMER_CLASS_BIT_NOT_DORMANT | TIMER_CLASS_BIT_TIME_OF_DAY;
125
126  return ( the_class & mask ) == TIMER_CLASS_BIT_NOT_DORMANT;
127}
128
129RTEMS_INLINE_ROUTINE bool _Timer_Is_on_task_class(
130  Timer_Classes the_class
131)
132{
133  Timer_Classes mask =
134    TIMER_CLASS_BIT_NOT_DORMANT | TIMER_CLASS_BIT_ON_TASK;
135
136  return ( the_class & mask ) == mask;
137}
138
139RTEMS_INLINE_ROUTINE Per_CPU_Watchdog_index _Timer_Watchdog_header_index(
140  Timer_Classes the_class
141)
142{
143  return ( the_class & TIMER_CLASS_BIT_TIME_OF_DAY );
144}
145
146RTEMS_INLINE_ROUTINE Watchdog_Interval _Timer_Get_CPU_ticks(
147  const Per_CPU_Control *cpu
148)
149{
150  return (Watchdog_Interval) cpu->Watchdog.ticks;
151}
152
153rtems_status_code _Timer_Fire(
154  rtems_id                           id,
155  rtems_interval                     interval,
156  rtems_timer_service_routine_entry  routine,
157  void                              *user_data,
158  Timer_Classes                      the_class,
159  Watchdog_Service_routine_entry     adaptor
160);
161
162rtems_status_code _Timer_Fire_after(
163  rtems_id                           id,
164  rtems_interval                     ticks,
165  rtems_timer_service_routine_entry  routine,
166  void                              *user_data,
167  Timer_Classes                      the_class,
168  Watchdog_Service_routine_entry     adaptor
169);
170
171rtems_status_code _Timer_Fire_when(
172  rtems_id                           id,
173  const rtems_time_of_day           *wall_time,
174  rtems_timer_service_routine_entry  routine,
175  void                              *user_data,
176  Timer_Classes                      the_class,
177  Watchdog_Service_routine_entry     adaptor
178);
179
180void _Timer_Cancel( Per_CPU_Control *cpu, Timer_Control *the_timer );
181
182void _Timer_Routine_adaptor( Watchdog_Control *the_watchdog );
183
184void _Timer_server_Routine_adaptor( Watchdog_Control *the_watchdog );
185
186RTEMS_INLINE_ROUTINE void _Timer_server_Acquire_critical(
187  Timer_server_Control *timer_server,
188  ISR_lock_Context     *lock_context
189)
190{
191  _ISR_lock_Acquire( &timer_server->Lock, lock_context );
192}
193
194RTEMS_INLINE_ROUTINE void _Timer_server_Release_critical(
195  Timer_server_Control *timer_server,
196  ISR_lock_Context     *lock_context
197)
198{
199  _ISR_lock_Release( &timer_server->Lock, lock_context );
200}
201
202/**@}*/
203
204#ifdef __cplusplus
205}
206#endif
207
208#endif
209/* end of include file */
Note: See TracBrowser for help on using the repository browser.