Contiki-NG
Toggle main menu visibility
Loading...
Searching...
No Matches
clock-arch.c
1
/*
2
* Copyright (c) 2026, RISE Research Institutes of Sweden AB
3
* All rights reserved.
4
*
5
* SPDX-License-Identifier: BSD-3-Clause
6
*/
7
8
#include "contiki.h"
9
#include "sys/clock.h"
10
#include "nrf.h"
11
#include <stdint.h>
12
13
/* GRTC runs at 1 MHz on nRF54L15 (matches the M33 clock-arch
14
* GRTC_TICK_FREQUENCY_HZ). 1 GRTC tick = 1 us. */
15
#define GRTC_TICK_HZ 1000000UL
16
17
/* The HAL exposes GRTC_SYSCOUNTER = SYSCOUNTER[NRF_GRTC_DOMAIN_INDEX], where
18
* NRF_GRTC_DOMAIN_INDEX = GRTC_IRQ_GROUP. With NRF_FLPR defined,
19
* GRTC_IRQ_GROUP = 0, so we read SYSCOUNTER[0] - the FLPR's dedicated read
20
* port. The underlying 52-bit counter is shared with the M33. */
21
22
static
inline
uint64_t
23
grtc_syscounter_now(
void
)
24
{
25
uint32_t lo, hi;
26
do
{
27
lo = NRF_GRTC_S->SYSCOUNTER[0].SYSCOUNTERL;
28
hi = NRF_GRTC_S->SYSCOUNTER[0].SYSCOUNTERH;
29
}
while
(hi & GRTC_SYSCOUNTER_SYSCOUNTERH_BUSY_Msk);
30
return
((uint64_t)(hi & GRTC_SYSCOUNTER_SYSCOUNTERH_VALUE_Msk) << 32) | lo;
31
}
32
33
void
34
clock_init
(
void
)
35
{
36
/* GRTC is already running - the M33 application brings it up before
37
* releasing the VPR. Nothing to do here. */
38
}
39
40
clock_time_t
41
clock_time
(
void
)
42
{
43
return
(clock_time_t)(grtc_syscounter_now() / (GRTC_TICK_HZ /
CLOCK_SECOND
));
44
}
45
46
unsigned
long
47
clock_seconds
(
void
)
48
{
49
return
(
unsigned
long
)(grtc_syscounter_now() / GRTC_TICK_HZ);
50
}
51
52
void
53
clock_wait
(clock_time_t t)
54
{
55
clock_time_t end =
clock_time
() + t;
56
while
(
clock_time
() < end) { }
57
}
58
59
void
60
clock_delay_usec
(uint16_t us)
61
{
62
uint64_t end = grtc_syscounter_now() + us;
63
while
(grtc_syscounter_now() < end) { }
64
}
65
66
void
67
clock_delay
(
unsigned
int
us)
68
{
69
clock_delay_usec
((uint16_t)us);
70
}
CLOCK_SECOND
#define CLOCK_SECOND
A second, measured in system clock time.
Definition
clock.h:105
clock_seconds
unsigned long clock_seconds(void)
Get the current value of the platform seconds.
Definition
clock-arch.c:98
clock_init
void clock_init(void)
Initialize the clock library.
Definition
clock-arch.c:77
clock_delay_usec
void clock_delay_usec(uint16_t dt)
Delay a given number of microseconds.
Definition
clock-arch.c:114
clock_wait
void clock_wait(clock_time_t i)
Wait for a given number of ticks.
Definition
clock-arch.c:104
clock_time
clock_time_t clock_time(void)
Get the current clock time.
Definition
clock-arch.c:92
clock_delay
void clock_delay(unsigned int i)
Obsolete delay function but we implement it here since some code still uses it.
Definition
clock-arch.c:139
arch
cpu
nrf-vpr
clock-arch.c
Generated on
for Contiki-NG by
1.17.0