File tree Expand file tree Collapse file tree 10 files changed +166
-1
lines changed Expand file tree Collapse file tree 10 files changed +166
-1
lines changed Original file line number Diff line number Diff line change 25
25
#include "nu_modutil.h"
26
26
#include "nu_bitutil.h"
27
27
#include <string.h>
28
+ #include <stdbool.h>
28
29
29
30
#if DEVICE_SERIAL_ASYNCH
30
31
#include "dma_api.h"
@@ -87,6 +88,8 @@ static void serial_check_dma_usage(DMAUsage *dma_usage, int *dma_ch);
87
88
static int serial_is_irq_en (serial_t * obj , SerialIrq irq );
88
89
#endif
89
90
91
+ bool serial_can_deep_sleep (void );
92
+
90
93
static struct nu_uart_var uart0_var = {
91
94
.ref_cnt = 0 ,
92
95
.obj = NULL ,
@@ -1171,4 +1174,23 @@ static int serial_is_irq_en(serial_t *obj, SerialIrq irq)
1171
1174
}
1172
1175
1173
1176
#endif // #if DEVICE_SERIAL_ASYNCH
1177
+
1178
+ bool serial_can_deep_sleep (void )
1179
+ {
1180
+ bool sleep_allowed = 1 ;
1181
+ const struct nu_modinit_s * modinit = uart_modinit_tab ;
1182
+ while (modinit -> var != NULL ) {
1183
+ struct nu_uart_var * uart_var = (struct nu_uart_var * ) modinit -> var ;
1184
+ UART_T * uart_base = (UART_T * ) NU_MODBASE (modinit -> modname );
1185
+ if (uart_var -> ref_cnt > 0 ) {
1186
+ if (!UART_IS_TX_EMPTY (uart_base )) {
1187
+ sleep_allowed = 0 ;
1188
+ break ;
1189
+ }
1190
+ }
1191
+ modinit ++ ;
1192
+ }
1193
+ return sleep_allowed ;
1194
+ }
1195
+
1174
1196
#endif // #if DEVICE_SERIAL
Original file line number Diff line number Diff line change 22
22
#include "device.h"
23
23
#include "objects.h"
24
24
#include "PeripheralPins.h"
25
+ #include <stdbool.h>
25
26
26
27
#if defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3U )
27
28
29
+ #if DEVICE_SERIAL
30
+ bool serial_can_deep_sleep (void );
31
+ #endif
32
+
28
33
/**
29
34
* Enter idle mode, in which just CPU is halted.
30
35
*/
@@ -42,6 +47,12 @@ void hal_sleep(void)
42
47
__NONSECURE_ENTRY
43
48
void hal_deepsleep (void )
44
49
{
50
+ #if DEVICE_SERIAL
51
+ if (!serial_can_deep_sleep ()) {
52
+ return ;
53
+ }
54
+ #endif
55
+
45
56
SYS_UnlockReg ();
46
57
CLK_PowerDown ();
47
58
SYS_LockReg ();
Original file line number Diff line number Diff line change 25
25
#include "nu_modutil.h"
26
26
#include "nu_bitutil.h"
27
27
#include <string.h>
28
+ #include <stdbool.h>
28
29
29
30
#if DEVICE_SERIAL_ASYNCH
30
31
#include "dma_api.h"
@@ -83,6 +84,8 @@ static void serial_check_dma_usage(DMAUsage *dma_usage, int *dma_ch);
83
84
static int serial_is_irq_en (serial_t * obj , SerialIrq irq );
84
85
#endif
85
86
87
+ bool serial_can_deep_sleep (void );
88
+
86
89
static struct nu_uart_var uart0_var = {
87
90
.ref_cnt = 0 ,
88
91
.obj = NULL ,
@@ -1088,4 +1091,23 @@ static int serial_is_irq_en(serial_t *obj, SerialIrq irq)
1088
1091
}
1089
1092
1090
1093
#endif // #if DEVICE_SERIAL_ASYNCH
1094
+
1095
+ bool serial_can_deep_sleep (void )
1096
+ {
1097
+ bool sleep_allowed = 1 ;
1098
+ const struct nu_modinit_s * modinit = uart_modinit_tab ;
1099
+ while (modinit -> var != NULL ) {
1100
+ struct nu_uart_var * uart_var = (struct nu_uart_var * ) modinit -> var ;
1101
+ UART_T * uart_base = (UART_T * ) NU_MODBASE (modinit -> modname );
1102
+ if (uart_var -> ref_cnt > 0 ) {
1103
+ if (!UART_IS_TX_EMPTY (uart_base )) {
1104
+ sleep_allowed = 0 ;
1105
+ break ;
1106
+ }
1107
+ }
1108
+ modinit ++ ;
1109
+ }
1110
+ return sleep_allowed ;
1111
+ }
1112
+
1091
1113
#endif // #if DEVICE_SERIAL
Original file line number Diff line number Diff line change 22
22
#include "device.h"
23
23
#include "objects.h"
24
24
#include "PeripheralPins.h"
25
+ #include <stdbool.h>
26
+
27
+ #if DEVICE_SERIAL
28
+ bool serial_can_deep_sleep (void );
29
+ #endif
25
30
26
31
/**
27
32
* Enter idle mode, in which just CPU is halted.
@@ -38,6 +43,12 @@ void hal_sleep(void)
38
43
*/
39
44
void hal_deepsleep (void )
40
45
{
46
+ #if DEVICE_SERIAL
47
+ if (!serial_can_deep_sleep ()) {
48
+ return ;
49
+ }
50
+ #endif
51
+
41
52
SYS_UnlockReg ();
42
53
CLK_PowerDown ();
43
54
SYS_LockReg ();
Original file line number Diff line number Diff line change 25
25
#include "nu_modutil.h"
26
26
#include "nu_bitutil.h"
27
27
#include <string.h>
28
+ #include <stdbool.h>
28
29
29
30
#if DEVICE_SERIAL_ASYNCH
30
31
#include "dma_api.h"
@@ -87,6 +88,8 @@ static void serial_check_dma_usage(DMAUsage *dma_usage, int *dma_ch);
87
88
static int serial_is_irq_en (serial_t * obj , SerialIrq irq );
88
89
#endif
89
90
91
+ bool serial_can_deep_sleep (void );
92
+
90
93
static struct nu_uart_var uart0_var = {
91
94
.ref_cnt = 0 ,
92
95
.obj = NULL ,
@@ -1145,4 +1148,23 @@ static int serial_is_irq_en(serial_t *obj, SerialIrq irq)
1145
1148
}
1146
1149
1147
1150
#endif // #if DEVICE_SERIAL_ASYNCH
1151
+
1152
+ bool serial_can_deep_sleep (void )
1153
+ {
1154
+ bool sleep_allowed = 1 ;
1155
+ const struct nu_modinit_s * modinit = uart_modinit_tab ;
1156
+ while (modinit -> var != NULL ) {
1157
+ struct nu_uart_var * uart_var = (struct nu_uart_var * ) modinit -> var ;
1158
+ UART_T * uart_base = (UART_T * ) NU_MODBASE (modinit -> modname );
1159
+ if (uart_var -> ref_cnt > 0 ) {
1160
+ if (!UART_IS_TX_EMPTY (uart_base )) {
1161
+ sleep_allowed = 0 ;
1162
+ break ;
1163
+ }
1164
+ }
1165
+ modinit ++ ;
1166
+ }
1167
+ return sleep_allowed ;
1168
+ }
1169
+
1148
1170
#endif // #if DEVICE_SERIAL
Original file line number Diff line number Diff line change 22
22
#include "device.h"
23
23
#include "objects.h"
24
24
#include "PeripheralPins.h"
25
+ #include <stdbool.h>
26
+
27
+ #if DEVICE_SERIAL
28
+ bool serial_can_deep_sleep (void );
29
+ #endif
25
30
26
31
/**
27
32
* Enter idle mode, in which just CPU is halted.
@@ -38,6 +43,12 @@ void hal_sleep(void)
38
43
*/
39
44
void hal_deepsleep (void )
40
45
{
46
+ #if DEVICE_SERIAL
47
+ if (!serial_can_deep_sleep ()) {
48
+ return ;
49
+ }
50
+ #endif
51
+
41
52
SYS_UnlockReg ();
42
53
CLK_PowerDown ();
43
54
SYS_LockReg ();
Original file line number Diff line number Diff line change 18
18
19
19
#if DEVICE_SERIAL
20
20
21
- #include <string.h>
22
21
#include "cmsis.h"
23
22
#include "mbed_error.h"
24
23
#include "mbed_assert.h"
25
24
#include "PeripheralPins.h"
26
25
#include "nu_modutil.h"
27
26
#include "nu_bitutil.h"
27
+ #include <string.h>
28
+ #include <stdbool.h>
28
29
29
30
#if DEVICE_SERIAL_ASYNCH
30
31
#include "dma_api.h"
@@ -76,6 +77,8 @@ static void serial_check_dma_usage(DMAUsage *dma_usage, int *dma_ch);
76
77
static int serial_is_irq_en (serial_t * obj , SerialIrq irq );
77
78
#endif
78
79
80
+ bool serial_can_deep_sleep (void );
81
+
79
82
static struct nu_uart_var uart0_var = {
80
83
.ref_cnt = 0 ,
81
84
.obj = NULL ,
@@ -990,4 +993,23 @@ static int serial_is_irq_en(serial_t *obj, SerialIrq irq)
990
993
}
991
994
992
995
#endif // #if DEVICE_SERIAL_ASYNCH
996
+
997
+ bool serial_can_deep_sleep (void )
998
+ {
999
+ bool sleep_allowed = 1 ;
1000
+ const struct nu_modinit_s * modinit = uart_modinit_tab ;
1001
+ while (modinit -> var != NULL ) {
1002
+ struct nu_uart_var * uart_var = (struct nu_uart_var * ) modinit -> var ;
1003
+ UART_T * uart_base = (UART_T * ) NU_MODBASE (modinit -> modname );
1004
+ if (uart_var -> ref_cnt > 0 ) {
1005
+ if (!UART_IS_TX_EMPTY (uart_base )) {
1006
+ sleep_allowed = 0 ;
1007
+ break ;
1008
+ }
1009
+ }
1010
+ modinit ++ ;
1011
+ }
1012
+ return sleep_allowed ;
1013
+ }
1014
+
993
1015
#endif // #if DEVICE_SERIAL
Original file line number Diff line number Diff line change 22
22
#include "device.h"
23
23
#include "objects.h"
24
24
#include "PeripheralPins.h"
25
+ #include <stdbool.h>
26
+
27
+ #if DEVICE_SERIAL
28
+ bool serial_can_deep_sleep (void );
29
+ #endif
25
30
26
31
/**
27
32
* Enter idle mode, in which just CPU is halted.
@@ -38,6 +43,12 @@ void hal_sleep(void)
38
43
*/
39
44
void hal_deepsleep (void )
40
45
{
46
+ #if DEVICE_SERIAL
47
+ if (!serial_can_deep_sleep ()) {
48
+ return ;
49
+ }
50
+ #endif
51
+
41
52
SYS_UnlockReg ();
42
53
CLK_PowerDown ();
43
54
SYS_LockReg ();
Original file line number Diff line number Diff line change 25
25
#include "nu_modutil.h"
26
26
#include "nu_bitutil.h"
27
27
#include <string.h>
28
+ #include <stdbool.h>
28
29
29
30
#if DEVICE_SERIAL_ASYNCH
30
31
#include "dma_api.h"
@@ -87,6 +88,8 @@ static void serial_check_dma_usage(DMAUsage *dma_usage, int *dma_ch);
87
88
static int serial_is_irq_en (serial_t * obj , SerialIrq irq );
88
89
#endif
89
90
91
+ bool serial_can_deep_sleep (void );
92
+
90
93
static struct nu_uart_var uart0_var = {
91
94
.ref_cnt = 0 ,
92
95
.obj = NULL ,
@@ -1136,4 +1139,23 @@ static int serial_is_irq_en(serial_t *obj, SerialIrq irq)
1136
1139
}
1137
1140
1138
1141
#endif // #if DEVICE_SERIAL_ASYNCH
1142
+
1143
+ bool serial_can_deep_sleep (void )
1144
+ {
1145
+ bool sleep_allowed = 1 ;
1146
+ const struct nu_modinit_s * modinit = uart_modinit_tab ;
1147
+ while (modinit -> var != NULL ) {
1148
+ struct nu_uart_var * uart_var = (struct nu_uart_var * ) modinit -> var ;
1149
+ UART_T * uart_base = (UART_T * ) NU_MODBASE (modinit -> modname );
1150
+ if (uart_var -> ref_cnt > 0 ) {
1151
+ if (!UART_IS_TX_EMPTY (uart_base )) {
1152
+ sleep_allowed = 0 ;
1153
+ break ;
1154
+ }
1155
+ }
1156
+ modinit ++ ;
1157
+ }
1158
+ return sleep_allowed ;
1159
+ }
1160
+
1139
1161
#endif // #if DEVICE_SERIAL
Original file line number Diff line number Diff line change 22
22
#include "device.h"
23
23
#include "objects.h"
24
24
#include "PeripheralPins.h"
25
+ #include <stdbool.h>
26
+
27
+ #if DEVICE_SERIAL
28
+ bool serial_can_deep_sleep (void );
29
+ #endif
25
30
26
31
/**
27
32
* Enter idle mode, in which just CPU is halted.
@@ -38,6 +43,12 @@ void hal_sleep(void)
38
43
*/
39
44
void hal_deepsleep (void )
40
45
{
46
+ #if DEVICE_SERIAL
47
+ if (!serial_can_deep_sleep ()) {
48
+ return ;
49
+ }
50
+ #endif
51
+
41
52
SYS_UnlockReg ();
42
53
CLK_PowerDown ();
43
54
SYS_LockReg ();
You can’t perform that action at this time.
0 commit comments