File tree Expand file tree Collapse file tree 4 files changed +67
-25
lines changed
include/zephyr/arch/common Expand file tree Collapse file tree 4 files changed +67
-25
lines changed Original file line number Diff line number Diff line change 14
14
#include <zephyr/arch/ cpu .h>
15
15
#include <zephyr/arch/ common /pm_s2ram.h>
16
16
17
- #define MAGIC ( 0xDABBAD00 )
18
-
19
17
_ASM_FILE_PROLOGUE
20
18
19
+ GTEXT(pm_s2ram_mark_set)
20
+ GTEXT(pm_s2ram_mark_check_and_clear)
21
21
GDATA(_cpu_context)
22
- GDATA(marker)
23
22
24
23
SECTION_FUNC(TEXT , arch_pm_s2ram_suspend)
25
24
/ *
@@ -64,11 +63,9 @@ SECTION_FUNC(TEXT, arch_pm_s2ram_suspend)
64
63
str r2 , [ r1 , #___cpu_context_t_control_OFFSET ]
65
64
66
65
/ *
67
- * Set the marker to MAGIC value
66
+ * Mark entering suspend to RAM.
68
67
* /
69
- ldr r1 , =marker
70
- ldr r2 , =MAGIC
71
- str r2 , [ r1 ]
68
+ bl pm_s2ram_mark_set
72
69
73
70
/ *
74
71
* Call the system_off function passed as parameter. This should never
@@ -82,35 +79,29 @@ SECTION_FUNC(TEXT, arch_pm_s2ram_suspend)
82
79
* /
83
80
84
81
/ *
85
- * Reset the marker
82
+ * Reset the marking of suspend to RAM , return is ignored.
86
83
* /
87
- ldr r1 , =marker
88
- mov r2 , # 0x0
89
- str r2 , [ r1 ]
84
+ push {r0}
85
+ bl pm_s2ram_mark_check_and_clear
86
+ pop {r0}
90
87
91
88
pop {r4 - r12 , lr}
92
89
bx lr
93
90
91
+
94
92
GTEXT(arch_pm_s2ram_resume)
95
93
SECTION_FUNC(TEXT , arch_pm_s2ram_resume)
96
94
/ *
97
- * Check if the marker is set
95
+ * Check if reset occurred after suspending to RAM.
98
96
* /
99
- ldr r0 , =marker
100
- ldr r0 , [ r0 ]
101
- ldr r1 , =MAGIC
102
- cmp r0 , r1
97
+ push {lr}
98
+ bl pm_s2ram_mark_check_and_clear
99
+ cmp r0 , # 0x1
100
+ pop {lr}
103
101
beq resume
104
102
bx lr
105
103
106
104
resume:
107
- / *
108
- * Reset the marker
109
- * /
110
- ldr r0 , =marker
111
- mov r1 , # 0x0
112
- str r1 , [ r0 ]
113
-
114
105
/ *
115
106
* Restore the CPU context
116
107
* /
Original file line number Diff line number Diff line change 9
9
10
10
#include <zephyr/arch/common/pm_s2ram.h>
11
11
12
+ #define MAGIC (0xDABBAD00)
13
+
12
14
/**
13
15
* CPU context for S2RAM
14
16
*/
15
17
__noinit _cpu_context_t _cpu_context ;
16
18
19
+ #ifndef CONFIG_PM_S2RAM_CUSTOM_MARKING
17
20
/**
18
21
* S2RAM Marker
19
22
*/
20
- __noinit uint32_t marker ;
23
+ static __noinit uint32_t marker ;
24
+
25
+ void pm_s2ram_mark_set (void )
26
+ {
27
+ marker = MAGIC ;
28
+ }
29
+
30
+ bool pm_s2ram_mark_check_and_clear (void )
31
+ {
32
+ if (marker == MAGIC ) {
33
+ marker = 0 ;
34
+
35
+ return true;
36
+ }
37
+
38
+ return false;
39
+ }
40
+
41
+ #endif /* CONFIG_PM_S2RAM_CUSTOM_MARKING */
Original file line number Diff line number Diff line change 7
7
*
8
8
* @brief public S2RAM APIs.
9
9
* @defgroup pm_s2ram S2RAM APIs
10
- * @ingroup subsys_pm
11
10
* @{
12
11
*/
13
12
@@ -57,6 +56,30 @@ typedef int (*pm_s2ram_system_off_fn_t)(void);
57
56
*/
58
57
int arch_pm_s2ram_suspend (pm_s2ram_system_off_fn_t system_off );
59
58
59
+ /**
60
+ * @brief Mark that core is entering suspend-to-RAM state.
61
+ *
62
+ * Function is called when system state is stored to RAM, just before going to system
63
+ * off.
64
+ *
65
+ * Default implementation is setting a magic word in RAM. CONFIG_PM_S2RAM_CUSTOM_MARKING
66
+ * allows custom implementation.
67
+ */
68
+ void pm_s2ram_mark_set (void );
69
+
70
+ /**
71
+ * @brief Check suspend-to-RAM marking and clear its state.
72
+ *
73
+ * Function is used to determine if resuming after suspend-to-RAM shall be performed
74
+ * or standard boot code shall be executed.
75
+ *
76
+ * Default implementation is checking a magic word in RAM. CONFIG_PM_S2RAM_CUSTOM_MARKING
77
+ * allows custom implementation.
78
+ *
79
+ * @retval true if marking is found which indicates resuming after suspend-to-RAM.
80
+ * @retval false if marking is not found which indicates standard boot.
81
+ */
82
+ bool pm_s2ram_mark_check_and_clear (void );
60
83
/**
61
84
* @}
62
85
*/
Original file line number Diff line number Diff line change @@ -37,6 +37,13 @@ config PM_S2RAM
37
37
help
38
38
This option enables suspend-to-RAM (S2RAM).
39
39
40
+ config PM_S2RAM_CUSTOM_MARKING
41
+ bool "Use custom marking functions"
42
+ depends on PM_S2RAM
43
+ help
44
+ By default a magic word in RAM is used to mark entering suspend-to-RAM. Enabling
45
+ this option allows custom implementation of functions which handles the marking.
46
+
40
47
config PM_NEED_ALL_DEVICES_IDLE
41
48
bool "System Low Power Mode Needs All Devices Idle"
42
49
depends on PM_DEVICE && !SMP
You can’t perform that action at this time.
0 commit comments