diff --git a/Libraries/PeriphDrivers/Include/MAX32657/rtc.h b/Libraries/PeriphDrivers/Include/MAX32657/rtc.h index 187e70ec41..25bab5351b 100644 --- a/Libraries/PeriphDrivers/Include/MAX32657/rtc.h +++ b/Libraries/PeriphDrivers/Include/MAX32657/rtc.h @@ -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 @@ -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 diff --git a/Libraries/PeriphDrivers/Source/RTC/rtc_me30.c b/Libraries/PeriphDrivers/Source/RTC/rtc_me30.c index 313a101295..57abb5c8a8 100644 --- a/Libraries/PeriphDrivers/Source/RTC/rtc_me30.c +++ b/Libraries/PeriphDrivers/Source/RTC/rtc_me30.c @@ -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); @@ -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)); }