From 5c1a33233865e77368c8c6ca65489a3aadf12b2d Mon Sep 17 00:00:00 2001 From: Furkan AKKIZ <94184469+hfakkiz@users.noreply.github.com> Date: Fri, 13 Sep 2024 22:31:22 +0300 Subject: [PATCH] feat(PeriphDrivers): Enable sysclk-div for MAX78002 (#1170) Signed-off-by: Furkan Akkiz --- .../PeriphDrivers/Include/MAX78002/mxc_sys.h | 23 +++++++++++++++++++ Libraries/PeriphDrivers/Source/SYS/sys_ai87.c | 19 +++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/Libraries/PeriphDrivers/Include/MAX78002/mxc_sys.h b/Libraries/PeriphDrivers/Include/MAX78002/mxc_sys.h index 163509a9a82..0f2ca395f33 100644 --- a/Libraries/PeriphDrivers/Include/MAX78002/mxc_sys.h +++ b/Libraries/PeriphDrivers/Include/MAX78002/mxc_sys.h @@ -187,6 +187,17 @@ typedef enum { MXC_V_GCR_CLKCTRL_SYSCLK_SEL_EXTCLK /**< Use the external system clock input. */ } mxc_sys_system_clock_t; +typedef enum { + MXC_SYS_CLOCK_DIV_1 = MXC_S_GCR_CLKCTRL_SYSCLK_DIV_DIV1, + MXC_SYS_CLOCK_DIV_2 = MXC_S_GCR_CLKCTRL_SYSCLK_DIV_DIV2, + MXC_SYS_CLOCK_DIV_4 = MXC_S_GCR_CLKCTRL_SYSCLK_DIV_DIV4, + MXC_SYS_CLOCK_DIV_8 = MXC_S_GCR_CLKCTRL_SYSCLK_DIV_DIV8, + MXC_SYS_CLOCK_DIV_16 = MXC_S_GCR_CLKCTRL_SYSCLK_DIV_DIV16, + MXC_SYS_CLOCK_DIV_32 = MXC_S_GCR_CLKCTRL_SYSCLK_DIV_DIV32, + MXC_SYS_CLOCK_DIV_64 = MXC_S_GCR_CLKCTRL_SYSCLK_DIV_DIV64, + MXC_SYS_CLOCK_DIV_128 = MXC_S_GCR_CLKCTRL_SYSCLK_DIV_DIV128 +} mxc_sys_system_clock_div_t; + #define MXC_SYS_USN_CHECKSUM_LEN 16 // Length of the USN + padding for checksum compute #define MXC_SYS_USN_CSUM_FIELD_LEN 2 // Size of the checksum field in the USN #define MXC_SYS_USN_LEN 13 // Size of the USN including the checksum @@ -355,6 +366,18 @@ int MXC_SYS_ClockSourceDisable(mxc_sys_system_clock_t clock); */ int MXC_SYS_Clock_Select(mxc_sys_system_clock_t clock); +/** + * @brief Set the system clock divider. + * @param div Enumeration for desired clock divider. + */ +void MXC_SYS_SetClockDiv(mxc_sys_system_clock_div_t div); + +/** + * @brief Get the system clock divider. + * @returns System clock divider. + */ +mxc_sys_system_clock_div_t MXC_SYS_GetClockDiv(void); + /** * @brief Wait for a clock to enable with timeout * @param ready The clock to wait for diff --git a/Libraries/PeriphDrivers/Source/SYS/sys_ai87.c b/Libraries/PeriphDrivers/Source/SYS/sys_ai87.c index 808705d1f38..dcf59a0a25a 100644 --- a/Libraries/PeriphDrivers/Source/SYS/sys_ai87.c +++ b/Libraries/PeriphDrivers/Source/SYS/sys_ai87.c @@ -502,6 +502,25 @@ int MXC_SYS_Clock_Select(mxc_sys_system_clock_t clock) return E_NO_ERROR; } +/* ************************************************************************** */ +void MXC_SYS_SetClockDiv(mxc_sys_system_clock_div_t div) +{ + /* Return if this setting is already current */ + if (div == MXC_SYS_GetClockDiv()) { + return; + } + + MXC_SETFIELD(MXC_GCR->clkctrl, MXC_F_GCR_CLKCTRL_SYSCLK_DIV, div); + + SystemCoreClockUpdate(); +} + +/* ************************************************************************** */ +mxc_sys_system_clock_div_t MXC_SYS_GetClockDiv(void) +{ + return (MXC_GCR->clkctrl & MXC_F_GCR_CLKCTRL_SYSCLK_DIV); +} + /* ************************************************************************** */ void MXC_SYS_Reset_Periph(mxc_sys_reset_t reset) {