Skip to content

Commit

Permalink
cpu/avr8_common: Add support to threadless idle
Browse files Browse the repository at this point in the history
Signed-off-by: Gerson Fernando Budke <[email protected]>
  • Loading branch information
nandojve committed Jun 18, 2023
1 parent 1bed7dd commit 6c6063e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions cpu/avr8_common/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ config CPU_ARCH_AVR8
bool
select HAS_ARCH_8BIT
select HAS_ARCH_AVR8
select HAS_NO_IDLE_THREAD

select MODULE_MALLOC_THREAD_SAFE if TEST_KCONFIG
select MODULE_TINY_STRERROR_AS_STRERROR if TEST_KCONFIG
Expand Down
1 change: 1 addition & 0 deletions cpu/avr8_common/Makefile.features
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
FEATURES_PROVIDED += arch_8bit
FEATURES_PROVIDED += arch_avr8
FEATURES_PROVIDED += no_idle_thread
FEATURES_PROVIDED += cpp
4 changes: 4 additions & 0 deletions cpu/avr8_common/avr8_cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <avr/io.h>
#include <avr/wdt.h>
#include <avr/pgmspace.h>
#include <avr/sleep.h>

#include "cpu.h"
#include "cpu_clock.h"
Expand Down Expand Up @@ -101,6 +102,9 @@ void cpu_init(void)

avr8_clk_init();

/* Set default sleep mode for LPM or threadless idle */
set_sleep_mode(SLEEP_MODE_IDLE);

/* Initialize stdio before periph_init() to allow use of DEBUG() there */
#ifdef MODULE_AVR_LIBC_EXTRA
avr8_stdio_init();
Expand Down
16 changes: 16 additions & 0 deletions cpu/avr8_common/thread_arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/

#include <stdio.h>
#include <avr/sleep.h>

#include "thread.h"
#include "sched.h"
Expand Down Expand Up @@ -427,3 +428,18 @@ __attribute__((always_inline)) static inline void avr8_context_restore(void)
"out __SREG__, __tmp_reg__ \n\t"
"pop __tmp_reg__ \n\t");
}

void sched_arch_idle(void)
{
#ifdef MODULE_PM_LAYERED
void pm_set_lowest(void);
pm_set_lowest();
#else
unsigned irq_state = irq_disable();
sleep_enable();
sei();
sleep_cpu();
sleep_disable();
irq_restore(irq_state);
#endif
}

0 comments on commit 6c6063e

Please sign in to comment.