7
7
#include <zephyr/kernel.h>
8
8
#include <zephyr/ztest.h>
9
9
#include <zephyr/drivers/gpio.h>
10
+ #include <zephyr/drivers/clock_control/nrf_clock_control.h>
10
11
11
12
12
13
static volatile uint32_t count_clk ;
@@ -15,6 +16,61 @@ static struct gpio_callback clk_cb_data;
15
16
static const struct gpio_dt_spec gpio_clk_spec =
16
17
GPIO_DT_SPEC_GET_BY_IDX (DT_PATH (zephyr_user ), gpios , 0 );
17
18
19
+ #define GRTC_NODE DT_NODELABEL(grtc)
20
+ #if DT_NODE_HAS_PROP (GRTC_NODE , clkout_fast_frequency_hz )
21
+ static struct onoff_client clk_cli ;
22
+ static volatile bool clock_requested ;
23
+
24
+ /* Callback for clock request. */
25
+ static void clock_started_callback (struct onoff_manager * mgr ,
26
+ struct onoff_client * cli ,
27
+ uint32_t state ,
28
+ int res )
29
+ {
30
+ (void )mgr ;
31
+ (void )cli ;
32
+ (void )state ;
33
+ (void )res ;
34
+
35
+ clock_requested = true;
36
+ }
37
+ #if DT_NODE_HAS_STATUS_OKAY (DT_NODELABEL (fll16m ))
38
+ #define NODE_HFCLK DT_NODELABEL(fll16m)
39
+ #define HFCLK_FREQUENCY DT_PROP_OR(NODE_HFCLK, frequency, 0)
40
+
41
+ static const struct device * fll16m = DEVICE_DT_GET (NODE_HFCLK );
42
+ static const struct nrf_clock_spec hfclk_spec = {
43
+ .frequency = HFCLK_FREQUENCY ,
44
+ };
45
+ #elif defined(CONFIG_SOC_SERIES_NRF54LX )
46
+ static struct onoff_manager * clk_mgr ;
47
+ #endif
48
+
49
+ static int hf_clock_request (void )
50
+ {
51
+ sys_notify_init_callback (& clk_cli .notify , clock_started_callback );
52
+ #if DT_NODE_HAS_STATUS_OKAY (DT_NODELABEL (fll16m ))
53
+ return nrf_clock_control_request (fll16m , & hfclk_spec , & clk_cli );
54
+ #elif defined(CONFIG_SOC_SERIES_NRF54LX )
55
+ clock_control_subsys_t subsys = CLOCK_CONTROL_NRF_SUBSYS_HF ;
56
+
57
+ clk_mgr = z_nrf_clock_control_get_onoff (subsys );
58
+ return onoff_request (clk_mgr , & clk_cli );
59
+ #endif
60
+ return - ENOTSUP ;
61
+ }
62
+
63
+ static int hf_clock_release (void )
64
+ {
65
+ #if DT_NODE_HAS_STATUS_OKAY (DT_NODELABEL (fll16m ))
66
+ return nrf_clock_control_release (fll16m , & hfclk_spec );
67
+ #elif defined(CONFIG_SOC_SERIES_NRF54LX )
68
+ return onoff_release (clk_mgr );
69
+ #endif
70
+ return - ENOTSUP ;
71
+ }
72
+ #endif /* DT_NODE_HAS_PROP(GRTC_NODE, clkout_fast_frequency_hz) */
73
+
18
74
/* ISR that counts rising edges on the CLK signal. */
19
75
static void gpio_clk_isr (const struct device * dev , struct gpio_callback * cb , uint32_t pins )
20
76
{
@@ -37,10 +93,23 @@ ZTEST(drivers_grtc_clk_out, test_grtc_clk_output)
37
93
TC_PRINT ("Frequency = %u\n" , CONFIG_TEST_GRTC_FREQUENCY );
38
94
TC_PRINT ("Tolerance = %u clock edges\n" , CONFIG_TEST_GRTC_TOLERANCE );
39
95
96
+ #if DT_NODE_HAS_PROP (GRTC_NODE , clkout_fast_frequency_hz )
97
+ int ret = hf_clock_request ();
98
+
99
+ zassert_true (ret >= 0 , "Failed to request clock." );
100
+ k_msleep (20 );
101
+ zassert_true (clock_requested == true, "Failed to request clock." );
102
+ #endif
103
+
40
104
count_clk = 0 ;
41
105
k_msleep (1000 );
42
106
temp = count_clk ;
43
107
108
+ #if DT_NODE_HAS_PROP (GRTC_NODE , clkout_fast_frequency_hz )
109
+ ret = hf_clock_release ();
110
+ zassert_true (ret >= 0 , "Failed to release clock." );
111
+ #endif
112
+
44
113
/* Verify number of edges on CLK (with some tolerance) */
45
114
zassert_true (temp >= min ,
46
115
"CLK has %u rising edges, while at least %u is expected." ,
0 commit comments