Skip to content

Commit da3b4bc

Browse files
bjarki-andreasenkartben
authored andcommitted
samples: boards: nordic: clock_control: add resolve and startup time
Add resolving the requested clock spec and getting the startup time of the clock for given clock spec to the nordic specific clock_control sample. Signed-off-by: Bjarki Arge Andreasen <[email protected]>
1 parent 077ff2b commit da3b4bc

File tree

1 file changed

+32
-7
lines changed
  • samples/boards/nordic/clock_control/src

1 file changed

+32
-7
lines changed

samples/boards/nordic/clock_control/src/main.c

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,43 @@ int main(void)
4545
int res;
4646
int64_t req_start_uptime;
4747
int64_t req_stop_uptime;
48+
struct nrf_clock_spec res_spec;
49+
const struct nrf_clock_spec req_spec = {
50+
.frequency = CONFIG_SAMPLE_CLOCK_FREQUENCY_HZ,
51+
.accuracy = CONFIG_SAMPLE_CLOCK_ACCURACY_PPM,
52+
.precision = CONFIG_SAMPLE_CLOCK_PRECISION,
53+
};
54+
uint32_t startup_time_us;
4855

4956
printk("\n");
5057
printk("clock name: %s\n", SAMPLE_CLOCK_NAME);
5158
printk("minimum frequency request: %uHz\n", CONFIG_SAMPLE_CLOCK_FREQUENCY_HZ);
5259
printk("minimum accuracy request: %uPPM\n", CONFIG_SAMPLE_CLOCK_ACCURACY_PPM);
5360
printk("minimum precision request: %u\n", CONFIG_SAMPLE_CLOCK_PRECISION);
5461

55-
const struct nrf_clock_spec spec = {
56-
.frequency = CONFIG_SAMPLE_CLOCK_FREQUENCY_HZ,
57-
.accuracy = CONFIG_SAMPLE_CLOCK_ACCURACY_PPM,
58-
.precision = CONFIG_SAMPLE_CLOCK_PRECISION,
59-
};
62+
printk("\n");
63+
ret = nrf_clock_control_resolve(sample_clock_dev, &req_spec, &res_spec);
64+
if (ret == 0) {
65+
printk("resolved frequency request: %uHz\n", res_spec.frequency);
66+
printk("resolved accuracy request: %uPPM\n", res_spec.accuracy);
67+
printk("resolved precision request: %u\n", res_spec.precision);
68+
} else if (ret == -ENOSYS) {
69+
printk("resolve not supported\n");
70+
} else {
71+
printk("minimum clock specs could not be resolved\n");
72+
return 0;
73+
}
74+
75+
printk("\n");
76+
ret = nrf_clock_control_get_startup_time(sample_clock_dev, &req_spec, &startup_time_us);
77+
if (ret == 0) {
78+
printk("startup time for requested spec: %uus\n", startup_time_us);
79+
} else if (ret == -ENOSYS) {
80+
printk("get startup time not supported\n");
81+
} else {
82+
printk("failed to get startup time\n");
83+
return 0;
84+
}
6085

6186
sys_notify_init_callback(&cli.notify, sample_notify_cb);
6287

@@ -65,7 +90,7 @@ int main(void)
6590
printk("\n");
6691
printk("requesting minimum clock specs\n");
6792
req_start_uptime = k_uptime_get();
68-
ret = nrf_clock_control_request(sample_clock_dev, &spec, &cli);
93+
ret = nrf_clock_control_request(sample_clock_dev, &req_spec, &cli);
6994
if (ret < 0) {
7095
printk("minimum clock specs could not be met\n");
7196
return 0;
@@ -95,7 +120,7 @@ int main(void)
95120

96121
printk("\n");
97122
printk("releasing requested clock specs\n");
98-
ret = nrf_clock_control_release(sample_clock_dev, &spec);
123+
ret = nrf_clock_control_release(sample_clock_dev, &req_spec);
99124
if (ret < 0) {
100125
printk("failed to release requested clock specs\n");
101126
return 0;

0 commit comments

Comments
 (0)