Skip to content

Commit

Permalink
Add ME30 RTC SetClockSource function
Browse files Browse the repository at this point in the history
This commit creates an enum for rtc clock sources and
adds a function to set clock source for ME30 rtc.

Signed-off-by: Mert Vatansever <[email protected]>
  • Loading branch information
mertvatansever committed Dec 23, 2024
1 parent 14ccd99 commit 5fd0303
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
16 changes: 16 additions & 0 deletions Libraries/PeriphDrivers/Include/MAX32657/rtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ typedef enum {
MXC_RTC_INT_FL_READY = MXC_F_RTC_CTRL_RDY, /**< Timer ready interrupt flag */
} mxc_rtc_int_fl_t;

/**
* @brief Clock settings
*/
typedef enum {
MXC_RTC_ERTCO_CLK = 4,
MXC_RTC_INRO_CLK = 5,
} mxc_rtc_clock_t;

/**
* @brief Set Time-of-Day alarm value and enable Interrupt
* @param ras 20-bit value 0-0xFFFFF
Expand All @@ -90,11 +98,19 @@ int MXC_RTC_SetTimeofdayAlarm(uint32_t ras);
*/
int MXC_RTC_SetSubsecondAlarm(uint32_t rssa);

/**
* @brief Set the RTC clock source
* @param clk_src Clock source to use
* @retval returns Success or Fail, see \ref MXC_ERROR_CODES
*/
int MXC_RTC_SetClockSource(mxc_rtc_clock_t clk_src);

/**
* @brief Start the Real Time Clock (Blocking function)
* @retval returns Success or Fail, see \ref MXC_ERROR_CODES
*/
int MXC_RTC_Start(void);

/**
* @brief Stop the Real Time Clock (Blocking function)
* @retval returns Success or Fail, see \ref MXC_ERROR_CODES
Expand Down
26 changes: 24 additions & 2 deletions Libraries/PeriphDrivers/Source/RTC/rtc_me30.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,30 @@ int MXC_RTC_SetSubsecondAlarm(uint32_t rssa)
return MXC_RTC_RevA_SetSubsecondAlarm((mxc_rtc_reva_regs_t *)MXC_RTC, rssa);
}

int MXC_RTC_SetClockSource(mxc_rtc_clock_t clk_src)
{
uint8_t retval = E_NO_ERROR;

switch (clk_src) {
case MXC_RTC_ERTCO_CLK:
MXC_GCR->clkctrl |= MXC_F_GCR_CLKCTRL_ERTCO_EN;
MXC_MCR->ctrl &= ~MXC_F_MCR_CTRL_CLKSEL;
MXC_MCR->ctrl |= MXC_S_MCR_CTRL_CLKSEL_ERTCO;
break;

case MXC_RTC_INRO_CLK:
MXC_MCR->ctrl &= ~MXC_F_MCR_CTRL_CLKSEL;
MXC_MCR->ctrl |= MXC_S_MCR_CTRL_CLKSEL_INRO_DIV4;
break;

default:
// Invalid clock source
return E_BAD_PARAM;
}

return retval;
}

int MXC_RTC_Start(void)
{
return MXC_RTC_RevA_Start((mxc_rtc_reva_regs_t *)MXC_RTC);
Expand All @@ -77,8 +101,6 @@ int MXC_RTC_Stop(void)

int MXC_RTC_Init(uint32_t sec, uint16_t ssec)
{
MXC_GCR->clkctrl |= MXC_F_GCR_CLKCTRL_ERTCO_EN;

return MXC_RTC_RevA_Init((mxc_rtc_reva_regs_t *)MXC_RTC, sec, (ssec & MXC_F_RTC_SSEC_SSEC));
}

Expand Down

0 comments on commit 5fd0303

Please sign in to comment.