Add RP RTC bit definitions + driver WIP
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@14148 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
parent
2bb8aac319
commit
21c59fea5c
|
@ -294,7 +294,7 @@ typedef struct {
|
|||
#define __UART0_BASE (__APBPERIPH_BASE + 0x00034000U)
|
||||
#define __UART1_BASE (__APBPERIPH_BASE + 0x00038000U)
|
||||
#define __SIO_BASE (__IOPORT_BASE + 0x00000000U)
|
||||
#define __RTC_BASE (__APBPERIPH_BASE + 0x0005c000U)
|
||||
#define __RTC_BASE (__APBPERIPH_BASE + 0x0005C000U)
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
|
@ -780,6 +780,152 @@ typedef struct {
|
|||
#define UART_UARTDMACR_RXDMAE UART_UARTDMACR_RXDMAE_Msk
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name RTC bits definitions
|
||||
* @{
|
||||
*/
|
||||
#define RTC_CLKDIV_M1_Pos 0U
|
||||
#define RTC_CLKDIV_M1_Msk (0xFFFFU << RTC_CLKDIV_M1_Pos)
|
||||
#define RTC_CLKDIV_M1 RTC_CLKDIV_M1_Msk
|
||||
|
||||
#define RTC_SETUP_0_YEAR_Pos 12U
|
||||
#define RTC_SETUP_0_YEAR_Msk (0xFFFU << RTC_SETUP_0_YEAR_Pos)
|
||||
#define RTC_SETUP_0_YEAR(n) ((n) << RTC_SETUP_0_YEAR_Pos)
|
||||
#define RTC_SETUP_0_MONTH_Pos 8U
|
||||
#define RTC_SETUP_0_MONTH_Msk (0xFU << RTC_SETUP_0_MONTH_Pos)
|
||||
#define RTC_SETUP_0_MONTH(n) ((n) << RTC_SETUP_0_MONTH_Pos)
|
||||
#define RTC_SETUP_0_DAY_Pos 4U
|
||||
#define RTC_SETUP_0_DAY_Msk (0x1FU << RTC_SETUP_0_DAY_Pos)
|
||||
#define RTC_SETUP_0_DAY(n) ((n) << RTC_SETUP_0_DAY_Pos)
|
||||
|
||||
#define RTC_SETUP_1_DOTW_Pos 24U
|
||||
#define RTC_SETUP_1_DOTW_Msk (0x7U << RTC_SETUP_1_DOTW_Pos)
|
||||
#define RTC_SETUP_1_DOTW(n) ((n) << RTC_SETUP_1_DOTW_Pos)
|
||||
#define RTC_SETUP_1_HOUR_Pos 16U
|
||||
#define RTC_SETUP_1_HOUR_Msk (0x1FU << RTC_SETUP_1_HOUR_Pos)
|
||||
#define RTC_SETUP_1_HOUR(n) ((n) << RTC_SETUP_1_HOUR_Pos)
|
||||
#define RTC_SETUP_1_MIN_Pos 8U
|
||||
#define RTC_SETUP_1_MIN_Msk (0x3FU << RTC_SETUP_1_MIN_Pos)
|
||||
#define RTC_SETUP_1_MIN(n) ((n) << RTC_SETUP_1_MIN_Pos)
|
||||
#define RTC_SETUP_1_SEC_Pos 0U
|
||||
#define RTC_SETUP_1_SEC_Msk (0x3FU << RTC_SETUP_1_SEC_Pos)
|
||||
#define RTC_SETUP_1_SEC(n) ((n) << RTC_SETUP_1_SEC_Pos)
|
||||
|
||||
#define RTC_CTRL_FORCE_NOTLEAPYEAR_Pos 8U
|
||||
#define RTC_CTRL_FORCE_NOTLEAPYEAR_Msk (1U << RTC_CTRL_FORCE_NOTLEAPYEAR_Pos)
|
||||
#define RTC_CTRL_FORCE_NOTLEAPYEAR RTC_CTRL_FORCE_NOTLEAPYEAR_Msk
|
||||
|
||||
#define RTC_CTRL_LOAD_Pos 4U
|
||||
#define RTC_CTRL_LOAD_Msk (1U << RTC_CTRL_LOAD_Pos)
|
||||
#define RTC_CTRL_LOAD RTC_CTRL_LOAD_Msk
|
||||
|
||||
#define RTC_CTRL_RTC_ACTIVE_Pos 1U
|
||||
#define RTC_CTRL_RTC_ACTIVE_Msk (1U << RTC_CTRL_RTC_ACTIVE_Pos)
|
||||
#define RTC_CTRL_RTC_ACTIVE RTC_CTRL_RTC_ACTIVE_Msk
|
||||
|
||||
#define RTC_CTRL_RTC_ENABLE_Pos 0U
|
||||
#define RTC_CTRL_RTC_ENABLE_Msk (1U << RTC_CTRL_RTC_ENABLE_Pos)
|
||||
#define RTC_CTRL_RTC_ENABLE RTC_CTRL_RTC_ENABLE_Msk
|
||||
|
||||
#define RTC_IRQ_SETUP_0_MATCH_ACTIVE_Pos 29U
|
||||
#define RTC_IRQ_SETUP_0_MATCH_ACTIVE_Msk (1U << RTC_IRQ_SETUP_0_MATCH_ACTIVE_Pos)
|
||||
#define RTC_IRQ_SETUP_0_MATCH_ACTIVE RTC_IRQ_SETUP_0_MATCH_ACTIVE_Msk
|
||||
#define RTC_IRQ_SETUP_0_MATCH_ENA_Pos 28U
|
||||
#define RTC_IRQ_SETUP_0_MATCH_ENA_Msk (1U << RTC_IRQ_SETUP_0_MATCH_ENA_Pos)
|
||||
#define RTC_IRQ_SETUP_0_MATCH_ENA RTC_IRQ_SETUP_0_MATCH_ENA_Msk
|
||||
#define RTC_IRQ_SETUP_0_YEAR_ENA_Pos 26U
|
||||
#define RTC_IRQ_SETUP_0_YEAR_ENA_Msk (1U << RTC_IRQ_SETUP_0_YEAR_ENA_Pos)
|
||||
#define RTC_IRQ_SETUP_0_YEAR_ENA RTC_IRQ_SETUP_0_YEAR_ENA_Msk
|
||||
#define RTC_IRQ_SETUP_0_MONTH_ENA_Pos 25U
|
||||
#define RTC_IRQ_SETUP_0_MONTH_ENA_Msk (1U << RTC_IRQ_SETUP_0_MONTH_ENA_Pos)
|
||||
#define RTC_IRQ_SETUP_0_MONTH_ENA RTC_IRQ_SETUP_0_MONTH_ENA_Msk
|
||||
#define RTC_IRQ_SETUP_0_DAY_ENA_Pos 24U
|
||||
#define RTC_IRQ_SETUP_0_DAY_ENA_Msk (1U << RTC_IRQ_SETUP_0_DAY_ENA_Pos)
|
||||
#define RTC_IRQ_SETUP_0_DAY_ENA RTC_IRQ_SETUP_0_DAY_ENA_Msk
|
||||
|
||||
#define RTC_IRQ_SETUP_0_YEAR_Pos 12U
|
||||
#define RTC_IRQ_SETUP_0_YEAR_Msk (0xFFFU << RTC_IRQ_SETUP_0_YEAR_Pos)
|
||||
#define RTC_IRQ_SETUP_0_YEAR(n) ((n) << RTC_IRQ_SETUP_0_YEAR_Pos)
|
||||
#define RTC_IRQ_SETUP_0_MONTH_Pos 8U
|
||||
#define RTC_IRQ_SETUP_0_MONTH_Msk (0xFU << RTC_IRQ_SETUP_0_MONTH_Pos)
|
||||
#define RTC_IRQ_SETUP_0_MONTH(n) ((n) << RTC_IRQ_SETUP_0_MONTH_Pos)
|
||||
#define RTC_IRQ_SETUP_0_DAY_Pos 4U
|
||||
#define RTC_IRQ_SETUP_0_DAY_Msk (0x1FU << RTC_IRQ_SETUP_0_DAY_Pos)
|
||||
#define RTC_IRQ_SETUP_0_DAY(n) ((n) << RTC_IRQ_SETUP_0_DAY_Pos)
|
||||
|
||||
#define RTC_IRQ_SETUP_1_DOTW_ENA_Pos 31U
|
||||
#define RTC_IRQ_SETUP_1_DOTW_ENA_Msk (1U << RTC_IRQ_SETUP_1_DOTW_ENA_Pos)
|
||||
#define RTC_IRQ_SETUP_1_DOTW_ENA RTC_IRQ_SETUP_1_DOTW_ENA_Msk
|
||||
#define RTC_IRQ_SETUP_1_HOUR_ENA_Pos 30U
|
||||
#define RTC_IRQ_SETUP_1_HOUR_ENA_Msk (1U << RTC_IRQ_SETUP_1_HOUR_ENA_Pos)
|
||||
#define RTC_IRQ_SETUP_1_HOUR_ENA RTC_IRQ_SETUP_1_HOUR_ENA_Msk
|
||||
#define RTC_IRQ_SETUP_1_MIN_ENA_Pos 29U
|
||||
#define RTC_IRQ_SETUP_1_MIN_ENA_Msk (1U << RTC_IRQ_SETUP_1_MIN_ENA_Pos)
|
||||
#define RTC_IRQ_SETUP_1_MIN_ENA RTC_IRQ_SETUP_1_MIN_ENA_Msk
|
||||
#define RTC_IRQ_SETUP_1_SEC_ENA_Pos 28U
|
||||
#define RTC_IRQ_SETUP_1_SEC_ENA_Msk (1U << RTC_IRQ_SETUP_1_SEC_ENA_Pos)
|
||||
#define RTC_IRQ_SETUP_1_SEC_ENA RTC_IRQ_SETUP_1_SEC_ENA_Msk
|
||||
|
||||
#define RTC_IRQ_SETUP_1_DOTW_Pos 24U
|
||||
#define RTC_IRQ_SETUP_1_DOTW_Msk (0x7U << RTC_IRQ_SETUP_1_DOTW_Pos)
|
||||
#define RTC_IRQ_SETUP_1_DOTW(n) ((n) << RTC_IRQ_SETUP_1_DOTW_Pos)
|
||||
#define RTC_IRQ_SETUP_1_HOUR_Pos 16U
|
||||
#define RTC_IRQ_SETUP_1_HOUR_Msk (0x1FU << RTC_IRQ_SETUP_1_HOUR_Pos)
|
||||
#define RTC_IRQ_SETUP_1_HOUR(n) ((n) << RTC_IRQ_SETUP_1_HOUR_Pos)
|
||||
#define RTC_IRQ_SETUP_1_MIN_Pos 8U
|
||||
#define RTC_IRQ_SETUP_1_MIN_Msk (0x3FU << RTC_IRQ_SETUP_1_MIN_Pos)
|
||||
#define RTC_IRQ_SETUP_1_MIN(n) ((n) << RTC_IRQ_SETUP_1_MIN_Pos)
|
||||
#define RTC_IRQ_SETUP_1_SEC_Pos 0U
|
||||
#define RTC_IRQ_SETUP_1_SEC_Msk (0x3FU << RTC_IRQ_SETUP_1_SEC_Pos)
|
||||
#define RTC_IRQ_SETUP_1_SEC(n) ((n) << RTC_IRQ_SETUP_1_SEC_Pos)
|
||||
|
||||
#define RTC_INTR_RTC_Pos 0U
|
||||
#define RTC_INTR_RTC_Msk (1U << RTC_INTR_RTC_Pos)
|
||||
#define RTC_INTR_RTC RTC_INTR_RTC_Msk
|
||||
|
||||
#define RTC_INTE_RTC_Pos 0U
|
||||
#define RTC_INTE_RTC_Msk (1U << RTC_INTE_RTC_Pos)
|
||||
#define RTC_INTE_RTC RTC_INTE_RTC_Msk
|
||||
|
||||
#define RTC_INTF_RTC_Pos 0U
|
||||
#define RTC_INTF_RTC_Msk (1U << RTC_INTF_RTC_Pos)
|
||||
#define RTC_INTF_RTC RTC_INTF_RTC_Msk
|
||||
|
||||
#define RTC_INTS_RTC_Pos 0U
|
||||
#define RTC_INTS_RTC_Msk (1U << RTC_INTS_RTC_Pos)
|
||||
#define RTC_INTS_RTC RTC_INTS_RTC_Msk
|
||||
|
||||
/* Normalisation of RTC0 & RTC1 fields read from RTC. */
|
||||
#define RTC_RTC_1_YEAR_Pos 12U
|
||||
#define RTC_RTC_1_YEAR_Msk (0xFFFU << RTC_RTC_1_YEAR_Pos)
|
||||
#define RTC_RTC_1_YEAR(n) ((n & RTC_RTC_1_YEAR_Msk) >> \
|
||||
RTC_RTC_1_YEAR_Pos)
|
||||
#define RTC_RTC_1_MONTH_Pos 8U
|
||||
#define RTC_RTC_1_MONTH_Msk (0xFU << RTC_RTC_1_MONTH_Pos)
|
||||
#define RTC_RTC_1_MONTH(n) ((n & RTC_RTC_1_MONTH_Msk) >> \
|
||||
RTC_RTC_1_DAY_Pos)
|
||||
#define RTC_RTC_1_DAY_Pos 0U
|
||||
#define RTC_RTC_1_DAY_Msk (0x1FU << RTC_RTC_1_DAY_Pos)
|
||||
#define RTC_RTC_1_DAY(n) ((n & RTC_RTC_1_DAY_Msk) >> \
|
||||
RTC_RTC_1_DAY_Pos)
|
||||
#define RTC_RTC_0_DOTW_Pos 24U
|
||||
#define RTC_RTC_0_DOTW_Msk (0x7U << RTC_RTC_0_DOTW_Pos)
|
||||
#define RTC_RTC_0_DOTW(n) ((n & RTC_RTC_0_DOTW_Msk) >> \
|
||||
RTC_RTC_0_DOTW_Pos)
|
||||
#define RTC_RTC_0_HOUR_Pos 16U
|
||||
#define RTC_RTC_0_HOUR_Msk (0x1FU << RTC_RTC_0_HOUR_Pos)
|
||||
#define RTC_RTC_0_HOUR(n) ((n & RTC_RTC_0_HOUR_Msk) >> \
|
||||
RTC_RTC_0_HOUR_Pos)
|
||||
#define RTC_RTC_0_MIN_Pos 8U
|
||||
#define RTC_RTC_0_MIN_Msk (0x3FU << RTC_RTC_0_MIN_Pos)
|
||||
#define RTC_RTC_0_MIN(n) ((n & RTC_RTC_0_MIN_Msk) >> \
|
||||
RTC_RTC_0_MIN_Pos)
|
||||
#define RTC_RTC_0_SEC_Pos 0U
|
||||
#define RTC_RTC_0_SEC_Msk (0x3FU << RTC_RTC_0_SEC_Pos)
|
||||
#define RTC_RTC_0_SEC(n) ((n & RTC_RTC_0_SEC_Msk) >> \
|
||||
RTC_RTC_0_SEC_Pos)
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
|
|
@ -48,6 +48,20 @@ RTCDriver RTCD1;
|
|||
/* Driver local functions. */
|
||||
/*===========================================================================*/
|
||||
|
||||
static void rtc_enable_alarm(RTCDriver *rtcp) {
|
||||
/* Enable matching and wait for it to be activated. */
|
||||
rtcp->rtc->IRQSETUP0 |= RTC_IRQ_SETUP_0_MATCH_ENA;
|
||||
while (!(rtcp->rtc->IRQSETUP0 & RTC_IRQ_SETUP_0_MATCH_ACTIVE))
|
||||
;
|
||||
}
|
||||
|
||||
static void rtc_disable_alarm(RTCDriver *rtcp) {
|
||||
/* Disable alarm matching and wait until deactivated. */
|
||||
rtcp->rtc->IRQSETUP0 &= ~RTC_IRQ_SETUP_0_MATCH_ENA;
|
||||
while (rtcp->rtc->IRQSETUP0 & RTC_IRQ_SETUP_0_MATCH_ACTIVE)
|
||||
;
|
||||
}
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver interrupt handlers. */
|
||||
/*===========================================================================*/
|
||||
|
@ -107,33 +121,31 @@ void rtc_lld_set_time(RTCDriver *rtcp, const RTCDateTime *timespec) {
|
|||
rtcp->rtc->CTRL = 0;
|
||||
|
||||
/* Wait for RTC to go inactive. */
|
||||
while ((rtcp->rtc->CTRL & RTC_CTRL_RTC_ACTIVE_BITS) != 0)
|
||||
while ((rtcp->rtc->CTRL & RTC_CTRL_RTC_ACTIVE) != 0)
|
||||
;
|
||||
|
||||
/* Entering a reentrant critical zone.*/
|
||||
syssts_t sts = osalSysGetStatusAndLockX();
|
||||
|
||||
/* Write setup to pre-load registers. */
|
||||
rtcp->rtc->SETUP0 =
|
||||
((timespec->year + 1980) << RTC_SETUP_0_YEAR_LSB) |
|
||||
(timespec->month << RTC_SETUP_0_MONTH_LSB) |
|
||||
(timespec->day << RTC_SETUP_0_DAY_LSB);
|
||||
rtcp->rtc->SETUP1 =
|
||||
((timespec->dayofweek - 1) << RTC_SETUP_1_DOTW_LSB) |
|
||||
(hour << RTC_SETUP_1_HOUR_LSB) |
|
||||
(min << RTC_SETUP_1_MIN_LSB) |
|
||||
(sec << RTC_SETUP_1_SEC_LSB);
|
||||
rtcp->rtc->SETUP0 = (RTC_SETUP_0_YEAR(timespec->year + 1980)) |
|
||||
(RTC_SETUP_0_MONTH(timespec->month)) |
|
||||
(RTC_SETUP_0_DAY(timespec->day));
|
||||
rtcp->rtc->SETUP1 = (RTC_SETUP_1_DOTW(timespec->dayofweek - 1)) |
|
||||
(RTC_SETUP_1_HOUR(hour)) |
|
||||
(RTC_SETUP_1_MIN(min)) |
|
||||
(RTC_SETUP_1_SEC(sec);
|
||||
|
||||
/* Move setup values into RTC clock domain. */
|
||||
rtcp->rtc->CTRL = RTC_CTRL_LOAD_BITS;
|
||||
rtcp->rtc->CTRL = RTC_CTRL_LOAD;
|
||||
|
||||
/* Enable RTC and wait for active. */
|
||||
rtcp->rtc->CTRL = RTC_CTRL_RTC_ENABLE_BITS;
|
||||
rtcp->rtc->CTRL = RTC_CTRL_RTC_ENABLE;
|
||||
|
||||
/* Leaving a reentrant critical zone.*/
|
||||
osalSysRestoreStatusX(sts);
|
||||
|
||||
while ((rtcp->rtc->CTRL & RTC_CTRL_RTC_ACTIVE_BITS) == 0)
|
||||
while ((rtcp->rtc->CTRL & RTC_CTRL_RTC_ACTIVE) == 0)
|
||||
;
|
||||
}
|
||||
|
||||
|
@ -159,20 +171,15 @@ void rtc_lld_get_time(RTCDriver *rtcp, RTCDateTime *timespec) {
|
|||
osalSysRestoreStatusX(sts);
|
||||
|
||||
/* Calculate and set milliseconds since midnight field. */
|
||||
timespec->millisecond =
|
||||
((((rtc_0 & RTC_RTC_0_HOUR_BITS) >> RTC_RTC_0_HOUR_LSB) * 3600)
|
||||
+ (((rtc_0 & RTC_RTC_0_MIN_BITS) >> RTC_RTC_0_MIN_LSB) * 60)
|
||||
+ (((rtc_0 & RTC_RTC_0_SEC_BITS) >> RTC_RTC_0_SEC_LSB))) * 1000;
|
||||
timespec->millisecond = (RTC_RTC_0_HOUR(rtc_0) * 3600) +
|
||||
(RTC_RTC_0_MIN(rtc_0) * 60) +
|
||||
(RTC_RTC_0_SEC(rtc_0) * 1000);
|
||||
|
||||
/* Set fields with adjustments. */
|
||||
timespec->dayofweek =
|
||||
((rtc_0 & RTC_RTC_0_DOTW_BITS) >> RTC_RTC_0_DOTW_LSB) + 1;
|
||||
timespec->year =
|
||||
((rtc_1 & RTC_RTC_1_YEAR_BITS) >> RTC_RTC_1_YEAR_LSB) - 1980;
|
||||
timespec->month =
|
||||
((rtc_1 & RTC_RTC_1_MONTH_BITS) >> RTC_RTC_1_MONTH_LSB);
|
||||
timespec->day =
|
||||
((rtc_1 & RTC_RTC_1_DAY_BITS) >> RTC_RTC_1_DAY_LSB);
|
||||
/* Set RTCDateTime fields with adjustments from RTC data. */
|
||||
timespec->dayofweek = RTC_RTC_0_DOTW(rtc_0) + 1;
|
||||
timespec->year = RTC_RTC_1_YEAR(rtc_1) - 1980;
|
||||
timespec->month = RTC_RTC_1_MONTH(rtc_1);
|
||||
timespec->day = RTC_RTC_1_DAY(rtc_1);
|
||||
}
|
||||
|
||||
#if (RTC_ALARMS > 0) || defined(__DOXYGEN__)
|
||||
|
@ -183,7 +190,7 @@ void rtc_lld_get_time(RTCDriver *rtcp, RTCDateTime *timespec) {
|
|||
* @note The function can be called from any context.
|
||||
*
|
||||
* @param[in] rtcp pointer to RTC driver structure.
|
||||
* @param[in] alarm alarm identifier. Can be 1 or 2.
|
||||
* @param[in] alarm alarm identifier. Can be 1.
|
||||
* @param[in] alarmspec pointer to a @p RTCAlarm structure.
|
||||
*
|
||||
* @notapi
|
||||
|
@ -193,48 +200,63 @@ void rtc_lld_set_alarm(RTCDriver *rtcp,
|
|||
const RTCAlarm *alarmspec) {
|
||||
|
||||
(void)alarm;
|
||||
RTCDateTime *t = &alarmspec->alarm;
|
||||
uint32_t sec = (uint32_t)t->millisecond / 1000;
|
||||
uint32_t hour = sec / 3600;
|
||||
uint32_t sec, min, hour, day, month, year, dotw, setup0, setup1;
|
||||
RTCDateTime *timespec = &alarmspec->alarm;
|
||||
sec = (uint32_t)timespec->millisecond / 1000;
|
||||
hour = sec / 3600;
|
||||
sec %= 3600;
|
||||
uint32_t min = sec / 60;
|
||||
min = sec / 60;
|
||||
sec %= 60;
|
||||
day = timespec->day;
|
||||
month = timespec->month;
|
||||
|
||||
rtc_disable_alarm();
|
||||
/* Normalise and setup for non-zero checking. */
|
||||
year = timespec->year == 0 ? 0 : timespec->year + 1980;
|
||||
dotw = timespec->dayofweek;
|
||||
|
||||
// Only add to setup if it isn't -1
|
||||
rtcp->rtc->IRQSETUP0 = ((t->year < 0) ? 0 : (((uint)t->year) << RTC_IRQ_SETUP_0_YEAR_LSB )) |
|
||||
((t->month < 0) ? 0 : (((uint)t->month) << RTC_IRQ_SETUP_0_MONTH_LSB)) |
|
||||
((t->day < 0) ? 0 : (((uint)t->day) << RTC_IRQ_SETUP_0_DAY_LSB ));
|
||||
rtcp->rtc->IRQSETUP1 = ((t->dotw == 0) ? 0 : (((uint)t->dotw) << RTC_IRQ_SETUP_1_DOTW_LSB)) |
|
||||
(t->hour << RTC_IRQ_SETUP_1_HOUR_LSB)) |
|
||||
(t->min << RTC_IRQ_SETUP_1_MIN_LSB )) |
|
||||
(t->sec << RTC_IRQ_SETUP_1_SEC_LSB ));
|
||||
/* Write all registers regardless. */
|
||||
setup0 = (RTC_IRQ_SETUP_0_YEAR(year)) |
|
||||
(RTC_IRQ_SETUP_0_MONTH(month)) |
|
||||
(RTC_IRQ_SETUP_0_DAY(day));
|
||||
setup1 = (RTC_IRQ_SETUP_1_DOTW(dotw - 1)) |
|
||||
(RTC_IRQ_SETUP_1_HOUR(hour)) |
|
||||
(RTC_IRQ_SETUP_1_MIN(min)) |
|
||||
(RTC_IRQ_SETUP_1_SEC(sec);
|
||||
|
||||
// Set the match enable bits for things we care about
|
||||
if (t->year >= 0) hw_set_bits(&rtc_hw->irq_setup_0, RTC_IRQ_SETUP_0_YEAR_ENA_BITS);
|
||||
if (t->month >= 0) hw_set_bits(&rtc_hw->irq_setup_0, RTC_IRQ_SETUP_0_MONTH_ENA_BITS);
|
||||
if (t->day >= 0) hw_set_bits(&rtc_hw->irq_setup_0, RTC_IRQ_SETUP_0_DAY_ENA_BITS);
|
||||
if (t->dotw >= 0) hw_set_bits(&rtc_hw->irq_setup_1, RTC_IRQ_SETUP_1_DOTW_ENA_BITS);
|
||||
if (t->hour >= 0) hw_set_bits(&rtc_hw->irq_setup_1, RTC_IRQ_SETUP_1_HOUR_ENA_BITS);
|
||||
if (t->min >= 0) hw_set_bits(&rtc_hw->irq_setup_1, RTC_IRQ_SETUP_1_MIN_ENA_BITS);
|
||||
if (t->sec >= 0) hw_set_bits(&rtc_hw->irq_setup_1, RTC_IRQ_SETUP_1_SEC_ENA_BITS);
|
||||
/* Check and set match enable bits for non-zero */
|
||||
if (year > 0) setup0 |= RTC_IRQ_SETUP_0_YEAR_ENA;
|
||||
if (month > 0) setup0 |= RTC_IRQ_SETUP_0_MONTH_ENA;
|
||||
if (day > 0) setup0 |= RTC_IRQ_SETUP_0_DAY_ENA;
|
||||
if (dotw > 0) setup1 |= RTC_IRQ_SETUP_1_DOTW_ENA;
|
||||
if (hour > 0) setup1 |= RTC_IRQ_SETUP_1_HOUR_ENA;
|
||||
if (min > 0) setup1 |= RTC_IRQ_SETUP_1_MIN_ENA;
|
||||
if (sec > 0) setup1 |= RTC_IRQ_SETUP_1_SEC_ENA;
|
||||
|
||||
/* Entering a reentrant critical zone.*/
|
||||
syssts_t sts = osalSysGetStatusAndLockX();
|
||||
|
||||
rtc_disable_alarm(rtcp);
|
||||
rtcp->rtc->IRQSETUP0 = setup0;
|
||||
rtcp->rtc->IRQSETUP1 = setup1;
|
||||
|
||||
// Does it repeat? I.e. do we not match on any of the bits
|
||||
_alarm_repeats = rtc_alarm_repeats(t);
|
||||
//_alarm_repeats = rtc_alarm_repeats(t);
|
||||
|
||||
// Store function pointer we can call later
|
||||
_callback = user_callback;
|
||||
//_callback = user_callback;
|
||||
|
||||
irq_set_exclusive_handler(RTC_IRQ, rtc_irq_handler);
|
||||
//irq_set_exclusive_handler(RTC_IRQ, rtc_irq_handler);
|
||||
|
||||
// Enable the IRQ at the peri
|
||||
rtc_hw->inte = RTC_INTE_RTC_BITS;
|
||||
//rtc_hw->inte = RTC_INTE_RTC_BITS;
|
||||
|
||||
// Enable the IRQ at the proc
|
||||
irq_set_enabled(RTC_IRQ, true);
|
||||
//irq_set_enabled(RTC_IRQ, true);
|
||||
|
||||
rtc_enable_alarm();
|
||||
rtc_enable_alarm(rtcp);
|
||||
|
||||
/* Leaving a reentrant critical zone.*/
|
||||
osalSysRestoreStatusX(sts);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -257,6 +279,22 @@ void rtc_lld_get_alarm(RTCDriver *rtcp,
|
|||
}
|
||||
#endif /* RTC_ALARMS > 0 */
|
||||
|
||||
/**
|
||||
* @brief Enables or disables RTC callbacks.
|
||||
* @details This function enables or disables callbacks, use a @p NULL pointer
|
||||
* in order to disable a callback.
|
||||
* @note The function can be called from any context.
|
||||
*
|
||||
* @param[in] rtcp pointer to RTC driver structure
|
||||
* @param[in] callback callback function pointer or @p NULL
|
||||
*
|
||||
* @notapi
|
||||
*/
|
||||
void rtc_lld_set_callback(RTCDriver *rtcp, rtccb_t callback) {
|
||||
|
||||
rtcp->callback = callback;
|
||||
}
|
||||
|
||||
#endif /* HAL_USE_RTC */
|
||||
|
||||
/** @} */
|
||||
|
|
|
@ -89,7 +89,6 @@ typedef enum {
|
|||
*/
|
||||
typedef void (*rtccb_t)(RTCDriver *rtcp, rtcevent_t event);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Type of a structure representing an RTC alarm time stamp.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue