Skip to content

Commit

Permalink
arch: cxd56xx: Fix RTC alarm cancellation process
Browse files Browse the repository at this point in the history
  • Loading branch information
SPRESENSE authored Oct 23, 2020
2 parents 548cd74 + ebd8bbe commit aeaed6a
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion arch/arm/src/cxd56xx/cxd56_rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ int cxd56_rtc_setalarm(FAR struct alm_setalarm_s *alminfo)
int ret = -EBUSY;
int id;
uint64_t count;
uint32_t mask;

ASSERT(alminfo != NULL);
DEBUGASSERT(RTC_ALARM_LAST > alminfo->as_id);
Expand All @@ -584,6 +585,13 @@ int cxd56_rtc_setalarm(FAR struct alm_setalarm_s *alminfo)

count -= g_rtc_save->offset;

/* clear previsous setting */

mask = RTCREG_ALM0_ERR_FLAG_MASK | RTCREG_ALM0_FLAG_MASK;
mask <<= id;

putreg32(mask, CXD56_RTC0_ALMCLR);

/* wait until previous alarm request is completed */

while (RTCREG_ASET_BUSY_MASK & getreg32(CXD56_RTC0_SETALMPRECNT(id)));
Expand Down Expand Up @@ -628,10 +636,11 @@ int cxd56_rtc_cancelalarm(enum alm_id_e alarmid)
FAR struct alm_cbinfo_s *cbinfo;
irqstate_t flags;
int ret = -ENODATA;
uint32_t mask;

DEBUGASSERT(RTC_ALARM_LAST > alarmid);

/* Set the alarm in hardware and enable interrupts */
/* Cancel the alarm in hardware and clear interrupts */

cbinfo = &g_alarmcb[alarmid];

Expand All @@ -647,6 +656,29 @@ int cxd56_rtc_cancelalarm(enum alm_id_e alarmid)

putreg32(0, CXD56_RTC0_ALMOUTEN(alarmid));

while (RTCREG_ALM_BUSY_MASK & getreg32(CXD56_RTC0_ALMOUTEN(alarmid)));

/* wait until previous alarm request is completed */

while (RTCREG_ASET_BUSY_MASK & getreg32(CXD56_RTC0_SETALMPRECNT(alarmid)));

/* clear the alarm counter */

putreg32(0, CXD56_RTC0_SETALMPOSTCNT(alarmid));
putreg32(0, CXD56_RTC0_SETALMPRECNT(alarmid));

while (RTCREG_ASET_BUSY_MASK & getreg32(CXD56_RTC0_SETALMPRECNT(alarmid)));

/* wait until the interrupt flag is clear */

mask = RTCREG_ALM0_ERR_FLAG_MASK | RTCREG_ALM0_FLAG_MASK;
mask <<= alarmid;

while (mask & getreg32(CXD56_RTC0_ALMFLG))
{
putreg32(mask, CXD56_RTC0_ALMCLR);
}

leave_critical_section(flags);

ret = OK;
Expand Down

0 comments on commit aeaed6a

Please sign in to comment.