Skip to content

Commit

Permalink
[nrf fromlist] drivers: clock_control: nrf: Move NRF_PERIPH_GET_FREQU…
Browse files Browse the repository at this point in the history
…ENCY

Move macro from nrf_clock_control.h to soc_nrf_common.h. Clock control
header fetches many dependencies (e.g. onoff.h) so move macro to more
low level header.

Upstream PR #: 85870

Signed-off-by: Krzysztof Chruściński <[email protected]>
  • Loading branch information
nordic-krch authored and nordicjm committed Feb 24, 2025
1 parent d1d8c78 commit 00cfdc0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
1 change: 1 addition & 0 deletions drivers/counter/counter_nrfx_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <soc.h>
#include <zephyr/drivers/counter.h>
#include <zephyr/drivers/clock_control/nrf_clock_control.h>
#include <zephyr/devicetree.h>
Expand Down
19 changes: 0 additions & 19 deletions include/zephyr/drivers/clock_control/nrf_clock_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -343,25 +343,6 @@ void nrf_clock_control_hfxo_release(void);

#endif /* defined(CONFIG_CLOCK_CONTROL_NRF2) */

/** @brief Get clock frequency that is used for the given node.
*
* Macro checks if node has clock property and if yes then if clock has clock_frequency property
* then it is returned. If it has supported_clock_frequency property with the list of supported
* frequencies then the last one is returned with assumption that they are ordered and the last
* one is the highest. If node does not have clock then 16 MHz is returned which is the default
* frequency.
*
* @param node Devicetree node.
*
* @return Frequency of the clock that is used for the node.
*/
#define NRF_PERIPH_GET_FREQUENCY(node) \
COND_CODE_1(DT_CLOCKS_HAS_IDX(node, 0), \
(COND_CODE_1(DT_NODE_HAS_PROP(DT_CLOCKS_CTLR(node), clock_frequency), \
(DT_PROP(DT_CLOCKS_CTLR(node), clock_frequency)), \
(DT_PROP_LAST(DT_CLOCKS_CTLR(node), supported_clock_frequency)))), \
(NRFX_MHZ_TO_HZ(16)))

#ifdef __cplusplus
}
#endif
Expand Down
19 changes: 19 additions & 0 deletions soc/nordic/common/soc_nrf_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,25 @@
DT_PINCTRL_HAS_NAME(node_id, sleep), \
DT_NODE_PATH(node_id) " defined without sleep state")

/** @brief Get clock frequency that is used for the given node.
*
* Macro checks if node has clock property and if yes then if clock has clock_frequency property
* then it is returned. If it has supported_clock_frequency property with the list of supported
* frequencies then the last one is returned with assumption that they are ordered and the last
* one is the highest. If node does not have clock then 16 MHz is returned which is the default
* frequency.
*
* @param node Devicetree node.
*
* @return Frequency of the clock that is used for the node.
*/
#define NRF_PERIPH_GET_FREQUENCY(node) \
COND_CODE_1(DT_CLOCKS_HAS_IDX(node, 0), \
(COND_CODE_1(DT_NODE_HAS_PROP(DT_CLOCKS_CTLR(node), clock_frequency), \
(DT_PROP(DT_CLOCKS_CTLR(node), clock_frequency)), \
(DT_PROP_LAST(DT_CLOCKS_CTLR(node), supported_clock_frequency)))), \
(NRFX_MHZ_TO_HZ(16)))

#endif /* !_ASMLANGUAGE */

#endif

0 comments on commit 00cfdc0

Please sign in to comment.