Skip to content

Commit 67da08b

Browse files
nordic-krchbjarki-andreasen
authored andcommitted
[nrf fromtree] drivers: clock_control: nrf: Add helper macro for getting clock frequency
Add NRF_PERIPH_GET_FREQUENCY() that returns the frequency of clock that is used for the node. Signed-off-by: Krzysztof Chruściński <[email protected]>
1 parent 65d3170 commit 67da08b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

include/zephyr/drivers/clock_control/nrf_clock_control.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,25 @@ int nrf_clock_control_cancel_or_release(const struct device *dev,
319319

320320
#endif /* defined(CONFIG_CLOCK_CONTROL_NRF2) */
321321

322+
/** @brief Get clock frequency that is used for the given node.
323+
*
324+
* Macro checks if node has clock property and if yes then if clock has clock_frequency property
325+
* then it is returned. If it has supported_clock_frequency property with the list of supported
326+
* frequencies then the last one is returned with assumption that they are ordered and the last
327+
* one is the highest. If node does not have clock then 16 MHz is returned which is the default
328+
* frequency.
329+
*
330+
* @param node Devicetree node.
331+
*
332+
* @return Frequency of the clock that is used for the node.
333+
*/
334+
#define NRF_PERIPH_GET_FREQUENCY(node) \
335+
COND_CODE_1(DT_CLOCKS_HAS_IDX(node, 0), \
336+
(COND_CODE_1(DT_NODE_HAS_PROP(DT_CLOCKS_CTLR(node), clock_frequency), \
337+
(DT_PROP(DT_CLOCKS_CTLR(node), clock_frequency)), \
338+
(DT_PROP_LAST(DT_CLOCKS_CTLR(node), supported_clock_frequency)))), \
339+
(DT_PROP_OR(node, max_frequency, NRFX_MHZ_TO_HZ(16))))
340+
322341
#ifdef __cplusplus
323342
}
324343
#endif

0 commit comments

Comments
 (0)