Skip to content

Commit

Permalink
[sw,dif_aon_timer] Add support to read wakeup cause
Browse files Browse the repository at this point in the history
Signed-off-by: Guillermo Maturana <[email protected]>
  • Loading branch information
matutem committed Jan 11, 2024
1 parent 56c1aa8 commit ff4673e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
11 changes: 11 additions & 0 deletions sw/device/lib/dif/dif_aon_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,17 @@ dif_result_t dif_aon_timer_wakeup_is_enabled(const dif_aon_timer_t *aon,
return kDifOk;
}

dif_result_t dif_aon_timer_get_wakeup_cause(const dif_aon_timer_t *aon,
bool *cause) {
if (aon == NULL || cause == NULL) {
return kDifBadArg;
}
uint32_t reg =
mmio_region_read32(aon->base_addr, AON_TIMER_WKUP_CAUSE_REG_OFFSET);
*cause = bitfield_bit32_read(reg, AON_TIMER_WKUP_CAUSE_CAUSE_BIT);
return kDifOk;
}

dif_result_t dif_aon_timer_clear_wakeup_cause(const dif_aon_timer_t *aon) {
if (aon == NULL) {
return kDifBadArg;
Expand Down
10 changes: 10 additions & 0 deletions sw/device/lib/dif/dif_aon_timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ dif_result_t dif_aon_timer_wakeup_restart(const dif_aon_timer_t *aon);
OT_WARN_UNUSED_RESULT
dif_result_t dif_aon_timer_wakeup_is_enabled(const dif_aon_timer_t *aon,
bool *is_enabled);
/**
* Gets the wakeup cause.
*
* @param aon An Always-On Timer handle.
* @param[out] cause The current cause state.
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_aon_timer_get_wakeup_cause(const dif_aon_timer_t *aon,
bool *cause);

/** Clear Always-On Timer wakeup cause
*
Expand Down
24 changes: 24 additions & 0 deletions sw/device/lib/dif/dif_aon_timer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,30 @@ class AonTimerTest : public Test, public MmioTest {
dif_aon_timer_t aon_ = {.base_addr = dev().region()};
};

class WakeupStatusTest : public AonTimerTest {};

TEST_F(WakeupStatusTest, GetNullArgs) {
bool cause;
EXPECT_DIF_BADARG(dif_aon_timer_get_wakeup_cause(nullptr, &cause));
EXPECT_DIF_BADARG(dif_aon_timer_get_wakeup_cause(&aon_, nullptr));
}

TEST_F(WakeupStatusTest, GetSuccess) {
bool cause = false;
EXPECT_READ32(AON_TIMER_WKUP_CAUSE_REG_OFFSET, 1);
EXPECT_DIF_OK(dif_aon_timer_get_wakeup_cause(&aon_, &cause));
EXPECT_EQ(cause, true);
}

TEST_F(WakeupStatusTest, ClearNullArgs) {
EXPECT_DIF_BADARG(dif_aon_timer_clear_wakeup_cause(nullptr));
}

TEST_F(WakeupStatusTest, ClearSuccess) {
EXPECT_WRITE32(AON_TIMER_WKUP_CAUSE_REG_OFFSET, 0);
EXPECT_DIF_OK(dif_aon_timer_clear_wakeup_cause(&aon_));
}

class WakeupStartTest : public AonTimerTest {};

TEST_F(WakeupStartTest, NullArgs) {
Expand Down

0 comments on commit ff4673e

Please sign in to comment.