Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(PeriphDrivers): Add MAX32657 non-blocking clock measurement #1322

Merged
merged 4 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Libraries/PeriphDrivers/Include/MAX32657/mxc_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,15 @@ int MXC_SYS_LockDAP_Permanent(void);
*
* @details Assumes that measurement clock and ERFO are enabled.
* Increasing compareClockTicks will provide a more accurate measurement,
* but there are limits that could cause overflow.
* but there are limits that could cause overflow. Start and Get function
* are used for non-blocking implementations.
*
* @param clock Enumeration for which clock to measure.
* @param compareClockTicks Number of ticks of the comparison clock to use for measurement.
*/
uint32_t MXC_SYS_ClockMeasure(mxc_sys_compare_clock_t clock, uint32_t compareClockTicks);
void MXC_SYS_StartClockMeasure(mxc_sys_compare_clock_t clock, uint32_t compareClockTicks);
uint32_t MXC_SYS_GetClockMeasure(void);
ttmut marked this conversation as resolved.
Show resolved Hide resolved

#ifdef __cplusplus
}
Expand Down
3 changes: 3 additions & 0 deletions Libraries/PeriphDrivers/Source/LP/lp_me30.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ void MXC_LP_EnterStandbyMode(void)

/* Go into Standby mode and wait for an interrupt to wake the processor */
__WFI();

/* Clear SLEEPDEEP bit to prevent WFI from entering deep sleep */
CLR_SLEEPDEEP();
}

void MXC_LP_EnterBackupMode(void)
Expand Down
24 changes: 21 additions & 3 deletions Libraries/PeriphDrivers/Source/SYS/sys_me30.c
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ int MXC_SYS_LockDAP_Permanent(void)
#endif

/* ************************************************************************** */
uint32_t MXC_SYS_ClockMeasure(mxc_sys_compare_clock_t clock, uint32_t compareClockTicks)
void MXC_SYS_StartClockMeasure(mxc_sys_compare_clock_t clock, uint32_t compareClockTicks)
{
/* Assuming that both clocks are already enabled */

Expand All @@ -563,14 +563,32 @@ uint32_t MXC_SYS_ClockMeasure(mxc_sys_compare_clock_t clock, uint32_t compareClo

/* Start the procedure */
MXC_FCR->frqcntctrl |= MXC_F_FCR_FRQCNTCTRL_START;
}

/* Wait for the procedure to finish */
while (!(MXC_FCR->intfl & MXC_F_FCR_INTFL_FRQCNT)) {}
/* ************************************************************************** */
uint32_t MXC_SYS_GetClockMeasure(void)
{
/* Return 0 if the procedure is incomplete */
if (!(MXC_FCR->intfl & MXC_F_FCR_INTFL_FRQCNT)) {
return 0;
}

/* Calculate the frequency */
uint64_t freq = (uint64_t)ERFO_FREQ * (uint64_t)MXC_FCR->cmpclk / (uint64_t)MXC_FCR->refclk;

return (uint32_t)freq;
}

/* ************************************************************************** */
uint32_t MXC_SYS_ClockMeasure(mxc_sys_compare_clock_t clock, uint32_t compareClockTicks)
{
/* Assuming that both clocks are already enabled */
MXC_SYS_StartClockMeasure(clock, compareClockTicks);

/* Wait for the procedure to finish */
while (!(MXC_FCR->intfl & MXC_F_FCR_INTFL_FRQCNT)) {}

return MXC_SYS_GetClockMeasure();
}

/**@} end of mxc_sys */
Loading