Zephyr Project API 4.2.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
clock_control_bflb_common.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025 MASSDRIVER EI (massdriver.space)
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7/* Contains short functions relevant to timing and clocks common to all Bouffalolab platforms */
8
9#ifndef ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_BFLB_COMMON_H_
10#define ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_BFLB_COMMON_H_
11
12/* Common main clock mux (clock_bflb_set_root_clock) */
13/* XCLK is RC32M, main clock is XCLK */
14#define BFLB_MAIN_CLOCK_RC32M 0
15/* XCLK is Crystal, main clock is XCLK */
16#define BFLB_MAIN_CLOCK_XTAL 1
17/* XCLK is RC32M, main clock is PLL */
18#define BFLB_MAIN_CLOCK_PLL_RC32M 2
19/* XCLK is Crystal, main clock is PLL */
20#define BFLB_MAIN_CLOCK_PLL_XTAL 3
21
22/* Function that busy waits for a few cycles */
23static inline void clock_bflb_settle(void)
24{
25 __asm__ volatile (".rept 20 ; nop ; .endr");
26}
27
28static inline void clock_bflb_set_root_clock(uint32_t clock)
29{
30 uint32_t tmp;
31
32 /* invalid value, fallback to internal 32M */
33 if (clock > BFLB_MAIN_CLOCK_PLL_XTAL) {
35 }
36 tmp = sys_read32(HBN_BASE + HBN_GLB_OFFSET);
37 tmp = (tmp & HBN_ROOT_CLK_SEL_UMSK) | (clock << HBN_ROOT_CLK_SEL_POS);
38 sys_write32(tmp, HBN_BASE + HBN_GLB_OFFSET);
39
41}
42
44{
45 uint32_t tmp;
46
47 tmp = sys_read32(HBN_BASE + HBN_GLB_OFFSET);
48 return ((tmp & HBN_ROOT_CLK_SEL_MSK) >> HBN_ROOT_CLK_SEL_POS);
49}
50
51#endif /* ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_BFLB_COMMON_H_ */
static uint32_t clock_bflb_get_root_clock(void)
Definition clock_control_bflb_common.h:43
static void clock_bflb_settle(void)
Definition clock_control_bflb_common.h:23
#define BFLB_MAIN_CLOCK_RC32M
Definition clock_control_bflb_common.h:14
#define BFLB_MAIN_CLOCK_PLL_XTAL
Definition clock_control_bflb_common.h:20
static void clock_bflb_set_root_clock(uint32_t clock)
Definition clock_control_bflb_common.h:28
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
static ALWAYS_INLINE void sys_write32(uint32_t data, mem_addr_t addr)
Definition sys-io-common.h:70
static ALWAYS_INLINE uint32_t sys_read32(mem_addr_t addr)
Definition sys-io-common.h:59