Skip to content

Commit

Permalink
soc: sam: Add poweroff implementation
Browse files Browse the repository at this point in the history
This commit adds an implementation of poweroff, which first
uses SUPC to enable all defined wakeup sources (except for
sam4l), followed by entering backup mode.

Signed-off-by: Bjarki Arge Andreasen <[email protected]>
  • Loading branch information
Bjarki Arge Andreasen authored and carlescufi committed Oct 24, 2023
1 parent 278d029 commit 9b21d4d
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 0 deletions.
2 changes: 2 additions & 0 deletions soc/arm/atmel_sam/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ zephyr_include_directories(.)
zephyr_library_sources_ifndef(CONFIG_SOC_SERIES_SAM4L soc_pmc.c)
zephyr_library_sources_ifndef(CONFIG_SOC_SERIES_SAM4L soc_gpio.c)
zephyr_library_sources_ifndef(CONFIG_SOC_SERIES_SAM4L soc_supc.c)
zephyr_library_sources_ifndef(CONFIG_SOC_SERIES_SAM4L soc_poweroff.c)

zephyr_library_sources_ifdef(CONFIG_SOC_SERIES_SAM4L soc_sam4l_pm.c)
zephyr_library_sources_ifdef(CONFIG_SOC_SERIES_SAM4L soc_sam4l_gpio.c)
zephyr_library_sources_ifdef(CONFIG_SOC_SERIES_SAM4L soc_sam4l_poweroff.c)
33 changes: 33 additions & 0 deletions soc/arm/atmel_sam/common/soc_poweroff.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2023 Bjarki Arge Andreasen
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/sys/poweroff.h>
#include <soc.h>

/*
* Poweroff will make the chip enter the backup low-power mode, which
* achieves the lowest possible power consumption. Wakeup from this mode
* requires enabling a wakeup source or input, or power cycling the device.
*/

static void soc_core_sleepdeep_enable(void)
{
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
}

static void soc_core_sleepdeep_wait(void)
{
__WFE();
__WFI();
}

void z_sys_poweroff(void)
{
soc_core_sleepdeep_enable();
soc_supc_core_voltage_regulator_off();
soc_core_sleepdeep_wait();

CODE_UNREACHABLE;
}
33 changes: 33 additions & 0 deletions soc/arm/atmel_sam/common/soc_sam4l_poweroff.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2023 Bjarki Arge Andreasen
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/sys/poweroff.h>
#include <soc.h>

/*
* Poweroff will make the chip enter the backup low-power mode, which
* achieves the lowest possible power consumption. Wakeup from this mode
* requires enabling a wakeup source or input, or power cycling the device.
*/

static void soc_core_sleepdeep_enable(void)
{
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
}

static void soc_core_sleepdeep_wait(void)
{
__WFE();
__WFI();
}

void z_sys_poweroff(void)
{
soc_core_sleepdeep_enable();
BPM->PMCON |= BPM_PMCON_BKUP;
soc_core_sleepdeep_wait();

CODE_UNREACHABLE;
}
1 change: 1 addition & 0 deletions soc/arm/atmel_sam/sam3x/Kconfig.series
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ config SOC_SERIES_SAM3X
select SOC_FAMILY_SAM
select PLATFORM_SPECIFIC_INIT
select ASF
select HAS_POWEROFF
help
Enable support for Atmel SAM3X Cortex-M3 microcontrollers.
Part No.: SAM3X8E
1 change: 1 addition & 0 deletions soc/arm/atmel_sam/sam4e/Kconfig.series
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ config SOC_SERIES_SAM4E
select SOC_FAMILY_SAM
select PLATFORM_SPECIFIC_INIT
select ASF
select HAS_POWEROFF
help
Enable support for Atmel SAM4E Cortex-M4 microcontrollers.
Part No.: SAM4E16E, SAM4E16C, SAM4E8E, SAM4E8C
1 change: 1 addition & 0 deletions soc/arm/atmel_sam/sam4l/Kconfig.series
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ config SOC_SERIES_SAM4L
select SOC_FAMILY_SAM
select PLATFORM_SPECIFIC_INIT
select ASF
select HAS_POWEROFF
help
Enable support for Atmel SAM4L Cortex-M4 microcontrollers.
Part No.: SAM4LS8C, SAM4LS8B, SAM4LS8A, SAM4LS4C, SAM4LS4B,
Expand Down
1 change: 1 addition & 0 deletions soc/arm/atmel_sam/sam4s/Kconfig.series
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ config SOC_SERIES_SAM4S
select SOC_FAMILY_SAM
select PLATFORM_SPECIFIC_INIT
select ASF
select HAS_POWEROFF
help
Enable support for Atmel SAM4S Cortex-M4 microcontrollers.
Part No.: SAM4S16C, SAM4S16B, SAM4S8C, SAM4S8B,
Expand Down
1 change: 1 addition & 0 deletions soc/arm/atmel_sam/same70/Kconfig.series
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ config SOC_SERIES_SAME70
select ASF
select HAS_SWO
select XIP
select HAS_POWEROFF
help
Enable support for Atmel SAM E70 ARM Cortex-M7 Microcontrollers.
Part No.: SAME70J19, SAME70J20, SAME70J21, SAME70N19, SAME70N20,
Expand Down
1 change: 1 addition & 0 deletions soc/arm/atmel_sam/samv71/Kconfig.series
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ config SOC_SERIES_SAMV71
select ASF
select HAS_SWO
select XIP
select HAS_POWEROFF
help
Enable support for Atmel SAM V71 ARM Cortex-M7 Microcontrollers.
Part No.: SAMV71J19, SAMV71J20, SAMV71J21, SAMV71N19, SAMV71N20,
Expand Down

0 comments on commit 9b21d4d

Please sign in to comment.