Skip to content

Commit bd26489

Browse files
committed
soc: ti: cc23x0: Add support for RTC alarms in power.c
In power management, add support to take into account the alarms set in RTC. Alarm from RTC is processed like any other from SYSTIM. This prevents from missing interrupts. Signed-off-by: Stoyan Bogdanov <sbogdanov@baylibre.com>
1 parent 5bf1bf7 commit bd26489

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

soc/ti/simplelink/cc23x0/power.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const PowerCC23X0_Config PowerCC23X0_config = {
4444
#define SYSTIM_CH(idx) (SYSTIM_O_CH0CC + idx * SYSTIM_CH_STEP)
4545
#define SYSTIM_TO_RTC_SHIFT 3U
4646
#define SYSTIM_CH_CNT 5U
47+
#define RTC_CH_CNT 2U
4748
#define RTC_NEXT(val, now) (((val - PowerCC23X0_WAKEDELAYSTANDBY) >> SYSTIM_TO_RTC_SHIFT) + now)
4849

4950
#endif
@@ -57,8 +58,10 @@ static void pm_cc23x0_systim_standby_restore(void);
5758

5859
/* Global to stash the SysTimer timeouts while we enter standby */
5960
static uint32_t systim[SYSTIM_CH_CNT];
61+
static uint32_t rtc[RTC_CH_CNT];
6062
static uintptr_t key;
6163
static uint32_t systim_mask;
64+
static uint32_t rtc_mask;
6265

6366
/* Shift values to convert between the different resolutions of the SysTimer
6467
* channels. Channel 0 can technically support either 1us or 250ns. Until the
@@ -83,7 +86,10 @@ static void pm_cc23x0_systim_standby_restore(void)
8386
ULLSync();
8487

8588
HwiP_clearInterrupt(INT_CPUIRQ16);
89+
HwiP_clearInterrupt(INT_CPUIRQ3);
90+
8691
HWREG(EVTSVT_BASE + EVTSVT_O_CPUIRQ16SEL) = EVTSVT_CPUIRQ16SEL_PUBID_SYSTIM0;
92+
HWREG(EVTSVT_BASE + EVTSVT_O_CPUIRQ3SEL) = EVTSVT_CPUIRQ16SEL_PUBID_AON_RTC_COMB;
8793

8894
while (HWREG(SYSTIM_BASE + SYSTIM_O_STATUS) != SYSTIM_STATUS_VAL_RUN) {
8995
;
@@ -96,9 +102,19 @@ static void pm_cc23x0_systim_standby_restore(void)
96102
}
97103

98104
HWREG(SYSTIM_BASE + SYSTIM_O_IMASK) = systim_mask;
105+
HWREG(RTC_BASE + RTC_O_IMASK) = rtc_mask;
106+
107+
if (rtc_mask != 0) {
108+
if (rtc_mask & 0x1) {
109+
HWREG(RTC_BASE + RTC_O_CH0CC8U) = rtc[0];
110+
}
111+
if (rtc_mask & 0x2) {
112+
HWREG(RTC_BASE + RTC_O_CH1CC8U) = rtc[1];
113+
}
114+
}
115+
99116
LRFDApplyClockDependencies();
100117
PowerCC23X0_notify(PowerLPF3_AWAKE_STANDBY);
101-
102118
HwiP_restore(key);
103119
}
104120
#endif
@@ -110,6 +126,7 @@ static void pm_cc23x0_enter_standby(void)
110126
uint32_t systim_now = 0;
111127
uint32_t systim_next = MAX_SYSTIMER_DELTA;
112128
uint32_t systim_delta = 0;
129+
uint32_t rtc_delta = 0;
113130

114131
key = HwiP_disable();
115132

@@ -146,7 +163,23 @@ static void pm_cc23x0_enter_standby(void)
146163
systim_next = MAX_SYSTIMER_DELTA;
147164
}
148165

166+
rtc_mask = HWREG(RTC_BASE + RTC_O_IMASK);
167+
if (rtc_mask != 0) {
168+
rtc_now = HWREG(RTC_BASE + RTC_O_TIME8U);
169+
if (rtc_mask & 0x1) {
170+
rtc[0] = HWREG(RTC_BASE + RTC_O_CH0CC8U);
171+
rtc_delta = (rtc[0] - rtc_now) << 3;
172+
systim_next = MIN(systim_next, rtc_delta);
173+
}
174+
if (rtc_mask & 0x2) {
175+
rtc[1] = HWREG(RTC_BASE + RTC_O_CH1CC8U);
176+
rtc_delta = (rtc[1] - rtc_now) << 3;
177+
systim_next = MIN(systim_next, rtc_delta);
178+
}
179+
}
180+
149181
if (systim_next > PowerCC23X0_TOTALTIMESTANDBY) {
182+
HWREG(EVTSVT_BASE + EVTSVT_O_CPUIRQ3SEL) = 0;
150183
HWREG(EVTSVT_BASE + EVTSVT_O_CPUIRQ16SEL) =
151184
EVTSVT_CPUIRQ16SEL_PUBID_AON_RTC_COMB;
152185
HwiP_clearInterrupt(INT_CPUIRQ16);

0 commit comments

Comments
 (0)