TT Zephyr Platforms 18.11.99
Tenstorrent Firmware
Loading...
Searching...
No Matches
timer.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 Tenstorrent AI ULC
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6#ifndef TIMER_H
7#define TIMER_H
8
9#include <stdint.h>
10
11#define NS_PER_REFCLK 20
12#define REFCLK_F_MHZ 50
13#define WAIT_1US 50 /* For 50 MHZ REFCLK (20 ns period) */
14#define WAIT_100NS 5 /* For 50 MHZ REFCLK (20 ns period) */
15#define WAIT_1MS (1000 * WAIT_1US) /* For 50MHz REFCLK (20ns period) */
16#define WAIT_20NS 1 /* For 50 MHz REFCLK */
17
18uint64_t TimerTimestamp(void); /* Get current reflck timestamp */
19void Wait(uint32_t cycles);
20
22{
23 return (ns + NS_PER_REFCLK - 1) / NS_PER_REFCLK;
24}
25
26static inline void WaitNs(uint32_t ns)
27{
29
30 Wait(cycles);
31}
32
33static inline void WaitUs(uint32_t us)
34{
35 uint32_t cycles = TimerGetCyclesForNsTime(us * 1000);
36
37 Wait(cycles);
38}
39
40static inline void WaitMs(uint32_t ms)
41{
42 uint32_t cycles = TimerGetCyclesForNsTime(ms * 1000000);
43
44 Wait(cycles);
45}
46#endif
__UINT32_TYPE__ uint32_t
__UINT64_TYPE__ uint64_t
static uint32_t TimerGetCyclesForNsTime(uint32_t ns)
Definition timer.h:21
#define NS_PER_REFCLK
Definition timer.h:11
static void WaitNs(uint32_t ns)
Definition timer.h:26
void Wait(uint32_t cycles)
Definition timer.c:20
uint64_t TimerTimestamp(void)
Definition timer.c:12
static void WaitMs(uint32_t ms)
Definition timer.h:40
static void WaitUs(uint32_t us)
Definition timer.h:33