hc
2024-11-01 2f529f9b558ca1c1bd74be7437a84e4711743404
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
/*
 * Copyright (C) 2011 Philippe Gerum <rpm@xenomai.org>.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
 */
 
#include <copperplate/threadobj.h>
#include "timer.h"
 
/**
 * @ingroup alchemy
 * @defgroup alchemy_timer Timer management services
 *
 * Services for reading and spinning on the hardware timer
 *
 * @{
 */
 
struct clockobj alchemy_clock;
 
/**
 * @fn RTIME rt_timer_ns2ticks(SRTIME ns)
 * @brief Convert nanoseconds to Alchemy clock ticks.
 *
 * Convert a count of nanoseconds to Alchemy clock ticks.  This
 * routine operates on signed nanosecond values. This is the converse
 * call to rt_timer_ticks2ns().
 *
 * @param ns The count of nanoseconds to convert.
 *
 * @return The corresponding value expressed in clock ticks of the
 * Alchemy clock. The resolution of the Alchemy clock can be set using
 * the --alchemy-clock-resolution option when starting the application
 * process (defaults to 1 nanosecond).
 *
 * @apitags{unrestricted}
 */
SRTIME rt_timer_ns2ticks(SRTIME ns)
{
   return clockobj_ns_to_ticks(&alchemy_clock, ns);
}
 
/**
 * @fn RTIME rt_timer_ticks2ns(SRTIME ns)
 * @brief Convert Alchemy clock ticks to nanoseconds.
 *
 * Convert a count of Alchemy clock ticks to nanoseconds.  This
 * routine operates on signed nanosecond values. This is the converse
 * call to rt_timer_ns2ticks().
 *
 * @param ns The count of nanoseconds to convert.
 *
 * @return The corresponding value expressed in nanoseconds.  The
 * resolution of the Alchemy clock can be set using the
 * --alchemy-clock-resolution option when starting the application
 * process (defaults to 1 nanosecond).
 *
 * @apitags{unrestricted}
 */
SRTIME rt_timer_ticks2ns(SRTIME ticks)
{
   return clockobj_ticks_to_ns(&alchemy_clock, ticks);
}
 
/**
 * @fn void rt_timer_inquire(RT_TIMER_INFO *info)
 * @brief Inquire about the Alchemy clock.
 *
 * Return status information about the Alchemy clock.
 *
 * @param info The address of a @ref RT_TIMER_INFO "structure" to fill
 * with the clock information.
 *
 * @apitags{unrestricted}
 */
void rt_timer_inquire(RT_TIMER_INFO *info)
{
   info->period = clockobj_get_resolution(&alchemy_clock);
   info->date = clockobj_get_time(&alchemy_clock);
}
 
/**
 * @fn void rt_timer_spin(RTIME ns)
 * @brief Busy wait burning CPU cycles.
 *
 * Enter a busy waiting loop for a count of nanoseconds.
 *
 * Since this service is always called with interrupts enabled, the
 * caller might be preempted by other real-time activities, therefore
 * the actual delay might be longer than specified.
 *
 * @param ns The time to wait expressed in nanoseconds.
 *
 * @apitags{unrestricted}
 */
void rt_timer_spin(RTIME ns)
{
   threadobj_spin(ns);
}
 
/** @} */