Skip to content

Commit 5c1a332

Browse files
authored
feat(PeriphDrivers): Enable sysclk-div for MAX78002 (#1170)
Signed-off-by: Furkan Akkiz <[email protected]>
1 parent 7d512b1 commit 5c1a332

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

Libraries/PeriphDrivers/Include/MAX78002/mxc_sys.h

+23
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,17 @@ typedef enum {
187187
MXC_V_GCR_CLKCTRL_SYSCLK_SEL_EXTCLK /**< Use the external system clock input. */
188188
} mxc_sys_system_clock_t;
189189

190+
typedef enum {
191+
MXC_SYS_CLOCK_DIV_1 = MXC_S_GCR_CLKCTRL_SYSCLK_DIV_DIV1,
192+
MXC_SYS_CLOCK_DIV_2 = MXC_S_GCR_CLKCTRL_SYSCLK_DIV_DIV2,
193+
MXC_SYS_CLOCK_DIV_4 = MXC_S_GCR_CLKCTRL_SYSCLK_DIV_DIV4,
194+
MXC_SYS_CLOCK_DIV_8 = MXC_S_GCR_CLKCTRL_SYSCLK_DIV_DIV8,
195+
MXC_SYS_CLOCK_DIV_16 = MXC_S_GCR_CLKCTRL_SYSCLK_DIV_DIV16,
196+
MXC_SYS_CLOCK_DIV_32 = MXC_S_GCR_CLKCTRL_SYSCLK_DIV_DIV32,
197+
MXC_SYS_CLOCK_DIV_64 = MXC_S_GCR_CLKCTRL_SYSCLK_DIV_DIV64,
198+
MXC_SYS_CLOCK_DIV_128 = MXC_S_GCR_CLKCTRL_SYSCLK_DIV_DIV128
199+
} mxc_sys_system_clock_div_t;
200+
190201
#define MXC_SYS_USN_CHECKSUM_LEN 16 // Length of the USN + padding for checksum compute
191202
#define MXC_SYS_USN_CSUM_FIELD_LEN 2 // Size of the checksum field in the USN
192203
#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);
355366
*/
356367
int MXC_SYS_Clock_Select(mxc_sys_system_clock_t clock);
357368

369+
/**
370+
* @brief Set the system clock divider.
371+
* @param div Enumeration for desired clock divider.
372+
*/
373+
void MXC_SYS_SetClockDiv(mxc_sys_system_clock_div_t div);
374+
375+
/**
376+
* @brief Get the system clock divider.
377+
* @returns System clock divider.
378+
*/
379+
mxc_sys_system_clock_div_t MXC_SYS_GetClockDiv(void);
380+
358381
/**
359382
* @brief Wait for a clock to enable with timeout
360383
* @param ready The clock to wait for

Libraries/PeriphDrivers/Source/SYS/sys_ai87.c

+19
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,25 @@ int MXC_SYS_Clock_Select(mxc_sys_system_clock_t clock)
502502
return E_NO_ERROR;
503503
}
504504

505+
/* ************************************************************************** */
506+
void MXC_SYS_SetClockDiv(mxc_sys_system_clock_div_t div)
507+
{
508+
/* Return if this setting is already current */
509+
if (div == MXC_SYS_GetClockDiv()) {
510+
return;
511+
}
512+
513+
MXC_SETFIELD(MXC_GCR->clkctrl, MXC_F_GCR_CLKCTRL_SYSCLK_DIV, div);
514+
515+
SystemCoreClockUpdate();
516+
}
517+
518+
/* ************************************************************************** */
519+
mxc_sys_system_clock_div_t MXC_SYS_GetClockDiv(void)
520+
{
521+
return (MXC_GCR->clkctrl & MXC_F_GCR_CLKCTRL_SYSCLK_DIV);
522+
}
523+
505524
/* ************************************************************************** */
506525
void MXC_SYS_Reset_Periph(mxc_sys_reset_t reset)
507526
{

0 commit comments

Comments
 (0)