Skyward boardcore
Loading...
Searching...
No Matches
KernelTime.h
Go to the documentation of this file.
1/* Copyright (c) 2024 Skyward Experimental Rocketry
2 * Author: Niccolò Betto
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23#pragma once
24
25#include <miosix.h>
26
27#include "TimeUtils.h"
28
29namespace Boardcore
30{
31
32namespace Kernel
33{
34
43inline long long getOldTick() { return nsToMs(miosix::getTime()); }
44
53inline long long IRQgetOldTick() { return nsToMs(miosix::IRQgetTime()); }
54
55namespace Thread
56{
57
69inline void sleepUntil(long long absoluteTimeMs)
70{
71 miosix::Thread::nanoSleepUntil(msToNs(absoluteTimeMs));
72}
73
87inline miosix::TimedWaitResult IRQenableIrqAndTimedWaitMs(
88 miosix::FastInterruptDisableLock& dLock, long long absoluteTimeMs)
89{
90 return miosix::Thread::IRQenableIrqAndTimedWait(dLock,
91 msToNs(absoluteTimeMs));
92}
93
94} // namespace Thread
95
96} // namespace Kernel
97
98} // namespace Boardcore
miosix::TimedWaitResult IRQenableIrqAndTimedWaitMs(miosix::FastInterruptDisableLock &dLock, long long absoluteTimeMs)
Stops the thread until wakeup() is called or the specified absolute time in milliseconds is reached.
Definition KernelTime.h:87
void sleepUntil(long long absoluteTimeMs)
Sleep until a given time in milliseconds.
Definition KernelTime.h:69
long long IRQgetOldTick()
Get the current time in milliseconds.
Definition KernelTime.h:53
long long getOldTick()
Get the current time in milliseconds.
Definition KernelTime.h:43
This file includes all the types the logdecoder script will decode.
constexpr long long msToNs(long long ms)
Convert milliseconds to nanoseconds.
Definition TimeUtils.h:56
constexpr long long nsToMs(long long ns)
Convert nanoseconds to milliseconds.
Definition TimeUtils.h:48