• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pybricks / pybricks-micropython / 9659196825

25 Jun 2024 08:35AM UTC coverage: 56.592% (+10.5%) from 46.065%
9659196825

push

github

laurensvalk
pybricks.hubs: Add update_heading_correction method to imu.

3760 of 6644 relevant lines covered (56.59%)

20292085.46 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.67
/lib/contiki-core/sys/timer.c
1
// SPDX-License-Identifier: BSD-3-Clause
2
/*
3
 * Copyright (c) 2004, Swedish Institute of Computer Science.
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions
8
 * are met:
9
 * 1. Redistributions of source code must retain the above copyright
10
 *    notice, this list of conditions and the following disclaimer.
11
 * 2. Redistributions in binary form must reproduce the above copyright
12
 *    notice, this list of conditions and the following disclaimer in the
13
 *    documentation and/or other materials provided with the distribution.
14
 * 3. Neither the name of the Institute nor the names of its contributors
15
 *    may be used to endorse or promote products derived from this software
16
 *    without specific prior written permission.
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
19
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
22
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28
 * SUCH DAMAGE.
29
 *
30
 * This file is part of the Contiki operating system.
31
 *
32
 * Author: Adam Dunkels <adam@sics.se>
33
 *
34
 */
35

36
/**
37
 * \file
38
 * Timer library implementation.
39
 * \author
40
 * Adam Dunkels <adam@sics.se>
41
 */
42

43
/**
44
 * \addtogroup timer
45
 * @{
46
 */
47

48
#include "contiki-conf.h"
49
#include "sys/clock.h"
50
#include "sys/timer.h"
51

52
/*---------------------------------------------------------------------------*/
53
/**
54
 * Set a timer.
55
 *
56
 * This function is used to set a timer for a time sometime in the
57
 * future. The function timer_expired() will evaluate to true after
58
 * the timer has expired.
59
 *
60
 * \param t A pointer to the timer
61
 * \param interval The interval before the timer expires.
62
 *
63
 */
64
void
65
timer_set(struct timer *t, clock_time_t interval)
92✔
66
{
67
  t->interval = interval;
92✔
68
  t->start = clock_time();
92✔
69
}
92✔
70
/*---------------------------------------------------------------------------*/
71
/**
72
 * Reset the timer with the same interval.
73
 *
74
 * This function resets the timer with the same interval that was
75
 * given to the timer_set() function. The start point of the interval
76
 * is the exact time that the timer last expired. Therefore, this
77
 * function will cause the timer to be stable over time, unlike the
78
 * timer_restart() function.
79
 *
80
 * \note Must not be executed before timer expired
81
 *
82
 * \param t A pointer to the timer.
83
 * \sa timer_restart()
84
 */
85
void
86
timer_reset(struct timer *t)
45,205✔
87
{
88
  t->start += t->interval;
45,205✔
89
}
45,205✔
90
/*---------------------------------------------------------------------------*/
91
/**
92
 * Restart the timer from the current point in time
93
 *
94
 * This function restarts a timer with the same interval that was
95
 * given to the timer_set() function. The timer will start at the
96
 * current time.
97
 *
98
 * \note A periodic timer will drift if this function is used to reset
99
 * it. For preioric timers, use the timer_reset() function instead.
100
 *
101
 * \param t A pointer to the timer.
102
 *
103
 * \sa timer_reset()
104
 */
105
void
106
timer_restart(struct timer *t)
×
107
{
108
  t->start = clock_time();
×
109
}
×
110
/*---------------------------------------------------------------------------*/
111
/**
112
 * Check if a timer has expired.
113
 *
114
 * This function tests if a timer has expired and returns true or
115
 * false depending on its status.
116
 *
117
 * \param t A pointer to the timer
118
 *
119
 * \return Non-zero if the timer has expired, zero otherwise.
120
 *
121
 */
122
int
123
timer_expired(struct timer *t)
246,874✔
124
{
125
  /* Note: Can not return diff >= t->interval so we add 1 to diff and return
126
     t->interval < diff - required to avoid an internal error in mspgcc. */
127
  clock_time_t diff = (clock_time() - t->start) + 1;
246,874✔
128
  return t->interval < diff;
246,874✔
129

130
}
131
/*---------------------------------------------------------------------------*/
132
/**
133
 * The time until the timer expires
134
 *
135
 * This function returns the time until the timer expires.
136
 *
137
 * \param t A pointer to the timer
138
 *
139
 * \return The time until the timer expires
140
 *
141
 */
142
clock_time_t
143
timer_remaining(struct timer *t)
×
144
{
145
  return t->start + t->interval - clock_time();
×
146
}
147
/*---------------------------------------------------------------------------*/
148

149
/** @} */
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc