diff --git a/Libraries/PeriphDrivers/Include/MAX32660/mxc_sys.h b/Libraries/PeriphDrivers/Include/MAX32660/mxc_sys.h index d1f4fe04b58..56f33446674 100644 --- a/Libraries/PeriphDrivers/Include/MAX32660/mxc_sys.h +++ b/Libraries/PeriphDrivers/Include/MAX32660/mxc_sys.h @@ -101,6 +101,17 @@ typedef enum { MXC_SYS_CLOCK_HIRC = MXC_V_GCR_CLK_CTRL_CLKSEL_HIRC, /**< High Frequency Internal Oscillator */ } mxc_sys_system_clock_t; +typedef enum { + MXC_SYS_CLOCK_DIV_1 = MXC_S_GCR_CLK_CTRL_PSC_DIV1, + MXC_SYS_CLOCK_DIV_2 = MXC_S_GCR_CLK_CTRL_PSC_DIV2, + MXC_SYS_CLOCK_DIV_4 = MXC_S_GCR_CLK_CTRL_PSC_DIV4, + MXC_SYS_CLOCK_DIV_8 = MXC_S_GCR_CLK_CTRL_PSC_DIV8, + MXC_SYS_CLOCK_DIV_16 = MXC_S_GCR_CLK_CTRL_PSC_DIV16, + MXC_SYS_CLOCK_DIV_32 = MXC_S_GCR_CLK_CTRL_PSC_DIV32, + MXC_SYS_CLOCK_DIV_64 = MXC_S_GCR_CLK_CTRL_PSC_DIV64, + MXC_SYS_CLOCK_DIV_128 = MXC_S_GCR_CLK_CTRL_PSC_DIV128 +} mxc_sys_system_clock_div_t; + #define MXC_SYS_USN_LEN 8 /***** Function Prototypes *****/ @@ -267,6 +278,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/Include/MAX32670/mxc_sys.h b/Libraries/PeriphDrivers/Include/MAX32670/mxc_sys.h index 93e3ec7eee3..07a7de89b8d 100644 --- a/Libraries/PeriphDrivers/Include/MAX32670/mxc_sys.h +++ b/Libraries/PeriphDrivers/Include/MAX32670/mxc_sys.h @@ -125,6 +125,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 @@ -293,6 +304,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/Include/MAX32675/mxc_sys.h b/Libraries/PeriphDrivers/Include/MAX32675/mxc_sys.h index 7be98d3934b..ece23f7a639 100644 --- a/Libraries/PeriphDrivers/Include/MAX32675/mxc_sys.h +++ b/Libraries/PeriphDrivers/Include/MAX32675/mxc_sys.h @@ -149,6 +149,17 @@ typedef enum { MXC_V_GCR_CLKCTRL_SYSCLK_SEL_EXTCLK /**< Select the External RTC Crystal Oscillator */ } 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 @@ -317,6 +328,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_me11.c b/Libraries/PeriphDrivers/Source/SYS/sys_me11.c index 9ee13a27adb..40b0221f56e 100644 --- a/Libraries/PeriphDrivers/Source/SYS/sys_me11.c +++ b/Libraries/PeriphDrivers/Source/SYS/sys_me11.c @@ -300,6 +300,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->clk_ctrl, MXC_F_GCR_CLK_CTRL_PSC, div); + + SystemCoreClockUpdate(); +} + +/* ************************************************************************** */ +mxc_sys_system_clock_div_t MXC_SYS_GetClockDiv(void) +{ + return (MXC_GCR->clk_ctrl & MXC_F_GCR_CLK_CTRL_PSC); +} + /* ************************************************************************** */ void MXC_SYS_Reset_Periph(mxc_sys_reset_t reset) { diff --git a/Libraries/PeriphDrivers/Source/SYS/sys_me15.c b/Libraries/PeriphDrivers/Source/SYS/sys_me15.c index 0e53e765fee..ed45814d4af 100644 --- a/Libraries/PeriphDrivers/Source/SYS/sys_me15.c +++ b/Libraries/PeriphDrivers/Source/SYS/sys_me15.c @@ -436,6 +436,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) {