Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit50cfd54

Browse files
committed
rp2: Sleep changes.
Stop using soft timer for mp_wfe_or_timeout. Now uses the alarm poolagain as issues with this code have been fixed. This resolves the "sev"issue that stops the rp2 port going idle.Change the sleep code to use the hardware timer library and alarm 2 asalarm 3 is used by the alarm poolSigned-off-by: Peter Harper <peter.harper@raspberrypi.com>
1 parent2a3a22d commit50cfd54

File tree

3 files changed

+20
-27
lines changed

3 files changed

+20
-27
lines changed

‎ports/rp2/main.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ int main(int argc, char **argv) {
8585
#endif
8686

8787
pendsv_init();
88-
soft_timer_init();
8988

9089
// Set the MCU frequency and as a side effect the peripheral clock to 48 MHz.
9190
set_sys_clock_khz(SYS_CLK_KHZ, false);

‎ports/rp2/modmachine.c

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ static void mp_machine_idle(void) {
121121
MICROPY_INTERNAL_WFE(1);
122122
}
123123

124+
staticvoidalarm_sleep_callback(uintalarm_id) {
125+
}
126+
124127
staticvoidmp_machine_lightsleep(size_tn_args,constmp_obj_t*args) {
125128
mp_int_tdelay_ms=0;
126129
booluse_timer_alarm= false;
@@ -190,22 +193,15 @@ static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
190193
// Disable ROSC.
191194
rosc_hw->ctrl=ROSC_CTRL_ENABLE_VALUE_DISABLE <<ROSC_CTRL_ENABLE_LSB;
192195

196+
intalarm_num=2;
193197
if (n_args==0) {
194198
#ifMICROPY_PY_NETWORK_CYW43
195199
gpio_set_dormant_irq_enabled(CYW43_PIN_WL_HOST_WAKE,GPIO_IRQ_LEVEL_HIGH, true);
196200
#endif
197201
xosc_dormant();
198202
}else {
199-
booltimer3_enabled=irq_is_enabled(3);
200-
201-
constuint32_talarm_num=3;
202-
constuint32_tirq_num=TIMER_ALARM_IRQ_NUM(timer_hw,alarm_num);
203+
hardware_alarm_claim(alarm_num);
203204
if (use_timer_alarm) {
204-
// Make sure ALARM3/IRQ3 is enabled on _this_ core
205-
if (!timer3_enabled) {
206-
irq_set_enabled(irq_num, true);
207-
}
208-
hw_set_bits(&timer_hw->inte,1u <<alarm_num);
209205
// Use timer alarm to wake.
210206
clocks_hw->sleep_en0=0x0;
211207
#ifPICO_RP2040
@@ -215,8 +211,12 @@ static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
215211
#else
216212
#error Unknown processor
217213
#endif
218-
timer_hw->intr=1u <<alarm_num;// clear any IRQ
219-
timer_hw->alarm[alarm_num]=timer_hw->timerawl+delay_ms*1000;
214+
hardware_alarm_set_callback(alarm_num,alarm_sleep_callback);
215+
if (hardware_alarm_set_target(alarm_num,make_timeout_time_ms(delay_ms))) {
216+
hardware_alarm_set_callback(alarm_num,NULL);
217+
hardware_alarm_unclaim(alarm_num);
218+
alarm_num=-1;
219+
}
220220
}else {
221221
// TODO: Use RTC alarm to wake.
222222
clocks_hw->sleep_en0=0x0;
@@ -246,11 +246,10 @@ static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
246246
#endif
247247

248248
// Go into low-power mode.
249-
__wfi();
250-
251-
if (!timer3_enabled) {
252-
irq_set_enabled(irq_num, false);
249+
if (alarm_num >=0) {
250+
__wfi();
253251
}
252+
254253
clocks_hw->sleep_en0 |= ~(0u);
255254
clocks_hw->sleep_en1 |= ~(0u);
256255
}
@@ -264,6 +263,11 @@ static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
264263

265264
// Re-sync mp_hal_time_ns() counter with aon timer.
266265
mp_hal_time_ns_set_from_rtc();
266+
if (alarm_num >=0) {
267+
hardware_alarm_cancel(alarm_num);
268+
hardware_alarm_set_callback(alarm_num,NULL);
269+
hardware_alarm_unclaim(alarm_num);
270+
}
267271
}
268272

269273
NORETURNstaticvoidmp_machine_deepsleep(size_tn_args,constmp_obj_t*args) {

‎ports/rp2/mphalport.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -266,15 +266,5 @@ void soft_timer_init(void) {
266266
}
267267

268268
voidmp_wfe_or_timeout(uint32_ttimeout_ms) {
269-
soft_timer_entry_ttimer;
270-
271-
// Note the timer doesn't have an associated callback, it just exists to create a
272-
// hardware interrupt to wake the CPU
273-
soft_timer_static_init(&timer,SOFT_TIMER_MODE_ONE_SHOT,0,NULL);
274-
soft_timer_insert(&timer,timeout_ms);
275-
276-
__wfe();
277-
278-
// Clean up the timer node if it's not already
279-
soft_timer_remove(&timer);
269+
best_effort_wfe_or_timeout(delayed_by_ms(get_absolute_time(),timeout_ms));
280270
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp